StatProjects   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 75
Duplicated Lines 36 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A list() 0 20 2
A create() 14 14 1
A update() 13 13 1
A delete() 0 6 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 SchulzeFelix\Stat\Api;
4
5
use Illuminate\Support\Collection;
6
use SchulzeFelix\Stat\Objects\StatProject;
7
8
class StatProjects extends BaseStat
9
{
10
    /**
11
     * @return Collection
12
     */
13
    public function list(): Collection
14
    {
15
        $response = $this->performQuery('projects/list');
16
17
        if ($response['resultsreturned'] == 1) {
18
            $response['Result'] = [$response['Result']];
19
        }
20
21
        $projects = collect($response['Result'])->map(function ($project) {
22
            return new StatProject([
23
                'id' => $project['Id'],
24
                'name' => $project['Name'],
25
                'total_sites' => $project['TotalSites'],
26
                'created_at' => $project['CreatedAt'],
27
                'updated_at' => $project['UpdatedAt'],
28
            ]);
29
        });
30
31
        return $projects;
32
    }
33
34
    /**
35
     * @param $name
36
     * @return StatProject
37
     */
38 View Code Duplication
    public function create($name)
0 ignored issues
show
Duplication introduced by
This method 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...
39
    {
40
        $name = rawurlencode($name);
41
42
        $response = $this->performQuery('projects/create', ['name' => $name]);
43
44
        return new StatProject([
45
            'id' => $response['Result']['Id'],
46
            'name' => $response['Result']['Name'],
47
            'total_sites' => 0,
48
            'created_at' => $response['Result']['CreatedAt'],
49
            'updated_at' => $response['Result']['UpdatedAt'],
50
        ]);
51
    }
52
53
    /**
54
     * @param $id
55
     * @param $name
56
     * @return StatProject
57
     */
58 View Code Duplication
    public function update($id, $name)
0 ignored issues
show
Duplication introduced by
This method 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...
59
    {
60
        $name = rawurlencode($name);
61
62
        $response = $this->performQuery('projects/update', ['id' => $id, 'name' => $name]);
63
64
        return new StatProject([
65
            'id' => $response['Result']['Id'],
66
            'name' => $response['Result']['Name'],
67
            'created_at' => $response['Result']['CreatedAt'],
68
            'updated_at' => $response['Result']['UpdatedAt'],
69
        ]);
70
    }
71
72
    /**
73
     * @param $id
74
     * @return int
75
     */
76
    public function delete($id)
77
    {
78
        $response = $this->performQuery('projects/delete', ['id' => $id]);
79
80
        return (int) $response['Result']['Id'];
81
    }
82
}
83