Code Duplication    Length = 41-43 lines in 2 locations

src/Service/InstantWin.php 1 location

@@ 24-66 (lines=43) @@
21
     * @param  string                 $formClass
22
     * @return \PlaygroundGame\Entity\Game
23
     */
24
    public function createOrUpdate(array $data, $game, $formClass)
25
    {
26
        $game = parent::createOrUpdate($data, $game, $formClass);
27
28
        if ($game) {
29
            $path = $this->getOptions()->getMediaPath() . DIRECTORY_SEPARATOR;
30
            $media_url = $this->getOptions()->getMediaUrl() . '/';
31
32
            if (!empty($data['uploadScratchcardImage']['tmp_name'])) {
33
                ErrorHandler::start();
34
                $data['uploadScratchcardImage']['name'] = $this->fileNewname(
35
                    $path,
36
                    $game->getId() . "-" . $data['uploadScratchcardImage']['name']
37
                );
38
                move_uploaded_file(
39
                    $data['uploadScratchcardImage']['tmp_name'],
40
                    $path . $data['uploadScratchcardImage']['name']
41
                );
42
                $game->setScratchcardImage($media_url . $data['uploadScratchcardImage']['name']);
43
                ErrorHandler::stop(true);
44
45
                $game = $this->getGameMapper()->update($game);
46
            }
47
48
            if (isset($data['deleteScratchcardImage']) &&
49
                $data['deleteScratchcardImage'] &&
50
                empty($data['uploadScratchcardImage']['tmp_name'])
51
            ) {
52
                ErrorHandler::start();
53
                $image = $game->getScratchcardImage();
54
                $image = str_replace($media_url, '', $image);
55
                unlink($path .$image);
56
                $game->setScratchcardImage(null);
57
                ErrorHandler::stop(true);
58
            }
59
60
            if ($game->getScheduleOccurrenceAuto()) {
61
                $this->scheduleOccurrences($game, $data);
62
            }
63
        }
64
65
        return $game;
66
    }
67
68
    /**
69
     * We can create Instant win occurrences dynamically

src/Service/Memory.php 1 location

@@ 44-84 (lines=41) @@
41
     * @param  string $formClass
42
     * @return \PlaygroundGame\Entity\Game
43
     */
44
    public function createOrUpdate(array $data, $game, $formClass)
45
    {
46
        $game = parent::createOrUpdate($data, $game, $formClass);
47
48
        if ($game) {
49
            $path = $this->getOptions()->getMediaPath() . DIRECTORY_SEPARATOR;
50
            $media_url = $this->getOptions()->getMediaUrl() . '/';
51
52
            if (!empty($data['uploadBackImage']['tmp_name'])) {
53
                ErrorHandler::start();
54
                $data['uploadBackImage']['name'] = $this->fileNewname(
55
                    $path,
56
                    $game->getId() . "-" . $data['uploadBackImage']['name']
57
                );
58
                move_uploaded_file(
59
                    $data['uploadBackImage']['tmp_name'],
60
                    $path . $data['uploadBackImage']['name']
61
                );
62
                $game->setBackImage($media_url . $data['uploadBackImage']['name']);
63
                ErrorHandler::stop(true);
64
65
                $game = $this->getGameMapper()->update($game);
66
            }
67
68
            if (isset($data['deleteBackImage']) &&
69
                $data['deleteBackImage'] &&
70
                empty($data['uploadBackImage']['tmp_name'])
71
            ) {
72
                ErrorHandler::start();
73
                $image = $game->getBackImage();
74
                $image = str_replace($media_url, '', $image);
75
                unlink($path .$image);
76
                $game->setBackImage(null);
77
                ErrorHandler::stop(true);
78
79
                $game = $this->getGameMapper()->update($game);
80
            }
81
        }
82
83
        return $game;
84
    }
85
86
    /**
87
     * @param  array $data