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

CheckAppClient   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 43
ccs 0
cts 18
cp 0
rs 10
wmc 6
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B handle() 0 16 5
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