Creator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Veslo project <https://github.com/symfony-doge/veslo>.
5
 *
6
 * (C) 2019 Pavel Petrov <[email protected]>.
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * @license https://opensource.org/licenses/GPL-3.0 GPL-3.0
12
 */
13
14
declare(strict_types=1);
15
16
namespace Veslo\AnthillBundle\Vacancy\Category;
17
18
use Veslo\AnthillBundle\Dto\Vacancy\Roadmap\ConfigurationDto;
19
use Veslo\AnthillBundle\Entity\Vacancy\Category;
20
use Veslo\AppBundle\Entity\Repository\BaseEntityRepository;
21
22
/**
23
 * Creates and persists a new category for vacancies in local storage
24
 */
25
class Creator
26
{
27
    /**
28
     * Vacancy category repository
29
     *
30
     * @var BaseEntityRepository
31
     */
32
    private $categoryRepository;
33
34
    /**
35
     * Creator constructor.
36
     *
37
     * @param BaseEntityRepository $categoryRepository Vacancy category repository
38
     */
39
    public function __construct(BaseEntityRepository $categoryRepository)
40
    {
41
        $this->categoryRepository = $categoryRepository;
42
    }
43
44
    /**
45
     * Creates and returns a new category entity according to specified roadmap configuration
46
     *
47
     * @param ConfigurationDto $configuration  Context of configuration for search algorithm used by roadmap
48
     * @param bool             $isCascadeChild Whenever entity creation is a part of the entity-owner creation and
49
     *                                         entity manager should not be instantly flushed (for transaction purposes)
50
     *
51
     * @return Category
52
     */
53
    public function createByRoadmapConfigurationDto(
54
        ConfigurationDto $configuration,
55
        bool $isCascadeChild = false
56
    ): Category {
57
        $category = new Category();
58
59
        $categoryName = $configuration->getKey();
60
        $category->setName($categoryName);
61
62
        $this->categoryRepository->save($category, !$isCascadeChild);
63
64
        return $category;
65
    }
66
}
67