1 | <?php |
||
17 | class Extract extends Model |
||
18 | { |
||
19 | |||
20 | /** |
||
21 | * Max parsing width (in columns) |
||
22 | */ |
||
23 | const MAX_COLS = 500; |
||
24 | |||
25 | /** |
||
26 | * Max parsing depth (in rows) |
||
27 | */ |
||
28 | const MAX_LINES = 5000; |
||
29 | |||
30 | /** |
||
31 | * An array of REGEXP patterns keyed by file extension |
||
32 | * @var array |
||
33 | */ |
||
34 | protected $patterns = array( |
||
35 | 'twig' => '/text\s*\(\s*([\'"])(.+?)\1\s*([\),])/s', // {{ text('Text to translate') }} |
||
|
|||
36 | 'js' => '/GplCart.text\s*\(\s*([\'"])(.+?)\1\s*([\),])/s', // GplCart.text('Text to translate'); |
||
37 | 'php' => array( |
||
38 | '/->text\s*\(\s*([\'"])(.+?)\1\s*([\),])/s', // $this->language->text('Text to translate'); |
||
39 | '/\/\*(?:\*|\s)+@text(?:\*|\s)+\*\/\s*([\'"])(.+?)\1\s*/', // /* @text */ 'Text to translate' |
||
40 | ) |
||
41 | ); |
||
42 | |||
43 | /** |
||
44 | * Constructor |
||
45 | */ |
||
46 | public function __construct() |
||
50 | |||
51 | /** |
||
52 | * Returns a pattern by a file extension or an array of pattern keyed by extension |
||
53 | * @param null|string $extension |
||
54 | * @return array|string |
||
55 | */ |
||
56 | public function getPattern($extension = null) |
||
73 | |||
74 | /** |
||
75 | * Returns an array of extracted strings from a file |
||
76 | * @param string $file |
||
77 | * @return array |
||
78 | */ |
||
79 | public function extractFromFile($file) |
||
104 | |||
105 | /** |
||
106 | * Returns an array of extracted strings from a source string |
||
107 | * @param string $string |
||
108 | * @param string|array $patterns |
||
109 | * @return array |
||
110 | */ |
||
111 | public function extractFromString($string, $patterns) |
||
130 | |||
131 | /** |
||
132 | * Clean up an array of extracted strings or a single string |
||
133 | * @param array|string $items |
||
134 | * @return array |
||
135 | */ |
||
136 | protected function clean($items) |
||
149 | |||
150 | /** |
||
151 | * Returns an array of scanned files to extract from or counts them |
||
152 | * @param array $options |
||
153 | * @return integer|array |
||
154 | */ |
||
155 | public function scan(array $options) |
||
180 | |||
181 | /** |
||
182 | * Whether the file can be parsed |
||
183 | * @param string $file |
||
184 | * @return bool |
||
185 | */ |
||
186 | public function isSupportedFile($file) |
||
190 | |||
191 | /** |
||
192 | * Returns an array of directories to be scanned |
||
193 | * @return array |
||
194 | */ |
||
195 | public function getScannedDirectories() |
||
207 | |||
208 | /** |
||
209 | * Recursive scans files in a directory |
||
210 | * @param string $directory |
||
211 | * @param array $results |
||
212 | * @return array |
||
213 | */ |
||
214 | protected function scanRecursive($directory, &$results = array()) |
||
232 | |||
233 | } |
||
234 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.