Completed
Push — master ( e36450...afb05a )
by Josh
02:57
created

LockFile   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 52
Duplicated Lines 53.85 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 28
loc 52
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 3

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A fromFilePath() 0 4 1
A getPackages() 14 14 3
A getDevPackages() 14 14 3
A get() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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