Completed
Push — develop ( 1f1021...56e7f0 )
by Neomerx
03:32
created

NestedGroup   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 32
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getName() 0 8 3
A createGroup() 0 6 1
1
<?php namespace Limoncello\Core\Routing;
2
3
/**
4
 * Copyright 2015-2017 [email protected]
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
use Limoncello\Contracts\Routing\GroupInterface;
20
21
/**
22
 * @package Limoncello\Core
23
 */
24
class NestedGroup extends BaseGroup
25
{
26
    /**
27
     * @param GroupInterface $parent
28
     */
29 15
    public function __construct(GroupInterface $parent)
30
    {
31 15
        $this->setParentGroup($parent);
32
    }
33
34
    /**
35
     * @inheritdoc
36
     */
37 8
    public function getName(): ?string
38
    {
39 8
        $parentGroupName = $this->parentGroup()->getName();
40 8
        $selfName        = parent::getName();
41 8
        $result          = $parentGroupName !== null || $selfName !== null ? $parentGroupName . $selfName : null;
42
43 8
        return $result;
44
    }
45
46
    /**
47
     * @return BaseGroup
48
     */
49 2
    protected function createGroup(): BaseGroup
50
    {
51 2
        $group = (new static($this))->setHasTrailSlash($this->hasTrailSlash());
52
53 2
        return $group;
54
    }
55
}
56