Completed
Push — master ( bc91aa...cd6df5 )
by Eric
115:14 queued 112:36
created

AbstractFileClassMetadataLoader   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 95%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 64
ccs 19
cts 20
cp 0.95
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 3
A getMappedClasses() 0 8 2
loadFile() 0 1 ?
A loadData() 0 10 3
1
<?php
2
3
/*
4
 * This file is part of the Ivory Serializer package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ivory\Serializer\Mapping\Loader;
13
14
use Ivory\Serializer\Type\Parser\TypeParserInterface;
15
16
/**
17
 * @author GeLo <[email protected]>
18
 */
19
abstract class AbstractFileClassMetadataLoader extends AbstractClassMetadataLoader implements MappedClassMetadataLoaderInterface
20
{
21
    /**
22
     * @var string
23
     */
24
    private $file;
25
26
    /**
27
     * @var mixed[]
28
     */
29
    private $data;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
30
31
    /**
32
     * @param string                   $file
33
     * @param TypeParserInterface|null $typeParser
34
     */
35 1396
    public function __construct($file, TypeParserInterface $typeParser = null)
36
    {
37 1396
        parent::__construct($typeParser);
38
39 1396
        if (!is_file($file)) {
40 24
            throw new \InvalidArgumentException(sprintf('The file "%s" does not exist.', $file));
41
        }
42
43 1396
        if (!is_readable($file)) {
44
            throw new \InvalidArgumentException(sprintf('The file "%s" is not readable.', $file));
45
        }
46
47 1396
        $this->file = $file;
48 1396
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53 560
    public function getMappedClasses()
54
    {
55 560
        if ($this->data === null) {
56 560
            $this->data = $this->loadFile($this->file);
57 280
        }
58
59 560
        return array_keys($this->data);
60
    }
61
62
    /**
63
     * @param string $file
64
     *
65
     * @return mixed[]
66
     */
67
    abstract protected function loadFile($file);
68
69
    /**
70
     * {@inheritdoc}
71
     */
72 1236
    protected function loadData($class)
73
    {
74 1236
        if ($this->data === null) {
75 676
            $this->data = $this->loadFile($this->file);
76 276
        }
77
78 1112
        if (isset($this->data[$class])) {
79 1084
            return $this->data[$class];
80
        }
81 28
    }
82
}
83