Passed
Pull Request — master (#572)
by Dmitriy
07:44
created

Request::getText()   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\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\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...
12
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...
13
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...
14
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...
15
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...
16
17
/**
18
 * @OA\Schema(
19
 *      schema="BlogPostCreate",
20
 *      @OA\Property(example="Title post", property="title", format="string"),
21
 *      @OA\Property(example="Text post", property="text", format="string"),
22
 *      @OA\Property(example=1, property="status", format="int"),
23
 * )
24
 */
25
final class Request extends RequestModel implements RulesProviderInterface
26
{
27
    public function getId(): int
28
    {
29
        return (int) $this->getAttributeValue('router.id');
30
    }
31
32
    public function getTitle(): string
33
    {
34
        return (string) $this->getAttributeValue('body.title');
35
    }
36
37
    public function getText(): string
38
    {
39
        return (string) $this->getAttributeValue('body.text');
40
    }
41
42
    public function getStatus(): PostStatus
43
    {
44
        return PostStatus::from($this->getAttributeValue('body.status'));
45
    }
46
47
    public function getUser(): User
48
    {
49
        /**
50
         * @var User $identity
51
         */
52
        return $this->getAttributeValue('attributes.' . Authentication::class);
53
    }
54
55
    public function getRules(): array
56
    {
57
        return [
58
            'body.title' => [
59
                new Required(),
60
                new Length(min: 5, max: 255),
61
            ],
62
            'body.text' => [
63
                new Required(),
64
                new Length(min: 5, max: 1000),
65
            ],
66
            'body.status' => [
67
                new Required(),
68
                static function ($value): Result {
69
                    $result = new Result();
70
                    if (!PostStatus::isValid($value)) {
71
                        $result->addError('Incorrect status');
72
                    }
73
                    return $result;
74
                },
75
            ],
76
        ];
77
    }
78
}
79