1 | <?php |
||
10 | class Code |
||
11 | { |
||
12 | private $name; |
||
13 | |||
14 | private $className; |
||
15 | |||
16 | private $config; |
||
17 | |||
18 | private $attributes = []; |
||
19 | |||
20 | private $dependencies = []; |
||
21 | |||
22 | private $files; |
||
23 | |||
24 | 4 | public function __construct($name, $config, $dependencies = [], Filesystem $files = null, UseSortFixer $useSortFixer = null) |
|
36 | |||
37 | public function __toString() |
||
41 | |||
42 | 2 | public function getAttributes($prefix = null) |
|
43 | { |
||
44 | 2 | if (empty($prefix) === true) { |
|
45 | return $this->attributes; |
||
46 | } |
||
47 | |||
48 | 2 | $attributes = []; |
|
49 | 2 | foreach ($this->attributes as $key => $value) { |
|
50 | 2 | $attributes[$prefix.'_'.$key] = $value; |
|
51 | } |
||
52 | |||
53 | 2 | return $attributes; |
|
54 | } |
||
55 | |||
56 | 4 | public function render() |
|
60 | |||
61 | 1 | public function store() |
|
62 | { |
||
63 | 1 | foreach ($this->dependencies as $dependency) { |
|
64 | 1 | $dependency->store(); |
|
65 | } |
||
66 | |||
67 | 1 | $file = Arr::get($this->config, 'path', '').'/'.$this->className.'.'.Arr::get($this->config, 'extension', 'php'); |
|
68 | 1 | $directory = dirname($file); |
|
69 | |||
70 | 1 | if ($this->files->isDirectory($directory) === false) { |
|
71 | 1 | $this->files->makeDirectory($directory, 0755, true); |
|
72 | } |
||
73 | |||
74 | 1 | return $this->files->exists($file) === false |
|
75 | 1 | ? $this->files->put($file, $this->render()) |
|
76 | 1 | : false; |
|
77 | } |
||
78 | |||
79 | 4 | private function getDummyAttributes() |
|
80 | { |
||
81 | 4 | $dummy = []; |
|
82 | 4 | foreach ($this->attributes as $key => $value) { |
|
83 | 4 | $dummy['Dummy'.Str::studly($key)] = $value; |
|
84 | 4 | $dummy['dummy'.Str::studly($key)] = Str::camel($value); |
|
85 | } |
||
86 | |||
87 | 4 | return $dummy; |
|
88 | } |
||
89 | |||
90 | 4 | private function renderStub() |
|
94 | |||
95 | 4 | private function format($content, $useSort = false) |
|
99 | |||
100 | 4 | private function mergeAttributes($dependencies) |
|
101 | { |
||
102 | 4 | $attributes = array_merge(Arr::get($this->config, 'attributes', []), [ |
|
122 | } |
||
123 |
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: