NestedGroup::getName()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

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