ThrottleMiddleware   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 15
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A call() 0 11 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Canvas\Middleware;
6
7
use Canvas\Http\Response;
8
use Canvas\Traits\ResponseTrait;
9
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...
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 Phalcon\Mvc\User\Plugin;
0 ignored issues
show
Bug introduced by
The type Phalcon\Mvc\User\Plugin 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...
12
use OakLabs\PhalconThrottler\ThrottlerInterface;
0 ignored issues
show
Bug introduced by
The type OakLabs\PhalconThrottler\ThrottlerInterface 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...
13
use Phalcon\Events\Event;
0 ignored issues
show
Bug introduced by
The type Phalcon\Events\Event 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 Canvas\Exception\ServerErrorHttpException;
15
16
/**
17
 * Class ThrottleMiddleware
18
 *
19
 * @package Canvas\Middleware
20
 *
21
 * @property Micro    $application
22
 * @property Response $response
23
 */
24
class ThrottleMiddleware extends Plugin implements MiddlewareInterface
25
{
26
    use ResponseTrait;
27
28
    public function call(Micro $api)
29
    {
30
        /** @var ThrottlerInterface $throttler */
31
        $throttler = $this->getDI()->get('throttler');
32
        $rateLimit = $throttler->consume($this->request->getClientAddress());
33
34
        if ($rateLimit->isLimited()) {
35
            /**
36
             *@todo give a more informative message
37
             */
38
            throw new ServerErrorHttpException('API Calls limit reached');
0 ignored issues
show
Deprecated Code introduced by
The class Canvas\Exception\ServerErrorHttpException has been deprecated: version 0.1.5 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

38
            throw /** @scrutinizer ignore-deprecated */ new ServerErrorHttpException('API Calls limit reached');
Loading history...
39
        }
40
    }
41
}
42