Completed
Push — master ( eece8c...a3a436 )
by Mr
02:11
created

Slots::__invoke()   B

Complexity

Conditions 9
Paths 34

Size

Total Lines 33

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 90

Importance

Changes 0
Metric Value
dl 0
loc 33
ccs 0
cts 26
cp 0
rs 8.0555
c 0
b 0
f 0
cc 9
nc 34
nop 6
crap 90
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 productId is provided, products that are not bookable by customers wil not be included in the result. If productId is provided, the product must be of type "fixed" or "fixedCourse". For products of type "flexibleTime", use /availability/matchingslots instead.
14
     * @param string $startTime    the start time to search from. Required unless pageNavigationToken is used.
15
     * @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.
16
     * @param string $pageNavigationToken
17
     * @param int    $itemsPerPage maximum: 300
18
     * @param int    $pageNumber
19
     *
20
     * @return $this
21
     */
22
    public function __invoke(string $productId = null, string $startTime = null, string $endTime = null, int $itemsPerPage = 50, string $pageNavigationToken = null, int $pageNumber = 1)
23
    {
24
        if (null !== $productId) {
25
            $this->appendToQuery('productId', $productId);
26
        }
27
28
        if (null !== $startTime && null === $pageNavigationToken) {
29
            $this->appendToQuery('startTime', $startTime);
30
        } elseif (null === $startTime && null !== $pageNavigationToken) {
31
            $this->appendToQuery('pageNavigationToken', $pageNavigationToken);
32
        } else {
33
            throw new \InvalidArgumentException('At least "startTime" or "pageNavigationToken" must be set');
34
        }
35
36
        if (null !== $startTime) {
37
            $this->appendToQuery('endTime', $endTime);
38
        }
39
40
        if (null !== $startTime) {
41
            $this->appendToQuery('itemsPerPage', $itemsPerPage);
42
        }
43
44
        if (null !== $pageNavigationToken) {
45
            $this->appendToQuery('pageNumber', $pageNumber);
46
        }
47
48
        // Set HTTP params
49
        $this->type     = 'get';
50
        $this->endpoint = '/availability/slots' . '?' . $this->getQuery();
51
        $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...
52
53
        return $this;
54
    }
55
}
56