StatProjects::update()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
dl 13
loc 13
rs 9.8333
c 0
b 0
f 0
cc 1
nc 1
nop 2
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