Dawid Mazur / @dwdmzr
"Experienced" Backend Developer @ Clearcode
Dawid Mazur / @dwdmzr
Pizza appreciation expert @ Clearcode
software regression a software bug that makes a feature stop functioning as intended after a certain event (for example, a system upgrade, system patching)
Dawid Mazur / @dwdmzr
Cringe artist @ Clearcode
refactoring (n.). A change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its existing behavior.
class OrderProcessor extends AbstractProcessor {
public function __construct()
{
$this->orderList = [];
}
// (MANY MANY LOC)
public function addOrders($orders) : void {
foreach($orders as $order) {
$order->setStatus(Order::STATUS_PROCESSING);
}
$this->orderList = array_merge($this->orderList, $orders);
}
// (MANY MANY LOC)
}
public function addOrders($orders) : void {
foreach($orders as $order) {
$order->setStatus(Order::STATUS_PROCESSING);
}
$this->orderList = array_merge($this->orderList, $orders);
}
public function addOrders($orders) : void {
foreach($orders as $order) {
$order->setStatus(Order::STATUS_PROCESSING);
}
$this->orderList = array_merge($this->orderList, $orders);
}
public function addOrders($orders) : void {
foreach($orders as $order) {
$order->setStatus(Order::STATUS_PROCESSING);
}
$this->orderList = array_merge($this->orderList, $orders);
}
public function addOrders($orders) : void {
foreach($orders as $order) {
$order->setStatus(Order::STATUS_PROCESSING);
}
$this->orderList = array_merge($this->orderList, $orders);
}
public function addOrders($orders) : void {
$orders = $this->filterUniqueAndProcessed($orders);
foreach($orders as $order) {
$order->setStatus(Order::STATUS_PROCESSING);
}
$this->orderList = array_merge($this->orderList, $orders);
}
public function addOrders($orders) : void {
$filter = new ProcessedOrderFilter();
$orders = $filter->filter($orders);
foreach($orders as $order) {
$order->setStatus(Order::STATUS_PROCESSING);
}
$this->orderList = array_merge($this->orderList, $orders);
}
private function addToProcessing(array $orders) {
foreach($orders as $order) {
$order->setStatus(Order::STATUS_PROCESSING);
}
$this->orderList = array_merge($this->orderList, $orders);
}
public function addOrders($orders) : void {
$this->log($orders);
$this->addToProcessing($orders);
}
class LoggedOrderProcessor extends OrderProcessor {
private function log(array $orders) {}
public function addOrders($orders) : void {
$this->log($orders);
parent::addOrders($orders);
}
}
class LoggingProcessorDecorator implements ProcessorInterface {
private $processor;
private function log(array $orders) {}
public function __construct(ProcessorInterface $processor)
{
$this->processor = $processor;
}
public function addOrders($orders) : void {
$this->log($orders);
$this->processor->addOrders($orders);
}
}
$processor = new LoggingProcessorDecorator(OrderProcessor());
public $seekIdPresentInSegment = false;
/**
* @param array $info
*/
private function parseEBML(&$info) {
$this->seekIdPresentInSegment = false;
// http://www.matroska.org/technical/specs/index.html#EBMLBasics
$this->current_offset = $info['avdataoffset'];
while ($this->getEBMLelement($sub_seek_entry, $seek_entry['end'], true)) {
switch ($sub_seek_entry['id']) {
case EBML_ID_SEEKID:
$this->seekIdPresentInSegment = true;
$seek_entry['target_id'] = self::EBML2Int($sub_seek_entry['data']);
$seek_entry['target_name'] = self::EBMLidName($seek_entry['target_id']);
break;
case EBML_ID_SEEKPOSITION:
$seek_entry['target_offset'] = $element_data['offset'] + getid3_lib::BigEndian2Int($sub_seek_entry['data']);
break;
default:
$this->unhandledElement('seekhead.seek', __LINE__, $sub_seek_entry); }
break;
}
use PHPUnit\Framework\TestCase;
class getid3_matroskaTest extends TestCase
{
public function testPushAndPop()
{
$id3 = new getID3();
$id3->openfile('./test/matroska_test_w1_1/test1.mkv');
$sut = new getid3_matroska($id3);
$sut->Analyze();
$this->assertTrue($sut->seekIdPresentInSegment);
}
}
➜ ./vendor/bin/phpunit test
PHPUnit 8.3.5 by Sebastian Bergmann and contributors.
. 1 / 1 (100%)
Time: 137 ms, Memory: 6.00 MB
OK (1 test, 1 assertion)
class OrderProcessor {
public function addOrders(
OrderCollection $orders,
int $capacity = 10) : void {
(...)
}
}
class OrderProcessingScheduler {
public __construct(
OrderProcessor $processor,
OrderCollection $orders,
int $capacity = 10
) {
$this->processor = $processor;
$this->orders = $orders;
$this->capacity = $capacity;
(...)
}
public addOrders() : void {}
}
class OrderProcessor extends OrderProcessorInterface {}
class OrderProcessingScheduler {
public __construct(
OrderProcessorInterface $processor,
OrderCollection $orders,
int $capacity = 10
) {
(...)
}
}
class OrderProcessor {
public function addOrders(OrderCollection $orders, int $capacity = 10) : void {
$scheduler = new OrderProcessingScheduler(
$this,
$orders,
$capacity
);
$scheduler->addOrders();
}
}
Stay safe and healthy out there :)
Questions?
@dwdmzr |
dwdmzr |
dwd.mazur
Check out IT Depends
Code with Coding Dojo Silesia
The slides are at dawidmazur.eu/legacy-code