Completed
Push — master ( b4dd2a...679ce7 )
by Craig
11:55
created

AbstractEntityInitialiser::initRoute()   C

Complexity

Conditions 7
Paths 27

Size

Total Lines 30
Code Lines 18

Duplication

Lines 17
Ratio 56.67 %

Importance

Changes 0
Metric Value
cc 7
eloc 18
nc 27
nop 1
dl 17
loc 30
rs 6.7272
c 0
b 0
f 0
1
<?php
2
/**
3
 * Routes.
4
 *
5
 * @copyright Zikula contributors (Zikula)
6
 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
7
 * @author Zikula contributors <[email protected]>.
8
 * @link http://www.zikula.org
9
 * @link http://zikula.org
10
 * @version Generated by ModuleStudio 0.7.4 (http://modulestudio.de).
11
 */
12
13
namespace Zikula\RoutesModule\Entity\Factory\Base;
14
15
use Zikula\RoutesModule\Entity\RouteEntity;
16
use Zikula\RoutesModule\Helper\ListEntriesHelper;
17
18
/**
19
 * Entity initialiser class used to dynamically apply default values to newly created entities.
20
 */
21
abstract class AbstractEntityInitialiser
22
{
23
    /**
24
     * @var ListEntriesHelper Helper service for managing list entries
25
     */
26
    protected $listEntriesHelper;
27
28
    /**
29
     * EntityInitialiser constructor.
30
     *
31
     * @param ListEntriesHelper $listEntriesHelper Helper service for managing list entries
32
     */
33
    public function __construct(ListEntriesHelper $listEntriesHelper)
34
    {
35
        $this->listEntriesHelper = $listEntriesHelper;
36
    }
37
38
    /**
39
     * Initialises a given route instance.
40
     *
41
     * @param RouteEntity $entity The newly created entity instance
42
     *
43
     * @return RouteEntity The updated entity instance
44
     */
45
    public function initRoute(RouteEntity $entity)
46
    {
47
        $listEntries = $this->listEntriesHelper->getRouteTypeEntriesForRoute();
48
        $items = [];
49 View Code Duplication
        foreach ($listEntries as $listEntry) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
50
            if (true === $listEntry['default']) {
51
                $items[] = $listEntry['value'];
52
            }
53
        }
54
        $entity->setRouteType(implode('###', $items));
55
56
        $listEntries = $this->listEntriesHelper->getSchemesEntriesForRoute();
57 View Code Duplication
        foreach ($listEntries as $listEntry) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
58
            if (true === $listEntry['default']) {
59
                $entity->setSchemes($listEntry['value']);
60
                break;
61
            }
62
        }
63
64
        $listEntries = $this->listEntriesHelper->getMethodsEntriesForRoute();
65 View Code Duplication
        foreach ($listEntries as $listEntry) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
66
            if (true === $listEntry['default']) {
67
                $entity->setMethods($listEntry['value']);
68
                break;
69
            }
70
        }
71
72
73
        return $entity;
74
    }
75
76
    /**
77
     * Returns the list entries helper.
78
     *
79
     * @return ListEntriesHelper
80
     */
81
    public function getListEntriesHelper()
82
    {
83
        return $this->listEntriesHelper;
84
    }
85
    
86
    /**
87
     * Sets the list entries helper.
88
     *
89
     * @param ListEntriesHelper $listEntriesHelper
90
     *
91
     * @return void
92
     */
93
    public function setListEntriesHelper($listEntriesHelper)
94
    {
95
        if ($this->listEntriesHelper != $listEntriesHelper) {
96
            $this->listEntriesHelper = $listEntriesHelper;
97
        }
98
    }
99
    
100
}
101