Completed
Push — master ( 7bbbc8...a7367f )
by Mr
01:59
created

Customers::authenticate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 7
cp 0
rs 9.9332
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\BookingsList;
7
use Bookeo\Models\Customer;
8
use Bookeo\Models\CustomersList;
9
use Bookeo\Models\LinkedPersonList;
10
11
/**
12
 * Operations to manage customers
13
 *
14
 * @package Bookeo\Endpoints
15
 */
16
class Customers extends Client
17
{
18
    /**
19
     * Retrieve customers
20
     *
21
     * Get a list of customers.
22
     *
23
     * @return $this
24
     */
25 View Code Duplication
    public function all(): 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...
26
    {
27
        // Set HTTP params
28
        $this->type     = 'get';
29
        $this->endpoint = '/customers' . '?' . $this->getQuery();
30
        $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...
31
32
        return $this;
33
    }
34
35
    /**
36
     * Create a new customer.
37
     *
38
     * 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.
39
     *
40
     * @param Customer $customer
41
     *
42
     * @return $this
43
     */
44 View Code Duplication
    public function create(Customer $customer): 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...
45
    {
46
        // Set HTTP params
47
        $this->type     = 'post';
48
        $this->endpoint = '/customers' . '?' . $this->getQuery();
49
        $this->params   = $customer;
50
        $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...
51
52
        return $this;
53
    }
54
55
    /**
56
     * Retrieve a customer
57
     *
58
     * Retrieve a customer by its id
59
     *
60
     * @param string $customer_id
61
     *
62
     * @return $this
63
     */
64 View Code Duplication
    public function __invoke(string $customer_id)
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...
65
    {
66
        $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...
67
68
        // Set HTTP params
69
        $this->type     = 'get';
70
        $this->endpoint = '/customers/' . $customer_id . '?' . $this->getQuery();
71
        $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...
72
73
        return $this;
74
    }
75
76
    /**
77
     * Update an existing customer
78
     *
79
     * @param Customer $customer
80
     *
81
     * @return $this
82
     */
83 View Code Duplication
    public function update(Customer $customer): 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...
84
    {
85
        // Set HTTP params
86
        $this->type     = 'put';
87
        $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...
88
        $this->params   = $customer;
89
90
        return $this;
91
    }
92
93
    /**
94
     * Delete a customer
95
     *
96
     * Please note it is not possible to delete customers that have bookings in the future, and that are not cancelled.
97
     * If your application needs to delete a customer with future bookings, make sure to cancel all future bookings for that customer first.
98
     *
99
     * @return $this
100
     */
101
    public function delete(): self
102
    {
103
        // Set HTTP params
104
        $this->type     = 'delete';
105
        $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...
106
107
        return $this;
108
    }
109
110
    /**
111
     * The customer's email address is the "username" used by Bookeo to authenticate customers.
112
     * So to authenticate a customer your application would typically use GET /customers to search for customers with a given email address, and then GET /customers/{id}/authenticate to authenticate.
113
     * Remember that there may be duplicate customer records with the same email address, ex. due to duplicate importing or manual record creation.
114
     *
115
     * @param string $password
116
     *
117
     * @return $this
118
     */
119
    public function authenticate(string $password): self
120
    {
121
        $this->appendToQuery('password', $password);
122
123
        // Set HTTP params
124
        $this->type     = 'get';
125
        $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...
126
127
        return $this;
128
    }
129
130
    /**
131
     * @param string|null $beginDate          if specified, only bookings on or after this date will be included
132
     * @param string|null $endDate            if specified, only bookings on or before this date will be included
133
     * @param bool        $expandParticipants if true, full details of the participants are included (provided the application has read permission over the participant)
134
     * @param int         $itemsPerPage       maximum: 100
135
     * @param string|null $pageNavigationToken
136
     * @param int         $pageNumber
137
     * @return Customers
138
     */
139
    public function bookings(string $beginDate = null, string $endDate = null, bool $expandParticipants = false, int $itemsPerPage = 50, string $pageNavigationToken = null, int $pageNumber = 1): self
140
    {
141
        if (null !== $beginDate) {
142
            $this->appendToQuery('beginDate', $beginDate);
143
        }
144
145
        if (null !== $endDate) {
146
            $this->appendToQuery('endDate', $endDate);
147
        }
148
149
        if (null !== $expandParticipants) {
150
            $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...
151
        }
152
153
        if (null !== $itemsPerPage) {
154
            $this->appendToQuery('itemsPerPage', $itemsPerPage);
155
        }
156
157
        if (null !== $pageNavigationToken) {
158
            $this->appendToQuery('pageNavigationToken', $pageNavigationToken);
159
        }
160
161
        if (null !== $pageNumber) {
162
            $this->appendToQuery('pageNumber', $pageNumber);
163
        }
164
165
        // Set HTTP params
166
        $this->type     = 'get';
167
        $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...
168
        $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...
169
170
        return $this;
171
    }
172
173
    /**
174
     * Get the people linked to a customer
175
     *
176
     * @param int         $itemsPerPage maximum: 100
177
     * @param string|null $pageNavigationToken
178
     * @param int         $pageNumber
179
     * @return Customers
180
     */
181 View Code Duplication
    public function linkedpeople(int $itemsPerPage = 50, string $pageNavigationToken = null, int $pageNumber = 1): 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...
182
    {
183
        if (null !== $itemsPerPage) {
184
            $this->appendToQuery('itemsPerPage', $itemsPerPage);
185
        }
186
187
        if (null !== $pageNavigationToken) {
188
            $this->appendToQuery('pageNavigationToken', $pageNavigationToken);
189
        }
190
191
        if (null !== $pageNumber) {
192
            $this->appendToQuery('pageNumber', $pageNumber);
193
        }
194
195
        // Set HTTP params
196
        $this->type     = 'get';
197
        $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...
198
        $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...
199
200
        return $this;
201
    }
202
}
203