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

ApplicationsApi   A

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\Application;
14
use Fnayou\InstapushPHP\Model\Applications;
15
16
/**
17
 * Class ApplicationsApi.
18
 */
19 View Code Duplication
class ApplicationsApi 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\Applications
23
     */
24
    public function list()
25
    {
26
        $applicationsApi = $this->doGet('/apps/list');
27
28
        // full absurdity
29
        if ('null' === $applicationsApi->getResponse()->getBody()->__toString()) {
30
            return new Applications();
31
        }
32
33
        return $this->transformResponse(Applications::class);
34
    }
35
36
    /**
37
     * @param \Fnayou\InstapushPHP\Model\Application $application
38
     *
39
     * @return \Fnayou\InstapushPHP\Model\Application
40
     */
41
    public function add(Application $application)
42
    {
43
        $this->doPost('/apps/add', $application->toArray());
44
45
        /** @var \Fnayou\InstapushPHP\Model\Applications $applications */
46
        $applications = $this->list();
47
48
        return $applications->last();
49
    }
50
}
51