Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
ComposerLock
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getInstalledDependencies
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3namespace Wikimedia\Composer;
4
5/**
6 * Reads a composer.lock file and provides accessors to get
7 * its hash and what is installed
8 *
9 * @since 1.25
10 */
11class ComposerLock {
12    /**
13     * @var array[]
14     * @phan-var array{packages:array{name:string,version:string,type:string,license?:string,authors?:mixed,description?:string}}
15     */
16    private $contents;
17
18    /**
19     * @param string $location
20     */
21    public function __construct( $location ) {
22        $this->contents = json_decode( file_get_contents( $location ), true );
23    }
24
25    /**
26     * Dependencies currently installed according to composer.lock
27     *
28     * @return array[]
29     */
30    public function getInstalledDependencies() {
31        $deps = [];
32        foreach ( $this->contents['packages'] as $installed ) {
33            $deps[$installed['name']] = [
34                'version' => ComposerJson::normalizeVersion( $installed['version'] ),
35                'type' => $installed['type'],
36                'licenses' => $installed['license'] ?? [],
37                'authors' => $installed['authors'] ?? [],
38                'description' => $installed['description'] ?? '',
39            ];
40        }
41
42        return $deps;
43    }
44}