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

SettingsReader   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A read() 0 12 2
A fileExists() 0 4 1
A isReadable() 0 4 1
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