Completed
Branch master (8ae5a6)
by Neomerx
01:35
created

NestedGroup::parentGroup()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
nc 1
cc 1
eloc 2
nop 0
crap 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