Cron::instantWinEmail()   B
last analyzed

Complexity

Conditions 5
Paths 12

Size

Total Lines 44

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 44
rs 8.9048
c 0
b 0
f 0
cc 5
nc 12
nop 0
1
<?php
2
3
namespace PlaygroundGame\Service;
4
5
use Zend\ServiceManager\ServiceManager;
6
use PlaygroundGame\Mapper\GameInterface as GameMapperInterface;
7
8
class Cron
9
{
10
    /**
11
     * @var GameMapperInterface
12
     */
13
    protected $gameMapper;
14
15
    /**
16
     * @var EntryMapperInterface
17
     */
18
    protected $entryMapper;
19
20
    /**
21
     * @var ServiceManager
22
     */
23
    protected $serviceManager;
24
25
    /**
26
     * @var UserServiceOptionsInterface
27
     */
28
    protected $options;
29
30
    public static function cronMail()
31
    {
32
        $configuration = require 'config/application.config.php';
33
        $smConfig = isset($configuration['service_manager']) ? $configuration['service_manager'] : array();
34
        $sm = new \Zend\ServiceManager\ServiceManager(new \Zend\Mvc\Service\ServiceManagerConfig($smConfig));
0 ignored issues
show
Documentation introduced by
new \Zend\Mvc\Service\Se...anagerConfig($smConfig) is of type object<Zend\Mvc\Service\ServiceManagerConfig>, but the function expects a array.

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...
35
        $sm->setService('ApplicationConfig', $configuration);
36
        $sm->get('ModuleManager')->loadModules();
37
        $sm->get('Application')->bootstrap();
38
39
        $mailService = $sm->get('playgrounduser_message');
40
        $gameService = $sm->get('playgroundgame_quiz_service');
41
42
        $from    = "[email protected]";
43
        $subject = "sujet game";
44
45
        $to = "[email protected]";
46
47
        $game = $gameService->checkGame('qooqo');
48
49
        // On recherche les joueurs qui n'ont pas partagé leur quiz après avoir joué
50
        // entry join user join game : distinct user et game et game_entry = 0 et updated_at <= jour-1 et > jour - 2
51
52
        $message = $mailService->createTextMessage(
53
            $from,
54
            $to,
55
            $subject,
56
            'playground-game/email/share_reminder',
57
            array('game' => $game)
58
        );
59
60
        $mailService->send($message);
61
    }
62
63
    public static function instantWinEmail()
64
    {
65
        $configuration = require 'config/application.config.php';
66
        $smConfig = isset($configuration['service_manager']) ? $configuration['service_manager'] : array();
67
        $sm = new \Zend\ServiceManager\ServiceManager(new \Zend\Mvc\Service\ServiceManagerConfig($smConfig));
0 ignored issues
show
Documentation introduced by
new \Zend\Mvc\Service\Se...anagerConfig($smConfig) is of type object<Zend\Mvc\Service\ServiceManagerConfig>, but the function expects a array.

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...
68
        $sm->setService('ApplicationConfig', $configuration);
69
        $sm->get('ModuleManager')->loadModules();
70
        $sm->get('Application')->bootstrap();
71
72
        $mailService = $sm->get('playgrounduser_message');
73
        $gameService = $sm->get('playgroundgame_instantwin_service');
74
75
        $from    = "[email protected]";
76
        $subject = "Votre jeu Instant gagnant";
77
78
        // Je recherche les jeux instantwin en cours
79
        $games = $gameService->getActiveGames(false, 'instantwin');
80
81
        // Je recherche les joueurs qui ont deja joué une seule fois au jeu mais pas rejoué dans le laps autorisé
82
        $arrayUsers = array();
83
        foreach ($games as $game) {
84
            $limitScale = $game->getPlayLimitScale();
85
            $limitDate = $gameService->getLimitDate($limitScale);
86
            $entries = $gameService->getEntryMapper()->findPlayersWithOneEntryBy($game, $limitDate);
87
            foreach ($entries as $e) {
88
                $arrayUsers[$e->getUser()->getId()]['user'] = $e->getUser();
89
                $arrayUsers[$e->getUser()->getId()]['game'] = $game;
90
            }
91
        }
92
93
        // J'envoie un mail de relance
94
        foreach ($arrayUsers as $k => $entry) {
95
            $user = $entry['user'];
96
            $game = $entry['game'];
97
            $message = $mailService->createHtmlMessage(
98
                $from,
99
                $user->getEmail(),
100
                $subject,
101
                'playground-game/email/game_instantwin_reminder',
102
                array('game' => $game, 'user' => $user)
103
            );
104
            $mailService->send($message);
105
        }
106
    }
107
}
108