ComposerInstall   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 93.75%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 51
ccs 15
cts 16
cp 0.9375
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 6 1
A findPhp() 0 10 2
A run() 0 5 1
A getPriority() 0 4 1
1
<?php
2
3
declare(strict_types = 1);
4
5
/*
6
 * This file is part of the skeleton package.
7
 *
8
 * (c) Gennady Knyazkin <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Gennadyx\Skeleton\Action;
15
16
use Gennadyx\Skeleton\Action\Traits\EventAwareTrait;
17
use Gennadyx\Skeleton\EventAwareInterface;
18
use Symfony\Component\Process\PhpExecutableFinder;
19
use Symfony\Component\Process\Process;
20
21
/**
22
 * Class ComposerInstall
23
 *
24
 * @author Gennady Knyazkin <[email protected]>
25
 */
26
final class ComposerInstall implements ActionInterface, EventAwareInterface
27
{
28
    use EventAwareTrait;
29
30
    /**
31
     * Execute action
32
     *
33
     * @return void
34
     * @throws \Exception
35
     */
36 2
    public function execute()
37
    {
38 2
        $phpBin  = $this->findPhp();
39 2
        $command = sprintf('%s %s update', $phpBin, realpath($_SERVER['argv'][0]));
40 2
        $this->run($command);
41 2
    }
42
43
    /**
44
     * @return string
45
     * @throws \RuntimeException
46
     */
47 2
    private function findPhp(): string
48
    {
49 2
        $phpBin = (new PhpExecutableFinder())->find();
50
51 2
        if (false === $phpBin) {
52
            throw new \RuntimeException('Failed to locate PHP binary to execute "composer install"');
53
        }
54
55 2
        return $phpBin;
56
    }
57
58
    /**
59
     * @param string $command
60
     *
61
     * @throws \Exception
62
     */
63 2
    private function run(string $command)
64
    {
65 2
        $cmd = new Process($command);
66 2
        $cmd->run();
67 2
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72 4
    public function getPriority(): int
73
    {
74 4
        return PHP_INT_MAX;
75
    }
76
}
77