Passed
Push — master ( 90a55c...bcadde )
by Gabriel
03:02
created

HasItemsDirectoryTrait::generateManagerDirectory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
ccs 3
cts 3
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
/**
6
 * Trait HasItemsDirectoryTrait
7
 * @package ByTIC\Models\SmartProperties\Properties\Definitions\Traits
8
 */
9
trait HasItemsDirectoryTrait
10
{
11
    protected $itemsDirectory = null;
12
13
14
    /**
15
     * @return null|string
16
     */
17 14
    public function getItemsDirectory()
18
    {
19 14
        if ($this->itemsDirectory == null) {
20 13
            $this->initItemsDirectory();
21
        }
22
23 14
        return $this->itemsDirectory;
24
    }
25
26
    /**
27
     * @param $dir
28
     */
29 14
    public function setItemsDirectory($dir)
30
    {
31 14
        $this->itemsDirectory = $dir;
32 14
    }
33
34 13
    protected function initItemsDirectory()
35
    {
36 13
        $this->setItemsDirectory($this->generateItemsDirectory());
37 13
    }
38
39
    /**
40
     * @return string
41
     */
42 13
    public function generateItemsDirectory()
43
    {
44 13
        $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

44
        $methodName = 'get' . $this->/** @scrutinizer ignore-call */ getName() . 'ItemsDirectory';
Loading history...
45 13
        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

45
        if (method_exists($this->/** @scrutinizer ignore-call */ getManager(), $methodName)) {
Loading history...
46
            return $this->getManager()->$methodName();
47
        }
48
49 13
        return $this->generateManagerDirectory() . DIRECTORY_SEPARATOR . $this->generatePropertyDirectory();
50
    }
51
52
    /**
53
     * @return string
54
     */
55 13
    protected function generateManagerDirectory()
56
    {
57 13
        $reflector = new \ReflectionObject($this->getManager());
58
59 13
        return dirname($reflector->getFileName());
60
    }
61
62
    /**
63
     * @return string
64
     */
65 13
    protected function generatePropertyDirectory()
66
    {
67 13
        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

67
        return $this->/** @scrutinizer ignore-call */ getLabel();
Loading history...
68
    }
69
}