Completed
Push — master ( 0b4911...4851fa )
by Valentyn
04:19 queued 11s
created

MoviesFixtures   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 11

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 70
c 0
b 0
f 0
wmc 4
lcom 1
cbo 11
ccs 0
cts 34
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A load() 0 41 2
A getDependencies() 0 6 1
1
<?php
2
3
namespace App\Movies\DataFixtures;
4
5
use App\Actors\Entity\Actor;
6
use App\Actors\Entity\ActorTMDB;
7
use App\Actors\Entity\ActorTranslations;
8
use App\Genres\DataFixtures\GenresFixtures;
9
use App\Genres\Entity\Genre;
10
use App\Genres\Entity\GenreTranslations;
11
use App\Movies\DTO\MovieDTO;
12
use App\Movies\DTO\MovieTranslationDTO;
13
use App\Movies\Entity\MovieTMDB;
14
use App\Movies\Service\MovieManageService;
15
use Doctrine\Bundle\FixturesBundle\Fixture;
16
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
17
use Doctrine\Common\Persistence\ObjectManager;
18
use Doctrine\ORM\EntityManager;
19
20
class MoviesFixtures extends Fixture implements DependentFixtureInterface
21
{
22
    const MOVIE_1_ID = 1;
23
    const MOVIE_2_ID = 2;
24
    const MOVIE_TITLE = 'zMs1Os7qwEqWxXvb';
25
    const MOVIE_TMDB_ID = 1;
26
    const MOVIE_TMDB_ID_2 = 2;
27
    const MOVIE_ACTOR_TMDB_ID = 91238;
28
29
    private $movieManageService;
30
31
    public function __construct(MovieManageService $movieManageService)
32
    {
33
        $this->movieManageService = $movieManageService;
34
    }
35
36
    /**
37
     * @param ObjectManager $manager
38
     *
39
     * @throws \Exception
40
     */
41
    public function load(ObjectManager $manager): void
42
    {
43
        if ($manager instanceof EntityManager === false) {
44
            throw new \InvalidArgumentException('MoviesFixtures $manager should be instance of EntityManager');
45
        }
46
        /* @var $manager EntityManager */
47
48
        $movieTitle = self::MOVIE_TITLE;
49
        $movieDTO1 = new MovieDTO($movieTitle, 'http://placehold.it/320x480', 'imdb-test-id1', 60000, 100, '01.01.2009');
50
        $movieDTO2 = new MovieDTO($movieTitle, 'http://placehold.it/320x480', 'imdb-test-id2', 60000, 100, '01.01.2019');
51
        $tmdb = new MovieTMDB(self::MOVIE_TMDB_ID, 7.8, 100);
52
        $tmdb2 = new MovieTMDB(self::MOVIE_TMDB_ID_2, 10, 100);
53
54
        $drama = $manager->getReference(Genre::class, GenresFixtures::GENRE_DRAMA_ID);
55
        $comedy = $manager->getReference(Genre::class, GenresFixtures::GENRE_COMEDY_ID);
56
        $criminal = $manager->getReference(Genre::class, GenresFixtures::GENRE_CRIMINAL_ID);
57
58
        $actor = new Actor('Test MovieActor', new ActorTMDB(self::MOVIE_ACTOR_TMDB_ID));
59
        $actor->addTranslation(new ActorTranslations($actor, 'en', 'Test MovieActor (en)'));
60
61
        $movie = $this->movieManageService->createMovieByDTO($movieDTO1, $tmdb, [$drama, $comedy, $criminal], [
0 ignored issues
show
Documentation introduced by
array($drama, $comedy, $criminal) is of type array<integer,object|nul...ll","2":"object|null"}>, but the function expects a array<integer,object<App\Genres\Entity\Genre>>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
62
            new MovieTranslationDTO('en', "$movieTitle (en)", 'Overview (en)', 'http://placehold.it/320x480'),
63
            new MovieTranslationDTO('uk', "$movieTitle (uk)", 'Overview (uk)', 'http://placehold.it/320x480'),
64
            new MovieTranslationDTO('ru', "$movieTitle (ru)", 'Overview (ru)', 'http://placehold.it/320x480'),
65
        ]);
66
        $movie->addActor($actor);
67
68
        $movie2 = $this->movieManageService->createMovieByDTO($movieDTO2, $tmdb2, [$drama], [
0 ignored issues
show
Documentation introduced by
array($drama) is of type array<integer,object|null,{"0":"object|null"}>, but the function expects a array<integer,object<App\Genres\Entity\Genre>>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
69
            new MovieTranslationDTO('en', "$movieTitle 2 (en)", 'Overview (en)', 'http://placehold.it/320x480'),
70
            new MovieTranslationDTO('uk', "$movieTitle 2 (uk)", 'Overview (uk)', 'http://placehold.it/320x480'),
71
            new MovieTranslationDTO('ru', "$movieTitle 2 (ru)", 'Overview (ru)', 'http://placehold.it/320x480'),
72
        ]);
73
        $movie2->addActor($actor);
74
75
        $manager->getConnection()->exec("ALTER SEQUENCE movies_id_seq RESTART WITH 1; UPDATE movies SET id=nextval('movies_id_seq');");
76
77
        $manager->persist($actor);
78
        $manager->persist($movie);
79
        $manager->persist($movie2);
80
        $manager->flush();
81
    }
82
83
    public function getDependencies(): array
84
    {
85
        return [
86
            GenresFixtures::class,
87
        ];
88
    }
89
}
90