VariantSwitch::switchVariant()   B
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 28
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 12
nc 2
nop 4
dl 0
loc 28
rs 8.5806
c 0
b 0
f 0
1
<?php
2
3
namespace DnVariantSwitch\Services;
4
5
use Shopware\Bundle\StoreFrontBundle\Service\AdditionalTextServiceInterface;
0 ignored issues
show
Bug introduced by
The type Shopware\Bundle\StoreFro...nalTextServiceInterface 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 Shopware\Bundle\StoreFrontBundle\Service\ContextServiceInterface;
0 ignored issues
show
Bug introduced by
The type Shopware\Bundle\StoreFro...ContextServiceInterface 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 Shopware\Bundle\StoreFrontBundle\Service\ListProductServiceInterface;
0 ignored issues
show
Bug introduced by
The type Shopware\Bundle\StoreFro...ProductServiceInterface 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 Shopware\Components\Model\ModelManager;
0 ignored issues
show
Bug introduced by
The type Shopware\Components\Model\ModelManager 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...
9
10
/**
11
 * Class VariantSwitch
12
 * @package DnVariantSwitch\Services
13
 */
14
class VariantSwitch implements VariantSwitchInterface
15
{
16
17
    /** @var ModelManager */
18
    private $models;
19
20
    /** @var \Enlight_Components_Session_Namespace */
0 ignored issues
show
Bug introduced by
The type Enlight_Components_Session_Namespace 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...
21
    private $session;
22
23
    /** @var ContextServiceInterface */
24
    private $context;
25
26
    /** @var ListProductServiceInterface */
27
    private $listProductService;
28
29
    /** @var AdditionalTextServiceInterface */
30
    private $additionalTextService;
31
32
    /**
33
     * VariantSwitch constructor.
34
     * @param ModelManager $models
35
     * @param \Enlight_Components_Session_Namespace $session
36
     * @param ContextServiceInterface $contextService
37
     * @param ListProductServiceInterface $listProductService
38
     * @param AdditionalTextServiceInterface $additionalTextService
39
     */
40
    public function __construct(
41
        ModelManager $models,
42
        \Enlight_Components_Session_Namespace $session,
43
        ContextServiceInterface $contextService,
44
        ListProductServiceInterface $listProductService,
45
        AdditionalTextServiceInterface $additionalTextService
46
    )
47
    {
48
        $this->models = $models;
49
        $this->session = $session;
50
        $this->context = $contextService;
51
        $this->listProductService = $listProductService;
52
        $this->additionalTextService = $additionalTextService;
53
    }
54
55
    /**
56
     * @inheritdoc
57
     */
58
    public function switchVariant(
59
        $number,
60
        $basketID,
61
        \sBasket $sBasket,
0 ignored issues
show
Bug introduced by
The type sBasket 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...
62
        $quantity = 1
63
    )
64
    {
65
        /** @var \Shopware\Models\Order\Basket $basket */
66
        $basket = $this->models->getRepository('Shopware\Models\Order\Basket')->find($basketID);
67
68
        if (!$basket || $basket->getSessionId() !== $this->session->get('sessionId')) {
0 ignored issues
show
introduced by
$basket is of type Shopware\Models\Order\Basket, thus it always evaluated to true.
Loading history...
69
            return;
70
        }
71
72
        $basket->setOrderNumber($number);
73
74
        $context = $this->context->getProductContext();
75
        $product = $this->listProductService->get($number, $context);
76
        /** @var \Shopware\Bundle\StoreFrontBundle\Struct\ListProduct $product */
77
        $product = $this->additionalTextService->buildAdditionalText($product, $context);
78
79
        $basket->setEsdArticle($product->getEsd() ? 1 : 0);
80
        $basket->setArticleName($product->getName() . ' ' . $product->getAdditional());
81
82
        $this->models->persist($basket);
83
        $this->models->flush();
84
85
        $sBasket->sUpdateArticle($basketID, $quantity);
86
    }
87
88
}