StructureDirectory::findByTemplate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 7
rs 10
1
<?php
2
3
namespace Maestriam\FileSystem\Foundation\Drive;
4
5
use Maestriam\FileSystem\Concerns\FluentGetter;
6
7
class StructureDirectory
8
{    
9
    use FluentGetter;
10
11
    /**
12
     * Caminho-raíz do projeto
13
     */
14
    private string $rootPath = '.';
15
16
    /**
17
     * Caminho onde está os arquivos de template
18
     */
19
    private string $templatePath = '.';
20
21
    /**
22
     * Lista de caminhos de template
23
     */
24
    private array $pathList = [];
25
26
    /**
27
     * Busc
28
     */
29
    private PathFinder $finder;
30
31
    /**
32
     * Define/Retorna o caminho-raíz do projeto, 
33
     * de acordo com o tipo de parâmetro 
34
     *
35
     * @param string $path
36
     * @return mixed
37
     */
38
    public function root(string $path = null)
39
    {
40
        return (! $path) ? $this->getRoot() : $this->setRoot($path);
41
    }
42
    
43
    /**
44
     * Define o caminho-raiz do projeto
45
     *
46
     * @param string $path
47
     * @return StructureDirectory
48
     */
49
    public function setRoot(string $path) : StructureDirectory
50
    {
51
        $this->rootPath = $path;
52
        
53
        return $this;
54
    }
55
    
56
    /**
57
     * Retorna o caminho-raiz do projeto
58
     *
59
     * @param string $path
60
     * @return StructureDirectory
61
     */
62
    private function getRoot() : string
63
    {
64
        return $this->rootPath;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->rootPath returns the type string which is incompatible with the documented return type Maestriam\FileSystem\Fou...rive\StructureDirectory.
Loading history...
65
    }
66
67
    /**
68
     * Define/Retorna o caminho de diretório de templates 
69
     *
70
     * @param string $path
71
     * @return mixed
72
     */
73
    public function template(string $path = null)
74
    {
75
        return (! $path) ? $this->getTemplate() : $this->setTemplate($path);
76
    }
77
78
    /**
79
     * Define o caminho de templates 
80
     *
81
     * @param string $path
82
     * @return mixed
83
     */    
84
    public function setTemplate(string $path) : StructureDirectory
85
    {
86
        $this->templatePath = $path;
87
        
88
        return $this;
89
    }
90
91
    /**
92
     * Retorna o caminho de templates 
93
     *
94
     * @param string $path
95
     * @return mixed
96
     */
97
    private function getTemplate() : string
98
    {
99
        return $this->templatePath;
100
    }
101
    
102
     /**
103
     * Retorna caminho baseado nas configurações de template
104
     *
105
     * @param string $file
106
     * @return string
107
     */
108
    public function findByTemplate(string $template) : string
109
    {   
110
        $folder = $this->finder->findByTemplate($template);
111
112
        $path = $this->root() . DS . $folder . DS;
113
114
        return PathSanitizer::sanitize($path); 
115
    }
116
117
    /**
118
     * 
119
     *
120
     * @param array $paths
121
     * @return mixed
122
     */
123
    public function paths(array $paths = null)
124
    {
125
        if (! $paths) {
126
            return $this->getPaths();
127
        }  
128
         
129
        return $this->setPaths($paths)->initFinder();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->setPaths($paths)->initFinder() targeting Maestriam\FileSystem\Fou...Directory::initFinder() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
130
    }
131
132
    /**
133
     * Inicia a instância com as regras de negócio para pesquisar
134
     * o diretório apropriado de acordo com o template
135
     *
136
     * @return void
137
     */
138
    private function initFinder()
139
    {
140
        $structure = $this->getPaths();
141
142
        $this->finder = new PathFinder($structure);
143
144
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Maestriam\FileSystem\Fou...rive\StructureDirectory which is incompatible with the documented return type void.
Loading history...
145
    }
146
    
147
    /**
148
     * Define a lista de caminho de templates
149
     *
150
     * @param string $path
151
     * @return mixed
152
     */
153
    public function setPaths(array $list) : StructureDirectory
154
    {
155
        $this->pathList = $list;
156
157
        return $this;
158
    }
159
160
    /**
161
     * Retorna a lista de caminhos definidos dentro do projeto
162
     *
163
     * @return void
164
     */
165
    public function getPaths() : array
166
    {
167
        return $this->pathList;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->pathList returns the type array which is incompatible with the documented return type void.
Loading history...
168
    }
169
}