Failed Conditions
Pull Request — master (#172)
by Łukasz
03:07
created

ShowTaxonDetailsAction::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 3
1
<?php
2
3
namespace Sylius\ShopApiPlugin\Controller\Taxon;
4
5
use FOS\RestBundle\View\View;
6
use FOS\RestBundle\View\ViewHandlerInterface;
7
use Sylius\Component\Taxonomy\Repository\TaxonRepositoryInterface;
8
use Sylius\ShopApiPlugin\Factory\TaxonDetailsViewFactoryInterface;
9
use Symfony\Component\HttpFoundation\Request;
10
use Symfony\Component\HttpFoundation\Response;
11
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
12
13
final class ShowTaxonDetailsAction
14
{
15
    /**
16
     * @var TaxonRepositoryInterface
17
     */
18
    private $taxonRepository;
19
20
    /**
21
     * @var ViewHandlerInterface
22
     */
23
    private $viewHandler;
24
25
    /**
26
     * @var TaxonDetailsViewFactoryInterface
27
     */
28
    private $taxonViewFactory;
29
30
    public function __construct(
31
        TaxonRepositoryInterface $taxonRepository,
32
        ViewHandlerInterface $viewHandler,
33
        TaxonDetailsViewFactoryInterface $taxonViewFactory
34
    ) {
35
        $this->taxonRepository = $taxonRepository;
36
        $this->viewHandler = $viewHandler;
37
        $this->taxonViewFactory = $taxonViewFactory;
38
    }
39
40
    public function __invoke(Request $request): Response
41
    {
42
        $taxonSlug = $request->attributes->get('slug');
43
        $locale = $request->query->get('locale');
44
45
        $taxon = $this->taxonRepository->findOneBySlug($taxonSlug, $locale);
46
47
        if (null === $taxon) {
48
            throw new NotFoundHttpException(sprintf('Taxon with slug %s has not been found in %s locale.', $taxonSlug, $locale));
49
        }
50
51
        return $this->viewHandler->handle(View::create($this->taxonViewFactory->create($taxon, $locale), Response::HTTP_OK));
0 ignored issues
show
Compatibility introduced by
$taxon of type object<Sylius\Component\...y\Model\TaxonInterface> is not a sub-type of object<Sylius\Component\...e\Model\TaxonInterface>. It seems like you assume a child interface of the interface Sylius\Component\Taxonomy\Model\TaxonInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
52
    }
53
}
54