Completed
Push — add/relase-scripts-package ( 6d2bc4 )
by Yaroslav
29:20 queued 22:51
created

Dependency_Tree::generate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
1
<?php
2
/**
3
 * Extended Composer's ShowCommand to get access to
4
 *
5
 * @package automattic/jetpack-scripts
6
 */
7
8
namespace Automattic\Jetpack\Scripts;
9
10
use Composer\Console\Application;
11
use Composer\Command\ShowCommand;
12
use Composer\Package\Version\VersionParser;
13
14
/**
15
 * Extended Composer's ShowCommand to get access to
16
 */
17
class Dependency_Tree extends ShowCommand {
18
	/**
19
	 * Composer instance
20
	 *
21
	 * @var Composer|null
22
	 */
23
	private $composer;
24
25
	/**
26
	 * Simple constructor
27
	 */
28
	public function __construct() {
29
		// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
30
		$this->versionParser = new VersionParser();
31
	}
32
33
	/**
34
	 * Returns Composer instance
35
	 */
36
	public function get_composer() {
37
		if ( null === $this->composer ) {
38
			$application    = new Application();
39
			$this->composer = $application->getComposer( true, null );
40
		}
41
42
		return $this->composer;
43
	}
44
45
	/**
46
	 * Generates a dependency tree
47
	 */
48
	public static function generate() {
49
		$it             = new Dependency_Tree();
50
		$package        = $it->get_composer()->getPackage();
51
		$repos          = $it->get_composer()->getRepositoryManager()->getLocalRepository();
52
		$installed_repo = $repos;
53
54
		$array_tree = $it->generatePackageTree( $package, $installed_repo, $repos );
55
56
		return $array_tree;
57
	}
58
}
59