Conditions | 31 |
Paths | 47 |
Total Lines | 104 |
Code Lines | 68 |
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 |
||
70 | public function loadFile($filename, $subDir = null) |
||
71 | { |
||
72 | if (is_file($filename)) { |
||
73 | if (strpos($filename, 'font') !== false) { |
||
74 | $this->fonts->append($filename); |
||
75 | } else { |
||
76 | $type = pathinfo($filename, PATHINFO_EXTENSION); |
||
77 | |||
78 | switch ($type) { |
||
79 | case 'css': |
||
80 | $this->styles->append($filename); |
||
81 | break; |
||
82 | |||
83 | case 'js': |
||
84 | $this->javascripts->append($filename); |
||
85 | break; |
||
86 | } |
||
87 | } |
||
88 | } elseif (isset($subDir)) { |
||
89 | $type = pathinfo($filename, PATHINFO_EXTENSION); |
||
90 | |||
91 | if (empty($type)) { |
||
92 | $type = substr($subDir, 0, -1); |
||
93 | } |
||
94 | |||
95 | switch ($type) { |
||
96 | case 'css': |
||
97 | if (input()->env('DEBUG_STAGE') === 'PRODUCTION') { |
||
98 | if (false !== ($filePath = $this->getFilePath($filename . '.min.css', $subDir))) { |
||
|
|||
99 | $this->styles->append($filePath); |
||
100 | } |
||
101 | } else { |
||
102 | if (false !== ($filePath = $this->getFilePath($filename . '.css', $subDir))) { |
||
103 | $this->styles->append($filePath); |
||
104 | } |
||
105 | } |
||
106 | break; |
||
107 | |||
108 | case 'fonts': |
||
109 | if (input()->env('DEBUG_STAGE') === 'PRODUCTION') { |
||
110 | if (false !== ($filePath = $this->getFilePath($filename . '.min.css', $subDir))) { |
||
111 | $this->fonts->append($filePath); |
||
112 | } |
||
113 | } else { |
||
114 | if (false !== ($filePath = $this->getFilePath($filename . '.css', $subDir))) { |
||
115 | $this->fonts->append($filePath); |
||
116 | } |
||
117 | } |
||
118 | break; |
||
119 | |||
120 | case 'js': |
||
121 | if (input()->env('DEBUG_STAGE') === 'PRODUCTION') { |
||
122 | if (false !== ($filePath = $this->getFilePath($filename . '.min.js', $subDir))) { |
||
123 | $this->styles->append($filePath); |
||
124 | } |
||
125 | } else { |
||
126 | if (false !== ($filePath = $this->getFilePath($filename . '.js', $subDir))) { |
||
127 | $this->styles->append($filePath); |
||
128 | } |
||
129 | } |
||
130 | break; |
||
131 | } |
||
132 | } else { |
||
133 | $type = pathinfo($filename, PATHINFO_EXTENSION); |
||
134 | |||
135 | if (empty($type)) { |
||
136 | if (input()->env('DEBUG_STAGE') === 'PRODUCTION') { |
||
137 | // Search Style or Font |
||
138 | if (false !== ($filePath = $this->getFilePath($filename . '.min.css'))) { |
||
139 | $this->styles->append($filePath); |
||
140 | } elseif (false !== ($filePath = $this->getFilePath($filename . '.min.css'))) { |
||
141 | $this->fonts->append($filePath); |
||
142 | } |
||
143 | |||
144 | // Search Javascript |
||
145 | if (false !== ($filePath = $this->getFilePath($filename . '.min.js'))) { |
||
146 | $this->javascripts->append($filePath); |
||
147 | } |
||
148 | } else { |
||
149 | // Search Style or Font |
||
150 | if (false !== ($filePath = $this->getFilePath($filename . '.css'))) { |
||
151 | $this->styles->append($filePath); |
||
152 | } elseif (false !== ($filePath = $this->getFilePath($filename . '.css'))) { |
||
153 | $this->fonts->append($filePath); |
||
154 | } |
||
155 | |||
156 | // Search Javascript |
||
157 | if (false !== ($filePath = $this->getFilePath($filename . '.js'))) { |
||
158 | $this->javascripts->append($filePath); |
||
159 | } |
||
160 | } |
||
161 | } else { |
||
162 | switch ($type) { |
||
163 | case 'css': |
||
164 | if (false !== ($filePath = $this->getFilePath($filename))) { |
||
165 | $this->styles->append($filePath); |
||
166 | } |
||
167 | break; |
||
168 | |||
169 | case 'js': |
||
170 | if (false !== ($filePath = $this->getFilePath($filename))) { |
||
171 | $this->javascripts->append($filePath); |
||
172 | } |
||
173 | break; |
||
174 | } |
||
299 | } |