HasTypeTrait   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 84.21%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 16
dl 0
loc 52
rs 10
c 1
b 0
f 1
ccs 16
cts 19
cp 0.8421
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A initType() 0 3 1
A setType() 0 5 1
A getType() 0 7 2
A generateType() 0 14 3
1
<?php
2
3
namespace Nip\Router\Route\Traits;
4
5
use Nip\Router\Route\Route;
6
7
/**
8
 * Trait HasTypeTrait
9
 * @package Nip\Router\Route\Traits
10
 */
11
trait HasTypeTrait
12
{
13
    /**
14
     * @var string
15
     */
16
    protected $type = null;
17
18
    /**
19
     * @return string
20
     */
21 2
    public function getType()
22
    {
23 2
        if ($this->type === null) {
24 2
            $this->initType();
25
        }
26
27 2
        return $this->type;
28
    }
29
30
    /**
31
     * @param string $type
32
     * @return $this
33
     */
34 2
    public function setType($type)
35
    {
36 2
        $this->type = $type;
37
38 2
        return $this;
39
    }
40
41 2
    protected function initType()
42
    {
43 2
        $this->setType($this->generateType());
44 2
    }
45
46
    /**
47
     * @return string
48
     */
49 2
    protected function generateType()
50
    {
51 2
        if ($this->getClassName() == Route::class) {
0 ignored issues
show
Bug introduced by
It seems like getClassName() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

51
        if ($this->/** @scrutinizer ignore-call */ getClassName() == Route::class) {
Loading history...
52 1
            return 'literal';
53
        }
54
55 1
        if ($this->isNamespaced()) {
0 ignored issues
show
Bug introduced by
It seems like isNamespaced() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

55
        if ($this->/** @scrutinizer ignore-call */ isNamespaced()) {
Loading history...
56 1
            $name = strtolower($this->getClassFirstName());
0 ignored issues
show
Bug introduced by
It seems like getClassFirstName() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

56
            $name = strtolower($this->/** @scrutinizer ignore-call */ getClassFirstName());
Loading history...
57 1
            return str_replace('route', '', $name);
58
        }
59
        $name = get_class($this);
60
        $parts = explode('_', $name);
61
62
        return strtolower(end($parts));
63
    }
64
}
65