EventsApi   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A list() 11 11 2
A add() 9 9 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
 * 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
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