Completed
Pull Request — master (#336)
by Jordi Sala
65:17
created

CKEditorScriptHandler::createCommand()   D

Complexity

Conditions 9
Paths 64

Size

Total Lines 33
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 17.7468

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 33
ccs 11
cts 21
cp 0.5238
rs 4.909
cc 9
eloc 17
nc 64
nop 1
crap 17.7468
1
<?php
2
3
/*
4
 * This file is part of the Ivory CKEditor package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ivory\CKEditorBundle\Composer;
13
14
use Composer\Script\CommandEvent;
15
use Composer\Script\Event;
16
use Sensio\Bundle\DistributionBundle\Composer\ScriptHandler;
17
18
/**
19
 * @author GeLo <[email protected]>
20
 */
21
class CKEditorScriptHandler extends ScriptHandler
22
{
23
    /**
24
     * @param CommandEvent|Event $event
25
     */
26 20
    public static function install($event)
27
    {
28 20
        static::executeCommand(
29 20
            $event,
30 20
            static::getConsoleDir($event, 'Install CKEditor'),
31 20
            static::createCommand($event)
32 16
        );
33 20
    }
34
35
    /**
36
     * @param CommandEvent|Event $event
37
     *
38
     * @return string
39
     */
40 20
    protected static function createCommand($event)
41
    {
42 20
        $extra = $event->getComposer()->getPackage()->getExtra();
43 20
        $command = 'ckeditor:install';
44
45 20
        if (isset($extra['ckeditor-path'])) {
46
            $command .= ' '.$extra['ckeditor-path'];
47
        }
48
49 20
        if (isset($extra['ckeditor-release'])) {
50
            $command .= ' --release='.$extra['ckeditor-release'];
51
        }
52
53 20
        if (isset($extra['ckeditor-tag'])) {
54
            $command .= ' --tag='.$extra['ckeditor-tag'];
55
        }
56
57 20
        if (isset($extra['ckeditor-clear'])) {
58 20
            $command .= ' --clear='.$extra['ckeditor-clear'];
59 16
        }
60
61 20
        if (isset($extra['ckeditor-quiet']) && $extra['ckeditor-quiet'] === 'true') {
62
            $command .= ' --quiet';
63
        }
64
65
        if (isset($extra['ckeditor-exclude'])) {
66
            foreach ($extra['ckeditor-exclude'] as $exclude) {
67 20
                $command .= ' --exclude='.$exclude;
68
            }
69
        }
70
71
        return $command;
72
    }
73
}
74