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

UpdateWatchedMovieRequest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 5
dl 0
loc 26
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 9 1
A getWatchedMovieDTO() 0 8 2
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