Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 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 |
||
| 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 |
|
| 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) |
|
| 77 | |||
| 78 | /** |
||
| 79 | * Delete a webhook |
||
| 80 | * |
||
| 81 | * @return $this |
||
| 82 | */ |
||
| 83 | public function delete(): self |
||
| 91 | } |
||
| 92 |
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@propertyannotation to your class or interface to document the existence of this variable.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.