RequestsCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 23
c 1
b 0
f 0
dl 0
loc 45
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A showBindings() 0 21 1
A handle() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Contains the Requests Command class
7
 *
8
 * @copyright   Copyright (c) Attila Fulop
9
 * @author      Attila Fulop
10
 * @license     MIT
11
 * @since       2017-12-09
12
 */
13
14
namespace Konekt\Concord\Console\Commands;
15
16
use Illuminate\Console\Command;
17
use Illuminate\Support\Collection;
18
use Konekt\Concord\Contracts\Concord;
19
20
class RequestsCommand extends Command
21
{
22
    protected $signature = 'concord:requests';
23
24
    protected $description = 'List Form Requests';
25
26
    protected $headers = ['Name', 'Contract', 'Concrete'];
27
28
    public function handle(Concord $concord)
29
    {
30
        $bindings = $concord->getRequestBindings();
31
32
        if ($bindings->count()) {
33
            $this->showBindings($bindings);
34
        } else {
35
            $this->line('No requests have been registered.');
36
        }
37
    }
38
39
    /**
40
     * Displays the list of enum bindings on the output
41
     *
42
     * @param Collection $bindings
43
     */
44
    protected function showBindings(Collection $bindings)
45
    {
46
        $table = [];
47
48
        $bindings->map(function ($item, $key) {
49
            return [
50
                'shortName' => shorten($key),
51
                'abstract' => $key,
52
                'concrete' => $item
53
            ];
54
        })->sort(function ($a, $b) {
55
            return $a['shortName'] <=> $b['shortName'];
56
        })->each(function ($binding) use (&$table) {
57
            $table[] = [
58
                $binding['shortName'],
59
                $binding['abstract'],
60
                $binding['concrete'],
61
            ];
62
        });
63
64
        $this->table($this->headers, $table);
65
    }
66
}
67