Passed
Push — master ( bcadde...416dc9 )
by Gabriel
02:50 queued 12s
created

generatePropertyDirectory()   A

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
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace ByTIC\Models\SmartProperties\Properties\Definitions\Traits;
4
5
use Nip\Utility\Str;
6
7
/**
8
 * Trait HasItemsDirectoryTrait
9
 * @package ByTIC\Models\SmartProperties\Properties\Definitions\Traits
10
 */
11
trait HasItemsDirectoryTrait
12
{
13
    protected $itemsDirectory = null;
14
15
16
    /**
17
     * @return null|string
18
     */
19 17
    public function getItemsDirectory()
20
    {
21 17
        if ($this->itemsDirectory == null) {
22 16
            $this->initItemsDirectory();
23
        }
24
25 17
        return $this->itemsDirectory;
26
    }
27
28
    /**
29
     * @param $dir
30
     */
31 17
    public function setItemsDirectory($dir)
32
    {
33 17
        $this->itemsDirectory = $dir;
34 17
    }
35
36 16
    protected function initItemsDirectory()
37
    {
38 16
        $this->setItemsDirectory($this->generateItemsDirectory());
39 16
    }
40
41
    /**
42
     * @return string
43
     */
44 16
    protected function generateItemsDirectory()
45
    {
46 16
        $methodName = 'get' . $this->getName() . 'ItemsDirectory';
0 ignored issues
show
Bug introduced by
It seems like getName() 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

46
        $methodName = 'get' . $this->/** @scrutinizer ignore-call */ getName() . 'ItemsDirectory';
Loading history...
47 16
        if (method_exists($this->getManager(), $methodName)) {
0 ignored issues
show
Bug introduced by
It seems like getManager() 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

47
        if (method_exists($this->/** @scrutinizer ignore-call */ getManager(), $methodName)) {
Loading history...
48
            return $this->getManager()->$methodName();
49
        }
50
51 16
        $methodName = 'get' . Str::plural($this->getName()) . 'Directory';
52 16
        if (method_exists($this->getManager(), $methodName)) {
53 4
            return $this->getManager()->$methodName();
54
        }
55
56 12
        return $this->generateManagerDirectory() . DIRECTORY_SEPARATOR . $this->generatePropertyDirectory();
57
    }
58
59
    /**
60
     * @return string
61
     */
62 12
    protected function generateManagerDirectory()
63
    {
64 12
        $reflector = new \ReflectionObject($this->getManager());
65
66 12
        return dirname($reflector->getFileName());
67
    }
68
69
    /**
70
     * @return string
71
     */
72 12
    protected function generatePropertyDirectory()
73
    {
74 12
        return $this->getLabel();
0 ignored issues
show
Bug introduced by
It seems like getLabel() 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

74
        return $this->/** @scrutinizer ignore-call */ getLabel();
Loading history...
75
    }
76
}
77