PatchesFile   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 48
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A load() 0 25 5
1
<?php
2
/**
3
 * Copyright © Vaimo Group. All rights reserved.
4
 * See LICENSE_VAIMO.txt for license details.
5
 */
6
namespace Vaimo\ComposerPatches\Patch\SourceLoaders;
7
8
use Vaimo\ComposerPatches\Config as PluginConfig;
9
10
class PatchesFile implements \Vaimo\ComposerPatches\Interfaces\PatchSourceLoaderInterface
11
{
12
    /**
13
     * @var \Composer\Installer\InstallationManager
14
     */
15
    private $installationManager;
16
17
    /**
18
     * @var \Vaimo\ComposerPatches\Package\ConfigReader
19
     */
20
    private $configLoader;
21
22
    /**
23
     * @param \Composer\Installer\InstallationManager $installationManager
24
     */
25
    public function __construct(
26
        \Composer\Installer\InstallationManager $installationManager
27
    ) {
28
        $this->installationManager = $installationManager;
29
30
        $this->configLoader = new \Vaimo\ComposerPatches\Package\ConfigReader();
31
    }
32
33
    public function load(\Composer\Package\PackageInterface $package, $source)
34
    {
35
        if (!is_array($source)) {
36
            $source = array($source);
37
        }
38
39
        $basePath = getcwd();
40
41
        if (!$package instanceof \Composer\Package\RootPackageInterface) {
42
            $basePath = $this->installationManager->getInstallPath($package);
43
        }
44
45
        $groups = array();
46
47
        foreach ($source as $item) {
48
            $fileContents = $this->configLoader->readToArray($basePath . DIRECTORY_SEPARATOR . $item);
49
50
            if (isset($fileContents[PluginConfig::DEFINITIONS_LIST])) {
51
                $fileContents = $fileContents[PluginConfig::DEFINITIONS_LIST];
52
            }
53
54
            $groups[] = $fileContents;
55
        }
56
57
        return $groups;
58
    }
59
}
60