Completed
Push — master ( 36858c...6c23f8 )
by Abdelrahman
07:21
created

AbilityFindCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 45
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
B handle() 0 23 5
1
<?php
2
3
/*
4
 * NOTICE OF LICENSE
5
 *
6
 * Part of the Rinvex Fort Package.
7
 *
8
 * This source file is subject to The MIT License (MIT)
9
 * that is bundled with this package in the LICENSE file.
10
 *
11
 * Package: Rinvex Fort Package
12
 * License: The MIT License (MIT)
13
 * Link:    https://rinvex.com
14
 */
15
16
namespace Rinvex\Fort\Console\Commands;
17
18
use Illuminate\Console\Command;
19
use Illuminate\Support\Facades\Lang;
20
21
class AbilityFindCommand extends Command
22
{
23
    /**
24
     * The name and signature of the console command.
25
     *
26
     * @var string
27
     */
28
    protected $signature = 'fort:ability:find {field? : Get specific ability by field}';
29
30
    /**
31
     * The console command description.
32
     *
33
     * @var string
34
     */
35
    protected $description = 'List matched abilities.';
36
37
    /**
38
     * Execute the console command.
39
     *
40
     * @return void
41
     */
42
    public function handle()
43
    {
44
        $columns = ['id', 'name', 'slug', 'created_at', 'updated_at'];
45
46
        // Find single ability
47
        if ($field = $this->argument('field')) {
48
            if (intval($field) && $ability = $this->laravel['rinvex.fort.ability']->find($field, $columns)) {
49
                return $this->table($columns, [$ability->toArray()]);
50
            } else if ($ability = $this->laravel['rinvex.fort.ability']->findWhere(['slug' => $field], $columns)->first()) {
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 124 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
51
                return $this->table($columns, $ability->toArray());
52
            }
53
54
            return $this->error(Lang::get('rinvex.fort::artisan.ability.invalid', ['field' => $field]));
55
        }
56
57
        // Find multiple abilities
58
        $field    = $this->anticipate(Lang::get('rinvex.fort::artisan.ability.field'), ['id', 'slug'], 'id');
59
        $operator = $this->anticipate(Lang::get('rinvex.fort::artisan.ability.operator'), ['=', '<', '>', '<=', '>=', '<>', '!=', 'like', 'like binary', 'not like', 'between', 'ilike', '&', '|', '^', '<<', '>>', 'rlike', 'regexp', 'not regexp', '~', '~*', '!~', '!~*', 'similar to', 'not similar to'], '=');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 307 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
60
        $value    = $this->ask(Lang::get('rinvex.fort::artisan.ability.value'));
61
        $results  = $this->laravel['rinvex.fort.ability']->where($field, $operator, $value)->get($columns);
62
63
        return $this->table($columns, $results->toArray());
64
    }
65
}
66