Completed
Push — master ( 163fd9...314ef3 )
by Neomerx
02:36
created

NestedGroup::getName()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
cc 3
eloc 5
nc 4
nop 0
crap 3
1
<?php namespace Limoncello\Core\Routing;
2
3
/**
4
 * Copyright 2015-2016 [email protected] (www.neomerx.com)
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\Core\Contracts\Routing\GroupInterface;
20
21
/**
22
 * @package Limoncello\Core
23
 */
24
class NestedGroup extends BaseGroup
25
{
26
    /**
27
     * @param GroupInterface $parent
28
     */
29 12
    public function __construct(GroupInterface $parent)
30
    {
31 12
        $this->setParentGroup($parent);
32 12
    }
33
34
    /**
35
     * @return GroupInterface
36
     */
37 12
    public function parentGroup()
38
    {
39 12
        return parent::parentGroup();
40
    }
41
42
    /**
43
     * @inheritdoc
44
     */
45 6
    public function getName()
46
    {
47 6
        $parentGroupName = $this->parentGroup()->getName();
48 6
        $selfName        = parent::getName();
49 6
        $result          = $parentGroupName !== null || $selfName !== null ? $parentGroupName . $selfName : null;
50
51 6
        return $result;
52
    }
53
54
    /**
55
     * @return NestedGroup
56
     */
57 2
    protected function createGroup()
58
    {
59 2
        $group = (new static($this))->setHasTrailSlash($this->hasTrailSlash());
60
61 2
        return $group;
62
    }
63
}
64