Completed
Push — master ( 265a2d...f9e310 )
by jerome
05:38 queued 02:58
created

SettingsReader::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace DP\Core\CoreBundle\Settings;
4
5
use Psr\Log\LoggerInterface;
6
use Symfony\Component\Yaml\Exception\ParseException;
7
use Symfony\Component\Yaml\Yaml;
8
9
class SettingsReader
10
{
11
    /**
12
     * @var string
13
     */
14
    private $filePath;
15
16
    /**
17
     * @var Logger
18
     */
19
    private $logger;
20
21
    /**
22
     * @param string $filePath
23
     * @param LoggerInterface $logger
24
     */
25
    public function __construct($filePath, LoggerInterface $logger)
26
    {
27
        $this->filePath = $filePath;
28
        $this->logger   = $logger;
0 ignored issues
show
Documentation Bug introduced by
It seems like $logger of type object<Psr\Log\LoggerInterface> is incompatible with the declared type object<DP\Core\CoreBundle\Settings\Logger> of property $logger.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
29
    }
30
31
    /**
32
     * @return array
33
     */
34
    public function read()
35
    {
36
        $settings = [];
37
38
        try {
39
            $settings = Yaml::parse($this->filePath);
40
        } catch (ParseException $e) {
41
            $this->logger->error(sprintf('Unable to read the core settings file "%s".', $this->filePath));
42
        }
43
44
        return $settings;
45
    }
46
47
    /**
48
     * @return bool
49
     */
50
    public function fileExists()
51
    {
52
        return file_exists($this->filePath);
53
    }
54
55
    /**
56
     * @return bool
57
     */
58
    public function isReadable()
59
    {
60
        return is_readable($this->filePath);
61
    }
62
}
63