VendorConfigExtractor::getConfig()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 3
nop 2
dl 0
loc 17
rs 9.9666
c 0
b 0
f 0
1
<?php
2
/**
3
 * Copyright © Vaimo Group. All rights reserved.
4
 * See LICENSE_VAIMO.txt for license details.
5
 */
6
namespace Vaimo\ComposerPatches\Package\ConfigExtractors;
7
8
use Vaimo\ComposerPatches\Config;
9
10
class VendorConfigExtractor implements \Vaimo\ComposerPatches\Interfaces\PackageConfigExtractorInterface
11
{
12
    /**
13
     * @var \Vaimo\ComposerPatches\Package\InfoResolver
14
     */
15
    private $packageInfoResolver;
16
17
    /**
18
     * @var \Vaimo\ComposerPatches\Package\ConfigReader
19
     */
20
    private $configLoader;
21
22
    /**
23
     * @param \Vaimo\ComposerPatches\Package\InfoResolver $packageInfoResolver
24
     */
25
    public function __construct(
26
        \Vaimo\ComposerPatches\Package\InfoResolver $packageInfoResolver
27
    ) {
28
        $this->packageInfoResolver = $packageInfoResolver;
29
30
        $this->configLoader = new \Vaimo\ComposerPatches\Package\ConfigReader();
31
    }
32
33
    public function getConfig(\Composer\Package\PackageInterface $package, $configKey)
34
    {
35
        $source = $this->packageInfoResolver->getSourcePath($package)
36
            . DIRECTORY_SEPARATOR
37
            . Config::PACKAGE_CONFIG_FILE;
38
39
        if (!file_exists($source)) {
40
            return null;
41
        }
42
43
        $fileContents = $this->configLoader->readToArray($source);
44
45
        if (!isset($fileContents[$configKey])) {
46
            return null;
47
        }
48
49
        return $fileContents[$configKey];
50
    }
51
}
52