LockFile::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace Composed;
3
4
/**
5
 * @author Josh Di Fabio <[email protected]>
6
 */
7
class LockFile
8
{
9
    private $root;
10
    private $json;
11
    private $packages;
12
13
    public function __construct(RootPackage $root, JsonObject $json)
14
    {
15
        $this->root = $root;
16
        $this->json = $json;
17
    }
18
19
    public static function fromFilePath(RootPackage $root, string $filePath) : self
20
    {
21
        return new self($root, JsonObject::fromFilePath($filePath));
22
    }
23
24 View Code Duplication
    public function getPackages() : PackageCollection
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...
25
    {
26
        if (null === $this->packages) {
27
            $packages = [];
28
            $packagesData = $this->json->get(['packages'], []);
29
            foreach ($packagesData as $packageData) {
30
                $package = Package::fromArray($this->root, $packageData);
31
                $packages[$package->getName()] = $package;
32
            }
33
            $this->packages = new PackageCollection($packages);
34
        }
35
36
        return $this->packages;
37
    }
38
39 View Code Duplication
    public function getDevPackages() : PackageCollection
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...
40
    {
41
        if (null === $this->packages) {
42
            $packages = [];
43
            $packagesData = $this->json->get(['packages-dev'], []);
44
            foreach ($packagesData as $packageData) {
45
                $package = Package::fromArray($this->root, $packageData);
46
                $packages[$package->getName()] = $package;
47
            }
48
            $this->packages = new PackageCollection($packages);
49
        }
50
51
        return $this->packages;
52
    }
53
54
    public function get($keys = [], $default = null)
55
    {
56
        return $this->json->get($keys, $default);
57
    }
58
}
59