Passed
Push — master ( 5cfb80...5d8a7b )
by CodexShaper
13:02
created

Install_Composer::__construct()   A

Complexity

Conditions 4
Paths 11

Size

Total Lines 30
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 14
nc 11
nop 0
dl 0
loc 30
rs 9.7998
c 0
b 0
f 0
1
<?php
2
3
class Install_Composer
4
{
5
	public function __construct()
6
	{
7
		if (! file_exists(__DIR__.'/vendor/autoload.php')) {
8
9
			require_once __DIR__.'/install/vendor/autoload.php';
10
11
			if(file_exists(__DIR__ . '/install/vendor/bin/composer')) {
12
				echo "composer file exists";
13
			}
14
15
			// Composer\Factory::getHomeDir() method 
16
			// needs COMPOSER_HOME environment variable set
17
			putenv('COMPOSER_HOME=' . __DIR__ . '/install/vendor/bin/composer');
18
19
			// call `composer install` command programmatically
20
			// if (file_exists(getcwd().'/composer.phar')) {
21
			//     $composer = '"'.PHP_BINARY.'" '.getcwd().'/composer.phar';
22
			// }
23
24
			$composer = 'composer';
25
26
			try {
27
				$process = \Symfony\Component\Process\Process::fromShellCommandline($composer.' install');
28
		    	$process->setEnv([
29
		    		'COMPOSER_HOME' => __DIR__ . '/install/vendor/bin/composer',
30
		    	]);
31
		    	$process->setTimeout(null); // Setting timeout to null to prevent installation from stopping at a certain point in time
32
		    	$process->setWorkingDirectory(__DIR__)->mustRun();
33
			} catch (\Exception $ex) {
34
				echo $ex->getMessage();
35
			}
36
		}
37
	}
38
}