ServeVendorStep::execute()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 9.488
c 0
b 0
f 0
cc 3
nc 3
nop 2
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
use Symfony\Component\Process\Process;
16
17
/**
18
 * @author Hubert Moutot <[email protected]>
19
 */
20
class ServeVendorStep extends AbstractStep
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function execute(ConsumerEvent $event, $directory)
26
    {
27
        $sha1LockFile = sha1_file($this->workingTempPath.'/'.$directory.'/composer.lock');
28
        $resultPath = $this->rootDir.'/../web/assets/'.$sha1LockFile;
29
30
        if (is_file($resultPath.'/vendor.zip')) {
31
            $this->triggerNewStep($event, ['message' => 'Serving cached vendor.zip']);
32
33
            return 0;
34
        }
35
36
        $this->triggerNewStep($event, ['message' => 'Compressing vendor.zip']);
37
38
        $this->filesystem->mkdir($resultPath);
39
40
        $process = new Process('zip -rq '.$resultPath.'/vendor.zip .');
41
        $process->setWorkingDirectory($this->workingTempPath.'/'.$directory);
42
        $process->run();
43
44
        if (!$process->isSuccessful()) {
45
            $this->triggerError($event, ['message' => $process->getErrorOutput()]);
46
47
            return 1;
48
        }
49
50
        return 0;
51
    }
52
}
53