Completed
Push — master ( 8ff94d...a4ae02 )
by Mr
02:02
created

Subaccounts::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 8
loc 8
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Bookeo\Endpoints;
4
5
use Bookeo\Client;
6
use Bookeo\Models\PortalSubaccountsList;
7
8
/**
9
 * Access subaccounts part of a Bookeo Portal
10
 *
11
 * @package Bookeo\Endpoints
12
 */
13
class Subaccounts extends Client
14
{
15
    /**
16
     * @var string
17
     */
18
    protected $namespace = __CLASS__;
19
20
    /**
21
     * Create a new API Key for this application to access a subaccount
22
     *
23
     * Install this application in a subaccount.
24
     * Note that the API key used in this call must be that of the portal manager account. The application installed in the subaccount will be the same as this one, with the same permissions.
25
     * If this application was already installed in the subaccount, its API key will be replaced by the one created in this call.
26
     *
27
     * @param string $subaccountId
28
     *
29
     * @return $this
30
     */
31 View Code Duplication
    public function create(string $subaccountId): self
0 ignored issues
show
Duplication introduced by
This method 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...
32
    {
33
        // Set HTTP params
34
        $this->type     = 'post';
35
        $this->endpoint = '/subaccounts/' . $subaccountId . '?' . $this->getQuery();
36
37
        return $this;
38
    }
39
40
    /**
41
     * Delete the API Key for this application from a subaccount
42
     *
43
     * Uninstall this application from a subaccount.
44
     *
45
     * @param string $subaccountId
46
     * @param string $apiKey
47
     *
48
     * @return $this
49
     */
50 View Code Duplication
    public function delete(string $subaccountId, string $apiKey): self
0 ignored issues
show
Duplication introduced by
This method 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...
51
    {
52
        // Set HTTP params
53
        $this->type     = 'delete';
54
        $this->endpoint = '/subaccounts/' . $subaccountId . '/apikeys/' . $apiKey . '?' . $this->getQuery();
55
56
        return $this;
57
    }
58
59
    /**
60
     * List all subaccounts in the portal
61
     *
62
     * Retrieve all the webhooks for this api key
63
     *
64
     * @param int         $itemsPerPage
65
     * @param string|null $pageNavigationToken
66
     * @param int         $pageNumber
67
     *
68
     * @return $this
69
     */
70
    public function all(int $itemsPerPage = 100, string $pageNavigationToken = null, int $pageNumber = 1): self
71
    {
72
        if (null !== $itemsPerPage) {
73
            $this->appendToQuery('itemsPerPage', $itemsPerPage);
74
        }
75
76
        if (null !== $pageNavigationToken) {
77
            $this->appendToQuery('pageNumber', $pageNumber);
78
        }
79
80
        if (null !== $pageNumber) {
81
            $this->appendToQuery('pageNumber', $pageNumber);
82
        }
83
84
        // Set HTTP params
85
        $this->type     = 'get';
86
        $this->endpoint = '/subaccounts' . '?' . $this->getQuery();
87
        $this->response = PortalSubaccountsList::class;
0 ignored issues
show
Documentation introduced by
The property response does not exist on object<Bookeo\Endpoints\Subaccounts>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
88
89
        return $this;
90
    }
91
}
92