Completed
Push — master ( 433a3a...426398 )
by Nikita
10:06
created

SiteService::deleteSite()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Yproximite\Api\Service;
5
6
use Yproximite\Api\Model\Site\Site;
7
use Yproximite\Api\Message\Site\SitePostMessage;
8
use Yproximite\Api\Message\Site\SiteDeleteMessage;
9
use Yproximite\Api\Message\Site\PlatformChildrenListMessage;
10
11
/**
12
 * Class SiteService
13
 */
14
class SiteService extends AbstractService implements ServiceInterface
15
{
16
    /**
17
     * @return Site[]
18
     */
19 View Code Duplication
    public function getSites(): array
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...
20
    {
21
        $path = 'sites';
22
23
        $response = $this->getClient()->sendRequest('GET', $path);
24
25
        /** @var Site[] $models */
26
        $models = $this->getModelFactory()->createMany(Site::class, $response);
27
28
        return $models;
29
    }
30
31
    /**
32
     * @param int $id
33
     *
34
     * @return Site
35
     */
36 View Code Duplication
    public function getSite(int $id): Site
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...
37
    {
38
        $path = sprintf('sites/%d', $id);
39
40
        $response = $this->getClient()->sendRequest('GET', $path);
41
42
        /** @var Site $model */
43
        $model = $this->getModelFactory()->create(Site::class, $response);
44
45
        return $model;
46
    }
47
48
    /**
49
     * @param SitePostMessage $message
50
     *
51
     * @return Site
52
     */
53
    public function postSite(SitePostMessage $message): Site
54
    {
55
        $path = 'sites';
56
        $data = ['api_site' => $message->build()];
57
58
        $response = $this->getClient()->sendRequest('POST', $path, $data);
59
60
        /** @var Site $model */
61
        $model = $this->getModelFactory()->create(Site::class, $response);
62
63
        return $model;
64
    }
65
66
    /**
67
     * @param SiteDeleteMessage $message
68
     */
69
    public function deleteSite(SiteDeleteMessage $message)
70
    {
71
        $path = sprintf('sites/%d', $message->getId());
72
73
        $this->getClient()->sendRequest('DELETE', $path);
74
    }
75
76
    /**
77
     * @param PlatformChildrenListMessage $message
78
     *
79
     * @return Site[]
80
     */
81 View Code Duplication
    public function getPlatformChildren(PlatformChildrenListMessage $message): array
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...
82
    {
83
        $path = sprintf('platform/%d/children', $message->getSiteId());
84
85
        $response = $this->getClient()->sendRequest('GET', $path);
86
87
        /** @var Site[] $models */
88
        $models = $this->getModelFactory()->createMany(Site::class, $response);
89
90
        return $models;
91
    }
92
}
93