Completed
Push — master ( df502b...4c9fbf )
by Rémi
17s
created

TeamWorkerService::patchTeamWorker()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 12
loc 12
rs 9.4285
cc 1
eloc 6
nc 1
nop 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Yproximite\Api\Service;
5
6
use Yproximite\Api\Model\TeamWorker\TeamWorker;
7
use Yproximite\Api\Message\TeamWorker\TeamWorkerPatchMessage;
8
use Yproximite\Api\Message\TeamWorker\TeamWorkerPostMessage;
9
10
/**
11
 * Class TeamWorkerService
12
 */
13 View Code Duplication
class TeamWorkerService extends AbstractService implements ServiceInterface
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...
14
{
15
    /**
16
     * @param TeamWorkerPostMessage $message
17
     *
18
     * @return TeamWorker
19
     */
20
    public function postTeamWorker(TeamWorkerPostMessage $message): TeamWorker
21
    {
22
        $path = sprintf('sites/%d/teams/workers', $message->getSiteId());
23
        $data = ['api_team_worker' => $message->build()];
24
25
        $response = $this->getClient()->sendRequest('POST', $path, $data);
26
27
        /** @var TeamWorker $model */
28
        $model = $this->getModelFactory()->create(TeamWorker::class, $response);
29
30
        return $model;
31
    }
32
33
    /**
34
     * @param TeamWorkerPatchMessage $message
35
     *
36
     * @return TeamWorker
37
     */
38
    public function patchTeamWorker(TeamWorkerPatchMessage $message): TeamWorker
39
    {
40
        $path = sprintf('sites/%d/teams/%d/worker', $message->getSiteId(), $message->getId());
41
        $data = ['api_team_worker' => $message->build()];
42
43
        $response = $this->getClient()->sendRequest('PATCH', $path, $data);
44
45
        /** @var TeamWorker $model */
46
        $model = $this->getModelFactory()->create(TeamWorker::class, $response);
47
48
        return $model;
49
    }
50
}
51