Issues (63)

src/Assigner/TaxonsAssigner.php (1 issue)

1
<?php
2
3
/*
4
 * This file was created by developers working at BitBag
5
 * Do you need more information about us and what we do? Visit our https://bitbag.io website!
6
 * We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
7
*/
8
9
declare(strict_types=1);
10
11
namespace BitBag\SyliusCmsPlugin\Assigner;
12
13
use BitBag\SyliusCmsPlugin\Entity\TaxonAwareInterface;
14
use Sylius\Component\Core\Model\TaxonInterface;
15
use Sylius\Component\Taxonomy\Repository\TaxonRepositoryInterface;
16
use Webmozart\Assert\Assert;
17
18
final class TaxonsAssigner implements TaxonsAssignerInterface
19
{
20
    /** @var TaxonRepositoryInterface */
21
    private $taxonRepository;
22
23
    public function __construct(TaxonRepositoryInterface $taxonRepository)
24
    {
25
        $this->taxonRepository = $taxonRepository;
26
    }
27
28
    public function assign(TaxonAwareInterface $taxonAware, array $taxonCodes): void
29
    {
30
        foreach ($taxonCodes as $taxonCode) {
31
            /** @var TaxonInterface|null $taxon */
32
            $taxon = $this->taxonRepository->findOneBy(['code' => $taxonCode]);
33
34
            Assert::notNull($taxon, sprintf('Taxon with %s code not found.', $taxonCode));
35
            $taxonAware->addTaxon($taxon);
0 ignored issues
show
It seems like $taxon can also be of type null; however, parameter $taxon of BitBag\SyliusCmsPlugin\E...reInterface::addTaxon() does only seem to accept Sylius\Component\Core\Model\TaxonInterface, 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
            $taxonAware->addTaxon(/** @scrutinizer ignore-type */ $taxon);
Loading history...
36
        }
37
    }
38
}
39