Completed
Push — master ( bc7d7f...7a9596 )
by Théo
02:46
created

FileExtensionCompactor   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
dl 0
loc 24
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A supports() 0 9 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the box project.
7
 *
8
 * (c) Kevin Herrera <[email protected]>
9
 *     Théo Fidry <[email protected]>
10
 *
11
 * This source file is subject to the MIT license that is bundled
12
 * with this source code in the file LICENSE.
13
 */
14
15
namespace KevinGH\Box\Compactor;
16
17
/**
18
 * An abstract compactor class that handles matching supported file by their types.
19
 */
20
abstract class FileExtensionCompactor implements Compactor
21
{
22
    private $extensions;
23
24
    /**
25
     * @param string[] $extensions the list of supported file extensions
26
     */
27
    public function __construct(array $extensions)
28
    {
29
        $this->extensions = $extensions;
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function supports(string $file): bool
36
    {
37
        return in_array(
38
            pathinfo(
39
                $file,
40
                PATHINFO_EXTENSION
41
            ),
42
            $this->extensions,
43
            true
44
        );
45
    }
46
}
47