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

Request   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 26
dl 0
loc 51
rs 10
c 1
b 0
f 0
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A validateStatus() 0 7 2
A getStatus() 0 3 1
A getText() 0 3 1
A getId() 0 3 1
A getTitle() 0 3 1
A getUser() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Infrastructure\IO\Http\Blog\PostCreate\Request;
6
7
use App\Application\Blog\Entity\Post\PostStatus;
8
use App\Application\User\Entity\User;
9
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...
10
use Yiisoft\Auth\Middleware\Authentication;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Auth\Middleware\Authentication 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\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...
12
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...
13
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...
14
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...
15
use Yiisoft\Input\Http\Attribute\Parameter\Request as RequestParameter;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Input\Http\Attribute\Parameter\Request 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\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...
17
use Yiisoft\Validator\Rule\Callback;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Validator\Rule\Callback 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...
18
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...
19
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...
20
21
/**
22
 * @OA\Schema(
23
 *      schema="BlogPostCreate",
24
 *      @OA\Property(example="Title post", property="title", format="string"),
25
 *      @OA\Property(example="Text post", property="text", format="string"),
26
 *      @OA\Property(example=1, property="status", format="int"),
27
 * )
28
 */
29
final class Request extends AbstractInput
30
{
31
    #[RouteArgument('id')]
32
    private int $id;
33
    #[Body('title')]
34
    #[Validate(new Required())]
35
    #[Validate(new Length(min: 5, max: 255))]
36
    private string $title;
37
    #[Body('text')]
38
    #[Validate(new Required())]
39
    #[Validate(new Length(min: 5, max: 1000))]
40
    private string $text;
41
    #[Body('status')]
42
    #[Validate(new Required())]
43
    #[Validate(new Callback([self::class, 'validateStatus']))]
44
    private int $status;
45
    #[RequestParameter(Authentication::class)]
46
    private User $user;
47
48
    public function getId(): int
49
    {
50
        return $this->id;
51
    }
52
53
    public function getTitle(): string
54
    {
55
        return $this->title;
56
    }
57
58
    public function getText(): string
59
    {
60
        return $this->text;
61
    }
62
63
    public function getStatus(): PostStatus
64
    {
65
        return PostStatus::from($this->status);
66
    }
67
68
    public function getUser(): User
69
    {
70
        return $this->user;
71
    }
72
73
    public static function validateStatus($value): Result
74
    {
75
        $result = new Result();
76
        if (!PostStatus::isValid($value)) {
77
            $result->addError('Incorrect status: ' . $value);
78
        }
79
        return $result;
80
    }
81
}
82