Code Duplication    Length = 36-36 lines in 2 locations

src/Type.php 2 locations

@@ 332-367 (lines=36) @@
329
     *
330
     * @return string[]
331
     */
332
    public function getAliases($strict = true)
333
    {
334
        $map = MapHandler::map();
335
        $subject = $this->toString(static::SHORT_TEXT);
336
337
        // Find all types.
338
        $types = [];
339
        if (!$this->isWildcard()) {
340
            if ($map->hasType($subject)) {
341
                $types[] = $subject;
342
            }
343
        } else {
344
            foreach ($map->listTypes($subject) as $t) {
345
                $types[] = $t;
346
            }
347
        }
348
349
        // No types found, throw exception or return emtpy array.
350
        if (empty($types)) {
351
            if ($strict) {
352
                throw new MappingException('No MIME type found for ' . $subject . ' in map');
353
            } else {
354
                return [];
355
            }
356
        }
357
358
        // Build the array of extensions.
359
        $aliases = [];
360
        foreach ($types as $t) {
361
            foreach ($map->getTypeAliases($t) as $a) {
362
                $aliases[$a] = $a;
363
            }
364
        }
365
366
        return array_keys($aliases);
367
    }
368
369
    /**
370
     * Returns the MIME type's preferred file extension.
@@ 418-453 (lines=36) @@
415
     *
416
     * @return string[]
417
     */
418
    public function getExtensions($strict = true)
419
    {
420
        $map = MapHandler::map();
421
        $subject = $this->toString(static::SHORT_TEXT);
422
423
        // Find all types.
424
        $types = [];
425
        if (!$this->isWildcard()) {
426
            if ($map->hasType($subject)) {
427
                $types[] = $subject;
428
            }
429
        } else {
430
            foreach ($map->listTypes($subject) as $t) {
431
                $types[] = $t;
432
            }
433
        }
434
435
        // No types found, throw exception or return emtpy array.
436
        if (empty($types)) {
437
            if ($strict) {
438
                throw new MappingException('No MIME type found for ' . $subject . ' in map');
439
            } else {
440
                return [];
441
            }
442
        }
443
444
        // Build the array of extensions.
445
        $extensions = [];
446
        foreach ($types as $t) {
447
            foreach ($map->getTypeExtensions($t) as $e) {
448
                $extensions[$e] = $e;
449
            }
450
        }
451
452
        return array_keys($extensions);
453
    }
454
}
455