Completed
Pull Request — master (#252)
by Cristian
04:03 queued 57s
created

AddSidebarContent::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
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 = Storage::disk('root');
44
        $code = $this->argument('code');
45
46
        if ($disk->exists($path)) {
47
            $contents = Storage::disk('root')->get($path);
48
49
            if ($disk->put($path, $contents.PHP_EOL.$code)) {
50
                $this->info('Successfully added code to sidebar_content file.');
51
            } else {
52
                $this->error('Could not write to sidebar_content file.');
53
            }
54
        } else {
55
            $this->error("The sidebar_content file does not exist. Make sure Backpack\Base is properly installed.");
56
        }
57
    }
58
}
59