FactFinderSdkPriceExpander::expand()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 11
c 3
b 0
f 0
dl 0
loc 19
rs 9.9
cc 3
nc 3
nop 4
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\FactFinderSdk\Business\Expander;
9
10
use Generated\Shared\Transfer\CurrencyTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\CurrencyTransfer 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 Generated\Shared\Transfer\LocaleTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\LocaleTransfer 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\StoreTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\StoreTransfer 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\PriceProduct\Persistence\Base\SpyPriceProduct;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\PriceProduct\Per...ce\Base\SpyPriceProduct 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 SprykerEco\Shared\FactFinderSdk\FactFinderSdkConstants;
15
16
class FactFinderSdkPriceExpander extends FactFinderSdkAbstractExpander
17
{
18
    /**
19
     * @param \Generated\Shared\Transfer\LocaleTransfer $localeTransfer
20
     * @param \Generated\Shared\Transfer\CurrencyTransfer $currencyTransfer
21
     * @param \Generated\Shared\Transfer\StoreTransfer $storeTransfer
22
     * @param array $productData
23
     *
24
     * @return array
25
     */
26
    public function expand(LocaleTransfer $localeTransfer, CurrencyTransfer $currencyTransfer, StoreTransfer $storeTransfer, $productData)
27
    {
28
        $priceProductQuery = $this->queryContainer
29
            ->getPricesQuery($productData[FactFinderSdkConstants::ITEM_PRODUCT_NUMBER], $currencyTransfer, $storeTransfer);
30
        $price = $priceProductQuery->findOne();
31
32
        if ($price !== null) {
33
            return $this->addPrice($productData, $price);
34
        }
35
36
        $priceProductQuery = $this->queryContainer
37
            ->getProductAbstractPriceQuery($productData[FactFinderSdkConstants::ITEM_PRODUCT_NUMBER], $currencyTransfer, $storeTransfer);
38
        $price = $priceProductQuery->findOne();
39
40
        if ($price !== null) {
41
            return $this->addPrice($productData, $price);
42
        }
43
44
        return $productData;
45
    }
46
47
    /**
48
     * @param \Orm\Zed\PriceProduct\Persistence\Base\SpyPriceProduct $price
49
     *
50
     * @return string
51
     */
52
    protected function getPrice(SpyPriceProduct $price)
53
    {
54
        $priceValue = $price->getVirtualColumn(FactFinderSdkConstants::ITEM_PRICE);
55
56
        return number_format($priceValue / 100, 2, '.', '');
57
    }
58
59
    /**
60
     * @param array $productData
61
     * @param \Orm\Zed\PriceProduct\Persistence\Base\SpyPriceProduct $price
62
     *
63
     * @return array
64
     */
65
    protected function addPrice($productData, SpyPriceProduct $price)
66
    {
67
        $productData[FactFinderSdkConstants::ITEM_PRICE] = $this->getPrice($price);
68
69
        return $productData;
70
    }
71
}
72