ServeVendorStep   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 1
cbo 3
dl 0
loc 33
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 27 3
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