Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
100.00% |
1 / 1 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
21 / 21 |
| ShippingMethodCollectionTransformer | |
100.00% |
1 / 1 |
|
100.00% |
4 / 4 |
7 | |
100.00% |
21 / 21 |
| __construct( SingleShippingMethodTransformer $singleShippingMethodTransformer ) | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
| transform( OrderInterface $order, ExtractorResult $extractorResult ) | |
100.00% |
1 / 1 |
2 | |
100.00% |
11 / 11 |
|||
| supports($propertyName) | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| checkCollection($collection) | |
100.00% |
1 / 1 |
3 | |
100.00% |
7 / 7 |
|||
| <?php | |
| /** | |
| * @author Krzysztof Gzocha <krzysztof.gzocha@xsolve.pl> | |
| */ | |
| namespace Team3\PayU\Order\Transformer\UserOrder\Strategy\ShippingMethod; | |
| use Team3\PayU\Order\Model\OrderInterface; | |
| use Team3\PayU\Order\Transformer\UserOrder\TransformerProperties; | |
| use Team3\PayU\PropertyExtractor\ExtractorException; | |
| use Team3\PayU\PropertyExtractor\ExtractorResult; | |
| use Team3\PayU\Order\Transformer\UserOrder\Strategy\UserOrderTransformerStrategyInterface; | |
| class ShippingMethodCollectionTransformer implements UserOrderTransformerStrategyInterface | |
| { | |
| /** | |
| * @var SingleShippingMethodTransformer | |
| */ | |
| private $singleShippingMethodTransformer; | |
| /** | |
| * @param SingleShippingMethodTransformer $singleShippingMethodTransformer | |
| */ | |
| public function __construct( | |
| SingleShippingMethodTransformer $singleShippingMethodTransformer | |
| ) { | |
| $this->singleShippingMethodTransformer = $singleShippingMethodTransformer; | |
| } | |
| /** | |
| * @inheritdoc | |
| */ | |
| public function transform( | |
| OrderInterface $order, | |
| ExtractorResult $extractorResult | |
| ) { | |
| /** @var \Traversable $shippingMethodCollection */ | |
| $shippingMethodCollection = $extractorResult->getValue(); | |
| $this->checkCollection($shippingMethodCollection); | |
| foreach ($shippingMethodCollection as $usersShippingMethod) { | |
| $order | |
| ->getShippingMethodCollection() | |
| ->addShippingMethod( | |
| $this | |
| ->singleShippingMethodTransformer | |
| ->transform( | |
| $usersShippingMethod | |
| ) | |
| ); | |
| } | |
| } | |
| /** | |
| * @inheritdoc | |
| */ | |
| public function supports($propertyName) | |
| { | |
| return TransformerProperties::SHIPPING_METHOD_COLLECTION === $propertyName; | |
| } | |
| /** | |
| * @param mixed $collection | |
| * | |
| * @throws ExtractorException | |
| */ | |
| protected function checkCollection($collection) | |
| { | |
| if (!is_array($collection) | |
| && !$collection instanceof \Traversable) { | |
| throw new ExtractorException(sprintf( | |
| 'Array or object which implements Traversable was expected, but %s was given', | |
| gettype($collection) | |
| )); | |
| } | |
| } | |
| } |