ComposerUpdateStep   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 4
dl 0
loc 39
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 33 5
1
<?php
2
3
/*
4
 * This file is part of `Composer as a service`.
5
 *
6
 * (c) Pascal Borreli <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ayaline\Bundle\ComposerBundle\Consumer\Step;
13
14
use Sonata\NotificationBundle\Consumer\ConsumerEvent;
15
16
/**
17
 * @author Hubert Moutot <[email protected]>
18
 */
19
class ComposerUpdateStep extends AbstractStep
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function execute(ConsumerEvent $event, $directory)
25
    {
26
        $this->triggerNewStep($event, ['message' => './composer update']);
27
28
        $output = null;
29
        $workingDirectory = $this->workingTempPath.'/'.$directory;
30
31
        $hasDevDeps = $event->getMessage()->getValue('hasDevDependencies');
32
        $requireDevOption = true === $hasDevDeps ? '--dev' : '--no-dev';
33
34
        $commandLine = sprintf('%s update %s', $this->composerBinPath, $requireDevOption);
35
        $commandLine .= ' --no-interaction --no-autoloader --no-scripts --prefer-dist --no-progress --no-plugins --ignore-platform-reqs --no-custom-installers';
36
37
        $process = $this->runProcess($commandLine, $workingDirectory, $output);
38
39
        if (!$process->isSuccessful()) {
40
            $this->triggerError($event, ['message' => nl2br($output)]);
41
            $this->triggerStepError($event, ['message' => 'Composer failed']);
42
43
            return 1;
44
        }
45
46
        if (!is_dir($this->workingTempPath.'/'.$directory.'/vendor')
47
            || !is_file($this->workingTempPath.'/'.$directory.'/composer.lock')) {
48
            $this->triggerStepError($event, ['message' => 'Fatal error during composer update']);
49
50
            return 1;
51
        }
52
53
        $this->triggerComposerOutput($event, ['message' => $process->getOutput()]);
54
55
        return 0;
56
    }
57
}
58