maestriam /
samurai
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Maestriam\Samurai\Foundation; |
||
| 4 | |||
| 5 | class FilenameParser |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * Baseado no caminho do arquivo, retorna o nome e o tipo da diretiva |
||
| 9 | * |
||
| 10 | * @param string $themepath |
||
| 11 | * @param string $filepath |
||
| 12 | * @return object |
||
| 13 | */ |
||
| 14 | public function file(string $themepath, string $filepath) : ?object |
||
| 15 | { |
||
| 16 | $file = $this->parserFilename($themepath, $filepath); |
||
| 17 | $type = $this->parseType($file); |
||
| 18 | $name = $this->parseFullName($file); |
||
| 19 | |||
| 20 | if (! $name || ! $type) return null; |
||
| 21 | |||
| 22 | $request = [ |
||
| 23 | 'name' => $name, |
||
| 24 | 'type' => $type |
||
| 25 | ]; |
||
| 26 | |||
| 27 | return (object) $request; |
||
| 28 | } |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Retorna o nome do arquivo e seu diretório, |
||
| 32 | * dado seu caminho dentro do sistema |
||
| 33 | * |
||
| 34 | * @param string $path |
||
| 35 | * @return object|null |
||
| 36 | */ |
||
| 37 | public function filename(string $file) : ?object |
||
| 38 | { |
||
| 39 | $name = $this->parseOnlyName($file); |
||
|
0 ignored issues
–
show
|
|||
| 40 | $folder = $this->parseFolder($file); |
||
|
0 ignored issues
–
show
Are you sure the assignment to
$folder is correct as $this->parseFolder($file) targeting Maestriam\Samurai\Founda...meParser::parseFolder() seems to always return null.
This check looks for function or method calls that always return null and whose return value is assigned to a variable. class A
{
function getObject()
{
return null;
}
}
$a = new A();
$object = $a->getObject();
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. Loading history...
|
|||
| 41 | |||
| 42 | if (! $name) { |
||
|
0 ignored issues
–
show
|
|||
| 43 | return null; |
||
| 44 | } |
||
| 45 | |||
| 46 | return (object) ['name' => $name, 'folder' => $folder]; |
||
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Interpreta a resposta do usuário para pegar |
||
| 51 | * o e-mail e nome do autor |
||
| 52 | * |
||
| 53 | * @param string $author |
||
| 54 | * @return object |
||
| 55 | */ |
||
| 56 | public function author(string $author) : object |
||
| 57 | { |
||
| 58 | $pieces = explode(' <', $author); |
||
| 59 | |||
| 60 | $obj = [ |
||
| 61 | 'name' => $pieces[0], |
||
| 62 | 'email' => str_replace('>', '', $pieces[1]), |
||
| 63 | ]; |
||
| 64 | |||
| 65 | return (object) $obj; |
||
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Undocumented function |
||
| 70 | * |
||
| 71 | * @param string $vendor |
||
| 72 | * @return object |
||
| 73 | */ |
||
| 74 | public function vendor(string $vendor) : object |
||
| 75 | { |
||
| 76 | $pieces = explode('/', $vendor); |
||
| 77 | |||
| 78 | return (object) [ |
||
| 79 | 'distributor' => $pieces[0], |
||
| 80 | 'name' => $pieces[1] |
||
| 81 | ]; |
||
| 82 | } |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Retorna apenas o nome do arquivo da diretiva |
||
| 86 | * Sem o caminho do tema a qual pertence |
||
| 87 | * |
||
| 88 | * @param string $theme |
||
| 89 | * @param string $path |
||
| 90 | * @return string |
||
| 91 | */ |
||
| 92 | private function parserFilename(string $theme, string $path) : string |
||
| 93 | { |
||
| 94 | return str_replace($theme . DS, '', $path); |
||
| 95 | } |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Undocumented function |
||
| 99 | * |
||
| 100 | * @param string $path |
||
| 101 | * @return array |
||
| 102 | */ |
||
| 103 | private function parseType(string $path) : string |
||
| 104 | { |
||
| 105 | $pieces = explode(DS, $path); |
||
| 106 | |||
| 107 | $filename = array_pop($pieces); |
||
| 108 | $filename = str_replace('.blade.php', '', $filename); |
||
| 109 | |||
| 110 | $name = explode('-', $filename); |
||
| 111 | $type = end($name) ?? null; |
||
| 112 | |||
| 113 | return $type; |
||
|
0 ignored issues
–
show
|
|||
| 114 | } |
||
| 115 | |||
| 116 | /** |
||
| 117 | * Undocumented function |
||
| 118 | * |
||
| 119 | * @param string $theme |
||
| 120 | * @param string $path |
||
| 121 | * @return string|null |
||
| 122 | */ |
||
| 123 | private function parseFullName(string $path) : ?string |
||
| 124 | { |
||
| 125 | $pieces = explode(DS, $path); |
||
| 126 | |||
| 127 | $name = array_pop($pieces); |
||
| 128 | |||
| 129 | if (empty($pieces)) { |
||
| 130 | return $name; |
||
| 131 | } |
||
| 132 | |||
| 133 | $name = (count($pieces) > 1) ? implode(DS, $pieces) : $pieces[0]; |
||
| 134 | |||
| 135 | return (! strlen($name)) ? null : $name; |
||
| 136 | } |
||
| 137 | |||
| 138 | /** |
||
| 139 | * Undocumented function |
||
| 140 | * |
||
| 141 | * @param string $name |
||
| 142 | * @return void |
||
| 143 | */ |
||
| 144 | private function parseFolder(string $name) |
||
| 145 | { |
||
| 146 | $pieces = explode('/', $name); |
||
| 147 | |||
| 148 | array_pop($pieces); |
||
| 149 | |||
| 150 | return implode(DS, $pieces); |
||
|
0 ignored issues
–
show
|
|||
| 151 | } |
||
| 152 | |||
| 153 | /** |
||
| 154 | * Undocumented function |
||
| 155 | * |
||
| 156 | * @param string $name |
||
| 157 | * @return void |
||
| 158 | */ |
||
| 159 | private function parseOnlyName(string $name) |
||
| 160 | { |
||
| 161 | $pieces = explode('/', $name); |
||
| 162 | |||
| 163 | return array_pop($pieces); |
||
| 164 | } |
||
| 165 | } |
||
| 166 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.