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

InstallCommand::addLibrary()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 13
ccs 9
cts 9
cp 1
rs 9.4285
cc 2
eloc 7
nc 2
nop 1
crap 2
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 Royce 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
     * 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 boolean
34
     */
35 3
    public function isEnabled()
36
    {
37 3
        $library = ucfirst($this->library);
38
39 3
        return ! file_exists(APPPATH . 'libraries/' . $library . '.php');
40
    }
41
42
    /**
43
     * Sets the configurations of the specified command.
44
     *
45
     * @return void
46
     */
47 33
    protected function configure()
48
    {
49 33
        $this
50 33
            ->setName('install:' . $this->library)
51 33
            ->setDescription('Installs ' . ucfirst($this->library));
52 33
    }
53
54
    /**
55
     * Adds the specified library in the autoload.php.
56
     * 
57
     * @param  string $library
58
     * @return void
59
     */
60 30
    protected function addLibrary($library)
61
    {
62 30
        $autoload = new Config('autoload', APPPATH . 'config');
63
64 30
        $libraries = $autoload->get('libraries', 60, 'array');
65
66 30
        if ( ! in_array($library, $libraries)) {
67 30
            array_push($libraries, $library);
68
69 30
            $autoload->set('libraries', 60, $libraries, 'array');
70 30
            $autoload->save();
71 30
        }
72 30
    }
73
}
74