Code Duplication    Length = 22-22 lines in 2 locations

src/MapHandler.php 2 locations

@@ 216-237 (lines=22) @@
213
     *
214
     * @return $this
215
     */
216
    public function setTypeDefaultExtension($type, $extension)
217
    {
218
        $type = strtolower($type);
219
        $extension = (string) strtolower($extension);
220
221
        if (!isset($this->map['types'][$type])) {
222
            throw new MappingException('Cannot set ' . $extension . ' as default extension for type ' . $type . ', type not defined');
223
        }
224
        $key = array_search($extension, $this->map['types'][$type]);
225
        if ($key === false) {
226
            throw new MappingException('Cannot set ' . $extension . ' as default extension for type ' . $type . ', extension not associated to this type');
227
        }
228
        $tmp = [$extension];
229
        foreach ($this->map['types'][$type] as $k => $v) {
230
            if ($k === $key) {
231
                continue;
232
            }
233
            $tmp[] = $v;
234
        }
235
        $this->map['types'][$type] = $tmp;
236
        return $this;
237
    }
238
239
    /**
240
     * Changes the default MIME type for a file extension.
@@ 251-272 (lines=22) @@
248
     *
249
     * @return $this
250
     */
251
    public function setExtensionDefaultType($extension, $type)
252
    {
253
        $type = strtolower($type);
254
        $extension = (string) strtolower($extension);
255
256
        if (!isset($this->map['extensions'][$extension])) {
257
            throw new MappingException('Cannot set ' . $type . ' as default type for extension ' . $extension . ', extension not defined');
258
        }
259
        $key = array_search($type, $this->map['extensions'][$extension]);
260
        if ($key === false) {
261
            throw new MappingException('Cannot set ' . $type . ' as default type for extension ' . $extension . ', type not associated to this extension');
262
        }
263
        $tmp = [$type];
264
        foreach ($this->map['extensions'][$extension] as $k => $v) {
265
            if ($k === $key) {
266
                continue;
267
            }
268
            $tmp[] = $v;
269
        }
270
        $this->map['extensions'][$extension] = $tmp;
271
        return $this;
272
    }
273
}
274