1 | <?php |
||
13 | class LineAligner implements LineAlignerInterface |
||
14 | { |
||
15 | /** |
||
16 | * Variable assignment code line regex |
||
17 | */ |
||
18 | const VARIABLE_ASSIGNMENT_REGEX_BEGIN = '^([^=\(]*)\s'; |
||
19 | const VARIABLE_ASSIGNMENT_REGEX_END = '\s(.*)$'; |
||
20 | |||
21 | private $allAssignmentCharacters = array( |
||
22 | '=', |
||
23 | '=>', |
||
24 | '\.=', |
||
25 | '<=', |
||
26 | ); |
||
27 | |||
28 | /** |
||
29 | * Constructor |
||
30 | * |
||
31 | * @param FileManagerInterface $fileManager |
||
32 | */ |
||
33 | public function __construct(FileManagerInterface $fileManager) |
||
37 | |||
38 | /** |
||
39 | * Search and align variable assignments code lines in a file |
||
40 | * |
||
41 | * @param string $filepath |
||
42 | * |
||
43 | * @throws Exception |
||
44 | */ |
||
45 | public function align($filepath) |
||
61 | |||
62 | /** |
||
63 | * Find in given eligible VariableAssignmentLineBlocks |
||
64 | * |
||
65 | * @param string $filepath |
||
66 | * |
||
67 | * @return array |
||
68 | */ |
||
69 | private function findBlocks($filepath) |
||
119 | |||
120 | /** |
||
121 | * Clean file lines according to found VariableAssignmentLineBlocks |
||
122 | * |
||
123 | * @param string $filepath |
||
124 | * @param array $blocks |
||
125 | * |
||
126 | * @return array |
||
127 | */ |
||
128 | private function createCleanedFile($filepath, array $blocks) |
||
150 | |||
151 | /** |
||
152 | * @param array $assignmentCharacters |
||
153 | * |
||
154 | * @return string |
||
155 | */ |
||
156 | private function buildVariableAssignmentLinePattern(array $assignmentCharacters) |
||
181 | |||
182 | /** |
||
183 | * Build alignment space |
||
184 | * |
||
185 | * @param integer $length |
||
186 | * |
||
187 | * @return string |
||
188 | */ |
||
189 | private function buildAlignmentSpace($length) |
||
198 | |||
199 | /** |
||
200 | * Filter valid blocks from given array of VariableAssignmentLineBlock |
||
201 | * |
||
202 | * @param array $blocks array of VariableAssignmentLineBlock |
||
203 | * |
||
204 | * @return array of valid VariableAssignmentLineBlock |
||
205 | */ |
||
206 | private function getValidBlocks(array $blocks) |
||
218 | } |
||
219 |
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: