This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @return array | |
*/ | |
function basketToViewModel(Basket $basket): array | |
{ | |
$items = \array_map(function (BasketItem $item): array { | |
return [ | |
'id' => $item->getProductId(), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class UserRepository | |
{ | |
public function getUsers(): array | |
{ | |
} | |
public function getUsersIncludingDeleted(): array | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class UserRepository | |
{ | |
public function getUsers(?bool $includingDeleted = false): array | |
{ | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ($isSuccess && $user->isActive() && $httpApi->hasAccess($user)) { | |
// if $isSuccess is false | |
// other conditions will not be evaluated | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ($httpApi->hasAccess($user) && $user->isActive() && $isSuccess) { | |
// all conditions must be met in order for this condition to execute | |
// in case of 'and' we should keep the heaviest conditions last | |
// and the fastest to execute in front | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getTotalWithTax(Payment $payment, int $taxPercent): float | |
{ | |
// descriptive variables with intermediary values for easier debugging | |
$paymentAmount = (int) $payment->getAmount(); | |
$taxCoefficient = 1 + ($taxPercent / 100); | |
$totalWithTax = $paymentAmount * $taxCoefficient; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getTotalWithTax(Payment $payment, int $taxPercent): float | |
{ | |
// is the order correct at all? | |
return (float) (int) $payment->getTotal() * (1 + $taxPercent / 100); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function mapOrderStatusToLabel(Order $order): string | |
{ | |
switch ($order->getStatus()) { | |
case 'complete': | |
return 'Completed'; | |
case 'pending': | |
case 'in_transport': |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function mapOrderStatusToLabel(Order $order): string | |
{ | |
$label = 'unknown'; | |
if ('complete' === $order->getStatus()) { | |
$label = 'Completed'; | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function mapOrderStatusToLabel(Order $order): string | |
{ | |
if ($order->isComplete()) { | |
return 'Completed'; | |
} | |
if ($order->isPending()) { | |
return 'In transport'; |