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 |
||
60 | |||
61 | self::addTypeFilter(self::EXTENSION_CSS, function ($fileName) { |
||
62 | return strpos($fileName, '.css') !== false; |
||
63 | }); |
||
64 | |||
65 | self::addTypeFilter(self::EXTENSION_JS, function ($fileName) { |
||
66 | return strpos($fileName, '.js') === strlen($fileName) - 3; |
||
67 | }); |
||
68 | |||
69 | self::addTypeFilter(self::EXTENSION_SASS, function ($fileName) { |
||
70 | return strpos($fileName, '.scss') !== false || strpos($fileName, '.sass') !== false; |
||
71 | }); |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * @param string $type |
||
76 | * @param callable $filter |
||
77 | */ |
||
78 | public static function addTypeFilter(string $type, callable $filter) { |
||
79 | self::$typeFilters[$type][] = $filter; |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * @param $fileName |
||
84 | * |
||
85 | * @return Parser|null |
||
86 | */ |
||
87 | public function getByFileName($fileName) : ?Parser { |
||
88 | if (!is_string($fileName)) { |
||
89 | return null; |
||
90 | } |
||
91 | |||
92 | $type = self::PARSER_DEFAULT; |
||
93 | |||
94 | /** |
||
95 | * @var string $filterType |
||
96 | * @var callable[] $filters |
||
97 | */ |
||
98 | foreach (self::$typeFilters as $filterType => $filters) { |
||
99 | foreach ($filters as $filterCheck) { |
||
100 | if ($filterCheck($fileName)) { |
||
101 | $type = $filterType; |
||
102 | break; |
||
103 | } |
||
127 |