Conditions | 6 |
Paths | 6 |
Total Lines | 67 |
Code Lines | 39 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
58 | public function handle() { |
||
59 | $start = microtime(true); |
||
60 | |||
61 | $this->line(''); |
||
62 | |||
63 | $aFiles = []; |
||
64 | |||
65 | $valid_extensions = ['php', 'html', 'js']; |
||
66 | $folders = [ |
||
67 | 'app', |
||
68 | 'resources/views', |
||
69 | 'resources/assets', |
||
70 | ]; |
||
71 | |||
72 | $regexes = [ |
||
73 | 'default' => '/(?:[\@|\_]t\()\'(?\'identifier\'.*?)\'(?:\)|(?:, (?\'parameters\'\[.*\]))(?:\)|, \'(?\'locale\'\w*?)\'))/', |
||
74 | 'js' => '/\$filter\(\'translate\'\)\(\'(?\'identifier\'.*?)\'\)/' |
||
75 | ]; |
||
76 | |||
77 | foreach ($folders as $folder) { |
||
78 | $aFiles = array_merge($aFiles, File::allFiles(base_path() . '/' . $folder)); |
||
79 | } |
||
80 | |||
81 | TranslatorFacade::setLocale('de_DE'); |
||
82 | |||
83 | $num_files = count($aFiles); |
||
84 | |||
85 | $this->bar = $this->output->createProgressBar($num_files); |
||
86 | $this->bar->setMessage('Analyzing ' . $num_files . ' files'); |
||
87 | $this->bar->setFormat('very_verbose'); |
||
88 | |||
89 | foreach ($aFiles as $file) { |
||
90 | |||
91 | $extension = $file->getExtension(); |
||
92 | |||
93 | if (in_array($extension, $valid_extensions)) { |
||
94 | $content = file_get_contents($file); |
||
95 | |||
96 | foreach ($regexes as $key => $regex) { |
||
97 | preg_match_all($regex, $content, $result, PREG_SET_ORDER); |
||
98 | |||
99 | if (!empty($result[0])) { |
||
100 | $this->addMissing($result, $key); |
||
101 | } |
||
102 | } |
||
103 | } |
||
104 | $this->bar->advance(); |
||
105 | } |
||
106 | |||
107 | $this->bar->finish(); |
||
108 | $this->line(''); |
||
109 | $this->line(''); |
||
110 | |||
111 | $this->table( |
||
112 | ['Num', 'Translations...'], |
||
113 | [ |
||
114 | [$this->found_identifier, "Found"], |
||
115 | [$this->new_identifier, "New"], |
||
116 | [$this->dupl_identifier, "Duplicates"], |
||
117 | [$this->found_parameters, "With Parameters"], |
||
118 | [$this->found_invalid, "Invalid"], |
||
119 | ] |
||
120 | ); |
||
121 | |||
122 | $this->line(''); |
||
123 | |||
124 | $this->info('Finished in: ' . number_format(microtime(true) - $start, 2) . 'sec'); |
||
125 | } |
||
187 | } |