Completed
Push — master ( 10c8f9...49b9c4 )
by Semyon
01:41
created

havingOutdatedDeviceToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 8
cp 0
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace SemyonChetvertnyh\ApnNotificationChannel;
4
5
use Illuminate\Support\Collection;
6
use Pushok\ApnsResponseInterface;
7
8
class ApnsResponseCollection extends Collection
9
{
10
    /**
11
     * Filter to only unsuccessful responses.
12
     *
13
     * @return \SemyonChetvertnyh\ApnNotificationChannel\ApnsResponseCollection
14
     */
15
    public function onlyUnsuccessful()
16
    {
17
        return $this->reject(function (ApnsResponseInterface $response) {
18
            return $response->getStatusCode() === 200;
19
        });
20
    }
21
22
    /**
23
     * Filter to having outdated token responses.
24
     *
25
     * @return \SemyonChetvertnyh\ApnNotificationChannel\ApnsResponseCollection
26
     */
27
    public function havingOutdatedDeviceToken()
28
    {
29
        return $this->filter(function (ApnsResponseInterface $response) {
30
            return in_array($response->getErrorReason(), [
31
                'BadDeviceToken',
32
                'Unregistered',
33
            ]);
34
        });
35
    }
36
37
    /**
38
     * Get all device tokens.
39
     *
40
     * @return array
41
     */
42
    public function allDeviceTokens()
43
    {
44
        return $this->map(function (ApnsResponseInterface $response) {
45
            return $response->getDeviceToken();
46
        })->all();
47
    }
48
}
49