InstallCommand::addLibrary()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 11
ccs 7
cts 7
cp 1
crap 2
rs 10
c 0
b 0
f 0
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
 * Install Command
14
 *
15
 * Installs Doctrine/Wildfire library for CodeIgniter.
16
 *
17
 * @package Combustor
18
 * @author  Rougin Gutib <[email protected]>
19
 */
20
class InstallCommand 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
     * @return boolean
31
     */
32 3
    public function isEnabled()
33
    {
34 3
        $library = ($this->library == 'doctrine') ? 'Wildfire' : 'Doctrine';
35
36 3
        return ! file_exists(APPPATH . 'libraries/' . $library . '.php');
0 ignored issues
show
Bug introduced by
The constant Rougin\Combustor\Common\Commands\APPPATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
37
    }
38
39
    /**
40
     * Sets the configurations of the specified command.
41
     *
42
     * @return void
43
     */
44 33
    protected function configure()
45
    {
46 22
        $this
47 33
            ->setName('install:' . $this->library)
48 33
            ->setDescription('Installs ' . ucfirst($this->library));
49 33
    }
50
51
    /**
52
     * Adds the specified library in the autoload.php.
53
     *
54
     * @param  string $library
55
     * @return void
56
     */
57 30
    protected function addLibrary($library)
58
    {
59 30
        $autoload = new Config('autoload', APPPATH . 'config');
0 ignored issues
show
Bug introduced by
The constant Rougin\Combustor\Common\Commands\APPPATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
60
61 30
        $libraries = $autoload->get('libraries', 60, 'array');
62
63 30
        if (! in_array($library, $libraries)) {
64 30
            array_push($libraries, $library);
65
66 30
            $autoload->set('libraries', 60, $libraries, 'array');
67 30
            $autoload->save();
68 20
        }
69 30
    }
70
}
71