Completed
Pull Request — master (#31)
by Asif
04:45
created

CreateShortcode::handle()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 12
nc 3
nop 0
1
<?php
2
namespace Webwizo\Shortcodes\Commands;
3
4
use Illuminate\Console\Command;
5
use Illuminate\Filesystem\Filesystem;
6
use File;
7
8
class CreateShortcode extends Command
9
{
10
    /**
11
     * The name and signature of the console command.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'shortcode:create {name}';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'Create New Shortcode';
23
24
    /**
25
     * Create a new command instance.
26
     *
27
     * @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...
28
     */
29
    public function __construct()
30
    {
31
        parent::__construct();
32
    }
33
34
    /**
35
     * Execute the console command.
36
     *
37
     * @return mixed
38
     */
39
    public function handle()
40
    {
41
        //
42
        $name = $this->argument('name');
43
        $file_path = app_path('Shortcodes'.'/'.$name.'.php');
44
        if(file_exists( $file_path ) === false){
45
            //create new shortcode file
46
            $this->info("Creating new shortcoode ".$name);
47
            $create_file = File::put($file_path, "<?php\nnamespace App\Shortcodes;\n\nclass ".$name." {\n\tpublic function register(\$shortcode, \$content, \$compiler, \$name, \$viewData)\n\t{\n\t\t//\n\t}\n}");
48
            if($create_file != false){
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $create_file of type integer to the boolean false. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
49
                $this->info('File Created');
50
            }else{
51
                $this->info('Unable to create file, please create manaully at '.$file_path);
52
            }
53
        }else{
54
            $this->info($name." already exists");
55
        }
56
    }
57
}
58
59