TaxonsAssigner   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
eloc 7
c 2
b 0
f 0
dl 0
loc 18
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A assign() 0 8 2
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
Bug introduced by
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