GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

GeneratorCommand::handle()   B
last analyzed

Complexity

Conditions 11
Paths 17

Size

Total Lines 42
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 132

Importance

Changes 0
Metric Value
cc 11
eloc 27
c 0
b 0
f 0
nc 17
nop 0
dl 0
loc 42
ccs 0
cts 28
cp 0
crap 132
rs 7.3166

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace SleepingOwl\Admin\Console\Commands;
4
5
use Barryvdh\LaravelIdeHelper\Console\GeneratorCommand as IdeHelperGeneratorCommand;
6
use SleepingOwl\Admin\Console\Generator;
7
8
/**
9
 * A command to generate autocomplete information for your IDE.
10
 *
11
 * @author Aios Dave <[email protected]>
12
 */
13
class GeneratorCommand extends IdeHelperGeneratorCommand
14
{
15
    /**
16
     * The console command name.
17
     *
18
     * @var string
19
     */
20
    protected $name = 'sleepingowl:ide:generate';
21
22
    /**
23
     * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
24
     */
25
    public function handle()
26
    {
27
        if (file_exists(base_path().'/vendor/compiled.php') ||
28
            file_exists(base_path().'/bootstrap/cache/compiled.php') ||
29
            file_exists(base_path().'/storage/framework/compiled.php')) {
30
            $this->error(
31
                'Error generating IDE Helper: first delete your compiled file (php artisan clear-compiled)'
32
            );
33
        } else {
34
            $filename = (string) $this->argument('filename');
35
            $format = (string) $this->option('format');
36
37
            // Strip the php extension
38
            if (substr($filename, -4, 4) == '.php') {
39
                $filename = substr($filename, 0, -4);
40
            }
41
42
            $filename = implode('.', [$filename, $format]);
43
44
            if ($this->option('memory')) {
45
                $this->useMemoryDriver();
46
            }
47
48
            $helpers = '';
49
            if ($this->option('helpers') || ($this->config->get('ide-helper.include_helpers'))) {
50
                foreach ($this->config->get('ide-helper.helper_files', []) as $helper) {
51
                    if (file_exists($helper)) {
52
                        $helpers .= str_replace(['<?php', '?>'], '', $this->files->get($helper));
53
                    }
54
                }
55
            } else {
56
                $helpers = '';
57
            }
58
59
            $generator = new Generator($this->config, $this->view, $this->getOutput(), $helpers);
60
            $content = $generator->generate($format);
61
            $written = (int) $this->files->put($filename, $content);
62
63
            if ($written === false) {
0 ignored issues
show
introduced by
The condition $written === false is always false.
Loading history...
64
                $this->error("The helper file could not be created at $filename");
65
            } else {
66
                $this->info("A new helper file was written to $filename");
67
            }
68
        }
69
    }
70
}
71