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

ApnsResponseCollection   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 41
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A onlyUnsuccessful() 0 6 1
A havingOutdatedDeviceToken() 0 9 1
A allDeviceTokens() 0 6 1
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