Completed
Push — master ( 2069c8...ec8153 )
by Mr
03:28
created

Customers::all()   C

Complexity

Conditions 9
Paths 256

Size

Total Lines 50

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 90

Importance

Changes 0
Metric Value
dl 0
loc 50
ccs 0
cts 39
cp 0
rs 6.3086
c 0
b 0
f 0
cc 9
nc 256
nop 8
crap 90

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace Bookeo\Endpoints;
4
5
use Bookeo\Client;
6
use Bookeo\Interfaces\QueryInterface;
7
use Bookeo\Models\BookingsList;
8
use Bookeo\Models\Customer;
9
use Bookeo\Models\CustomersList;
10
use Bookeo\Models\LinkedPersonList;
11
12
/**
13
 * Operations to manage customers
14
 *
15
 * @package Bookeo\Endpoints
16
 */
17
class Customers extends Client
18
{
19
    /**
20
     * Retrieve customers
21
     *
22
     * Get a list of customers.
23
     *
24
     * @param string|null $searchText
25
     * @param string|null $searchField
26
     * @param string|null $createdSince date-time
27
     * @param bool|null   $currentMembers
28
     * @param bool|null   $currentNonMembers
29
     * @param int         $itemsPerPage maximum: 100
30
     * @param string|null $pageNavigationToken
31
     * @param int         $pageNumber
32
     *
33
     * @return \Bookeo\Interfaces\QueryInterface
34
     */
35
    public function all(
36
        string $searchText = null,
37
        string $searchField = null,
38
        string $createdSince = null,
39
        bool $currentMembers = true,
40
        bool $currentNonMembers = true,
41
        int $itemsPerPage = 50,
42
        string $pageNavigationToken = null,
43
        int $pageNumber = 1
44
    ): QueryInterface {
45
46
        if (!empty($searchText)) {
47
            $this->appendToQuery('searchText', $searchText);
48
        }
49
50
        if (!empty($searchField)) {
51
            $this->appendToQuery('searchField', $searchField);
52
        }
53
54
        if (!empty($createdSince)) {
55
            $this->appendToQuery('createdSince', $createdSince);
56
        }
57
58
        if ($currentMembers !== null) {
59
            $this->appendToQuery('currentMembers', $currentMembers);
0 ignored issues
show
Documentation introduced by
$currentMembers is of type boolean, but the function expects a string|integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
60
        }
61
62
        if ($currentNonMembers !== null) {
63
            $this->appendToQuery('currentNonMembers', $currentNonMembers);
0 ignored issues
show
Documentation introduced by
$currentNonMembers is of type boolean, but the function expects a string|integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
64
        }
65
66
        if (!empty($itemsPerPage)) {
67
            $this->appendToQuery('itemsPerPage', $itemsPerPage);
68
        }
69
70
        if (!empty($pageNavigationToken)) {
71
            $this->appendToQuery('pageNavigationToken', $pageNavigationToken);
72
        }
73
74
        if (!empty($pageNumber)) {
75
            $this->appendToQuery('pageNumber', $pageNumber);
76
        }
77
78
        // Set HTTP params
79
        $this->type     = 'get';
80
        $this->endpoint = '/customers' . '?' . $this->getQuery();
81
        $this->response = CustomersList::class;
0 ignored issues
show
Documentation introduced by
The property response does not exist on object<Bookeo\Endpoints\Customers>. 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...
82
83
        return $this;
84
    }
85
86
    /**
87
     * Create a new customer.
88
     *
89
     * Please note there is a limit to the number of customers that can be imported in Bookeo. Bookeo is primarily a booking system, not a CRM.
90
     *
91
     * @param Customer $customer
92
     *
93
     * @return \Bookeo\Interfaces\QueryInterface
94
     */
95
    public function create(Customer $customer): QueryInterface
96
    {
97
        // Set HTTP params
98
        $this->type     = 'post';
99
        $this->endpoint = '/customers' . '?' . $this->getQuery();
100
        $this->params   = $customer;
101
        $this->response = Customer::class;
0 ignored issues
show
Documentation introduced by
The property response does not exist on object<Bookeo\Endpoints\Customers>. 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...
102
103
        return $this;
104
    }
105
106
    /**
107
     * Retrieve a customer
108
     *
109
     * Retrieve a customer by its id
110
     *
111
     * @param string $customer_id
112
     *
113
     * @return $this
114
     */
115
    public function __invoke(string $customer_id)
116
    {
117
        $this->customer_id = $customer_id;
0 ignored issues
show
Documentation introduced by
The property customer_id does not exist on object<Bookeo\Endpoints\Customers>. 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...
118
119
        // Set HTTP params
120
        $this->type     = 'get';
121
        $this->endpoint = '/customers/' . $customer_id . '?' . $this->getQuery();
122
        $this->response = Customer::class;
0 ignored issues
show
Documentation introduced by
The property response does not exist on object<Bookeo\Endpoints\Customers>. 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...
123
124
        return $this;
125
    }
126
127
    /**
128
     * Update an existing customer
129
     *
130
     * @param Customer $customer
131
     *
132
     * @return \Bookeo\Interfaces\QueryInterface
133
     */
134 View Code Duplication
    public function update(Customer $customer): QueryInterface
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...
135
    {
136
        // Set HTTP params
137
        $this->type     = 'put';
138
        $this->endpoint = '/customers/' . $this->customer_id . '?' . $this->getQuery();
0 ignored issues
show
Documentation introduced by
The property customer_id does not exist on object<Bookeo\Endpoints\Customers>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
139
        $this->params   = $customer;
140
141
        return $this;
142
    }
143
144
    /**
145
     * Delete a customer
146
     *
147
     * Please note it is not possible to delete customers that have bookings in the future, and that are not cancelled.
148
     * If your application needs to delete a customer with future bookings, make sure to cancel all future bookings for that customer first.
149
     *
150
     * @return \Bookeo\Interfaces\QueryInterface
151
     */
152
    public function delete(): QueryInterface
153
    {
154
        // Set HTTP params
155
        $this->type     = 'delete';
156
        $this->endpoint = '/customers/' . $this->customer_id . '?' . $this->getQuery();
0 ignored issues
show
Documentation introduced by
The property customer_id does not exist on object<Bookeo\Endpoints\Customers>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
157
158
        return $this;
159
    }
160
161
    /**
162
     * The customer's email address is the "username" used by Bookeo to authenticate customers.
163
     * So to authenticate a customer your application would typically use GET /customers to search for customers with a given email address, and then GET
164
     * /customers/{id}/authenticate to authenticate. Remember that there may be duplicate customer records with the same email address, ex. due to duplicate importing or manual
165
     * record creation.
166
     *
167
     * @param string $password
168
     *
169
     * @return \Bookeo\Interfaces\QueryInterface
170
     */
171 View Code Duplication
    public function authenticate(string $password): QueryInterface
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...
172
    {
173
        $this->appendToQuery('password', $password);
174
175
        // Set HTTP params
176
        $this->type     = 'get';
177
        $this->endpoint = '/customers/' . $this->customer_id . '/authenticate?' . $this->getQuery();
0 ignored issues
show
Documentation introduced by
The property customer_id does not exist on object<Bookeo\Endpoints\Customers>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
178
179
        return $this;
180
    }
181
182
    /**
183
     * @param string|null $beginDate          if specified, only bookings on or after this date will be included
184
     * @param string|null $endDate            if specified, only bookings on or before this date will be included
185
     * @param bool        $expandParticipants if true, full details of the participants are included (provided the application has read permission over the participant)
186
     * @param int         $itemsPerPage       maximum: 100
187
     * @param string|null $pageNavigationToken
188
     * @param int         $pageNumber
189
     *
190
     * @return \Bookeo\Interfaces\QueryInterface
191
     */
192
    public function bookings(
193
        string $beginDate = null,
194
        string $endDate = null,
195
        bool $expandParticipants = false,
196
        int $itemsPerPage = 50,
197
        string $pageNavigationToken = null,
198
        int $pageNumber = 1
199
    ): QueryInterface {
200
201
        if (!empty($beginDate)) {
202
            $this->appendToQuery('beginDate', $beginDate);
203
        }
204
205
        if (!empty($endDate)) {
206
            $this->appendToQuery('endDate', $endDate);
207
        }
208
209
        if (!empty($expandParticipants)) {
210
            $this->appendToQuery('expandParticipants', $expandParticipants);
0 ignored issues
show
Documentation introduced by
$expandParticipants is of type boolean, but the function expects a string|integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
211
        }
212
213
        if (!empty($itemsPerPage)) {
214
            $this->appendToQuery('itemsPerPage', $itemsPerPage);
215
        }
216
217
        if (!empty($pageNavigationToken)) {
218
            $this->appendToQuery('pageNavigationToken', $pageNavigationToken);
219
        }
220
221
        if (!empty($pageNumber)) {
222
            $this->appendToQuery('pageNumber', $pageNumber);
223
        }
224
225
        // Set HTTP params
226
        $this->type     = 'get';
227
        $this->endpoint = '/customers/' . $this->customer_id . '/bookings?' . $this->getQuery();
0 ignored issues
show
Documentation introduced by
The property customer_id does not exist on object<Bookeo\Endpoints\Customers>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
228
        $this->response = BookingsList::class;
0 ignored issues
show
Documentation introduced by
The property response does not exist on object<Bookeo\Endpoints\Customers>. 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...
229
230
        return $this;
231
    }
232
233
    /**
234
     * Get the people linked to a customer
235
     *
236
     * @param int         $itemsPerPage maximum: 100
237
     * @param string|null $pageNavigationToken
238
     * @param int         $pageNumber
239
     *
240
     * @return \Bookeo\Interfaces\QueryInterface
241
     */
242 View Code Duplication
    public function linkedpeople(
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...
243
        int $itemsPerPage = 50,
244
        string $pageNavigationToken = null,
245
        int $pageNumber = 1
246
    ): QueryInterface {
247
248
        if (!empty($itemsPerPage)) {
249
            $this->appendToQuery('itemsPerPage', $itemsPerPage);
250
        }
251
252
        if (!empty($pageNavigationToken)) {
253
            $this->appendToQuery('pageNavigationToken', $pageNavigationToken);
254
        }
255
256
        if (!empty($pageNumber)) {
257
            $this->appendToQuery('pageNumber', $pageNumber);
258
        }
259
260
        // Set HTTP params
261
        $this->type     = 'get';
262
        $this->endpoint = '/customers/' . $this->customer_id . '/linkedpeople?' . $this->getQuery();
0 ignored issues
show
Documentation introduced by
The property customer_id does not exist on object<Bookeo\Endpoints\Customers>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
263
        $this->response = LinkedPersonList::class;
0 ignored issues
show
Documentation introduced by
The property response does not exist on object<Bookeo\Endpoints\Customers>. 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...
264
265
        return $this;
266
    }
267
}
268