Passed
Push — master ( c5502b...385fa8 )
by Radu
04:32
created

AbstractSecurity::verifySsl()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
namespace WebServCo\Api;
3
4
abstract class AbstractSecurity
5
{
6
    protected $request;
7
8
    public function __construct(\WebServCo\Framework\Interfaces\RequestInterface $request)
9
    {
10
        $this->request = $request;
11
    }
12
13
    public function verify()
14
    {
15
        $this->verifySsl();
16
        $this->verifyMethod();
17
        $this->verifyContentType();
18
    }
19
20
    abstract protected function getSupportedContentTypes();
21
22
    abstract protected function getAllowedMethods();
23
24
    abstract public function verifyAuthorization();
25
26
    protected function verifyContentType()
27
    {
28
        $clientContentTypes = $this->request->getAcceptContentTypes();
0 ignored issues
show
Bug introduced by
The method getAcceptContentTypes() does not exist on WebServCo\Framework\Interfaces\RequestInterface. ( Ignorable by Annotation )

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

28
        /** @scrutinizer ignore-call */ 
29
        $clientContentTypes = $this->request->getAcceptContentTypes();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
29
        if (array_key_exists(0, $clientContentTypes)) {
30
            unset($clientContentTypes[0]); // $q == 0 means, that mime-type isn’t supported!
31
        }
32
        $supportedContentTypes = $this->getSupportedContentTypes();
33
        $intersection = array_intersect($clientContentTypes, $supportedContentTypes);
34
        if (empty($intersection)) {
35
            throw new \WebServCo\Framework\Exceptions\UnsupportedMediaTypeException('Unsupported content type');
0 ignored issues
show
Bug introduced by
The type WebServCo\Framework\Exce...ortedMediaTypeException 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...
36
        }
37
        return true;
38
    }
39
40
    protected function verifyMethod()
41
    {
42
        if (!in_array($this->request->getMethod(), $this->getAllowedMethods())) {
43
            throw new \WebServCo\Framework\Exceptions\MethodNotAllowedException('Unsupported method');
0 ignored issues
show
Bug introduced by
The type WebServCo\Framework\Exce...thodNotAllowedException 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...
44
        }
45
        return true;
46
    }
47
48
    protected function verifySsl()
49
    {
50
        $schema = $this->request->getSchema();
51
        if ('https' != $schema) {
52
            throw new \WebServCo\Framework\Exceptions\SslRequiredException('SSL required');
0 ignored issues
show
Bug introduced by
The type WebServCo\Framework\Exce...ns\SslRequiredException 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...
53
        }
54
        return true;
55
    }
56
}
57