Passed
Pull Request — master (#13)
by Oleksandr
20:56 queued 15:27
created

ItemsCapturePlugin   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 9 1
A getItemsForCapturing() 0 13 2
1
<?php
2
3
/**
4
 * MIT License
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
namespace SprykerEco\Zed\Braintree\Communication\Plugin\Oms\Command;
9
10
use ArrayObject;
11
use Generated\Shared\Transfer\ItemTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\ItemTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Generated\Shared\Transfer\TransactionMetaTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\TransactionMetaTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Orm\Zed\Sales\Persistence\SpySalesOrder;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Sales\Persistence\SpySalesOrder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Spryker\Zed\Kernel\Communication\AbstractPlugin;
15
use Spryker\Zed\Oms\Business\Util\ReadOnlyArrayObject;
16
use Spryker\Zed\Oms\Dependency\Plugin\Command\CommandByOrderInterface;
17
18
/**
19
 * @method \SprykerEco\Zed\Braintree\Business\BraintreeFacadeInterface getFacade()
20
 * @method \SprykerEco\Zed\Braintree\Communication\BraintreeCommunicationFactory getFactory()
21
 * @method \SprykerEco\Zed\Braintree\BraintreeConfig getConfig()
22
 * @method \SprykerEco\Zed\Braintree\Persistence\BraintreeQueryContainerInterface getQueryContainer()
23
 */
24
class ItemsCapturePlugin extends AbstractPlugin implements CommandByOrderInterface
25
{
26
    /**
27
     * @api
28
     *
29
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrderItem[] $orderItems
30
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrder $orderEntity
31
     * @param \Spryker\Zed\Oms\Business\Util\ReadOnlyArrayObject $data
32
     *
33
     * @return array
34
     */
35
    public function run(array $orderItems, SpySalesOrder $orderEntity, ReadOnlyArrayObject $data): array
36
    {
37
        $transactionMetaTransfer = new TransactionMetaTransfer();
38
        $transactionMetaTransfer->setIdSalesOrder($orderEntity->getIdSalesOrder());
39
        $transactionMetaTransfer->setItems($this->getItemsForCapturing($orderItems));
40
41
        $this->getFacade()->captureItemsPayment($transactionMetaTransfer);
42
43
        return [];
44
    }
45
46
    /**
47
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrderItem[] $orderItems
48
     *
49
     * @return \ArrayObject
50
     */
51
    protected function getItemsForCapturing(array $orderItems): ArrayObject
52
    {
53
        $itemsForCapturing = [];
54
55
        foreach ($orderItems as $orderItem) {
56
            $itemTransfer = new ItemTransfer();
57
            $itemTransfer->fromArray($orderItem->toArray(), true);
58
            $itemsForCapturing[] = $itemTransfer;
59
        }
60
61
        $itemsForCapturing = new ArrayObject($itemsForCapturing);
62
63
        return $itemsForCapturing;
64
    }
65
}
66