Completed
Push — master ( 3599e8...a4b34c )
by Rougin
05:04
created

RemoveCommand::execute()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 25
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 3

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 25
ccs 15
cts 15
cp 1
rs 8.8571
cc 3
eloc 13
nc 4
nop 2
crap 3
1
<?php
2
3
namespace Rougin\Combustor\Common\Commands;
4
5
use Symfony\Component\Console\Input\InputInterface;
6
use Symfony\Component\Console\Output\OutputInterface;
7
8
use Rougin\Combustor\Common\Tools;
9
use Rougin\Combustor\Common\Config;
10
use Rougin\Combustor\Commands\AbstractCommand;
11
12
/**
13
 * Remove Command
14
 *
15
 * Removes Doctrine/Wildfire library from CodeIgniter.
16
 * 
17
 * @package Combustor
18
 * @author  Rougin Royce Gutib <[email protected]>
19
 */
20
class RemoveCommand extends AbstractCommand
21
{
22
    /**
23
     * @var string
24
     */
25
    protected $library = '';
26
27
    /**
28
     * Checks whether the command is enabled or not in the current environment.
29
     *
30
     * Override this to check for x or y and return false if the command can not
31
     * run properly under the current conditions.
32
     *
33
     * @return bool
34
     */
35 3
    public function isEnabled()
36
    {
37 3
        if ($this->library == 'doctrine') {
38 3
            return Tools::isDoctrineEnabled();
39
        }
40
41 3
        return Tools::isWildfireEnabled();
42
    }
43
44
    /**
45
     * Sets the configurations of the specified command.
46
     *
47
     * @return void
48
     */
49 9
    protected function configure()
50
    {
51 9
        $this
52 9
            ->setName('remove:' . $this->library)
53 9
            ->setDescription('Removes ' . ucfirst($this->library));
54 9
    }
55
56
    /**
57
     * Executes the command.
58
     * 
59
     * @param \Symfony\Component\Console\Input\InputInterface   $input
60
     * @param \Symfony\Component\Console\Output\OutputInterface $output
61
     * @return OutputInterface
62
     */
63 6
    protected function execute(InputInterface $input, OutputInterface $output)
64
    {
65 6
        $autoload = new Config('autoload', APPPATH . 'config');
66
67 6
        $libraries = $autoload->get('libraries', 60, 'array');
68
69 6
        if (in_array($this->library, $libraries)) {
70 6
            $position = array_search($this->library, $libraries);
71
72 6
            unset($libraries[$position]);
73
74 6
            $autoload->set('libraries', 60, $libraries, 'array');
75 6
            $autoload->save();
76 6
        }
77
78 6
        if ($this->library == 'doctrine') {
79 3
            system('composer remove doctrine/orm');
80 3
        }
81
82 6
        unlink(APPPATH . 'libraries/' . ucfirst($this->library) . '.php');
83
84 6
        $message = ucfirst($this->library) . ' is now successfully removed!';
85
86 6
        return $output->writeln('<info>' . $message . '</info>');
87
    }
88
}
89