Completed
Pull Request — master (#3)
by Aymen
02:08
created

EventsApi::add()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
dl 9
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
/**
3
 * This file is part of the fnayou/instapush-php project.
4
 *
5
 * Copyright (c) 2017. Aymen FNAYOU <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Fnayou\InstapushPHP\Api;
12
13
use Fnayou\InstapushPHP\Model\Event;
14
use Fnayou\InstapushPHP\Model\Events;
15
16
/**
17
 * Class EventsApi.
18
 */
19 View Code Duplication
class EventsApi extends AbstractApi
1 ignored issue
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...
20
{
21
    /**
22
     * @return \Fnayou\InstapushPHP\Model\Events
23
     */
24
    public function list()
25
    {
26
        $eventsApi = $this->doGet('/events/list');
27
28
        // full absurdity
29
        if ('null' === $eventsApi->getResponse()->getBody()->__toString()) {
30
            return new Events();
31
        }
32
33
        return $eventsApi->transformResponse(Events::class);
34
    }
35
36
    /**
37
     * @param \Fnayou\InstapushPHP\Model\Event $event
38
     *
39
     * @return \Fnayou\InstapushPHP\Model\Event
40
     */
41
    public function add(Event $event)
42
    {
43
        $this->doPost('/events/add', $event->toArray());
44
45
        /** @var \Fnayou\InstapushPHP\Model\Events $events */
46
        $events = $this->list();
47
48
        return $events->last();
49
    }
50
}
51