Conditions | 18 |
Paths | 40 |
Total Lines | 53 |
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 |
||
29 | public function actionCheckGuide($directory = null) |
||
30 | { |
||
31 | if ($directory === null) { |
||
32 | $directory = \dirname(\dirname(__DIR__)) . '/docs'; |
||
33 | } |
||
34 | if (is_file($directory)) { |
||
35 | $files = [$directory]; |
||
36 | } else { |
||
37 | $files = FileHelper::findFiles($directory, [ |
||
38 | 'only' => ['*.md'], |
||
39 | ]); |
||
40 | } |
||
41 | |||
42 | foreach ($files as $file) { |
||
43 | $content = file_get_contents($file); |
||
44 | $chars = preg_split('//u', $content, null, PREG_SPLIT_NO_EMPTY); |
||
45 | |||
46 | $line = 1; |
||
47 | $pos = 0; |
||
48 | foreach ($chars as $c) { |
||
49 | $ord = $this->unicodeOrd($c); |
||
50 | |||
51 | $pos++; |
||
52 | if ($ord == 0x000A) { |
||
53 | $line++; |
||
54 | $pos = 0; |
||
55 | } |
||
56 | |||
57 | if ($ord === false) { |
||
58 | $this->found('BROKEN UTF8', $c, $line, $pos, $file); |
||
59 | continue; |
||
60 | } |
||
61 | |||
62 | // http://unicode-table.com/en/blocks/general-punctuation/ |
||
63 | if (0x2000 <= $ord && $ord <= 0x200F |
||
64 | || 0x2028 <= $ord && $ord <= 0x202E |
||
65 | || 0x205f <= $ord && $ord <= 0x206F |
||
66 | ) { |
||
67 | $this->found('UNSUPPORTED SPACE CHARACTER', $c, $line, $pos, $file); |
||
68 | continue; |
||
69 | } |
||
70 | if ($ord < 0x0020 && $ord != 0x000A && $ord != 0x0009 || |
||
71 | 0x0080 <= $ord && $ord < 0x009F) { |
||
72 | $this->found('CONTROL CHARARCTER', $c, $line, $pos, $file); |
||
73 | continue; |
||
74 | } |
||
75 | // if ($ord > 0x009F) { |
||
76 | // $this->found("NON ASCII CHARARCTER", $c, $line, $pos, $file); |
||
77 | // continue; |
||
78 | // } |
||
79 | } |
||
80 | } |
||
81 | } |
||
82 | |||
127 |