Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
100.00% |
1 / 1 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
25 / 25 |
SingleShippingMethodTransformer | |
100.00% |
1 / 1 |
|
100.00% |
4 / 4 |
9 | |
100.00% |
25 / 25 |
__construct( ExtractorInterface $extractor ) | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
transform($usersShippingMethod) | |
100.00% |
1 / 1 |
3 | |
100.00% |
7 / 7 |
|||
supports($propertyName) | |
100.00% |
1 / 1 |
1 | |
100.00% |
3 / 3 |
|||
copyValue( ShippingMethodInterface $shippingMethod, ExtractorResult $extractorResult ) | |
100.00% |
1 / 1 |
4 | |
100.00% |
13 / 13 |
<?php | |
/** | |
* @author Krzysztof Gzocha <krzysztof.gzocha@xsolve.pl> | |
*/ | |
namespace Team3\PayU\Order\Transformer\UserOrder\Strategy\ShippingMethod; | |
use Team3\PayU\Order\Model\ShippingMethods\ShippingMethod; | |
use Team3\PayU\Order\Model\ShippingMethods\ShippingMethodInterface; | |
use Team3\PayU\Order\Transformer\UserOrder\TransformerProperties; | |
use Team3\PayU\Order\Transformer\UserOrder\TransformerPropertiesRegExp; | |
use Team3\PayU\PropertyExtractor\ExtractorInterface; | |
use Team3\PayU\PropertyExtractor\ExtractorResult; | |
class SingleShippingMethodTransformer | |
{ | |
/** | |
* @var ExtractorInterface | |
*/ | |
private $extractor; | |
/** | |
* @param ExtractorInterface $extractor | |
*/ | |
public function __construct( | |
ExtractorInterface $extractor | |
) { | |
$this->extractor = $extractor; | |
} | |
/** | |
* @param mixed $usersShippingMethod | |
* | |
* @return ShippingMethod | |
*/ | |
public function transform($usersShippingMethod) | |
{ | |
$shippingMethod = new ShippingMethod(); | |
foreach ($this->extractor->extract($usersShippingMethod) as $extractedResult) { | |
if ($this->supports($extractedResult->getPropertyName())) { | |
$this->copyValue($shippingMethod, $extractedResult); | |
} | |
} | |
return $shippingMethod; | |
} | |
/** | |
* @param string $propertyName | |
* | |
* @return bool | |
*/ | |
protected function supports($propertyName) | |
{ | |
return 1 === preg_match( | |
TransformerPropertiesRegExp::SHIPPING_METHOD_REGEXP, | |
$propertyName | |
); | |
} | |
/** | |
* @param ShippingMethodInterface $shippingMethod | |
* @param ExtractorResult $extractorResult | |
*/ | |
protected function copyValue( | |
ShippingMethodInterface $shippingMethod, | |
ExtractorResult $extractorResult | |
) { | |
switch ($extractorResult->getPropertyName()) { | |
case TransformerProperties::SHIPPING_METHOD_NAME: | |
$shippingMethod->setName($extractorResult->getValue()); | |
break; | |
case TransformerProperties::SHIPPING_METHOD_PRICE: | |
$shippingMethod->setPrice($extractorResult->getValue()); | |
break; | |
case TransformerProperties::SHIPPING_METHOD_COUNTRY: | |
$shippingMethod->setCountry($extractorResult->getValue()); | |
break; | |
default: | |
} | |
} | |
} |