Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
100.00% |
1 / 1 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
23 / 23 |
OrderAutocomplete | |
100.00% |
1 / 1 |
|
100.00% |
4 / 4 |
6 | |
100.00% |
23 / 23 |
__construct(LoggerInterface $logger) | |
100.00% |
1 / 1 |
1 | |
100.00% |
3 / 3 |
|||
autocomplete( OrderInterface $order, ConfigurationInterface $configuration ) | |
100.00% |
1 / 1 |
3 | |
100.00% |
7 / 7 |
|||
addStrategy( AutocompleteStrategyInterface $autocompleteStrategy ) | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
logAutocompletion( OrderInterface $order, AutocompleteStrategyInterface $strategy ) | |
100.00% |
1 / 1 |
1 | |
100.00% |
11 / 11 |
<?php | |
/** | |
* @author Krzysztof Gzocha <krzysztof.gzocha@xsolve.pl> | |
*/ | |
namespace Team3\PayU\Order\Autocomplete; | |
use Psr\Log\LoggerInterface; | |
use Team3\PayU\Configuration\ConfigurationInterface; | |
use Team3\PayU\Order\Autocomplete\Strategy\AutocompleteStrategyInterface; | |
use Team3\PayU\Order\Model\OrderInterface; | |
class OrderAutocomplete implements OrderAutocompleteInterface | |
{ | |
/** | |
* @var AutocompleteStrategyInterface[] | |
*/ | |
private $strategies; | |
/** | |
* @var LoggerInterface | |
*/ | |
private $logger; | |
/** | |
* @param LoggerInterface $logger | |
*/ | |
public function __construct(LoggerInterface $logger) | |
{ | |
$this->strategies = []; | |
$this->logger = $logger; | |
} | |
/** | |
* @param OrderInterface $order | |
* @param ConfigurationInterface $configuration | |
*/ | |
public function autocomplete( | |
OrderInterface $order, | |
ConfigurationInterface $configuration | |
) { | |
foreach ($this->strategies as $strategy) { | |
if ($strategy->supports($order)) { | |
$strategy->autocomplete($order, $configuration); | |
$this->logAutocompletion($order, $strategy); | |
} | |
} | |
} | |
/** | |
* @param AutocompleteStrategyInterface $autocompleteStrategy | |
* | |
* @return $this | |
*/ | |
public function addStrategy( | |
AutocompleteStrategyInterface $autocompleteStrategy | |
) { | |
$this->strategies[] = $autocompleteStrategy; | |
return $this; | |
} | |
/** | |
* @param OrderInterface $order | |
* @param AutocompleteStrategyInterface $strategy | |
*/ | |
private function logAutocompletion( | |
OrderInterface $order, | |
AutocompleteStrategyInterface $strategy | |
) { | |
$this | |
->logger | |
->info( | |
sprintf( | |
'Order with ID %s parameters were autocompleted by %s', | |
$order->getOrderId(), | |
get_class($strategy) | |
), | |
[ | |
'order' => $order, | |
'strategy' => $strategy, | |
] | |
); | |
} | |
} |