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

InstallCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 4
c 3
b 0
f 1
lcom 1
cbo 3
dl 0
loc 54
ccs 17
cts 17
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isEnabled() 0 6 1
A configure() 0 6 1
A addLibrary() 0 13 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