Passed
Pull Request — master (#572)
by Dmitriy
01:33
created

Request::getText()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Infrastructure\IO\Http\Blog\PutUpdate\Request;
6
7
use App\Application\Blog\Entity\Post\PostStatus;
8
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...
9
use Yiisoft\Hydrator\Validator\Attribute\Validate;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Hydrator\Validator\Attribute\Validate 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\Input\Http\AbstractInput;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Input\Http\AbstractInput 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\Input\Http\Attribute\Parameter\Body;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Input\Http\Attribute\Parameter\Body 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\Hydrator\Temp\RouteArgument;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Hydrator\Temp\RouteArgument 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 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...
14
use Yiisoft\Validator\Rule\Length;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Validator\Rule\Length 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 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...
16
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...
17
18
/**
19
 * @OA\Schema(
20
 *      schema="BlogUpdateRequest",
21
 *      @OA\Property(example="Title post", property="title", format="string"),
22
 *      @OA\Property(example="Text post", property="text", format="string"),
23
 *      @OA\Property(example=1, property="status", format="int"),
24
 * )
25
 */
26
final class Request extends AbstractInput implements RulesProviderInterface
27
{
28
    #[RouteArgument('id')]
29
    private int $id;
30
31
    #[Body('title')]
32
    #[Validate(new Required())]
33
    private string $title = '';
34
35
    #[Body('text')]
36
    #[Validate(new Required())]
37
    private string $text = '';
38
39
    #[Body('status')]
40
    #[Validate(new Required())]
41
    private int $status;
42
43
    public function getId(): int
44
    {
45
        return $this->id;
46
    }
47
48
    public function getTitle(): string
49
    {
50
        return $this->title;
51
    }
52
53
    public function getText(): string
54
    {
55
        return $this->text;
56
    }
57
58
    public function getStatus(): PostStatus
59
    {
60
        return PostStatus::from($this->status);
61
    }
62
63
    public function getRules(): array
64
    {
65
        return [
66
            'title' => [
67
                new Length(min: 5, max: 255),
68
            ],
69
            'text' => [
70
                new Length(min: 5, max: 1000),
71
            ],
72
            'status' => [
73
                static function ($value): Result {
74
                    $result = new Result();
75
                    if (!PostStatus::isValid($value)) {
76
                        $result->addError('Incorrect status');
77
                    }
78
                    return $result;
79
                },
80
            ],
81
        ];
82
    }
83
}
84