Failed Conditions
Branch master (e37483)
by Maximo
06:09
created

TokenBase   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 24
rs 10
c 0
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A isValidCheck() 0 15 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Canvas\Middleware;
6
7
use Canvas\Http\Request;
8
use Canvas\Traits\TokenTrait;
9
use Canvas\Traits\SubscriptionPlanLimitTrait;
10
use Phalcon\Mvc\Micro\MiddlewareInterface;
0 ignored issues
show
Bug introduced by
The type Phalcon\Mvc\Micro\MiddlewareInterface 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...
11
use Canvas\Exception\UnauthorizedHttpException;
12
use Canvas\Exception\SubscriptionPlanFailureException;
13
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...
14
use Phalcon\Http\RequestInterface;
1 ignored issue
show
Bug introduced by
The type Phalcon\Http\RequestInterface 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...
15
use Canvas\Models\Subscription;
16
17
/**
18
 * Class AuthenticationMiddleware.
19
 *
20
 * @package Niden\Middleware
21
 */
22
abstract class TokenBase implements MiddlewareInterface
23
{
24
    use TokenTrait;
25
    use SubscriptionPlanLimitTrait;
26
27
    /**
28
     * @param Request $request
29
     * @return bool
30
     */
31
    protected function isValidCheck(RequestInterface $request, Micro $app): bool
32
    {
33
        $calledRoute = $app['router']->getMatchedRoute()->getCompiledPattern();
34
35
        if (isset($app['userData']) && !Subscription::getPaymentStatus($app->getDI()->getUserData())) {
36
            if (!array_key_exists($calledRoute, $this->bypassRoutes)) {
37
                throw new SubscriptionPlanFailureException('Subscription expired,update payment method or verify payment');
38
            } else {
39
                if (!in_array($request->getMethod(), $this->bypassRoutes[$calledRoute])) {
40
                    throw new SubscriptionPlanFailureException('Subscription expired,update payment method or verify payment');
41
                }
42
            }
43
        }
44
45
        return true;
46
    }
47
}
48