Passed
Push — master ( cbe288...130872 )
by Peter
02:31
created

PageCategory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 5
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Website\Service\Execute;
6
7
use AbterPhp\Framework\Domain\Entities\IStringerEntity;
8
use AbterPhp\Framework\Http\Service\Execute\RepoServiceAbstract;
9
use AbterPhp\Website\Domain\Entities\PageCategory as Entity;
10
use AbterPhp\Website\Orm\PageCategoryRepo as GridRepo;
11
use AbterPhp\Website\Validation\Factory\PageCategory as ValidatorFactory;
12
use Cocur\Slugify\Slugify;
13
use Opulence\Events\Dispatchers\IEventDispatcher;
14
use Opulence\Orm\IUnitOfWork;
15
16
class PageCategory extends RepoServiceAbstract
17
{
18
    /** @var Slugify */
19
    protected $slugify;
20
21
    /**
22
     * PageCategory constructor.
23
     *
24
     * @param GridRepo         $repo
25
     * @param ValidatorFactory $validatorFactory
26
     * @param IUnitOfWork      $unitOfWork
27
     * @param IEventDispatcher $eventDispatcher
28
     * @param Slugify          $slugify
29
     */
30
    public function __construct(
31
        GridRepo $repo,
32
        ValidatorFactory $validatorFactory,
33
        IUnitOfWork $unitOfWork,
34
        IEventDispatcher $eventDispatcher,
35
        Slugify $slugify
36
    ) {
37
        parent::__construct($repo, $validatorFactory, $unitOfWork, $eventDispatcher);
38
39
        $this->slugify = $slugify;
40
    }
41
42
43
    /**
44
     * @param string $entityId
45
     *
46
     * @return Entity
47
     */
48
    protected function createEntity(string $entityId): IStringerEntity
49
    {
50
        return new Entity($entityId, '', '');
51
    }
52
53
    /**
54
     * @param Entity $entity
55
     * @param array  $data
56
     *
57
     * @return Entity
58
     */
59
    protected function fillEntity(IStringerEntity $entity, array $data): IStringerEntity
60
    {
61
        if (empty($data['identifier'])) {
62
            $data['identifier'] = $data['name'];
63
        }
64
65
        $identifier = $this->slugify->slugify((string)$data['identifier']);
66
67
        $entity
68
            ->setIdentifier($identifier)
0 ignored issues
show
Bug introduced by
The method setIdentifier() does not exist on AbterPhp\Framework\Domain\Entities\IStringerEntity. It seems like you code against a sub-type of said class. However, the method does not exist in AbterPhp\Admin\Domain\Entities\LoginAttempt or AbterPhp\Admin\Domain\Entities\User. Are you sure you never get one of those? ( Ignorable by Annotation )

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

68
            ->/** @scrutinizer ignore-call */ 
69
              setIdentifier($identifier)
Loading history...
69
            ->setName((string)$data['name'])
70
        ;
71
72
        return $entity;
73
    }
74
}
75