Passed
Push — master ( f5f62a...783e97 )
by Christian
12:34 queued 10s
created

PromotionActionController::getIndividualCodes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Core\Checkout\Promotion\Api;
4
5
use Shopware\Core\Checkout\Cart\LineItem\Group\LineItemGroupPackagerInterface;
6
use Shopware\Core\Checkout\Cart\LineItem\Group\LineItemGroupServiceRegistry;
7
use Shopware\Core\Checkout\Cart\LineItem\Group\LineItemGroupSorterInterface;
8
use Shopware\Core\Checkout\Promotion\Cart\Discount\Filter\FilterPickerInterface;
9
use Shopware\Core\Checkout\Promotion\Cart\Discount\Filter\FilterServiceRegistry;
10
use Shopware\Core\Checkout\Promotion\Util\PromotionCodesLoader;
11
use Shopware\Core\Checkout\Promotion\Util\PromotionCodesRemover;
12
use Shopware\Core\Framework\Context;
13
use Shopware\Core\Framework\Routing\Annotation\Acl;
14
use Shopware\Core\Framework\Routing\Annotation\RouteScope;
15
use Shopware\Core\Framework\Routing\Annotation\Since;
16
use Shopware\Core\Framework\Uuid\Exception\InvalidUuidException;
17
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
18
use Symfony\Component\HttpFoundation\JsonResponse;
19
use Symfony\Component\HttpFoundation\Response;
20
use Symfony\Component\Routing\Annotation\Route;
21
22
/**
23
 * @deprecated tag:v6.4.0.0 - Use PromotionCodeService instead
24
 * @RouteScope(scopes={"api"})
25
 */
26
class PromotionActionController extends AbstractController
27
{
28
    /**
29
     * @var PromotionCodesLoader
30
     */
31
    private $codesLoader;
32
33
    /**
34
     * @var PromotionCodesRemover
35
     */
36
    private $codesRemover;
37
38
    /**
39
     * @var LineItemGroupServiceRegistry
40
     */
41
    private $serviceRegistry;
42
43
    /**
44
     * @var FilterServiceRegistry
45
     */
46
    private $filterServiceRegistry;
47
48
    public function __construct(PromotionCodesLoader $codesLoader, PromotionCodesRemover $codesRemover, LineItemGroupServiceRegistry $serviceRegistry, FilterServiceRegistry $filterServiceRegistry)
49
    {
50
        $this->codesLoader = $codesLoader;
51
        $this->codesRemover = $codesRemover;
52
        $this->serviceRegistry = $serviceRegistry;
53
        $this->filterServiceRegistry = $filterServiceRegistry;
54
    }
55
56
    /**
57
     * @Since("6.0.0.0")
58
     * @Route("/api/v{version}/_action/promotion/{promotionId}/codes/individual", name="api.action.promotion.codes", methods={"GET"})
59
     * @Acl({"promotion.viewer"})
60
     *
61
     * @throws InvalidUuidException
62
     */
63
    public function getIndividualCodes(string $promotionId, Context $context): JsonResponse
0 ignored issues
show
Unused Code introduced by
The parameter $context is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

63
    public function getIndividualCodes(string $promotionId, /** @scrutinizer ignore-unused */ Context $context): JsonResponse

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
64
    {
65
        return new JsonResponse($this->codesLoader->loadIndividualCodes($promotionId));
66
    }
67
68
    /**
69
     * @Since("6.0.0.0")
70
     * @Route("/api/v{version}/_action/promotion/{promotionId}/codes/individual", name="api.action.promotion.codes.remove", methods={"DELETE"})
71
     * @Acl({"promotion.deleter"})
72
     *
73
     * @throws InvalidUuidException
74
     */
75
    public function deleteIndividualCodes(string $promotionId, Context $context): Response
76
    {
77
        $this->codesRemover->removeIndividualCodes($promotionId, $context);
78
79
        return new Response(null, Response::HTTP_NO_CONTENT);
80
    }
81
82
    /**
83
     * @Since("6.0.0.0")
84
     * @Route("/api/v{version}/_action/promotion/setgroup/packager", name="api.action.promotion.setgroup.packager", methods={"GET"})
85
     * @Acl({"promotion.viewer"})
86
     *
87
     * @throws InvalidUuidException
88
     */
89
    public function getSetGroupPackagers(): JsonResponse
90
    {
91
        $packagerKeys = [];
92
93
        /** @var LineItemGroupPackagerInterface $packager */
94
        foreach ($this->serviceRegistry->getPackagers() as $packager) {
95
            $packagerKeys[] = $packager->getKey();
96
        }
97
98
        return new JsonResponse($packagerKeys);
99
    }
100
101
    /**
102
     * @Since("6.0.0.0")
103
     * @Route("/api/v{version}/_action/promotion/setgroup/sorter", name="api.action.promotion.setgroup.sorter", methods={"GET"})
104
     * @Acl({"promotion.viewer"})
105
     *
106
     * @throws InvalidUuidException
107
     */
108
    public function getSetGroupSorters(): JsonResponse
109
    {
110
        $sorterKeys = [];
111
112
        /** @var LineItemGroupSorterInterface $sorter */
113
        foreach ($this->serviceRegistry->getSorters() as $sorter) {
114
            $sorterKeys[] = $sorter->getKey();
115
        }
116
117
        return new JsonResponse($sorterKeys);
118
    }
119
120
    /**
121
     * @Since("6.3.4.0")
122
     * @Route("/api/v{version}/_action/promotion/discount/picker", name="api.action.promotion.discount.picker", methods={"GET"})
123
     * @Acl({"promotion.viewer"})
124
     *
125
     * @throws InvalidUuidException
126
     */
127
    public function getDiscountFilterPickers(): JsonResponse
128
    {
129
        $pickerKeys = [];
130
131
        /** @var FilterPickerInterface $picker */
132
        foreach ($this->filterServiceRegistry->getPickers() as $picker) {
133
            $pickerKeys[] = $picker->getKey();
134
        }
135
136
        return new JsonResponse($pickerKeys);
137
    }
138
}
139