InstallComposer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 25
rs 10
c 1
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 18 3
1
<?php
2
/**
3
 * Install composer.
4
 *
5
 * @link       https://github.com/maab16
6
 * @since      1.0.0
7
 */
8
9
/**
10
 * Register all actions and filters for the plugin.
11
 *
12
 * Maintain a list of all hooks that are registered throughout
13
 * the plugin, and register them with the WordPress API. Call the
14
 * run function to execute the list of actions and filters.
15
 *
16
 * @author     Md Abu Ahsan basir <[email protected]>
17
 */
18
class InstallComposer
19
{
20
    /**
21
     * Install composer factory.
22
     *
23
     * @since    1.0.0
24
     */
25
    public function __construct()
26
    {
27
        if (!file_exists(__DIR__.'/../vendor/autoload.php')) {
28
            require_once __DIR__.'/../vendor/autoload.php';
29
30
            $composer = 'composer';
31
32
            try {
33
                $process = \Symfony\Component\Process\Process::fromShellCommandline($composer.' install');
34
                $process->setEnv(
35
                    [
36
                        'COMPOSER_HOME' => __DIR__.'/../vendor/bin/composer',
37
                    ]
38
                );
39
                $process->setTimeout(null); // Setting timeout to null to prevent installation from stopping at a certain point in time.
40
                $process->setWorkingDirectory(__DIR__)->mustRun();
41
            } catch (\Exception $ex) {
42
                echo $ex->getMessage();
43
            }
44
        }
45
    }
46
}
47