Conditions | 30 |
Paths | 0 |
Total Lines | 109 |
Code Lines | 72 |
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 |
||
83 | public function giveFile($file) { |
||
84 | if (!file_exists($file) && file_exists(mb_convert_encoding($file, 'Windows-1251', 'UTF-8'))) { |
||
85 | $file = mb_convert_encoding($file, 'Windows-1251', 'UTF-8'); |
||
86 | } |
||
87 | if (!file_exists($file)) { |
||
88 | header('HTTP/1.1 404 Not Found'); |
||
89 | exit(); |
||
90 | } |
||
91 | |||
92 | $fileinfo = pathinfo($file); |
||
93 | if (empty($fileinfo['extension'])) { |
||
94 | header('HTTP/1.1 404 Not Found'); |
||
95 | exit(); |
||
96 | } |
||
97 | |||
98 | if (!empty($_GET['resize'])) { |
||
99 | |||
100 | $allow_resize = false; |
||
101 | if (App::$cur->db->connect) { |
||
102 | $type = Files\Type::get($fileinfo['extension'], 'ext'); |
||
103 | $allow_resize = $type ? $type->allow_resize : false; |
||
104 | } |
||
105 | if (!$type && in_array(strtolower($fileinfo['extension']), array('png', 'jpg', 'jpeg', 'gif'))) { |
||
106 | $allow_resize = true; |
||
107 | } |
||
108 | if ($allow_resize) { |
||
109 | |||
110 | $sizes = explode('x', $_GET['resize']); |
||
111 | $sizes[0] = intval($sizes[0]); |
||
112 | if (isset($sizes[1])) { |
||
113 | $sizes[1] = intval($sizes[1]); |
||
114 | } else { |
||
115 | $sizes[1] = 0; |
||
116 | } |
||
117 | |||
118 | if (!$sizes[0] || !$sizes[1]) { |
||
119 | header('HTTP/1.1 404 Not Found'); |
||
120 | exit(); |
||
121 | } elseif ($sizes[0] > 2000 || $sizes[1] > 2000) { |
||
122 | header('HTTP/1.1 404 Not Found'); |
||
123 | exit(); |
||
124 | } else { |
||
125 | $dir = App::$primary->path; |
||
126 | |||
127 | if (!empty($_GET['resize_crop'])) { |
||
128 | if (in_array($_GET['resize_crop'], array('q', 'c'))) { |
||
129 | $crop = $_GET['resize_crop']; |
||
130 | } else { |
||
131 | $crop = 'c'; |
||
132 | } |
||
133 | } elseif (!empty($_GET['resize_quadro'])) { |
||
134 | $crop = 'q'; |
||
135 | } else { |
||
136 | $crop = ''; |
||
137 | } |
||
138 | $pos = 'center'; |
||
139 | if (!empty($_GET['resize_pos']) && in_array($_GET['resize_pos'], array('top', 'center'))) { |
||
140 | $pos = $_GET['resize_pos']; |
||
141 | } |
||
142 | $file = INJI_BASE_DIR . rtrim(Statics::file($file, $sizes[0] . 'x' . $sizes[1], $crop, $pos, true), '/'); |
||
143 | } |
||
144 | } |
||
145 | } |
||
146 | |||
147 | $request = getallheaders(); |
||
148 | if (isset($request['If-Modified-Since'])) { |
||
149 | // Разделяем If-Modified-Since (Netscape < v6 отдаёт их неправильно) |
||
150 | $modifiedSince = explode(';', $request['If-Modified-Since']); |
||
151 | |||
152 | // Преобразуем запрос клиента If-Modified-Since в таймштамп |
||
153 | $modifiedSince = strtotime($modifiedSince[0]); |
||
154 | } else { |
||
155 | // Устанавливаем время модификации в ноль |
||
156 | $modifiedSince = 0; |
||
157 | } |
||
158 | |||
159 | header("Cache-control: public"); |
||
160 | header("Accept-Ranges: bytes"); |
||
161 | header("Pragma: public"); |
||
162 | header("Content-Length: " . filesize($file)); |
||
163 | header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($file)) . ' GMT'); |
||
164 | header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 60 * 60 * 24 * 256) . ' GMT'); |
||
165 | if (filemtime($file) <= $modifiedSince && (!isset($_SERVER['HTTP_CACHE_CONTROL']) || $_SERVER['HTTP_CACHE_CONTROL'] != 'no-cache')) { |
||
166 | // Разгружаем канал передачи данных! |
||
167 | header('HTTP/1.1 304 Not Modified'); |
||
168 | exit(); |
||
169 | } |
||
170 | |||
171 | header('Content-Description: File Transfer'); |
||
172 | if (isset($this->mimes[strtolower($fileinfo['extension'])])) { |
||
173 | header("Content-Type: " . $this->mimes[strtolower($fileinfo['extension'])]); |
||
174 | } |
||
175 | |||
176 | if (isset($_GET['frustrate_dl']) || in_array($fileinfo['extension'], array('doc', 'docx', 'xls', 'xlsx'))) { |
||
177 | |||
178 | $fileName = $fileinfo['filename'] . '.' . $fileinfo['extension']; |
||
179 | if (App::$cur->db->connect) { |
||
180 | $fileObj = Files\File::get(['path', '%/' . $fileinfo['filename'] . '.' . $fileinfo['extension'], 'LIKE']); |
||
181 | if ($fileObj) { |
||
182 | $fileName = $fileObj->original_name; |
||
183 | } |
||
184 | } |
||
185 | header('Content-Disposition: attachment; filename="' . $fileName . '"'); |
||
186 | } |
||
187 | |||
188 | header('Content-Transfer-Encoding: binary'); |
||
189 | |||
190 | readfile($file); |
||
191 | exit(); |
||
192 | } |
||
193 | } |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths