Last active
July 9, 2020 05:09
-
-
Save DarkGhostHunter/1aba442f489bbfb243ab6d765cf2202e to your computer and use it in GitHub Desktop.
Container example
This file contains 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 ExampleController | |
{ | |
/** | |
* The new way | |
* | |
* @param Transport $transport | |
* @param Package $package | |
* @param Weather $weather | |
* @return PendingDelivery | |
*/ | |
public function theNewWay(Transport $transport, Package $package, Weather $weather) | |
{ | |
return $transport->when($package->isBig())->useVan() | |
->when($package->isFragile())->handleWithCaution() | |
->when($weather->isDangerous())->notifyPossibleDelay() | |
->deliver(); | |
} | |
/** | |
* The old way | |
* | |
* @param Transport $transport | |
* @param Package $package | |
* @param Weather $weather | |
* @return PendingDelivery | |
*/ | |
public function theOldWay(Transport $transport, Package $package, Weather $weather) | |
{ | |
if ($package->isBig()) { | |
$transport->useVan(); | |
} | |
if ($package->isFragile()) { | |
$transport->handleWithCaution(); | |
} | |
if ($weather->isDangerous()) { | |
$transport->notifyPossibleDelay(); | |
} | |
return $transport->deliver(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment