Skip to content

Commit e868670

Browse files
committed
Add "kind" argument to notifications getAll method
1 parent b0aa124 commit e868670

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"psr/http-client-implementation": "^1.0",
1717
"psr/http-factory": "^1.0",
1818
"psr/http-factory-implementation": "^1.0",
19+
"symfony/deprecation-contracts": "^2.1",
1920
"symfony/options-resolver": "^3.4|^4.0|^5.0"
2021
},
2122
"require-dev": {

src/Notifications.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,20 @@ public function getOne(string $id): array
3939
*
4040
* @param int $limit How many notifications to return (max 50)
4141
* @param int $offset Results offset (results are sorted by ID)
42+
* @param int $kind Kind of notifications returned. Default (not set) is all notification types
4243
*/
43-
public function getAll(int $limit = null, int $offset = null): array
44+
public function getAll(int $limit = null, int $offset = null/*, int $kind = null */): array
4445
{
46+
if (func_num_args() > 2 && !is_int(func_get_arg(2))) {
47+
trigger_deprecation('norkunas/onesignal-php-api', '2.1.0', 'Method %s() will have a third `int $kind` argument. Not defining it or passing a non integer value is deprecated.', __METHOD__);
48+
} elseif (__CLASS__ !== static::class) {
49+
$r = new \ReflectionMethod($this, __FUNCTION__);
50+
51+
if (\count($r->getParameters()) > 2) {
52+
trigger_deprecation('norkunas/onesignal-php-api', '2.1.0', 'Method %s() will have a third `int $kind` argument. Not defining it or passing a non integer value is deprecated.', __METHOD__);
53+
}
54+
}
55+
4556
$query = ['app_id' => $this->client->getConfig()->getApplicationId()];
4657

4758
if ($limit !== null) {
@@ -52,6 +63,10 @@ public function getAll(int $limit = null, int $offset = null): array
5263
$query['offset'] = $offset;
5364
}
5465

66+
if (func_num_args() > 2 && is_int(func_get_arg(2))) {
67+
$query['kind'] = func_get_arg(2);
68+
}
69+
5570
$request = $this->createRequest('GET', '/notifications?'.http_build_query($query));
5671
$request = $request->withHeader('Authorization', "Basic {$this->client->getConfig()->getApplicationAuthKey()}");
5772

0 commit comments

Comments
 (0)