Completed
Push — master ( fd3cdf...64e9a4 )
by Mr
02:05
created

Webhooks::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 10
loc 10
ccs 0
cts 8
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\Webhook;
7
use Bookeo\Models\WebhooksList;
8
9
/**
10
 * Manage callback notifications
11
 *
12
 * @package Bookeo\Endpoints
13
 */
14
class Webhooks extends Client
15
{
16
    /**
17
     * List all webhooks
18
     *
19
     * Retrieve all the webhooks for this api key
20
     *
21
     * @return $this
22
     */
23
    public function all(): self
24
    {
25
        // Set HTTP params
26
        $this->type     = 'get';
27
        $this->endpoint = '/webhooks' . '?' . $this->getQuery();
28
        $this->response = WebhooksList::class;
0 ignored issues
show
Documentation introduced by
The property response does not exist on object<Bookeo\Endpoints\Webhooks>. 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...
29
30
        return $this;
31
    }
32
33
    /**
34
     * Create a new webhook
35
     *
36
     * Note that if an existing webhook for the same domain and type was already set for this api key, it will be automatically replaced by this new webhook.
37
     * In other words, there can be only one webhook for each combination of domain and type, for an API key.
38
     * So to upgrade an existing webhook URL, simply create a new one with the same domain and type, but a different URL.
39
     *
40
     * For webhook with domain "bookings" and type "deleted", the notification will be sent whether the booking is canceled or completely deleted.
41
     * Users can delete bookings by, for example, deleting their associated customer.
42
     * Also note that these "bookings" "deleted" notifications are sent even for bookings in the past.
43
     *
44
     * @param Webhook $webhook
45
     *
46
     * @return $this
47
     */
48 View Code Duplication
    public function create(Webhook $webhook): 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...
49
    {
50
        // Set HTTP params
51
        $this->type     = 'post';
52
        $this->endpoint = '/webhooks' . '?' . $this->getQuery();
53
        $this->params   = $webhook;
54
        $this->response = Webhook::class;
0 ignored issues
show
Documentation introduced by
The property response does not exist on object<Bookeo\Endpoints\Webhooks>. 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...
55
56
        return $this;
57
    }
58
59
    /**
60
     * Retrieve a webhook
61
     *
62
     * @param string $webhook_id
63
     *
64
     * @return $this
65
     */
66 View Code Duplication
    public function __invoke(string $webhook_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...
67
    {
68
        $this->webhook_id = $webhook_id;
0 ignored issues
show
Documentation introduced by
The property webhook_id does not exist on object<Bookeo\Endpoints\Webhooks>. 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...
69
70
        // Set HTTP params
71
        $this->type     = 'get';
72
        $this->endpoint = '/webhooks/' . $webhook_id . '?' . $this->getQuery();
73
        $this->response = Webhook::class;
0 ignored issues
show
Documentation introduced by
The property response does not exist on object<Bookeo\Endpoints\Webhooks>. 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...
74
75
        return $this;
76
    }
77
78
    /**
79
     * Delete a webhook
80
     *
81
     * @return $this
82
     */
83
    public function delete(): self
84
    {
85
        // Set HTTP params
86
        $this->type     = 'delete';
87
        $this->endpoint = '/webhooks/' . $this->webhook_id;
0 ignored issues
show
Documentation introduced by
The property webhook_id does not exist on object<Bookeo\Endpoints\Webhooks>. 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
89
        return $this;
90
    }
91
}
92