Completed
Branch master (537795)
by
unknown
33:10
created

ComposerLock   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 29
loc 29
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 3 3 1
B getInstalledDependencies() 14 14 5

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
3
/**
4
 * Reads a composer.lock file and provides accessors to get
5
 * its hash and what is installed
6
 *
7
 * @since 1.25
8
 */
9 View Code Duplication
class ComposerLock {
0 ignored issues
show
Duplication introduced by
This class 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...
10
11
	/**
12
	 * @param string $location
13
	 */
14
	public function __construct( $location ) {
15
		$this->contents = json_decode( file_get_contents( $location ), true );
0 ignored issues
show
Bug introduced by
The property contents does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
16
	}
17
18
	/**
19
	 * Dependencies currently installed according to composer.lock
20
	 *
21
	 * @return array
22
	 */
23
	public function getInstalledDependencies() {
24
		$deps = [];
25
		foreach ( $this->contents['packages'] as $installed ) {
26
			$deps[$installed['name']] = [
27
				'version' => ComposerJson::normalizeVersion( $installed['version'] ),
28
				'type' => $installed['type'],
29
				'licenses' => isset( $installed['license'] ) ? $installed['license'] : [],
30
				'authors' => isset( $installed['authors'] ) ? $installed['authors'] : [],
31
				'description' => isset( $installed['description'] ) ? $installed['description']: '',
32
			];
33
		}
34
35
		return $deps;
36
	}
37
}
38