Passed
Pull Request — master (#15)
by Dmitriy
13:06
created

ComposerUpdateHook   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A executeBeforeFirstTest() 0 16 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Composer\Config\Tests\Integration;
6
7
use PHPUnit\Runner\BeforeFirstTestHook;
8
9
final class ComposerUpdateHook implements BeforeFirstTestHook
10
{
11
    public function executeBeforeFirstTest(): void
12
    {
13
        $commandArguments = $_SERVER['argv'] ?? [];
14
        $isDebug = in_array('--debug', $commandArguments, true);
15
        $hideLogs = !$isDebug ? '2>/dev/null' : '';
16
        $command = sprintf(
17
            'cd %s && %s && %s',
18
            __DIR__ . '/Environment',
19
            'rm vendor -rf ' . $hideLogs,
20
            'composer upd -n --prefer-dist --no-progress --no-suggest --ignore-platform-reqs ' . $hideLogs
21
        );
22
23
        $res = exec($command, $_, $returnCode);
24
25
        if ((int) $returnCode !== 0) {
26
            throw new \RuntimeException($res);
27
        }
28
    }
29
}
30