Completed
Push — master ( 4f25b6...e7033c )
by Joao
02:34
created

ConfigCommand::checkSentinelConfigFiles()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 3

Duplication

Lines 17
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 17
loc 17
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php namespace jlourenco\support\Commands;
2
3
use Illuminate\Console\Command;
4
use Symfony\Component\Console\Input\InputOption;
5
use Symfony\Component\Console\Input\InputArgument;
6
use File;
7
use jlourenco\support\Helpers\FileLoader;
8
use Setting;
9
use Schema;
10
11 View Code Duplication
class ConfigCommand extends Command {
0 ignored issues
show
Duplication introduced by
This class 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...
12
13
    /**
14
     * The console command name.
15
     *
16
     * @var string
17
     */
18
    protected $name = 'jlourenco:config';
19
20
    /**
21
     * The console command description.
22
     *
23
     * @var string
24
     */
25
    protected $description = 'Command to setup all the configurations for the jlourenco packages';
26
27
    /**
28
     * Create a new command instance.
29
     */
30
    public function __construct()
31
    {
32
        parent::__construct();
33
    }
34
35
    /**
36
     * Execute the console command.
37
     *
38
     * @return mixed
39
     */
40
    public function fire()
41
    {
42
        if (!$this->confirm('Running this command will reset all jlourenco config files. Are you sure? '))
43
        {
44
            $this->info('Command was aborted by the user.');
45
            return;
46
        }
47
48
        $this->compileConfigFiles();
49
        // $this->checkSentinelConfigFiles();
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
50
51
        $this->info('Command ran successfully');
52
    }
53
54
    private function compileConfigFiles()
55
    {
56
        $path = base_path('/config');
57
        $mainFile = $path . '/jlourenco.php';
58
        $fileExists = file_exists($mainFile);
59
60
        $files = array_filter(scandir($path), function ($var) {
61
            return (!(stripos($var, 'jlourenco.') === false) && $var != 'jlourenco.php');
62
        });
63
64
        if ($fileExists)
65
            unlink($mainFile);
66
67
        touch($mainFile);
68
69
        $content = "<?php\n";
70
        $content .= "return [\n\n";
71
72
        foreach ($files as $file)
73
        {
74
            $in = fopen($path . '/' . $file, "r");
75
76
            while ($line = fgets($in))
77
            {
78
                if ((stripos($line, '<?php') === false) && (stripos($line, '];') === false) && (stripos($line, 'return [') === false))
79
                    $content .= $line;
80
            }
81
82
            fclose($in);
83
84
            unlink($path . '/' . $file);
85
        }
86
87
        $content .= "];\n";
88
89
        $bytesWritten = File::append($mainFile, $content);
90
91
        if ($bytesWritten === false)
92
            $this->info('Couldn\'t write to config file.');
93
94
        $this->info('Config files compiled');
95
    }
96
97
    private function checkSentinelConfigFiles()
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
98
    {
99
        Setting::set('cartalyst.sentinel.users.model', 'jlourenco\base\Models\BaseUser');
100
        Setting::set('cartalyst.sentinel.roles.model', 'jlourenco\base\Models\Group');
101
102
        /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
103
        $l = new FileLoader(
104
            new \Illuminate\Filesystem\Filesystem(),
105
            base_path().'/config/cartalyst.sentinel.php'
106
        );
107
108
        $conf = ['' => ''];
109
        $conf2 = ['cartalyst.sentinel.roles.model' => 'jlourenco\base\Models\Group'];
110
111
        $l->save($conf, '', 'cartalyst.sentinel');
112
        */
113
    }
114
115
}
116