InstallComposer::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 6

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 11
nc 6
nop 0
dl 0
loc 18
rs 9.9
c 1
b 0
f 0
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