SectionsAssigner   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A assign() 0 8 2
A __construct() 0 3 1
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\SectionableInterface;
14
use BitBag\SyliusCmsPlugin\Entity\SectionInterface;
15
use BitBag\SyliusCmsPlugin\Repository\SectionRepositoryInterface;
16
use Webmozart\Assert\Assert;
17
18
final class SectionsAssigner implements SectionsAssignerInterface
19
{
20
    /** @var SectionRepositoryInterface */
21
    private $sectionRepository;
22
23
    public function __construct(SectionRepositoryInterface $sectionRepository)
24
    {
25
        $this->sectionRepository = $sectionRepository;
26
    }
27
28
    public function assign(SectionableInterface $sectionsAware, array $sectionsCodes): void
29
    {
30
        foreach ($sectionsCodes as $sectionCode) {
31
            /** @var SectionInterface|null $section */
32
            $section = $this->sectionRepository->findOneBy(['code' => $sectionCode]);
33
34
            Assert::notNull($section, sprintf('Section with %s code not found.', $sectionCode));
35
            $sectionsAware->addSection($section);
0 ignored issues
show
Bug introduced by
It seems like $section can also be of type null; however, parameter $section of BitBag\SyliusCmsPlugin\E...Interface::addSection() does only seem to accept BitBag\SyliusCmsPlugin\Entity\SectionInterface, 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
            $sectionsAware->addSection(/** @scrutinizer ignore-type */ $section);
Loading history...
36
        }
37
    }
38
}
39