Code Duplication    Length = 29-30 lines in 2 locations

includes/libs/composer/ComposerInstalled.php 1 location

@@ 9-38 (lines=30) @@
6
 *
7
 * @since 1.27
8
 */
9
class ComposerInstalled {
10
11
	/**
12
	 * @param string $location
13
	 */
14
	public function __construct( $location ) {
15
		$this->contents = json_decode( file_get_contents( $location ), true );
16
	}
17
18
	/**
19
	 * Dependencies currently installed according to installed.json
20
	 *
21
	 * @return array
22
	 */
23
	public function getInstalledDependencies() {
24
		$deps = [];
25
		foreach ( $this->contents 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
		ksort( $deps );
36
		return $deps;
37
	}
38
}
39

includes/libs/composer/ComposerLock.php 1 location

@@ 9-37 (lines=29) @@
6
 *
7
 * @since 1.25
8
 */
9
class ComposerLock {
10
11
	/**
12
	 * @param string $location
13
	 */
14
	public function __construct( $location ) {
15
		$this->contents = json_decode( file_get_contents( $location ), true );
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