Completed
Push — master ( a50b1c...e356c0 )
by Mr
02:11
created

Slots::__invoke()   C

Complexity

Conditions 12
Paths 98

Size

Total Lines 45

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 156

Importance

Changes 0
Metric Value
dl 0
loc 45
ccs 0
cts 37
cp 0
rs 6.9666
c 0
b 0
f 0
cc 12
nc 98
nop 6
crap 156

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Bookeo\Endpoints\Availability;
4
5
use Bookeo\Endpoints\Availability;
6
use Bookeo\Models\SlotList;
7
8
class Slots extends Availability
9
{
10
    /**
11
     * Navigate results of a matching slots search
12
     *
13
     * @param string $productId    the product id (see /settings/products). If not provided, all products of type "fixed" or "fixedCourse" will be included in the result. If no
14
     *                             productId is provided, products that are not bookable by customers wil not be included in the result. If productId is provided, the product must
15
     *                             be of type "fixed" or "fixedCourse". For products of type "flexibleTime", use /availability/matchingslots instead.
16
     * @param string $startTime    the start time to search from. Required unless pageNavigationToken is used.
17
     * @param string $endTime      the end time to search to. Required unless pageNavigationToken is used. The maximum date range in a single call is 31 days.
18
     * @param string $pageNavigationToken
19
     * @param int    $itemsPerPage maximum: 300
20
     * @param int    $pageNumber
21
     *
22
     * @return $this
23
     */
24
    public function __invoke(
25
        string $productId = null,
26
        string $startTime = null,
27
        string $endTime = null,
28
        int $itemsPerPage = 50,
29
        string $pageNavigationToken = null,
30
        int $pageNumber = 1
31
    ) {
32
        if (!empty($productId)) {
33
            $this->appendToQuery('productId', $productId);
34
        }
35
36
        if (!empty($startTime) && empty($pageNavigationToken)) {
37
            $this->appendToQuery('startTime', $startTime);
38
        } elseif (empty($startTime) && !empty($pageNavigationToken)) {
39
            $this->appendToQuery('pageNavigationToken', $pageNavigationToken);
40
        } elseif (!empty($startTime) && !empty($pageNavigationToken)) {
41
            $this->appendToQuery('pageNavigationToken', $pageNavigationToken);
42
        } else {
43
            throw new \InvalidArgumentException('At least "startTime" or "pageNavigationToken" must be set');
44
        }
45
46
        if (!empty($endTime)) {
47
            $this->appendToQuery('endTime', $endTime);
48
        }
49
50
        if (!empty($itemsPerPage)) {
51
            $this->appendToQuery('itemsPerPage', $itemsPerPage);
52
        }
53
54
        if (!empty($pageNavigationToken)) {
55
            $this->appendToQuery('pageNavigationToken', $pageNavigationToken);
56
        }
57
58
        if (!empty($pageNumber)) {
59
            $this->appendToQuery('pageNumber', $pageNumber);
60
        }
61
62
        // Set HTTP params
63
        $this->type     = 'get';
64
        $this->endpoint = '/availability/slots' . '?' . $this->getQuery();
65
        $this->response = SlotList::class;
0 ignored issues
show
Documentation introduced by
The property response does not exist on object<Bookeo\Endpoints\Availability\Slots>. 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...
66
67
        return $this;
68
    }
69
}
70