AbstractFileLoader   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 40
wmc 5
lcom 1
cbo 2
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A matchExtension() 0 10 3
A validateExtension() 0 11 2
1
<?php
2
/*
3
 * This file is part of the Borobudur-Config package.
4
 *
5
 * (c) Hexacodelabs <http://hexacodelabs.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Borobudur\Config\FileLoader;
12
13
use Borobudur\Config\Exception\InvalidArgumentException;
14
15
/**
16
 * @author      Iqbal Maulana <[email protected]>
17
 * @created     8/12/15
18
 */
19
abstract class AbstractFileLoader implements FileLoaderInterface
20
{
21
    use FileTrait;
22
23
    /**
24
     * @var array
25
     */
26
    protected $extensions = array();
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function matchExtension($extension)
32
    {
33
        foreach($this->extensions as $ext) {
34
            if ($extension === $ext) {
35
                return true;
36
            }
37
        }
38
39
        return false;
40
    }
41
42
    /**
43
     * Validate extensions.
44
     *
45
     * @param string $extension
46
     */
47
    protected function validateExtension($extension)
48
    {
49
        if (!in_array($extension, $this->extensions)) {
50
            throw new InvalidArgumentException(sprintf(
51
                '%s cannot process file with extension "%s". Accepted extension: "%s"',
52
                get_called_class(),
53
                $extension,
54
                implode(', ', $this->extensions)
55
            ));
56
        }
57
    }
58
}
59