HasControllerRecordsTrait::setController()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Nip\Records\Traits\HasController;
4
5
/**
6
 * Trait HasControllerRecordsTrait
7
 * @package Nip\Records\Traits\HasController
8
 */
9
trait HasControllerRecordsTrait
10
{
11
12
    /**
13
     * @var null|string
14
     */
15
    protected $controller = null;
16
    /**
17
     * @return string
18
     */
19 15
    public function getController()
20
    {
21 15
        if ($this->controller === null) {
22 15
            $this->initController();
23
        }
24
25 15
        return $this->controller;
26
    }
27
28
    /**
29
     * @param null|string $controller
30
     */
31 15
    public function setController($controller)
32
    {
33 15
        $this->controller = $controller;
34 15
    }
35
36 15
    protected function initController()
37
    {
38 15
        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

38
        if ($this->/** @scrutinizer ignore-call */ isNamespaced()) {
Loading history...
39 10
            $controller = $this->generateControllerNamespaced();
40
        } else {
41 5
            $controller = $this->generateControllerGeneric();
42
        }
43 15
        $this->setController($controller);
44 15
    }
45
46
    /**
47
     * @return string
48
     */
49 10
    protected function generateControllerNamespaced()
50
    {
51 10
        $class = $this->getModelNamespacePath();
0 ignored issues
show
Bug introduced by
It seems like getModelNamespacePath() 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
        /** @scrutinizer ignore-call */ 
52
        $class = $this->getModelNamespacePath();
Loading history...
52 10
        $class = trim($class, '\\');
53
54 10
        return inflector()->unclassify($class);
55
    }
56
57
    /**
58
     * @return string
59
     */
60 5
    protected function generateControllerGeneric()
61
    {
62 5
        $class = $this->getClassName();
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

62
        /** @scrutinizer ignore-call */ 
63
        $class = $this->getClassName();
Loading history...
63
64 5
        return inflector()->unclassify($class);
65
    }
66
}
67