Completed
Push — master ( 665a2d...66f2ad )
by Valentyn
03:38
created

UpdateWatchedMovieRequest::rules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace App\Movies\Request;
4
5
use App\Movies\DTO\WatchedMovieDTO;
6
use App\Request\BaseRequest;
7
use Symfony\Component\Validator\Constraints as Assert;
8
9
class UpdateWatchedMovieRequest extends BaseRequest
10
{
11 2
    public function rules()
12
    {
13 2
        return new Assert\Collection([
14 2
            'movie' => new Assert\Collection([
15 2
                'vote' => [new Assert\Range(['min' => 0.0, 'max' => 10.0])],
16 2
                'watchedAt' => [new Assert\Date()],
17
            ]),
18
        ]);
19
    }
20
21
    /**
22
     * @throws \Exception
23
     *
24
     * @return WatchedMovieDTO
25
     */
26 2
    public function getWatchedMovieDTO()
27
    {
28 2
        $movieData = $this->get('movie');
29 2
        $vote = (float) $movieData['vote'] ?? null;
30 2
        $watchedAt = !empty($movieData['watchedAt']) ? new \DateTimeImmutable($movieData['watchedAt']) : null;
31
32 2
        return new WatchedMovieDTO(null, null, $vote, $watchedAt);
33
    }
34
}
35