Completed
Push — master ( f87faf...b3e46e )
by Pablo
03:15
created

PreCommitConfig::getMessages()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php
2
3
namespace PhpGitHooks\Application\Config;
4
5
use PhpGitHooks\Application\Message\MessageConfigData;
6
use PhpGitHooks\Infrastructure\Disk\Config\ConfigFileReaderInterface;
7
use Symfony\Component\Config\Definition\Exception\Exception;
8
9
/**
10
 * Class PreCommitConfig.
11
 */
12
class PreCommitConfig implements HookConfigInterface, HookConfigExtraToolInterface
13
{
14
    const HOOK_NAME = 'pre-commit';
15
    /** @var  ConfigFileReaderInterface */
16
    private $configFileReader;
17
18
    /**
19
     * PreCommitConfig constructor.
20
     *
21
     * @param ConfigFileReaderInterface $configFileReader
22
     */
23 6
    public function __construct(ConfigFileReaderInterface $configFileReader)
24
    {
25 6
        $this->configFileReader = $configFileReader;
26 6
    }
27
28
    /**
29
     * @param $service
30
     *
31
     * @return bool
32
     */
33 4
    public function isEnabled($service)
34
    {
35 4
        $data = $this->getData();
36
37 3
        if (false === isset($data[$service]) || false === is_bool($data[$service])) {
38 2
            return false;
39
        }
40
41 1
        return $data[$service];
42
    }
43
44
    /**
45
     * @return array
46
     */
47 5
    private function getData()
48
    {
49 5
        $data = $this->configFileReader->getFileContents();
50
51 5
        if (!$data) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $data of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
52 1
            throw new Exception('php-git-hooks.yml file not found');
53
        }
54
55 4
        return $data[self::HOOK_NAME]['execute'];
56
    }
57
58
    /**
59
     * @return array
60
     */
61 1
    public function getMessages()
62
    {
63 1
        $data = $this->configFileReader->getFileContents();
64
65 1
        return $data[self::HOOK_NAME][MessageConfigData::TOOL];
66
    }
67
68
    /**
69
     * @param array $tool
70
     *
71
     * @return array
72
     */
73 1
    public function extraOptions($tool)
74
    {
75 1
        $data = $this->getData();
76
77 1
        return $data[$tool];
78
    }
79
}
80