Conditions | 12 |
Paths | 11 |
Total Lines | 43 |
Code Lines | 22 |
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 |
||
41 | public function getByFileName($fileName) : ?Parser { |
||
42 | if (!is_string($fileName)) { |
||
43 | return null; |
||
44 | } |
||
45 | |||
46 | if (strpos($fileName, '/') === strlen($fileName) - 1) { |
||
47 | return $this->getByType(self::EXTENSION_FOLDER); |
||
48 | } |
||
49 | |||
50 | if (strpos($fileName, '.json') !== false) { |
||
51 | return $this->getByType(self::EXTENSION_JSON); |
||
52 | } |
||
53 | |||
54 | if (strpos($fileName, '.md') !== false) { |
||
55 | return $this->getByType(self::EXTENSION_MD); |
||
56 | } |
||
57 | |||
58 | if (strpos($fileName, '.yml') !== false) { |
||
59 | return $this->getByType(self::EXTENSION_YML); |
||
60 | } |
||
61 | |||
62 | if (strpos($fileName, '.jpg') !== false) { |
||
63 | return $this->getByType(self::EXTENSION_IMG); |
||
64 | } |
||
65 | |||
66 | if (strpos($fileName, '.png') !== false) { |
||
67 | return $this->getByType(self::EXTENSION_IMG); |
||
68 | } |
||
69 | |||
70 | if (strpos($fileName, '.css') !== false) { |
||
71 | return $this->getByType(self::EXTENSION_CSS); |
||
72 | } |
||
73 | |||
74 | if (strpos($fileName, '.js') !== false) { |
||
75 | return $this->getByType(self::EXTENSION_JS); |
||
76 | } |
||
77 | |||
78 | if (strpos($fileName, '.scss') !== false || strpos($fileName, '.sass') !== false) { |
||
79 | return $this->getByType(self::EXTENSION_SASS); |
||
80 | } |
||
81 | |||
82 | return $this->getByType(self::PARSER_DEFAULT); |
||
83 | } |
||
84 | |||
116 |