SubscriptionMiddleware   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 6
c 2
b 0
f 0
dl 0
loc 20
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A call() 0 11 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Canvas\Middleware;
6
7
use Phalcon\Mvc\Micro;
0 ignored issues
show
Bug introduced by
The type Phalcon\Mvc\Micro was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Canvas\Http\Exception\UnauthorizedException;
9
use Canvas\Models\Subscription;
10
11
/**
12
 * Class AuthenticationMiddleware.
13
 *
14
 * @package Niden\Middleware
15
 */
16
class SubscriptionMiddleware extends TokenBase
17
{
18
    /**
19
     * Call me.
20
     *
21
     * @param Micro $api
22
     * @todo need to check section for auth here
23
     * @return bool
24
     */
25
    public function call(Micro $api)
26
    {
27
        if ($api->getDI()->has('userData')) {
28
            $user = $api->getDI()->getUserData();
29
30
            if (!Subscription::getByDefaultCompany($user)->active()) {
31
                throw new UnauthorizedException('Subscription expired, Verify Payment');
32
            }
33
        }
34
35
        return true;
36
    }
37
}
38