JsonAuthorizationResponse   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 9
dl 0
loc 20
rs 10
c 2
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A from() 0 3 1
A __construct() 0 13 2
1
<?php
2
3
/**
4
 * Copyright 2022 SURFnet bv
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
0 ignored issues
show
Coding Style introduced by
Missing @link tag in file comment
Loading history...
18
19
namespace Surfnet\StepupMiddleware\ApiBundle\Response;
20
21
use Assert\Assertion;
22
use Surfnet\StepupMiddleware\ApiBundle\Authorization\Value\AuthorizationDecision;
0 ignored issues
show
Bug introduced by
The type Surfnet\StepupMiddleware...e\AuthorizationDecision 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...
23
use Symfony\Component\HttpFoundation\JsonResponse;
24
25
class JsonAuthorizationResponse extends JsonResponse
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class JsonAuthorizationResponse
Loading history...
26
{
27
    public function __construct(int $code, array $errors = [])
28
    {
29
        Assertion::choice($code, [200, 403], 'The status code can be either 200 or 403');
30
        Assertion::allString($errors, 'The error messages should all be strings');
31
32
        $data = [
33
            'code' => $code,
34
        ];
35
        if ($errors !== []) {
36
            $data['errors'] = $errors;
37
        }
38
        // Don't confuse the HTTP status code with the authorization status code
39
        parent::__construct($data, 200);
40
    }
41
42
    public static function from(AuthorizationDecision $decision): self
43
    {
44
        return new self($decision->getCode(), $decision->getErrorMessages());
45
    }
46
}
47