CreateCollection::handle()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Colligator\Console\Commands;
4
5
use Colligator\Collection;
6
use Illuminate\Console\Command;
7
8
class CreateCollection extends Command
9
{
10
    /**
11
     * The name and signature of the console command.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'colligator:create-collection
16
                            {name  : Name of the collection}
17
                            {label : A descriptionve label}';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = 'Create a new collection.';
25
26
    /**
27
     * Execute the console command.
28
     *
29
     * @return mixed
30
     */
31
    public function handle()
32
    {
33
        $name = $this->argument('name');
34
        $label = $this->argument('label');
35
        $c = Collection::firstOrNew(['name' => $name, 'label' => $label]);
36
        if ($c->isDirty()) {
37
            $this->info("Created collection '$name'.");
38
            $c->save();
39
        } else {
40
            $this->info("Collection '$name' already exists.");
41
        }
42
    }
43
}
44