RootPackage::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Composed;
3
4
/**
5
 * @author Josh Di Fabio <[email protected]>
6
 */
7
class RootPackage extends AbstractPackage
8
{
9
    private $packages;
10
    private $installedPackagesFile;
11
12
    public function __construct(string $dirPath, JsonObject $config)
13
    {
14
        parent::__construct($this, $dirPath, $config);
15
    }
16
17
    public static function createFromPath(string $dirPath) : self
18
    {
19
        return new static($dirPath, JsonObject::fromFilePath($dirPath . DIRECTORY_SEPARATOR . 'composer.json'));
20
    }
21
22
    /**
23
     * Returns all packages in the project, including the root one
24
     */
25
    public function getPackages() : PackageCollection
26
    {
27
        if (null === $this->packages) {
28
            $packages = array_merge(
29
                array(
30
                    $this->getName() => $this,
31
                ),
32
                $this->getInstalledPackagesFile()->getPackages()->toArray()
33
            );
34
35
            $this->packages = new PackageCollection($packages);
36
        }
37
38
        return $this->packages;
39
    }
40
41
    public function getLockFile() : LockFile
42
    {
43
        if (null === $lockFile = parent::getLockFile()) {
44
            throw new \RuntimeException('Lock file not found.');
45
        }
46
47
        return $lockFile;
48
    }
49
50 View Code Duplication
    public function getInstalledPackagesFile() : InstalledPackagesFile
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
51
    {
52
        if (null === $this->installedPackagesFile) {
53
            $filePath = $this->getPath('vendor/composer/installed.json');
54
            if (file_exists($filePath)) {
55
                $this->installedPackagesFile = InstalledPackagesFile::fromFilePath($this, $filePath);
56
            }
57
        }
58
59
        return $this->installedPackagesFile;
60
    }
61
62
    public function getVendorDir() : string
63
    {
64
        return 'vendor';
65
    }
66
67
    public function getVendorPath(string $relativePath = '') : string
68
    {
69
        return $this->getPath($this->getVendorDir() . (strlen($relativePath) ? DIRECTORY_SEPARATOR . $relativePath : ''));
70
    }
71
}
72