Passed
Pull Request — master (#1)
by Grebenikov
04:32
created

MinuboRepository   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
dl 0
loc 81
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
A getOrderDataUpdatedSinceLastRun() 0 33 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\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...
16
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...
17
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...
18
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...
19
use Propel\Runtime\ActiveQuery\Criteria;
20
use Propel\Runtime\Formatter\ArrayFormatter;
21
use Spryker\Zed\Kernel\Persistence\AbstractRepository;
22
23
/**
24
 * @method \SprykerEco\Zed\Minubo\Persistence\MinuboPersistenceFactory getFactory()
25
 */
26
class MinuboRepository extends AbstractRepository implements MinuboRepositoryInterface
27
{
28
    const LAST_RUN_DATETIME_FORMAT = 'Y-m-d H:i:s.u';
29
30
    /**
31
     * @return null|string
32
     */
33
    public function getLastMinuboRunTime(): ?string
34
    {
35
        $lastRun = $this->getFactory()
36
            ->createMinuboRunQuery()
37
            ->orderByRanAt(Criteria::DESC)
38
            ->findOne();
39
40
        if ($lastRun) {
41
            return $lastRun->getRanAt(static::LAST_RUN_DATETIME_FORMAT);
42
        }
43
44
        return null;
45
    }
46
47
    /**
48
     * @return array
49
     */
50
    public function getOrderDataUpdatedSinceLastRun(): array
51
    {
52
        $lastRunTime = $this->getLastMinuboRunTime();
53
54
        $query = $this->getFactory()
55
            ->getSalesOrderQuery()
56
            ->leftJoinWithOrderTotal()
57
            ->leftJoinWithLocale()
58
            ->leftJoinWithSpySalesShipment()
59
            ->leftJoinWithItem()
60
            ->useItemQuery(null, Criteria::LEFT_JOIN)
61
                ->leftJoinWithSalesOrderItemBundle()
62
                ->leftJoinWithProcess()
63
                ->leftJoinWithState()
64
                ->leftJoinWithTransitionLog()
65
            ->endUse()
66
            ->leftJoinBillingAddress('BillingAddress')
67
            ->with('BillingAddress')
68
            ->leftJoinShippingAddress('ShippingAddress')
69
            ->with('ShippingAddress')
70
            ->setFormatter(ArrayFormatter::class);
71
72
        if ($lastRunTime) {
73
            $query->addAnd(SpySalesOrderTableMap::COL_UPDATED_AT, $lastRunTime, Criteria::GREATER_EQUAL);
74
            $query->addOr(SpySalesOrderTotalsTableMap::COL_UPDATED_AT, $lastRunTime, Criteria::GREATER_EQUAL);
75
            $query->addOr(SpySalesOrderItemTableMap::COL_UPDATED_AT, $lastRunTime, Criteria::GREATER_EQUAL);
76
            $query->addOr(SpySalesOrderItemBundleTableMap::COL_UPDATED_AT, $lastRunTime, Criteria::GREATER_EQUAL);
77
            $query->addOr(SpyOmsOrderProcessTableMap::COL_UPDATED_AT, $lastRunTime, Criteria::GREATER_EQUAL);
78
            $query->addOr(SpySalesShipmentTableMap::COL_UPDATED_AT, $lastRunTime, Criteria::GREATER_EQUAL);
79
            $query->addOr(SpyOmsTransitionLogTableMap::COL_CREATED_AT, $lastRunTime, Criteria::GREATER_EQUAL);
80
        }
81
82
        return $query->find()->toArray();
83
    }
84
85
    /**
86
     * @return array
87
     */
88
    public function getCustomerDataUpdatedSinceLastRun(): array
89
    {
90
        $lastRunTime = $this->getLastMinuboRunTime();
91
92
        $query = $this->getFactory()
93
            ->getCustomerQuery()
94
            ->leftJoinWithLocale()
95
            ->leftJoinWithAddress()
96
            ->useAddressQuery(null, Criteria::LEFT_JOIN)
97
                ->leftJoinWithRegion()
98
                ->leftJoinWithCountry()
99
            ->endUse()
100
            ->setFormatter(ArrayFormatter::class);
101
102
        if ($lastRunTime) {
103
            $query->addAnd(SpyCustomerTableMap::COL_UPDATED_AT, $lastRunTime, Criteria::GREATER_EQUAL)
104
                ->addOr(SpyCustomerAddressTableMap::COL_UPDATED_AT, $lastRunTime, Criteria::GREATER_EQUAL);
105
        }
106
        return $query->find()->toArray();
107
    }
108
}
109