ApplicationsApi::add()   A
last analyzed

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\Application;
14
use Fnayou\InstapushPHP\Model\Applications;
15
16
/**
17
 * Class ApplicationsApi.
18
 */
19 View Code Duplication
class ApplicationsApi extends AbstractApi
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