Completed
Push — master ( 8c9c54...6d4889 )
by Elf
44:15
created

CheckAppClient::handle()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 5
eloc 9
c 2
b 0
f 0
nc 3
nop 2
dl 0
loc 16
ccs 0
cts 14
cp 0
crap 30
rs 8.8571
1
<?php
2
3
namespace ElfSundae\Support\Http\Middleware;
4
5
use Closure;
6
use ElfSundae\Laravel\Agent\Client;
7
use ElfSundae\Laravel\Api\Exceptions\ApiResponseException;
8
9
class CheckAppClient
10
{
11
    /**
12
     * The agent client instance.
13
     *
14
     * @var \ElfSundae\Laravel\Agent\Client
15
     */
16
    protected $client;
17
18
    /**
19
     * Constructor.
20
     *
21
     * @param  \ElfSundae\Laravel\Agent\Client  $client
22
     */
23
    public function __construct(Client $client)
24
    {
25
        $this->client = $client;
26
    }
27
28
    /**
29
     * Handle an incoming request.
30
     *
31
     * @param  \Illuminate\Http\Request  $request
32
     * @param  \Closure  $next
33
     * @return mixed
34
     */
35
    public function handle($request, Closure $next)
36
    {
37
        if (! $this->client->is('AppClient')) {
38
            throw new ApiResponseException('Unauthorized Client', 403);
39
        }
40
41
        if (
42
            $this->client->is('iOS') &&
43
            $this->client->appChannel('App Store') &&
44
            $this->client->get('appVersion') === config('var.ios.app_store_reviewing_version')
45
        ) {
46
            $this->client->set('isAppStoreReviewing', true);
47
        }
48
49
        return $next($request);
50
    }
51
}
52