Passed
Pull Request — master (#545)
by Dmitriy
01:31
created

EditPostRequest::getId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Blog;
6
7
use OpenApi\Annotations as OA;
0 ignored issues
show
Bug introduced by
The type OpenApi\Annotations 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 Yiisoft\RequestModel\RequestModel;
0 ignored issues
show
Bug introduced by
The type Yiisoft\RequestModel\RequestModel 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...
9
use Yiisoft\Validator\Result;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Validator\Result 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 Yiisoft\Validator\Rule\HasLength;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Validator\Rule\HasLength 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 Yiisoft\Validator\Rule\Required;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Validator\Rule\Required 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 Yiisoft\Validator\RulesProviderInterface;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Validator\RulesProviderInterface 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
14
/**
15
 * @OA\Schema(
16
 *      schema="EditPostRequest",
17
 *      @OA\Property(example="Title post", property="title", format="string"),
18
 *      @OA\Property(example="Text post", property="text", format="string"),
19
 *      @OA\Property(example=1, property="status", format="int"),
20
 * )
21
 */
22
final class EditPostRequest extends RequestModel implements RulesProviderInterface
23
{
24
    public function getId(): int
25
    {
26
        return (int) $this->getAttributeValue('router.id');
27
    }
28
29
    public function getTitle(): string
30
    {
31
        return (string) $this->getAttributeValue('body.title');
32
    }
33
34
    public function getText(): string
35
    {
36
        return (string) $this->getAttributeValue('body.text');
37
    }
38
39
    public function getStatus(): PostStatus
40
    {
41
        return PostStatus::from($this->getAttributeValue('body.status'));
42
    }
43
44
    public function getRules(): array
45
    {
46
        return [
47
            'body.title' => [
48
                new Required(),
49
                new HasLength(min: 5, max: 255),
50
            ],
51
            'body.text' => [
52
                new Required(),
53
                new HasLength(min: 5, max: 1000),
54
            ],
55
            'body.status' => [
56
                new Required(),
57
                static function ($value): Result {
58
                    $result = new Result();
59
                    if (!PostStatus::isValid($value)) {
60
                        $result->addError('Incorrect status');
61
                    }
62
63
                    return $result;
64
                },
65
            ],
66
        ];
67
    }
68
}
69