Issues (3877)

Communication/Controller/ViewController.php (1 issue)

1
<?php
2
3
/**
4
 * Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace Spryker\Zed\ProductLabelGui\Communication\Controller;
9
10
use Generated\Shared\Transfer\ProductLabelTransfer;
11
use Spryker\Zed\Kernel\Communication\Controller\AbstractController;
12
use Symfony\Component\HttpFoundation\Request;
13
14
/**
15
 * @method \Spryker\Zed\ProductLabelGui\Communication\ProductLabelGuiCommunicationFactory getFactory()
16
 * @method \Spryker\Zed\ProductLabelGui\Persistence\ProductLabelGuiQueryContainerInterface getQueryContainer()
17
 * @method \Spryker\Zed\ProductLabelGui\Persistence\ProductLabelGuiRepositoryInterface getRepository()
18
 */
19
class ViewController extends AbstractController
20
{
21
    /**
22
     * @var string
23
     */
24
    public const PARAM_ID_PRODUCT_LABEL = 'id-product-label';
25
26
    /**
27
     * @param \Symfony\Component\HttpFoundation\Request $request
28
     *
29
     * @return array
30
     */
31
    public function indexAction(Request $request)
32
    {
33
        $idProductLabel = $this->castId($request->query->get(static::PARAM_ID_PRODUCT_LABEL));
34
        $productLabelTransfer = $this->findProductLabelById($idProductLabel);
35
        $this->hydrateLocaleTransferIntoLocalizedAttributes($productLabelTransfer);
0 ignored issues
show
It seems like $productLabelTransfer can also be of type null; however, parameter $productLabelTransfer of Spryker\Zed\ProductLabel...toLocalizedAttributes() does only seem to accept Generated\Shared\Transfer\ProductLabelTransfer, maybe add an additional type check? ( Ignorable by Annotation )

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

35
        $this->hydrateLocaleTransferIntoLocalizedAttributes(/** @scrutinizer ignore-type */ $productLabelTransfer);
Loading history...
36
37
        return $this->viewResponse([
38
            'productLabelTransfer' => $productLabelTransfer,
39
            'relatedProductTable' => $this->getRelatedProductTable($idProductLabel)->render(),
40
        ]);
41
    }
42
43
    /**
44
     * @param int $idProductLabel
45
     *
46
     * @return \Generated\Shared\Transfer\ProductLabelTransfer|null
47
     */
48
    protected function findProductLabelById($idProductLabel)
49
    {
50
        return $this
51
            ->getFactory()
52
            ->getProductLabelFacade()
53
            ->findLabelById($idProductLabel);
54
    }
55
56
    /**
57
     * @param \Generated\Shared\Transfer\ProductLabelTransfer $productLabelTransfer
58
     *
59
     * @return void
60
     */
61
    protected function hydrateLocaleTransferIntoLocalizedAttributes(ProductLabelTransfer $productLabelTransfer)
62
    {
63
        foreach ($productLabelTransfer->getLocalizedAttributesCollection() as $localizedAttributesTransfer) {
64
            $localeTransfer = $this
65
                ->getFactory()
66
                ->getLocaleFacade()
67
                ->getLocaleById($localizedAttributesTransfer->getFkLocale());
68
            $localizedAttributesTransfer->setLocale($localeTransfer);
69
        }
70
    }
71
72
    /**
73
     * @param int $idProductLabel
74
     *
75
     * @return \Spryker\Zed\ProductLabelGui\Communication\Table\RelatedProductOverviewTable
76
     */
77
    protected function getRelatedProductTable($idProductLabel)
78
    {
79
        return $this
80
            ->getFactory()
81
            ->createRelatedProductOverviewTable($idProductLabel);
82
    }
83
84
    /**
85
     * @param \Symfony\Component\HttpFoundation\Request $request
86
     *
87
     * @return \Symfony\Component\HttpFoundation\JsonResponse
88
     */
89
    public function tableAction(Request $request)
90
    {
91
        $idProductLabel = $this->castId($request->query->get(static::PARAM_ID_PRODUCT_LABEL));
92
        $relatedProductTable = $this->getRelatedProductTable($idProductLabel);
93
94
        return $this->jsonResponse($relatedProductTable->fetchData());
95
    }
96
}
97