|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Yarak\Console; |
|
4
|
|
|
|
|
5
|
|
|
use Yarak\Helpers\Creator; |
|
6
|
|
|
use Yarak\Helpers\NamespaceResolver; |
|
7
|
|
|
|
|
8
|
|
|
class DirectoryCreator extends Creator |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* Create all directories and files for console. |
|
12
|
|
|
*/ |
|
13
|
|
|
public function create($createExample = true) |
|
14
|
|
|
{ |
|
15
|
|
|
$createdDirs = (bool) count($this->makeDirectoryStructure([ |
|
16
|
|
|
'console' => $this->config->getConsoleDirectory(), |
|
17
|
|
|
'commands' => $this->config->getCommandsDirectory(), |
|
18
|
|
|
], $this->output)); |
|
19
|
|
|
|
|
20
|
|
|
$createdKernel = $this->createKernel(); |
|
21
|
|
|
|
|
22
|
|
|
$createdExample = $createExample ? $this->createExampleCommand() : false; |
|
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
$this->outputNothingCreated([$createdDirs, $createdKernel]); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Create the kernel file. |
|
29
|
|
|
* |
|
30
|
|
|
* @return bool |
|
31
|
|
|
*/ |
|
32
|
|
View Code Duplication |
protected function createKernel() |
|
|
|
|
|
|
33
|
|
|
{ |
|
34
|
|
|
$path = $this->config->getConsoleDirectory('Kernel.php'); |
|
35
|
|
|
|
|
36
|
|
|
if (!file_exists($path)) { |
|
37
|
|
|
$this->writeFile( |
|
38
|
|
|
$path, |
|
39
|
|
|
$this->getKernelStub() |
|
40
|
|
|
); |
|
41
|
|
|
|
|
42
|
|
|
$this->output->writeInfo('Created kernel file.'); |
|
43
|
|
|
|
|
44
|
|
|
return true; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
return false; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Get the kernel stub. |
|
52
|
|
|
* |
|
53
|
|
|
* @return string |
|
54
|
|
|
*/ |
|
55
|
|
|
protected function getKernelStub() |
|
56
|
|
|
{ |
|
57
|
|
|
$stub = file_get_contents(__DIR__.'/Stubs/kernel.stub'); |
|
58
|
|
|
|
|
59
|
|
|
return $this->setNamespace($stub, NamespaceResolver::resolve('console')); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Create an example command. |
|
64
|
|
|
* |
|
65
|
|
|
* @return bool |
|
66
|
|
|
*/ |
|
67
|
|
View Code Duplication |
protected function createExampleCommand() |
|
|
|
|
|
|
68
|
|
|
{ |
|
69
|
|
|
$path = $this->config->getCommandsDirectory('ExampleCommand.php'); |
|
70
|
|
|
|
|
71
|
|
|
if (!file_exists($path)) { |
|
72
|
|
|
$this->writeFile( |
|
73
|
|
|
$path, |
|
74
|
|
|
$this->getExampleStub() |
|
75
|
|
|
); |
|
76
|
|
|
|
|
77
|
|
|
$this->output->writeInfo('Created example command file.'); |
|
78
|
|
|
|
|
79
|
|
|
return true; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
return false; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
protected function getExampleStub() |
|
86
|
|
|
{ |
|
87
|
|
|
$stub = file_get_contents(__DIR__.'/Stubs/exampleCommand.stub'); |
|
88
|
|
|
|
|
89
|
|
|
return $this->setNamespace($stub, NamespaceResolver::resolve('console', 'Commands')); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.