These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Recca0120\Generator; |
||
4 | |||
5 | use Illuminate\Support\Arr; |
||
6 | use Illuminate\Filesystem\Filesystem; |
||
7 | use Recca0120\Generator\Fixers\UseSortFixer; |
||
8 | |||
9 | class Generator |
||
10 | { |
||
11 | private $config; |
||
12 | |||
13 | private $fils; |
||
14 | |||
15 | private $useSortFixer; |
||
16 | |||
17 | 3 | public function __construct($config, Filesystem $files = null, UseSortFixer $useSortFixer = null) |
|
18 | { |
||
19 | 3 | $this->config = $config; |
|
20 | 3 | $this->files = $files ?: new Filesystem; |
|
0 ignored issues
–
show
|
|||
21 | 3 | $this->useSortFixer = $useSortFixer ?: new UseSortFixer(); |
|
22 | 3 | } |
|
23 | |||
24 | 3 | public function generate($command, $name) |
|
25 | { |
||
26 | 3 | $config = Arr::get($this->config, $command, []); |
|
27 | |||
28 | 3 | return new Code( |
|
29 | 3 | $name, |
|
30 | 3 | $config, |
|
31 | 3 | $this->generateDependencies($name, Arr::get($config, 'dependencies', [])), |
|
32 | 3 | $this->files, |
|
33 | 3 | $this->useSortFixer |
|
34 | 3 | ); |
|
35 | } |
||
36 | |||
37 | 3 | private function generateDependencies($name, $dependencies) |
|
38 | { |
||
39 | 3 | $codes = []; |
|
40 | 3 | foreach ($dependencies as $dependency) { |
|
41 | 1 | $dependencyConfig = Arr::get($this->config, $dependency, []); |
|
42 | 1 | $codes[$dependency] = new Code( |
|
43 | 1 | $name, |
|
44 | 1 | $dependencyConfig, |
|
45 | 1 | [], |
|
46 | 1 | $this->files, |
|
47 | 1 | $this->useSortFixer |
|
48 | 1 | ); |
|
49 | 3 | } |
|
50 | |||
51 | 3 | return $codes; |
|
52 | } |
||
53 | } |
||
54 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: