PluginCommandHandler::handleDelete()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 15
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 2
nop 1
dl 15
loc 15
ccs 7
cts 7
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the puli/cli package.
5
 *
6
 * (c) Bernhard Schussek <[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 Puli\Cli\Handler;
13
14
use Puli\Manager\Api\Module\RootModuleFileManager;
15
use RuntimeException;
16
use Webmozart\Console\Api\Args\Args;
17
use Webmozart\Console\Api\IO\IO;
18
19
/**
20
 * Handles the "plugin" command.
21
 *
22
 * @since  1.0
23
 *
24
 * @author Bernhard Schussek <[email protected]>
25
 */
26
class PluginCommandHandler
27
{
28
    /**
29
     * @var RootModuleFileManager
30
     */
31
    private $manager;
32
33
    /**
34
     * Creates the handler.
35
     *
36
     * @param RootModuleFileManager $manager The root module file manager
37
     */
38 6
    public function __construct(RootModuleFileManager $manager)
39
    {
40 6
        $this->manager = $manager;
41 6
    }
42
43
    /**
44
     * Handles the "puli plugin --list" command.
45
     *
46
     * @param Args $args The console arguments
47
     * @param IO   $io   The I/O
48
     *
49
     * @return int The status code
50
     */
51 2
    public function handleList(Args $args, IO $io)
0 ignored issues
show
Unused Code introduced by
The parameter $args is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
52
    {
53 2
        $pluginClasses = $this->manager->getPluginClasses();
54
55 2
        if (!$pluginClasses) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $pluginClasses of type string[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
56 1
            $io->writeLine('No plugin classes. Use "puli plugin --install <class>" to install a plugin class.');
57
58 1
            return 0;
59
        }
60
61 1
        foreach ($pluginClasses as $pluginClass) {
62 1
            $io->writeLine(sprintf('<c1>%s</c1>', $pluginClass));
63
        }
64
65 1
        return 0;
66
    }
67
68
    /**
69
     * Handles the "puli plugin --install" command.
70
     *
71
     * @param Args $args The console arguments
72
     *
73
     * @return int The status code
74
     */
75 2 View Code Duplication
    public function handleInstall(Args $args)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
76
    {
77 2
        $pluginClass = $args->getArgument('class');
78
79 2
        if ($this->manager->hasPluginClass($pluginClass)) {
80 1
            throw new RuntimeException(sprintf(
81 1
                'The plugin class "%s" is already installed.',
82
                $pluginClass
83
            ));
84
        }
85
86 1
        $this->manager->addPluginClass($pluginClass);
87
88 1
        return 0;
89
    }
90
91
    /**
92
     * Handles the "puli plugin --remove" command.
93
     *
94
     * @param Args $args The console arguments
95
     *
96
     * @return int The status code
97
     */
98 2 View Code Duplication
    public function handleDelete(Args $args)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
99
    {
100 2
        $pluginClass = $args->getArgument('class');
101
102 2
        if (!$this->manager->hasPluginClass($pluginClass)) {
103 1
            throw new RuntimeException(sprintf(
104 1
                'The plugin class "%s" is not installed.',
105
                $pluginClass
106
            ));
107
        }
108
109 1
        $this->manager->removePluginClass($pluginClass);
110
111 1
        return 0;
112
    }
113
}
114