GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ClassMetadataFactory::resolveCache()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.4285
cc 2
eloc 6
nc 2
nop 0
crap 2
1
<?php
2
3
namespace Ma27\ApiKeyAuthenticationBundle\Service\Mapping;
4
5
use Ma27\ApiKeyAuthenticationBundle\Service\Mapping\Driver\ModelConfigurationDriverInterface;
6
use Symfony\Component\Filesystem\Filesystem;
7
8
/**
9
 * ClassMetadataFactory builds a metadata object from a driver or cache.
10
 *
11
 * @internal This code is part of the internal API to gather the appropriate model information and shouldn't be used for else use-cases
12
 */
13
final class ClassMetadataFactory
14
{
15
    /**
16
     * @var ModelConfigurationDriverInterface
17
     */
18
    private $driver;
19
20
    /**
21
     * @var Filesystem
22
     */
23
    private $filesystem;
24
25
    /**
26
     * @var bool
27
     */
28
    private $isCacheEnabled;
29
30
    /**
31
     * @var string
32
     */
33
    private $cacheFile;
34
35
    /**
36
     * Constructor.
37
     *
38
     * @param ModelConfigurationDriverInterface $driver
39
     * @param Filesystem                        $filesystem
40
     * @param bool                              $isCacheEnabled
41
     * @param string                            $cacheFile
42
     */
43 17
    public function __construct(ModelConfigurationDriverInterface $driver, Filesystem $filesystem, $isCacheEnabled, $cacheFile)
44
    {
45 17
        $this->driver = $driver;
46 17
        $this->filesystem = $filesystem;
47 17
        $this->isCacheEnabled = (bool) $isCacheEnabled;
48 17
        $this->cacheFile = $cacheFile;
49 17
    }
50
51
    /**
52
     * Creates the class metadata object.
53
     *
54
     * @return ClassMetadata
55
     */
56 17
    public function createMetadataObject()
57
    {
58 17
        return new ClassMetadata($this->resolveProperties());
59
    }
60
61
    /**
62
     * Resolves the class properties.
63
     *
64
     * @return \ReflectionProperty[]
65
     */
66 17
    private function resolveProperties()
67
    {
68 17
        if ($this->isCacheEnabled) {
69 9
            return $this->resolveCache();
70
        }
71
72 8
        return $this->driver->getMetadataForUser();
73
    }
74
75
    /**
76
     * Fetches the data from the cache.
77
     *
78
     * @return \ReflectionProperty[]
79
     */
80 9
    private function resolveCache()
81
    {
82 9
        if (!$this->filesystem->exists($this->cacheFile)) {
83 1
            throw new \RuntimeException(sprintf(
84 1
                'The file "%s" can\'t be parsed!',
85 1
                $this->cacheFile
86
            ));
87
        }
88
89 8
        return unserialize(file_get_contents($this->cacheFile));
90
    }
91
}
92