Passed
Pull Request — master (#1)
by Grebenikov
03:50
created

MinuboRepository   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
dl 0
loc 82
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getCustomerDataUpdatedSinceLastRun() 0 19 2
A getLastMinuboRunTime() 0 12 2
B getOrderDataUpdatedSinceLastRun() 0 34 2
1
<?php
2
3
/**
4
 * MIT License
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Zed\Minubo\Persistence;
9
10
use Orm\Zed\Customer\Persistence\Map\SpyCustomerAddressTableMap;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Customer\Persist...CustomerAddressTableMap 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...
11
use Orm\Zed\Customer\Persistence\Map\SpyCustomerTableMap;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Customer\Persist...Map\SpyCustomerTableMap 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 Orm\Zed\Oms\Persistence\Map\SpyOmsOrderProcessTableMap;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Oms\Persistence\...OmsOrderProcessTableMap 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\Oms\Persistence\Map\SpyOmsTransitionLogTableMap;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Oms\Persistence\...msTransitionLogTableMap 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 Orm\Zed\ProductBundle\Persistence\Map\SpySalesOrderItemBundleTableMap;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\ProductBundle\Pe...OrderItemBundleTableMap 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...
15
use Orm\Zed\Sales\Persistence\Map\SpySalesOrderAddressTableMap;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Sales\Persistenc...lesOrderAddressTableMap 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...
16
use Orm\Zed\Sales\Persistence\Map\SpySalesOrderItemTableMap;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Sales\Persistenc...ySalesOrderItemTableMap 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...
17
use Orm\Zed\Sales\Persistence\Map\SpySalesOrderTableMap;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Sales\Persistenc...p\SpySalesOrderTableMap 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...
18
use Orm\Zed\Sales\Persistence\Map\SpySalesOrderTotalsTableMap;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Sales\Persistenc...alesOrderTotalsTableMap 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...
19
use Orm\Zed\Sales\Persistence\Map\SpySalesShipmentTableMap;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Sales\Persistenc...pySalesShipmentTableMap 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...
20
use Propel\Runtime\ActiveQuery\Criteria;
21
use Propel\Runtime\Formatter\ArrayFormatter;
22
use Spryker\Zed\Kernel\Persistence\AbstractRepository;
23
24
/**
25
 * @method \SprykerEco\Zed\Minubo\Persistence\MinuboPersistenceFactory getFactory()
26
 */
27
class MinuboRepository extends AbstractRepository implements MinuboRepositoryInterface
28
{
29
    const LAST_RUN_DATETIME_FORMAT = 'Y-m-d H:i:s.u';
30
31
    /**
32
     * @return null|string
33
     */
34
    public function getLastMinuboRunTime(): ?string
35
    {
36
        $lastRun = $this->getFactory()
37
            ->createMinuboRunQuery()
38
            ->orderByRanAt(Criteria::DESC)
39
            ->findOne();
40
41
        if ($lastRun) {
42
            return $lastRun->getRanAt(static::LAST_RUN_DATETIME_FORMAT);
43
        }
44
45
        return null;
46
    }
47
48
    /**
49
     * @return array
50
     */
51
    public function getOrderDataUpdatedSinceLastRun(): array
52
    {
53
        $lastRunTime = $this->getLastMinuboRunTime();
54
55
        $query = $this->getFactory()
56
            ->getSalesOrderQuery()
57
            ->leftJoinWithOrderTotal()
58
            ->leftJoinWithLocale()
59
            ->leftJoinWithSpySalesShipment()
60
            ->leftJoinWithItem()
61
            ->useItemQuery()
62
                ->leftJoinWithSalesOrderItemBundle()
63
                ->leftJoinWithProcess()
64
                ->leftJoinWithState()
65
                ->leftJoinWithTransitionLog()
66
            ->endUse()
67
            ->leftJoinBillingAddress('BillingAddress')
68
            ->with('BillingAddress')
69
            ->leftJoinShippingAddress('ShippingAddress')
70
            ->with('ShippingAddress')
71
            ->setFormatter(ArrayFormatter::class);
72
73
        if ($lastRunTime) {
74
            $query->addAnd(SpySalesOrderTableMap::COL_UPDATED_AT, $lastRunTime, Criteria::GREATER_EQUAL)
75
                ->addOr(SpySalesOrderTotalsTableMap::COL_UPDATED_AT, $lastRunTime, Criteria::GREATER_EQUAL)
76
                ->addOr(SpySalesOrderItemTableMap::COL_UPDATED_AT, $lastRunTime, Criteria::GREATER_EQUAL)
77
                ->addOr(SpySalesOrderAddressTableMap::COL_UPDATED_AT, $lastRunTime, Criteria::GREATER_EQUAL)
78
                ->addOr(SpySalesOrderItemBundleTableMap::COL_UPDATED_AT, $lastRunTime, Criteria::GREATER_EQUAL)
79
                ->addOr(SpyOmsOrderProcessTableMap::COL_UPDATED_AT, $lastRunTime, Criteria::GREATER_EQUAL)
80
                ->addOr(SpySalesShipmentTableMap::COL_UPDATED_AT, $lastRunTime, Criteria::GREATER_EQUAL)
81
                ->addOr(SpyOmsTransitionLogTableMap::COL_CREATED_AT, $lastRunTime, Criteria::GREATER_EQUAL);
82
        }
83
84
        return $query->find()->toArray();
85
    }
86
87
    /**
88
     * @return array
89
     */
90
    public function getCustomerDataUpdatedSinceLastRun(): array
91
    {
92
        $lastRunTime = $this->getLastMinuboRunTime();
93
94
        $query = $this->getFactory()
95
            ->getCustomerQuery()
96
            ->leftJoinWithLocale()
97
            ->leftJoinWithAddress()
98
            ->useAddressQuery(null, Criteria::LEFT_JOIN)
99
                ->leftJoinWithRegion()
100
                ->leftJoinWithCountry()
101
            ->endUse()
102
            ->setFormatter(ArrayFormatter::class);
103
104
        if ($lastRunTime) {
105
            $query->addAnd(SpyCustomerTableMap::COL_UPDATED_AT, $lastRunTime, Criteria::GREATER_EQUAL)
106
                ->addOr(SpyCustomerAddressTableMap::COL_UPDATED_AT, $lastRunTime, Criteria::GREATER_EQUAL);
107
        }
108
        return $query->find()->toArray();
109
    }
110
}
111