LicenseChecker   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 8 2
A validLicense() 0 9 3
1
<?php
2
3
namespace Elimuswift\Core\Middleware;
4
5
use Closure;
6
7
class LicenseChecker
8
{
9
    /**
10
     * Handle an incoming request.
11
     *
12
     * @param \Illuminate\Http\Request $request
13
     * @param \Closure                 $next
14
     *
15
     * @return mixed
16
     */
17
    public function handle($request, Closure $next, $licenseKey = null)
18
    {
19
        if ($this->validLicense($licenseKey)) {
20
            return $next($request);
21
        } else {
22
            return response()->json(['UnAuthorized' => 'Invalid Purchase Key'], 403);
23
        }
24
    }
25
26
    /**
27
     * Check if license key is valid.
28
     *
29
     * @return bool
30
     **/
31
    private function validLicense($licenseKey)
32
    {
33
        $purchase = app()->envatoapi->verifyPurchase($licenseKey);
34
        if (is_array($purchase) and $purchase['status'] == 'success') {
35
            return true;
36
        }
37
38
        return false;
39
    }
40
}
41