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

HasItemsDirectoryTrait   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 95%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 14
c 1
b 0
f 0
dl 0
loc 59
ccs 19
cts 20
cp 0.95
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A initItemsDirectory() 0 3 1
A generateItemsDirectory() 0 8 2
A generatePropertyDirectory() 0 3 1
A generateManagerDirectory() 0 5 1
A setItemsDirectory() 0 3 1
A getItemsDirectory() 0 7 2
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
}