AddSidebarContent   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 52
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 19 3
1
<?php
2
3
namespace Backpack\Base\app\Console\Commands;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Support\Facades\Storage;
7
8
class AddSidebarContent extends Command
9
{
10
    /**
11
     * The name and signature of the console command.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'backpack:base:add-sidebar-content
16
                                {code : HTML/PHP code that shows the sidebar item. Use either single quotes or double quotes. Never both. }';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Add HTML/PHP code to the Backpack sidebar_content file';
24
25
    /**
26
     * Create a new command instance.
27
     *
28
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
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 handle()
41
    {
42
        $path = 'resources/views/vendor/backpack/base/inc/sidebar_content.blade.php';
43
        $disk_name = config('backpack.base.root_disk_name');
44
        $disk = Storage::disk($disk_name);
45
        $code = $this->argument('code');
46
47
        if ($disk->exists($path)) {
48
            $contents = Storage::disk($disk_name)->get($path);
49
50
            if ($disk->put($path, $contents.PHP_EOL.$code)) {
51
                $this->info('Successfully added code to sidebar_content file.');
52
            } else {
53
                $this->error('Could not write to sidebar_content file.');
54
            }
55
        } else {
56
            $this->error("The sidebar_content file does not exist. Make sure Backpack\Base is properly installed.");
57
        }
58
    }
59
}
60