Passed
Push — karoly/akeneo-skeleton ( dfb631 )
by Karoly
05:38
created

AbstractSyncer::sync()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 24
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 13
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 24
rs 9.8333
1
<?php
2
3
namespace Spryker\Zed\AkeneoPim\Business\Syncer;
4
5
use Generated\Shared\Transfer\AkeneoSyncResultTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\AkeneoSyncResultTransfer 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...
6
use Generated\Shared\Transfer\AkeneoSyncValidateResultTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...cValidateResultTransfer 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...
7
use Generated\Shared\Transfer\AkeneoSyncWriteResultTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...SyncWriteResultTransfer 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...
8
use Spryker\Shared\Kernel\Transfer\AbstractTransfer;
9
10
abstract class AbstractSyncer
11
{
12
    protected $resultHandler;
13
14
    /**
15
     * @param AbstractTransfer $syncConfig
16
     *
17
     * @return AkeneoSyncResultTransfer
18
     */
19
    public final function sync($syncConfig): AkeneoSyncResultTransfer
20
    {
21
        $akeneoEntities = $this->read($syncConfig);
22
23
        foreach($akeneoEntities as $akeneoEntity) {
24
            $validationResult = $this->validate($akeneoEntity, $syncConfig);
25
            if ($validationResult->getIsSuccess() === false) {
26
                $this->resultHandler->addError($akeneoEntity, $validationResult, $syncConfig);
27
28
                if ($validationResult->getIsTerminate() === true) {
29
                    break;
30
                }
31
32
                continue;
33
            }
34
35
            $akeneoEntity = $this->translate($akeneoEntity, $syncConfig);
36
            $sprykerEntity = $this->map($akeneoEntity, $syncConfig);
37
            $this->write($sprykerEntity, $syncConfig);
38
39
            $this->resultHandler->addSuccess($sprykerEntity, $akeneoEntity, $syncConfig);
40
        }
41
42
        return $this->resultHandler->getResults();
43
    }
44
45
    /**
46
     * Read all "to be processed" akeneo entities
47
     *
48
     * @param AbstractTransfer $syncConfig
49
     *
50
     * @return array
51
     */
52
    protected abstract function read($syncConfig): array;
53
54
    /**
55
     * Validates if the data is eligable for processing for workflow requirements
56
     *
57
     * @param array $akeneoEntity
58
     * @param AbstractTransfer $syncConfig
59
     *
60
     * @return AkeneoSyncValidateResultTransfer
61
     */
62
    protected abstract function validate(array $akeneoEntity, $syncConfig): AkeneoSyncValidateResultTransfer;
63
64
    /**
65
     * Translates Akeneo values into Spryker values (eg: akeneo stores prices in float major currency units, and spryker stores int minor currency units)
66
     *
67
     * @param array $akeneoEntity
68
     * @param AbstractTransfer $syncConfig
69
     *
70
     * @return array
71
     */
72
    protected abstract function translate(array $akeneoEntity, $syncConfig): array;
73
74
    /**
75
     * Maps the Akeneo entity with already translated values into Spryker entity.
76
     *
77
     * @param array $akeneoEntity
78
     * @param AbstractTransfer $syncConfig
79
     *
80
     * @return array
81
     */
82
    protected abstract function map(array $akeneoEntity, $syncConfig): array;
83
84
    /**
85
     * @param array $sprykerEntity
86
     * @param AbstractTransfer $syncConfig
87
     *
88
     * @return AkeneoSyncWriteResultTransfer
89
     */
90
    protected abstract function write(array $sprykerEntity, $syncConfig): AkeneoSyncWriteResultTransfer;
91
}
92