PublishTodo   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 80
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 80
loc 80
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
B handle() 24 24 2
A abortCommandExecution() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Acacha\ForgePublish\Commands;
4
5
use Acacha\ForgePublish\Commands\Traits\AborstIfEnvVariableIsnotInstalled;
6
use Acacha\ForgePublish\Commands\Traits\ItFetchesAssignments;
7
use GuzzleHttp\Client;
8
use Illuminate\Console\Command;
9
10
/**
11
 * Class PublishTodo.
12
 *
13
 * @package Acacha\ForgePublish\Commands
14
 */
15 View Code Duplication
class PublishTodo extends Command
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
16
{
17
18
    use ItFetchesAssignments, AborstIfEnvVariableIsnotInstalled;
19
20
    /**
21
     * The name and signature of the console command.
22
     *
23
     * @var string
24
     */
25
    protected $signature = 'publish:todo';
26
27
    /**
28
     * The console command description.
29
     *
30
     * @var string
31
     */
32
    protected $description = 'List current student assignments';
33
34
    /**
35
     * Assignments.
36
     *
37
     * @var
38
     */
39
    protected $assignments;
40
41
    /**
42
     * Server names.
43
     *
44
     * @var Client
45
     */
46
    protected $http;
47
48
    /**
49
     * SaveEnvVariable constructor.
50
     *
51
     */
52
    public function __construct(Client $http)
53
    {
54
        parent::__construct();
55
        $this->http = $http;
56
    }
57
58
    /**
59
     * Execute the console command.
60
     *
61
     */
62
    public function handle()
63
    {
64
        //TODO
65
        $this->abortCommandExecution();
66
        $this->assignments = $this->fetchAssignments();
67
68
        $headers = ['Id', 'Name','Repository','Repo Type','Forge site','Forge Server','Created','Updated'];
69
70
        $rows = [];
71
        foreach ($this->assignments as $assignment) {
72
            $rows[] = [
73
                $assignment->id,
74
                $assignment->name,
75
                $assignment->repository_uri,
76
                $assignment->repository_type,
77
                $assignment->forge_site,
78
                $assignment->forge_server,
79
                $assignment->created_at,
80
                $assignment->updated_at
81
            ];
82
        }
83
84
        $this->table($headers, $rows);
85
    }
86
87
    /**
88
     * Abort command execution.
89
     */
90
    protected function abortCommandExecution()
91
    {
92
        $this->abortsIfEnvVarIsNotInstalled('ACACHA_FORGE_ACCESS_TOKEN');
93
    }
94
}
95