Completed
Push — master ( 8a3179...d462e2 )
by greg
24:52 queued 21:12
created

GameController::checkFbRegistration()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 40
rs 9.28
c 0
b 0
f 0
cc 4
nc 4
nop 2
1
<?php
2
3
namespace PlaygroundGame\Controller\Frontend;
4
5
use PlaygroundGame\Service\GameService;
6
use PlaygroundGame\Service\Prize as PrizeService;
7
use Zend\Http\PhpEnvironment\Response;
8
use Zend\Mvc\Controller\AbstractActionController;
9
use Zend\ServiceManager\ServiceLocatorInterface;
10
use Zend\Session\Container;
11
use Zend\Stdlib\Parameters;
12
use Zend\View\Model\JsonModel;
13
use Zend\View\Model\ViewModel;
14
15
class GameController extends AbstractActionController
16
{
17
    /**
18
     * @var \PlaygroundGame\Service\GameService
19
     */
20
    protected $gameService;
21
22
    protected $prizeService;
23
24
    protected $options;
25
26
    protected $game;
27
28
    protected $user;
29
30
    protected $withGame = array(
31
        'home',
32
        'index',
33
        'terms',
34
        'conditions',
35
        'leaderboard',
36
        'register',
37
        'bounce',
38
        'createTeam',
39
        'inviteToTeam',
40
        'prizes',
41
        'prize',
42
        'share',
43
        'optin',
44
        'login',
45
        'logout',
46
        'ajaxforgot',
47
        'play',
48
        'result',
49
        'preview',
50
        'list',
51
        'comments',
52
    );
53
54
    protected $withOnlineGame = array(
55
        'leaderboard',
56
        'register',
57
        'bounce',
58
        'play',
59
        'result',
60
    );
61
62
    protected $withAnyUser = array(
63
        'share',
64
        'result',
65
        'play',
66
        'logout',
67
        'createTeam',
68
        'inviteToTeam',
69
    );
70
71
    protected $isSoloGame = false;
72
73
    /**
74
     *
75
     * @var ServiceManager
76
     */
77
    protected $serviceLocator;
78
79
    public function __construct(ServiceLocatorInterface $locator)
80
    {
81
        $this->serviceLocator = $locator;
0 ignored issues
show
Documentation Bug introduced by
It seems like $locator of type object<Zend\ServiceManag...erviceLocatorInterface> is incompatible with the declared type object<PlaygroundGame\Co...rontend\ServiceManager> of property $serviceLocator.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
82
    }
83
84
    public function getServiceLocator()
85
    {
86
        return $this->serviceLocator;
87
    }
88
89
    public function setEventManager(\Zend\EventManager\EventManagerInterface $events)
90
    {
91
        parent::setEventManager($events);
92
93
        $controller = $this;
94
95
        $events->attach('dispatch', function (\Zend\Mvc\MvcEvent $e) use ($controller) {
96
97
            $session = new Container('facebook');
98
            $identifier = $e->getRouteMatch()->getParam('id');
99
100
            // I set the right identifier if I come from FB
101
            // From FB, the games have all the same identifier. I use the FB Page Id to find the right game
102
            // So for 1 FB page, you can have only 1 game ;/
103
            if ($identifier === 'facebook' && $session->offsetExists('signed_request')) {
104
                $sr = $session->offsetGet('signed_request');
105
                $identifier = $controller->getGameService()->getGameIdentifierFromFacebook($sr['page']['id']);
106
            }
107
     
108
            $controller->game = $controller->getGameService()->checkGame($identifier, false);
109
110
            if (!$controller->game &&
111
                    in_array($controller->params('action'), $controller->withGame)
112
                ) {
113
                return $controller->notFoundAction();
114
            }
115
116
            if ($controller->game &&
117
                    $controller->game->isClosed() &&
118
                    in_array($controller->params('action'), $controller->withOnlineGame)
119
                ) {
120
                return $controller->notFoundAction();
121
            }
122
123
            $config = $this->getServiceLocator()->get('config');
124
            $customUrl = str_replace('frontend.', '', $e->getRouteMatch()->getMatchedRouteName());
125
            $customUrl = explode("/", $customUrl)[0];
126
127
            if (
128
                    isset($config['custom_games']) &&
129
                    $controller->game !== false &&
130
                    isset($config['custom_games'][$controller->game->getIdentifier()]) &&
131
                    $controller->getRequest()->getUri()->getHost() === $customUrl
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Zend\Stdlib\RequestInterface as the method getUri() does only exist in the following implementations of said interface: Zend\Http\PhpEnvironment\Request, Zend\Http\Request, Zend\Psr7Bridge\Zend\Request.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
132
                ) {
133
                $this->isSoloGame = true;
134
            }
135
136
            if ($controller->game) {
137
                // this is possible to create a specific game design in /design/frontend/default/custom.
138
                //It will precede all others templates.
139
                $templatePathResolver = $controller->getServiceLocator()->get('Zend\View\Resolver\TemplatePathStack');
140
                $l = $templatePathResolver->getPaths();
141
                $templatePathResolver->addPath($l[0].'custom/'.$controller->game->getIdentifier());
142
            }
143
144
                $controller->user = $controller->zfcUserAuthentication()->getIdentity();
0 ignored issues
show
Documentation Bug introduced by
The method zfcUserAuthentication does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
145
            if ($controller->game &&
146
                    !$controller->user &&
147
                    !$controller->game->getAnonymousAllowed() &&
148
                    in_array($controller->params('action'), $controller->withAnyUser)
149
                ) {
150
                $redirect = urlencode(
151
                    $controller->url()->fromRoute(
152
                        'frontend/'.$controller->game->getClassType().'/'.$controller->params('action'),
153
                        array('id'              => $controller->game->getIdentifier()),
154
                        array('force_canonical' => true)
155
                    )
156
                );
157
158
                if ($this->isSoloGame) {
159
                     $urlRegister = $controller->url()->fromRoute(
160
                         'frontend.'.$customUrl.'/'.$controller->game->getClassType().'/user-register',
161
                         array(),
162
                         array('force_canonical' => true)
163
                     ).'?redirect='.$redirect;
164
                } else {
165
                    $urlRegister = $controller->url()->fromRoute(
166
                        'frontend/zfcuser/register',
167
                        array(),
168
                        array('force_canonical' => true)
169
                    ).'?redirect='.$redirect;
170
                }
171
172
                // code permettant d'identifier un custom game
173
                // ligne $config = $controller->getGameService()->getServiceManager()->get('config');
174
                // ligne $customUrl = str_replace('frontend.', '', $e->getRouteMatch()->getParam('area', ''));
175
                // ligne if ($config['custom_games'][$controller->game->getIdentifier()] &&
176
                // ligne    $controller->getRequest()->getUri()->getHost() === $customUrl
177
                // ligne ) {
178
                return $controller->redirect()->toUrl($urlRegister);
179
            }
180
181
                return;
182
        }, 100);// execute before executing action logic
183
    }
184
185
    /**
186
     * Action called if matched action does not exist
187
     * For this view not to be catched by Zend\Mvc\View\RouteNotFoundStrategy
188
     * it has to be rendered in the controller. Hence the code below.
189
     *
190
     * This action is injected as a catchall action for each custom_games definition
191
     * This way, when a custom_game is created, the 404 is it's responsability and the
192
     * view can be defined in design/frontend/default/custom/$slug/playground_game/$gametype/404.phtml
193
     *
194
     *
195
     * @return \Zend\Stdlib\ResponseInterface
196
     */
197
    public function notFoundAction()
198
    {
199
        $templatePathResolver = $this->getServiceLocator()->get('Zend\View\Resolver\TemplatePathStack');
200
201
        // I create a template path in which I can find a custom template
202
        $controller     = explode('\\', get_class($this));
203
        $controllerPath = str_replace('Controller', '', end($controller));
204
        $controllerPath = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '-\\1', $controllerPath));
205
        $uri            = $this->getRequest()->getUri()->getPath();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Zend\Stdlib\RequestInterface as the method getUri() does only exist in the following implementations of said interface: Zend\Http\PhpEnvironment\Request, Zend\Http\Request, Zend\Psr7Bridge\Zend\Request.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
206
        if ($this->game) {
207
            $uri = str_replace($controllerPath.'/'.$this->game->getIdentifier().'/', '', $uri);
208
        }
209
        $uri      = str_replace("/".$this->getEvent()->getRouteMatch()->getParam('locale')."/", "/", $uri);
210
        $template = 'playground-game/'.$controllerPath.'/custom'.$uri;
211
212
        if (false === $templatePathResolver->resolve($template)) {
213
            $viewRender = $this->getServiceLocator()->get('ViewRenderer');
214
215
            $this->getEvent()->getRouteMatch()->setParam('action', 'not-found');
216
            $this->response->setStatusCode(404);
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Zend\Stdlib\ResponseInterface as the method setStatusCode() does only exist in the following implementations of said interface: Zend\Http\PhpEnvironment\Response, Zend\Http\Response, Zend\Http\Response\Stream.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
217
218
            $res = 'error/404';
219
220
            $viewModel = $this->buildView($this->game);
221
            $viewModel->setTemplate($res);
0 ignored issues
show
Bug introduced by
The method setTemplate does only exist in Zend\View\Model\ViewModel, but not in Zend\Http\PhpEnvironment\Response.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
222
223
            $this->layout()->setVariable("content", $viewRender->render($viewModel));
0 ignored issues
show
Bug introduced by
The method setVariable does only exist in Zend\View\Model\ModelInterface, but not in Zend\Mvc\Controller\Plugin\Layout.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
224
            $this->response->setContent($viewRender->render($this->layout()));
225
226
            return $this->response;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->response; (Zend\Stdlib\ResponseInterface) is incompatible with the return type of the parent method Zend\Mvc\Controller\Abst...troller::notFoundAction of type Zend\View\Model\ViewModel.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
227
        }
228
229
        $viewModel = $this->buildView($this->game);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->buildView($this->game); of type Zend\Http\PhpEnvironment...nd\View\Model\ViewModel adds the type Zend\View\Model\ViewModel to the return on line 232 which is incompatible with the return type documented by PlaygroundGame\Controlle...troller::notFoundAction of type Zend\Stdlib\ResponseInterface.
Loading history...
230
        $viewModel->setTemplate($template);
231
232
        return $viewModel;
233
    }
234
235
    /**
236
     * This action acts as a hub : Depending on the first step of the game, it will forward the action to this step
237
     */
238
    public function homeAction()
239
    {
240
        // This fix exists only for safari in FB on Windows : we need to redirect the user to the page
241
        // outside of iframe for the cookie to be accepted. PlaygroundCore redirects to the FB Iframed page when
242
        // it discovers that the user arrives for the first time on the game in FB.
243
        // When core redirects, it adds a 'redir_fb_page_id' var in the querystring
244
        // Here, we test if this var exist, and then send the user back to the game in FB.
245
        // Now the cookie will be accepted by Safari...
246
        $pageId = $this->params()->fromQuery('redir_fb_page_id');
247
        if (!empty($pageId)) {
248
            $appId = 'app_'.$this->game->getFbAppId();
249
            $url   = '//www.facebook.com/pages/game/'.$pageId.'?sk='.$appId;
250
251
            return $this->redirect()->toUrl($url);
252
        }
253
254
        // If an entry has already been done during this session, I reset the anonymous_identifier cookie
255
        // so that another person can play the same game (if game conditions are fullfilled)
256
        $session = new Container('anonymous_identifier');
257
        if ($session->offsetExists('anonymous_identifier')) {
258
            $session->offsetUnset('anonymous_identifier');
259
        }
260
261
        $classGame = __NAMESPACE__ . '\\' . ucfirst($this->game->getClassType());
262
        return $this->forward()->dispatch(
263
            $classGame,
264
            array(
265
                'controller' => $classGame,
266
                'action'     => $this->game->firstStep(),
267
                'id'         => $this->game->getIdentifier()
268
            )
269
        );
270
    }
271
272
    /**
273
     * Homepage of the game
274
     */
275
    public function indexAction()
276
    {
277
        $isSubscribed = false;
278
279
        $entry = $this->getGameService()->checkExistingEntry($this->game, $this->user);
280
        if ($entry) {
281
            $isSubscribed = true;
282
        }
283
284
        $viewModel = $this->buildView($this->game);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->buildView($this->game); of type Zend\Http\PhpEnvironment...nd\View\Model\ViewModel adds the type Zend\Http\PhpEnvironment\Response to the return on line 289 which is incompatible with the return type of the parent method Zend\Mvc\Controller\Abst...Controller::indexAction of type Zend\View\Model\ViewModel.
Loading history...
285
        $viewModel->setVariables(array(
0 ignored issues
show
Bug introduced by
The method setVariables does only exist in Zend\View\Model\ViewModel, but not in Zend\Http\PhpEnvironment\Response.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
286
            'isSubscribed' => $isSubscribed,
287
        ));
288
289
        return $viewModel;
290
    }
291
292
    /**
293
     * leaderboardAction
294
     *
295
     * @return ViewModel $viewModel
296
     */
297
    public function leaderboardAction()
298
    {
299
        $filter = $this->getEvent()->getRouteMatch()->getParam('filter');
300
        $p      = $this->getEvent()->getRouteMatch()->getParam('p');
301
302
        $beforeLayout = $this->layout()->getTemplate();
0 ignored issues
show
Bug introduced by
The method getTemplate does only exist in Zend\View\Model\ModelInterface, but not in Zend\Mvc\Controller\Plugin\Layout.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
303
        $subViewModel = $this->forward()->dispatch(
304
            'playgroundreward',
305
            array('action' => 'leaderboard', 'filter' => $filter, 'p' => $p)
306
        );
307
308
        // suite au forward, le template de layout a changé, je dois le rétablir...
309
        $this->layout()->setTemplate($beforeLayout);
310
        $this->layout()->setVariables(
0 ignored issues
show
Bug introduced by
The method setVariables does only exist in Zend\View\Model\ModelInterface, but not in Zend\Mvc\Controller\Plugin\Layout.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
311
            array(
312
                'action' => $this->params('action'),
313
                'game'   => $this->game,
314
            )
315
        );
316
317
        $subViewModel->setVariables($this->getShareData($this->game));
318
        $subViewModel->setVariables(array('game' => $this->game, 'user' => $this->user));
319
320
        return $subViewModel;
321
    }
322
323
    /**
324
     * This action has been designed to be called by other controllers
325
     * It gives the ability to display an information form and persist it in the game entry
326
     *
327
     * @return \Zend\View\Model\ViewModel
328
     */
329
    public function registerAction()
330
    {
331
        $formDef = $this->game->getPlayerForm();
332
        if ($formDef !== null) {
333
            $form = $this->getGameService()->createFormFromJson($formDef->getForm(), 'playerForm');
334
        } else {
335
            return $this->notFoundAction();
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->notFoundAction(); (Zend\Stdlib\ResponseInterface) is incompatible with the return type documented by PlaygroundGame\Controlle...troller::registerAction of type Zend\View\Model\ViewModel.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
336
        }
337
338
        if ($this->getRequest()->isPost()) {
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Zend\Stdlib\RequestInterface as the method isPost() does only exist in the following implementations of said interface: Zend\Http\PhpEnvironment\Request, Zend\Http\Request, Zend\Psr7Bridge\Zend\Request.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
339
            // POST Request: Process form
340
            $data = array_merge_recursive(
341
                $this->getRequest()->getPost()->toArray(),
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Zend\Stdlib\RequestInterface as the method getPost() does only exist in the following implementations of said interface: Zend\Http\PhpEnvironment\Request, Zend\Http\Request, Zend\Psr7Bridge\Zend\Request.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
342
                $this->getRequest()->getFiles()->toArray()
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Zend\Stdlib\RequestInterface as the method getFiles() does only exist in the following implementations of said interface: Zend\Http\PhpEnvironment\Request, Zend\Http\Request, Zend\Psr7Bridge\Zend\Request.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
343
            );
344
345
            $form->setData($data);
346
347
            if ($form->isValid()) {
348
                // steps of the game
349
                $steps = $this->game->getStepsArray();
350
                // sub steps of the game
351
                $viewSteps = $this->game->getStepsViewsArray();
352
353
                // register position
354
                $key = array_search($this->params('action'), $viewSteps);
355
                if (!$key) {
356
                    // register is not a substep of the game so it's a step
357
                    $key     = array_search($this->params('action'), $steps);
358
                    $keyStep = true;
359
                } else {
360
                    // register was a substep, i search the index of its parent
361
                    $key     = array_search($key, $steps);
362
                    $keyStep = false;
363
                }
364
365
                // play position
366
                $keyplay = array_search('play', $viewSteps);
367
368
                if (!$keyplay) {
369
                    // play is not a substep, so it's a step
370
                    $keyplay     = array_search('play', $steps);
371
                    $keyplayStep = true;
372
                } else {
373
                    // play is a substep so I search the index of its parent
374
                    $keyplay     = array_search($keyplay, $steps);
375
                    $keyplayStep = false;
376
                }
377
378
                // If register step before play, I don't have no entry yet. I have to create one
379
                // If register after play step, I search for the last entry created by play step.
380
381
                if ($key < $keyplay || ($keyStep && !$keyplayStep && $key <= $keyplay)) {
382
                    $entry = $this->getGameService()->play($this->game, $this->user);
383
                    if (!$entry) {
384
                        // the user has already taken part of this game and the participation limit has been reached
385
                        $this->flashMessenger()->addMessage('Vous avez déjà participé');
0 ignored issues
show
Documentation Bug introduced by
The method flashMessenger does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
386
387
                        return $this->redirect()->toUrl(
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->redirect()...me->getIdentifier()))); (Zend\Http\Response) is incompatible with the return type documented by PlaygroundGame\Controlle...troller::registerAction of type Zend\View\Model\ViewModel.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
388
                            $this->frontendUrl()->fromRoute(
0 ignored issues
show
Documentation Bug introduced by
The method frontendUrl does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
389
                                $this->game->getClassType().'/result',
390
                                array(
391
                                    'id' => $this->game->getIdentifier(),
392
                                )
393
                            )
394
                        );
395
                    }
396
                } else {
397
                    // I'm looking for an entry without anonymousIdentifier (the active entry in fact).
398
                    $entry = $this->getGameService()->findLastEntry($this->game, $this->user);
399
                    if ($this->getGameService()->hasReachedPlayLimit($this->game, $this->user)) {
400
                        // the user has already taken part of this game and the participation limit has been reached
401
                        $this->flashMessenger()->addMessage('Vous avez déjà participé');
0 ignored issues
show
Documentation Bug introduced by
The method flashMessenger does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
402
403
                        return $this->redirect()->toUrl(
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->redirect()...me->getIdentifier()))); (Zend\Http\Response) is incompatible with the return type documented by PlaygroundGame\Controlle...troller::registerAction of type Zend\View\Model\ViewModel.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
404
                            $this->frontendUrl()->fromRoute(
0 ignored issues
show
Documentation Bug introduced by
The method frontendUrl does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
405
                                $this->game->getClassType().'/result',
406
                                array(
407
                                    'id' => $this->game->getIdentifier(),
408
                                )
409
                            )
410
                        );
411
                    }
412
                }
413
414
                $this->getGameService()->updateEntryPlayerForm($form->getData(), $this->game, $this->user, $entry);
415
416
                if (!empty($this->game->nextStep($this->params('action')))) {
417
                    return $this->redirect()->toUrl(
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->redirect()..._canonical' => true))); (Zend\Http\Response) is incompatible with the return type documented by PlaygroundGame\Controlle...troller::registerAction of type Zend\View\Model\ViewModel.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
418
                        $this->frontendUrl()->fromRoute(
0 ignored issues
show
Documentation Bug introduced by
The method frontendUrl does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
419
                            $this->game->getClassType().'/'.$this->game->nextStep($this->params('action')),
420
                            array('id'              => $this->game->getIdentifier()),
421
                            array('force_canonical' => true)
422
                        )
423
                    );
424
                }
425
            }
426
        }
427
428
        $viewModel = $this->buildView($this->game);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->buildView($this->game); of type Zend\Http\PhpEnvironment...nd\View\Model\ViewModel adds the type Zend\Http\PhpEnvironment\Response to the return on line 433 which is incompatible with the return type documented by PlaygroundGame\Controlle...troller::registerAction of type Zend\View\Model\ViewModel.
Loading history...
429
        $viewModel->setVariables(array(
0 ignored issues
show
Bug introduced by
The method setVariables does only exist in Zend\View\Model\ViewModel, but not in Zend\Http\PhpEnvironment\Response.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
430
                'form' => $form,
431
            ));
432
433
        return $viewModel;
434
    }
435
436
    /**
437
     * This action takes care of the terms of the game
438
     */
439
    public function termsAction()
440
    {
441
        $viewModel = $this->buildView($this->game);
442
443
        return $viewModel;
444
    }
445
446
    /**
447
     * This action takes care of the conditions of the game
448
     */
449
    public function conditionsAction()
450
    {
451
        $viewModel = $this->buildView($this->game);
452
453
        return $viewModel;
454
    }
455
456
    /**
457
     * This action takes care of bounce page of the game
458
     */
459
    public function bounceAction()
460
    {
461
        $availableGames = $this->getGameService()->getAvailableGames($this->user);
462
463
        $rssUrl = '';
464
        $config = $this->getGameService()->getServiceManager()->get('config');
465
        if (isset($config['rss']['url'])) {
466
            $rssUrl = $config['rss']['url'];
467
        }
468
469
        $viewModel = $this->buildView($this->game);
470
        $viewModel->setVariables(array(
0 ignored issues
show
Bug introduced by
The method setVariables does only exist in Zend\View\Model\ViewModel, but not in Zend\Http\PhpEnvironment\Response.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
471
                'rssUrl'         => $rssUrl,
472
                'user'           => $this->user,
473
                'availableGames' => $availableGames,
474
            ));
475
476
        return $viewModel;
477
    }
478
479
    /**
480
     * This action displays the Prizes page associated to the game
481
     */
482
    public function prizesAction()
483
    {
484
        if (count($this->game->getPrizes()) == 0) {
485
            return $this->notFoundAction();
486
        }
487
488
        $viewModel = $this->buildView($this->game);
489
490
        return $viewModel;
491
    }
492
493
    /**
494
     * This action displays a specific Prize page among those associated to the game
495
     */
496
    public function prizeAction()
497
    {
498
        $prizeIdentifier = $this->getEvent()->getRouteMatch()->getParam('prize');
499
        $prize           = $this->getPrizeService()->getPrizeMapper()->findByIdentifier($prizeIdentifier);
500
501
        if (!$prize) {
502
            return $this->notFoundAction();
503
        }
504
505
        $viewModel = $this->buildView($this->game);
506
        $viewModel->setVariables(array('prize' => $prize));
0 ignored issues
show
Bug introduced by
The method setVariables does only exist in Zend\View\Model\ViewModel, but not in Zend\Http\PhpEnvironment\Response.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
507
508
        return $viewModel;
509
    }
510
511
    public function gameslistAction()
512
    {
513
        $layoutViewModel = $this->layout();
514
515
        $slider = new ViewModel();
516
        $slider->setTemplate('playground-game/common/top_promo');
517
518
        $sliderItems = $this->getGameService()->getActiveSliderGames();
519
520
        $slider->setVariables(array('sliderItems' => $sliderItems));
521
522
        $layoutViewModel->addChild($slider, 'slider');
0 ignored issues
show
Bug introduced by
The method addChild does only exist in Zend\View\Model\ModelInterface, but not in Zend\Mvc\Controller\Plugin\Layout.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
523
524
        $games = $this->getGameService()->getActiveGames(false, '', 'endDate');
525
        if (is_array($games)) {
526
            $paginator = new \Zend\Paginator\Paginator(new \Zend\Paginator\Adapter\ArrayAdapter($games));
527
        } else {
528
            $paginator = $games;
529
        }
530
531
        $paginator->setItemCountPerPage(7);
532
        $paginator->setCurrentPageNumber($this->getEvent()->getRouteMatch()->getParam('p'));
533
534
        $bitlyclient = $this->getOptions()->getBitlyUrl();
535
        $bitlyuser   = $this->getOptions()->getBitlyUsername();
536
        $bitlykey    = $this->getOptions()->getBitlyApiKey();
537
538
        $this->getViewHelper('HeadMeta')->setProperty('bt:client', $bitlyclient);
539
        $this->getViewHelper('HeadMeta')->setProperty('bt:user', $bitlyuser);
540
        $this->getViewHelper('HeadMeta')->setProperty('bt:key', $bitlykey);
541
542
        $this->layout()->setVariables(
0 ignored issues
show
Bug introduced by
The method setVariables does only exist in Zend\View\Model\ModelInterface, but not in Zend\Mvc\Controller\Plugin\Layout.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
543
            array(
544
                'sliderItems'  => $sliderItems,
545
                'currentPage'  => array(
546
                    'pageGames'   => 'games',
547
                    'pageWinners' => '',
548
                ),
549
            )
550
        );
551
552
        return new ViewModel(
553
            array(
554
                'games' => $paginator,
555
            )
556
        );
557
    }
558
559
    public function shareAction()
560
    {
561
        $statusMail = null;
562
        $lastEntry  = null;
563
564
        // steps of the game
565
        $steps = $this->game->getStepsArray();
566
        // sub steps of the game
567
        $viewSteps = $this->game->getStepsViewsArray();
568
569
        // share position
570
        $key = array_search($this->params('action'), $viewSteps);
571
        if (!$key) {
572
            // share is not a substep of the game so it's a step
573
            $key = array_search($this->params('action'), $steps);
574
        } else {
575
            // share was a substep, I search the index of its parent
576
            $key = array_search($key, $steps);
577
        }
578
579
        // play position
580
        $keyplay = array_search('play', $viewSteps);
581
582
        if (!$keyplay) {
583
            // play is not a substep, so it's a step
584
            $keyplay = array_search('play', $steps);
585
        } else {
586
            // play is a substep so I search the index of its parent
587
            $keyplay = array_search($keyplay, $steps);
588
        }
589
590
        if ($key && $keyplay && $keyplay <= $key) {
591
            // Has the user finished the game ?
592
            $lastEntry = $this->getGameService()->findLastInactiveEntry($this->game, $this->user);
593
594
            if ($lastEntry === null) {
595
                return $this->redirect()->toUrl(
596
                    $this->frontendUrl()->fromRoute(
0 ignored issues
show
Documentation Bug introduced by
The method frontendUrl does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
597
                        $this->game->getClassType(),
598
                        array('id' => $this->game->getIdentifier())
599
                    )
600
                );
601
            }
602
        }
603
604
        $form = $this->getServiceLocator()->get('playgroundgame_sharemail_form');
605
        $form->setAttribute('method', 'post');
606
607
        // buildView must be before sendMail because it adds the game template path to the templateStack
608
        $viewModel = $this->buildView($this->game);
609
610 View Code Duplication
        if ($this->getRequest()->isPost()) {
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Zend\Stdlib\RequestInterface as the method isPost() does only exist in the following implementations of said interface: Zend\Http\PhpEnvironment\Request, Zend\Http\Request, Zend\Psr7Bridge\Zend\Request.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
611
            $data = $this->getRequest()->getPost()->toArray();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Zend\Stdlib\RequestInterface as the method getPost() does only exist in the following implementations of said interface: Zend\Http\PhpEnvironment\Request, Zend\Http\Request, Zend\Psr7Bridge\Zend\Request.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
612
            $form->setData($data);
613
            if ($form->isValid()) {
614
                $result = $this->getGameService()->sendShareMail($data, $this->game, $this->user, $lastEntry);
615
                if ($result) {
616
                    $statusMail = true;
617
                }
618
            }
619
        }
620
621
        $viewModel->setVariables(array(
0 ignored issues
show
Bug introduced by
The method setVariables does only exist in Zend\View\Model\ViewModel, but not in Zend\Http\PhpEnvironment\Response.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
622
                'statusMail' => $statusMail,
623
                'form'       => $form,
624
            ));
625
626
        return $viewModel;
627
    }
628
629
    public function inviteToTeamAction()
630
    {
631
632
        if (count($this->user->getTeams()) == 0) {
633
            return $this->redirect()->toUrl(
634
                $this->frontendUrl()->fromRoute(
0 ignored issues
show
Documentation Bug introduced by
The method frontendUrl does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
635
                    $this->game->getClassType().'/create-team',
636
                    array('id' => $this->game->getIdentifier())
637
                )
638
            );
639
        }
640
641
        $team = $this->user->getTeams()->first(); 
642
        $invitationMapper = $this->getServiceLocator()->get('playgroundgame_invitation_mapper');
643
        $invitations = $invitationMapper->findBy(array('host' => $this->user, 'game' => $this->game));
644
        $statusMail = null;
645
        $message = '';
646
        $isHost = ($this->user->getId() === $team->getHost()->getId()) ? true : false;
647
648
        $form = $this->getServiceLocator()->get('playgroundgame_sharemail_form');
649
        $form->setAttribute('method', 'post');
650
651
        if ($this->getRequest()->isPost()) {
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Zend\Stdlib\RequestInterface as the method isPost() does only exist in the following implementations of said interface: Zend\Http\PhpEnvironment\Request, Zend\Http\Request, Zend\Psr7Bridge\Zend\Request.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
652
            $data = $this->getRequest()->getPost()->toArray();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Zend\Stdlib\RequestInterface as the method getPost() does only exist in the following implementations of said interface: Zend\Http\PhpEnvironment\Request, Zend\Http\Request, Zend\Psr7Bridge\Zend\Request.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
653
            $form->setData($data);
654
            if ($form->isValid()) {
655
                $result = $this->getGameService()->inviteToTeam($data, $this->game, $this->user);
656
                if ($result['result']) {
657
                    $statusMail = true;
658
                } else {
659
                    $statusMail = false;
660
                    $message    = $result['message'];
661
                }
662
            }
663
        }
664
665
        $viewModel = $this->buildView($this->game);
666
        $viewModel->setVariables(array(
0 ignored issues
show
Bug introduced by
The method setVariables does only exist in Zend\View\Model\ViewModel, but not in Zend\Http\PhpEnvironment\Response.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
667
            'team'       => $team,
668
            'invitations'=> $invitations,
669
            'message'    => $message,
670
            'statusMail' => $statusMail,
671
            'form'       => $form,
672
            'isHost'     => $isHost,
673
        ));
674
675
        return $viewModel;
676
    }
677
678
    public function createTeamAction()
679
    {
680
        if (count($this->user->getTeams()) > 0) {
681
            return $this->redirect()->toUrl(
682
                $this->frontendUrl()->fromRoute(
0 ignored issues
show
Documentation Bug introduced by
The method frontendUrl does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
683
                    $this->game->getClassType().'/invite-to-team',
684
                    array('id' => $this->game->getIdentifier())
685
                )
686
            );
687
        }
688
689
        $form = $this->getServiceLocator()->get('playgroundgame_createteam_form');
690
        $form->setAttribute('method', 'post');
691
692
        if ($this->getRequest()->isPost()) {
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Zend\Stdlib\RequestInterface as the method isPost() does only exist in the following implementations of said interface: Zend\Http\PhpEnvironment\Request, Zend\Http\Request, Zend\Psr7Bridge\Zend\Request.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
693
            $data = $this->getRequest()->getPost()->toArray();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Zend\Stdlib\RequestInterface as the method getPost() does only exist in the following implementations of said interface: Zend\Http\PhpEnvironment\Request, Zend\Http\Request, Zend\Psr7Bridge\Zend\Request.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
694
            $form->setData($data);
695
            if ($form->isValid()) {
696
                $teamMapper = $this->getServiceLocator()->get('playgrounduser_team_mapper');
697
                $users = new \Doctrine\Common\Collections\ArrayCollection();
698
                $users->add($this->user);
699
                $teamName = $data['name'];
700
                $slugify = new \PlaygroundCore\Filter\Slugify;
701
702
                $team = new \PlaygroundUser\Entity\Team();
703
                $team->setName($teamName);
704
                $team->setIdentifier($slugify($teamName));
705
                $team->setHost($this->user);
706
                $team->addUsers($users);
707
708
                $teamMapper->insert($team);
709
710
                return $this->redirect()->toUrl(
711
                    $this->frontendUrl()->fromRoute(
0 ignored issues
show
Documentation Bug introduced by
The method frontendUrl does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
712
                        $this->game->getClassType().'/invite-to-team',
713
                        array('id' => $this->game->getIdentifier())
714
                    )
715
                );
716
            }
717
        }
718
719
        $viewModel = $this->buildView($this->game);
720
        $viewModel->setVariables(array(
0 ignored issues
show
Bug introduced by
The method setVariables does only exist in Zend\View\Model\ViewModel, but not in Zend\Http\PhpEnvironment\Response.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
721
            'form'       => $form,
722
        ));
723
724
        return $viewModel;
725
    }
726
727 View Code Duplication
    public function fbshareAction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
728
    {
729
        $viewModel = new JsonModel();
730
        $viewModel->setTerminal(true);
731
        $fbId = $this->params()->fromQuery('fbId');
732
        if (!$this->game) {
733
            return $this->errorJson();
734
        }
735
        $entry = $this->getGameService()->checkExistingEntry($this->game, $this->user);
736
        if (!$entry) {
737
            return $this->errorJson();
738
        }
739
        if (!$fbId) {
740
            return $this->errorJson();
741
        }
742
743
        $this->getGameService()->postFbWall($fbId, $this->game, $this->user, $entry);
744
745
        return $this->successJson();
746
    }
747
748
    public function fbrequestAction()
749
    {
750
        $viewModel = new ViewModel();
751
        $viewModel->setTerminal(true);
752
        $fbId = $this->params()->fromQuery('fbId');
753
        $to   = $this->params()->fromQuery('to');
754
755
        if (!$this->game) {
756
            return $this->errorJson();
757
        }
758
        $entry = $this->getGameService()->checkExistingEntry($this->game, $this->user);
759
        if (!$entry) {
760
            return $this->errorJson();
761
        }
762
        if (!$fbId) {
763
            return $this->errorJson();
764
        }
765
766
        $this->getGameService()->postFbRequest($fbId, $this->game, $this->user, $entry, $to);
767
768
        return $this->successJson();
769
    }
770
771
    public function tweetAction()
772
    {
773
        $tweetId = $this->params()->fromQuery('tweetId');
774
775
        if (!$this->game) {
776
            return $this->errorJson();
777
        }
778
        $entry = $this->getGameService()->checkExistingEntry($this->game, $this->user);
779
        if (!$entry) {
780
            return $this->errorJson();
781
        }
782
        if (!$tweetId) {
783
            return $this->errorJson();
784
        }
785
786
        $this->getGameService()->postTwitter($tweetId, $this->game, $this->user, $entry);
787
788
        return $this->successJson();
789
    }
790
791 View Code Duplication
    public function googleAction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
792
    {
793
        $viewModel = new ViewModel();
794
        $viewModel->setTerminal(true);
795
        $googleId = $this->params()->fromQuery('googleId');
796
797
        if (!$this->game) {
798
            return $this->errorJson();
799
        }
800
        $entry = $this->getGameService()->checkExistingEntry($this->game, $this->user);
801
        if (!$entry) {
802
            return $this->errorJson();
803
        }
804
        if (!$googleId) {
805
            return $this->errorJson();
806
        }
807
808
        $this->getGameService()->postGoogle($googleId, $this->game, $this->user, $entry);
809
810
        return $this->successJson();
811
    }
812
813
    public function optinAction()
814
    {
815
        $userService = $this->getServiceLocator()->get('zfcuser_user_service');
816
817
        if ($this->getRequest()->isPost()) {
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Zend\Stdlib\RequestInterface as the method isPost() does only exist in the following implementations of said interface: Zend\Http\PhpEnvironment\Request, Zend\Http\Request, Zend\Psr7Bridge\Zend\Request.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
818
            $data['optin']        = ($this->params()->fromPost('optin'))?1:0;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
819
            $data['optinPartner'] = ($this->params()->fromPost('optinPartner'))?1:0;
820
821
            $userService->updateNewsletter($data);
822
        }
823
824
        return $this->redirect()->toUrl(
825
            $this->frontendUrl()->fromRoute(
0 ignored issues
show
Documentation Bug introduced by
The method frontendUrl does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
826
                $this->game->getClassType(),
827
                array('id' => $this->game->getIdentifier())
828
            )
829
        );
830
    }
831
832
    public function loginAction()
833
    {
834
        $request = $this->getRequest();
835
        $redirect = "";
836
        if ($request->getQuery()->get('redirect') != '') {
837
            $redirect = $request->getQuery()->get('redirect');
838
        }
839
        $form    = $this->getServiceLocator()->get('zfcuser_login_form');
840
841
        if ($request->isPost()) {
842
            $form->setData($request->getPost());
843
844
            if (!$form->isValid()) {
845
                $this->flashMessenger()->addMessage(
0 ignored issues
show
Documentation Bug introduced by
The method flashMessenger does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
846
                    'Authentication failed. Please try again.'
847
                );
848
849
                $viewModel = $this->buildView($this->game);
850
                $viewModel->setVariables(array(
0 ignored issues
show
Bug introduced by
The method setVariables does only exist in Zend\View\Model\ViewModel, but not in Zend\Http\PhpEnvironment\Response.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
851
                        'form'          => $form,
852
                        'flashMessages' => $this->flashMessenger()->getMessages(),
0 ignored issues
show
Documentation Bug introduced by
The method flashMessenger does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
853
                    ));
854
855
                return $viewModel;
856
            }
857
858
            // clear adapters
859
            $this->zfcUserAuthentication()->getAuthAdapter()->resetAdapters();
0 ignored issues
show
Documentation Bug introduced by
The method zfcUserAuthentication does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
860
            $this->zfcUserAuthentication()->getAuthService()->clearIdentity();
0 ignored issues
show
Documentation Bug introduced by
The method zfcUserAuthentication does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
861
862
            $logged = $this->forward()->dispatch('playgrounduser_user', array('action' => 'ajaxauthenticate'));
863
864
            if (!$logged) {
865
                $this->flashMessenger()->addMessage(
0 ignored issues
show
Documentation Bug introduced by
The method flashMessenger does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
866
                    'Authentication failed. Please try again.'
867
                );
868
869
                return $this->redirect()->toUrl(
870
                    $this->frontendUrl()->fromRoute(
0 ignored issues
show
Documentation Bug introduced by
The method frontendUrl does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
871
                        $this->game->getClassType().'/login',
872
                        array('id' => $this->game->getIdentifier())
873
                    )
874
                );
875 View Code Duplication
            } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
876
                if ($redirect != "") {
877
                    return $this->redirect()->toUrl($redirect);
878
                } else {
879
                    return $this->redirect()->toUrl(
880
                        $this->frontendUrl()->fromRoute(
0 ignored issues
show
Documentation Bug introduced by
The method frontendUrl does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
881
                            $this->game->getClassType().'/'.$this->game->nextStep('index'),
882
                            array('id' => $this->game->getIdentifier())
883
                        )
884
                    );
885
                }
886
            }
887
        }
888
889
        $form->setAttribute(
890
            'action',
891
            $this->frontendUrl()->fromRoute(
0 ignored issues
show
Documentation Bug introduced by
The method frontendUrl does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
892
                $this->game->getClassType().'/login',
893
                array('id' => $this->game->getIdentifier())
894
            )
895
        );
896
        $viewModel = $this->buildView($this->game);
897
        $viewModel->setVariables(array(
898
                'form'          => $form,
899
                'flashMessages' => $this->flashMessenger()->getMessages(),
0 ignored issues
show
Documentation Bug introduced by
The method flashMessenger does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
900
            ));
901
        return $viewModel;
902
    }
903
904
    public function logoutAction()
905
    {
906
        $viewModel = $this->forward()->dispatch(
907
            'playgrounduser_user',
908
            array(
909
                'controller' => 'playgrounduser_user',
910
                'action'     => 'logout',
911
                'id'         => $this->game->getIdentifier()
912
            )
913
        );
914
915
        if ($viewModel && $viewModel instanceof \Zend\View\Model\ViewModel) {
916
            $this->layout()->setVariables(array('game' => $this->game));
0 ignored issues
show
Bug introduced by
The method setVariables does only exist in Zend\View\Model\ModelInterface, but not in Zend\Mvc\Controller\Plugin\Layout.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
917
            $viewModel->setVariables(array('game'      => $this->game));
918
        }
919
920
        return $viewModel;
921
    }
922
923
    public function userregisterAction()
924
    {
925
        $pguserOptions = $this->getServiceLocator()->get('playgrounduser_module_options');
926
        $userOptions = $this->getServiceLocator()->get('zfcuser_module_options');
927
928 View Code Duplication
        if ($this->zfcUserAuthentication()->hasIdentity()) {
0 ignored issues
show
Documentation Bug introduced by
The method zfcUserAuthentication does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
929
            return $this->redirect()->toUrl(
930
                $this->frontendUrl()->fromRoute(
0 ignored issues
show
Documentation Bug introduced by
The method frontendUrl does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
931
                    $this->game->getClassType().'/'.$this->game->nextStep('index'),
932
                    array('id' => $this->game->getIdentifier())
933
                )
934
            );
935
        }
936
        $request       = $this->getRequest();
937
        $service       = $this->getServiceLocator()->get('zfcuser_user_service');
938
        $form          = $this->getServiceLocator()->get('playgroundgame_register_form');
939
        $socialnetwork = $this->params()->fromRoute('socialnetwork', false);
940
        $form->setAttribute(
941
            'action',
942
            $this->frontendUrl()->fromRoute(
0 ignored issues
show
Documentation Bug introduced by
The method frontendUrl does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
943
                $this->game->getClassType().'/user-register',
944
                array('id' => $this->game->getIdentifier())
945
            )
946
        );
947
        $params            = array();
948
        $socialCredentials = array();
949
950
        if ($userOptions->getUseRedirectParameterIfPresent() && $request->getQuery()->get('redirect')) {
951
            $redirect = $request->getQuery()->get('redirect');
952
        } else {
953
            $redirect = false;
954
        }
955
956
        if ($socialnetwork) {
957
            $infoMe = $this->getProviderService()->getInfoMe($socialnetwork);
0 ignored issues
show
Documentation Bug introduced by
The method getProviderService does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
958
959
            if (!empty($infoMe)) {
960
                $user = $this->getProviderService()->getUserProviderMapper()->findUserByProviderId(
0 ignored issues
show
Documentation Bug introduced by
The method getProviderService does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
961
                    $infoMe->identifier,
962
                    $socialnetwork
963
                );
964
965
                if ($user || $service->getOptions()->getCreateUserAutoSocial() === true) {
966
                    //on le dirige vers l'action d'authentification
967
                    if (!$redirect && $userOptions->getLoginRedirectRoute() != '') {
968
                        $redirect = $this->frontendUrl()->fromRoute(
0 ignored issues
show
Documentation Bug introduced by
The method frontendUrl does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
969
                            $this->game->getClassType().'/login',
970
                            array('id' => $this->game->getIdentifier())
971
                        );
972
                    }
973
                    $redir = $this->frontendUrl()->fromRoute(
0 ignored issues
show
Documentation Bug introduced by
The method frontendUrl does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
974
                        $this->game->getClassType().'/login',
975
                        array('id' => $this->game->getIdentifier())
976
                    ).'/'.$socialnetwork.($redirect?'?redirect='.$redirect:'');
977
978
                    return $this->redirect()->toUrl($redir);
979
                }
980
981
                // Je retire la saisie du login/mdp
982
                $form->setAttribute(
983
                    'action',
984
                    $this->frontendUrl()->fromRoute(
0 ignored issues
show
Documentation Bug introduced by
The method frontendUrl does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
985
                        $this->game->getClassType().'/user-register',
986
                        array(
987
                            'id'            => $this->game->getIdentifier(),
988
                            'socialnetwork' => $socialnetwork,
989
990
                        )
991
                    )
992
                );
993
                $form->remove('password');
994
                $form->remove('passwordVerify');
995
996
                $birthMonth = $infoMe->birthMonth;
997
                if (strlen($birthMonth) <= 1) {
998
                    $birthMonth = '0'.$birthMonth;
999
                }
1000
                $birthDay = $infoMe->birthDay;
1001
                if (strlen($birthDay) <= 1) {
1002
                    $birthDay = '0'.$birthDay;
1003
                }
1004
1005
                $gender = $infoMe->gender;
1006
                if ($gender == 'female') {
1007
                    $title = 'Me';
1008
                } else {
1009
                    $title = 'M';
1010
                }
1011
1012
                $params = array(
1013
                    //'birth_year'  => $infoMe->birthYear,
1014
                    'title'      => $title,
1015
                    'dob'        => $birthDay.'/'.$birthMonth.'/'.$infoMe->birthYear,
1016
                    'firstname'  => $infoMe->firstName,
1017
                    'lastname'   => $infoMe->lastName,
1018
                    'email'      => $infoMe->email,
1019
                    'postalCode' => $infoMe->zip,
1020
                );
1021
                $socialCredentials = array(
1022
                    'socialNetwork' => strtolower($socialnetwork),
1023
                    'socialId'      => $infoMe->identifier,
1024
                );
1025
            }
1026
        }
1027
1028
        $redirectUrl = $this->frontendUrl()->fromRoute(
0 ignored issues
show
Documentation Bug introduced by
The method frontendUrl does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
1029
            $this->game->getClassType().'/user-register',
1030
            array('id' => $this->game->getIdentifier())
1031
        ).($socialnetwork?'/'.$socialnetwork:'').($redirect?'?redirect='.$redirect:'');
1032
        $prg = $this->prg($redirectUrl, true);
0 ignored issues
show
Documentation Bug introduced by
The method prg does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
1033
1034
        if ($prg instanceof Response) {
1035
            return $prg;
1036
        } elseif ($prg === false) {
1037
            $form->setData($params);
1038
            $viewModel = $this->buildView($this->game);
1039
            $viewModel->setVariables(array(
0 ignored issues
show
Bug introduced by
The method setVariables does only exist in Zend\View\Model\ViewModel, but not in Zend\Http\PhpEnvironment\Response.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
1040
                'registerForm'       => $form,
1041
                'enableRegistration' => $userOptions->getEnableRegistration(),
1042
                'redirect'           => $redirect,
1043
            ));
1044
            return $viewModel;
1045
        }
1046
1047
        $post = $prg;
1048
        if (isset($post['optin'])) {
1049
            $post['optin'] = 1;
1050
        }
1051
        if (isset($post['optinPartner'])) {
1052
            $post['optinPartner'] = 1;
1053
        }
1054
        $post = array_merge(
1055
            $post,
1056
            $socialCredentials
1057
        );
1058
1059
        if ($pguserOptions->getUseRecaptcha()) {
1060
            if (!isset($post['g-recaptcha-response']) || $post['g-recaptcha-response'] == '' || !$this->recaptcha()->recaptcha($post['g-recaptcha-response'])) {
0 ignored issues
show
Documentation Bug introduced by
The method recaptcha does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
1061
                $this->flashMessenger()->addErrorMessage('Invalid Captcha. Please try again.');
0 ignored issues
show
Documentation Bug introduced by
The method flashMessenger does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
1062
                $form->setData($post);
1063
                $viewModel = $this->buildView($this->game);
1064
                $viewModel->setVariables(array(
1065
                        'registerForm'       => $form,
1066
                        'enableRegistration' => $userOptions->getEnableRegistration(),
1067
                        'redirect'           => $redirect,
1068
                        'bah'                => 'coco',
1069
                        'flashMessages'      => $this->flashMessenger()->getMessages(),
0 ignored issues
show
Documentation Bug introduced by
The method flashMessenger does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
1070
                        'flashErrors'        => $this->flashMessenger()->getErrorMessages(),
0 ignored issues
show
Documentation Bug introduced by
The method flashMessenger does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
1071
                    ));
1072
1073
                return $viewModel;
1074
            }
1075
        }
1076
1077
        if ($this->game->getOnInvitation()) {
1078
            $credential = trim(
1079
                $post[$this->getGameService()->getOptions()->getOnInvitationField()]
1080
            );
1081
            if (!$credential) {
1082
                $credential = $this->params()->fromQuery(
1083
                    $this->getGameService()->getOptions()->getOnInvitationField()
1084
                );
1085
            }
1086
            $found = $this->getGameService()->getInvitationMapper()->findOneBy(array('requestKey' => $credential));
1087
1088
            if (!$found || !empty($found->getUser())) {
1089
                $this->flashMessenger()->addMessage(
0 ignored issues
show
Documentation Bug introduced by
The method flashMessenger does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
1090
                    'Authentication failed. Please try again.'
1091
                );
1092
                $form->setData($post);
1093
                $viewModel = $this->buildView($this->game);
1094
                $viewModel->setVariables(array(
1095
                        'registerForm'       => $form,
1096
                        'enableRegistration' => $userOptions->getEnableRegistration(),
1097
                        'redirect'           => $redirect,
1098
                        'flashMessages'      => $this->flashMessenger()->getMessages(),
0 ignored issues
show
Documentation Bug introduced by
The method flashMessenger does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
1099
                        'flashErrors'        => $this->flashMessenger()->getErrorMessages(),
0 ignored issues
show
Documentation Bug introduced by
The method flashMessenger does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
1100
                    ));
1101
1102
                return $viewModel;
1103
            }
1104
        }
1105
1106
        $user = $service->register($post, 'playgroundgame_register_form');
1107
1108
        if (!$user) {
1109
            $viewModel = $this->buildView($this->game);
1110
            $viewModel->setVariables(array(
1111
                    'registerForm'       => $form,
1112
                    'enableRegistration' => $userOptions->getEnableRegistration(),
1113
                    'redirect'           => $redirect,
1114
                    'flashMessages'      => $this->flashMessenger()->getMessages(),
0 ignored issues
show
Documentation Bug introduced by
The method flashMessenger does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
1115
                    'flashErrors'        => $this->flashMessenger()->getErrorMessages(),
0 ignored issues
show
Documentation Bug introduced by
The method flashMessenger does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
1116
                ));
1117
1118
            return $viewModel;
1119
        }
1120
1121
        if ($this->game->getOnInvitation()) {
1122
            // user has been created, associate the code with the userId
1123
            $found->setUser($user);
0 ignored issues
show
Bug introduced by
The variable $found does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1124
            $this->getGameService()->getInvitationMapper()->update($found);
1125
        }
1126
1127
        if ($service->getOptions()->getEmailVerification()) {
1128
            $vm = new ViewModel(array('userEmail' => $user->getEmail()));
1129
            $vm->setTemplate('playground-user/register/registermail');
1130
1131
            return $vm;
1132
        } elseif ($service->getOptions()->getLoginAfterRegistration()) {
1133
            $identityFields = $service->getOptions()->getAuthIdentityFields();
1134
            if (in_array('email', $identityFields)) {
1135
                $post['identity'] = $user->getEmail();
1136
            } elseif (in_array('username', $identityFields)) {
1137
                $post['identity'] = $user->getUsername();
1138
            }
1139
            $post['credential'] = isset($post['password'])?$post['password']:'';
1140
            $request->setPost(new Parameters($post));
1141
1142
            // clear adapters
1143
            $this->zfcUserAuthentication()->getAuthAdapter()->resetAdapters();
0 ignored issues
show
Documentation Bug introduced by
The method zfcUserAuthentication does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
1144
            $this->zfcUserAuthentication()->getAuthService()->clearIdentity();
0 ignored issues
show
Documentation Bug introduced by
The method zfcUserAuthentication does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
1145
1146
            $logged = $this->forward()->dispatch('playgrounduser_user', array('action' => 'ajaxauthenticate'));
1147
1148
            if ($logged) {
1149
                return $this->redirect()->toUrl(
1150
                    $this->frontendUrl()->fromRoute(
0 ignored issues
show
Documentation Bug introduced by
The method frontendUrl does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
1151
                        $this->game->getClassType().'/'.$this->game->nextStep('index'),
1152
                        array('id' => $this->game->getIdentifier())
1153
                    )
1154
                );
1155 View Code Duplication
            } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1156
                $this->flashMessenger()->setNamespace('zfcuser-login-form')->addMessage(
0 ignored issues
show
Documentation Bug introduced by
The method flashMessenger does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
1157
                    'Authentication failed. Please try again.'
1158
                );
1159
                return $this->redirect()->toUrl(
1160
                    $this->frontendUrl()->fromRoute(
0 ignored issues
show
Documentation Bug introduced by
The method frontendUrl does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
1161
                        $this->game->getClassType().'/login',
1162
                        array('id' => $this->game->getIdentifier())
1163
                    )
1164
                );
1165
            }
1166
        }
1167
1168
        $redirect = $this->frontendUrl()->fromRoute(
0 ignored issues
show
Documentation Bug introduced by
The method frontendUrl does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
1169
            $this->game->getClassType().'/login',
1170
            array('id' => $this->game->getIdentifier())
1171
        ).($socialnetwork?'/'.$socialnetwork:'').($redirect?'?redirect='.$redirect:'');
1172
1173
        return $this->redirect()->toUrl($redirect);
1174
    }
1175
1176 View Code Duplication
    public function checkTokenAction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1177
    {
1178
        $viewModel = $this->forward()->dispatch(
1179
            'playgrounduser_user',
1180
            array(
1181
                'controller' => 'playgrounduser_user',
1182
                'action' => 'check-token',
1183
                'id' => $this->game->getIdentifier(),
1184
                'token' => $this->params()->fromRoute('token', null)
1185
            )
1186
        );
1187
1188
        if ($viewModel && $viewModel instanceof \Zend\View\Model\ViewModel) {
1189
            $this->layout()->setVariables(array('game' => $this->game));
0 ignored issues
show
Bug introduced by
The method setVariables does only exist in Zend\View\Model\ModelInterface, but not in Zend\Mvc\Controller\Plugin\Layout.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
1190
            $viewModel->setVariables(array('game' => $this->game));
1191
        }
1192
1193
        return $viewModel;
1194
    }
1195
1196
    public function userProfileAction()
1197
    {
1198
        $viewModel = $this->forward()->dispatch(
1199
            'playgrounduser_user',
1200
            array(
1201
                'controller' => 'playgrounduser_user',
1202
                'action'     => 'profile',
1203
                'id'         => $this->game->getIdentifier()
1204
            )
1205
        );
1206
1207
        if ($viewModel && $viewModel instanceof \Zend\View\Model\ViewModel) {
1208
            $this->layout()->setVariables(array('game' => $this->game));
0 ignored issues
show
Bug introduced by
The method setVariables does only exist in Zend\View\Model\ModelInterface, but not in Zend\Mvc\Controller\Plugin\Layout.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
1209
            $viewModel->setVariables(array('game'      => $this->game));
1210
        }
1211
1212
        return $viewModel;
1213
    }
1214
1215
    public function userresetAction()
1216
    {
1217
        $viewModel = $this->forward()->dispatch(
1218
            'playgrounduser_forgot',
1219
            array(
1220
                'controller' => 'playgrounduser_forgot',
1221
                'action'     => 'reset',
1222
                'id'         => $this->game->getIdentifier(),
1223
                'userId'     => $this->params()->fromRoute('userId', null),
1224
                'token'      => $this->params()->fromRoute('token', null),
1225
            )
1226
        );
1227
1228
        if ($viewModel && $viewModel instanceof \Zend\View\Model\ViewModel) {
1229
            $this->layout()->setVariables(array('game' => $this->game));
0 ignored issues
show
Bug introduced by
The method setVariables does only exist in Zend\View\Model\ModelInterface, but not in Zend\Mvc\Controller\Plugin\Layout.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
1230
            $viewModel->setVariables(array('game'      => $this->game));
1231
        }
1232
1233
        return $viewModel;
1234
    }
1235
1236
    public function ajaxforgotAction()
1237
    {
1238
        $view = $this->forward()->dispatch(
1239
            'playgrounduser_forgot',
1240
            array(
1241
                'controller' => 'playgrounduser_forgot',
1242
                'action'     => 'ajaxforgot',
1243
                'id'         => $this->game->getIdentifier()
1244
            )
1245
        );
1246
1247
        if ($view && $view instanceof \Zend\View\Model\ViewModel) {
1248
            $this->layout()->setVariables(array('game' => $this->game));
0 ignored issues
show
Bug introduced by
The method setVariables does only exist in Zend\View\Model\ModelInterface, but not in Zend\Mvc\Controller\Plugin\Layout.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
1249
            $view->setVariables(array('game'           => $this->game));
1250
        }
1251
1252
        return $view;
1253
    }
1254
1255 View Code Duplication
    public function cmsPageAction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1256
    {
1257
        $viewModel = $this->forward()->dispatch(
1258
            'playgroundcms',
1259
            array(
1260
                'controller' => 'playgroundcms',
1261
                'action'     => 'index',
1262
                'id'         => $this->game->getIdentifier(),
1263
                'pid'        => $this->getEvent()->getRouteMatch()->getParam('pid')
1264
            )
1265
        );
1266
1267
        if ($viewModel && $viewModel instanceof \Zend\View\Model\ViewModel) {
1268
            $this->layout()->setVariables(array('game' => $this->game));
0 ignored issues
show
Bug introduced by
The method setVariables does only exist in Zend\View\Model\ModelInterface, but not in Zend\Mvc\Controller\Plugin\Layout.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
1269
            $viewModel->setVariables(array('game'      => $this->game));
1270
        }
1271
1272
        return $viewModel;
1273
    }
1274
1275 View Code Duplication
    public function cmsListAction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1276
    {
1277
        $viewModel = $this->forward()->dispatch(
1278
            'playgroundcms',
1279
            array(
1280
                'controller' => 'playgroundcms',
1281
                'action'     => 'list',
1282
                'id'         => $this->game->getIdentifier(),
1283
                'category'   => $this->game->getIdentifier()
1284
            )
1285
        );
1286
1287
        if ($viewModel && $viewModel instanceof \Zend\View\Model\ViewModel) {
1288
            $this->layout()->setVariables(array('game' => $this->game));
0 ignored issues
show
Bug introduced by
The method setVariables does only exist in Zend\View\Model\ModelInterface, but not in Zend\Mvc\Controller\Plugin\Layout.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
1289
            $viewModel->setVariables(array('game'      => $this->game));
1290
        }
1291
1292
        return $viewModel;
1293
    }
1294
1295
    /**
1296
     *
1297
     * @param \PlaygroundGame\Entity\Game $game
1298
     * @param \PlaygroundUser\Entity\User $user
1299
     */
1300
    public function checkFbRegistration($user, $game)
1301
    {
1302
        $redirect = false;
1303
        $session  = new Container('facebook');
1304
        if ($session->offsetExists('signed_request')) {
1305
            if (!$user) {
1306
                // Get Playground user from Facebook info
1307
                $beforeLayout = $this->layout()->getTemplate();
0 ignored issues
show
Bug introduced by
The method getTemplate does only exist in Zend\View\Model\ModelInterface, but not in Zend\Mvc\Controller\Plugin\Layout.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
1308
                $view         = $this->forward()->dispatch(
1309
                    'playgrounduser_user',
1310
                    array(
1311
                        'controller' => 'playgrounduser_user',
1312
                        'action'     => 'registerFacebookUser',
1313
                        'provider'   => 'facebook',
1314
                    )
1315
                );
1316
1317
                $this->layout()->setTemplate($beforeLayout);
1318
                $user = $view->user;
1319
1320
                // If the user can not be created/retrieved from Facebook info, redirect to login/register form
1321
                if (!$user) {
1322
                    $redirectUrl = urlencode(
1323
                        $this->frontendUrl()->fromRoute(
0 ignored issues
show
Documentation Bug introduced by
The method frontendUrl does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
1324
                            $game->getClassType().'/play',
1325
                            array('id'              => $game->getIdentifier()),
1326
                            array('force_canonical' => true)
1327
                        )
1328
                    );
1329
                    $redirect = $this->redirect()->toUrl(
1330
                        $this->frontendUrl()->fromRoute(
0 ignored issues
show
Documentation Bug introduced by
The method frontendUrl does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
1331
                            'zfcuser/register'
1332
                        ).'?redirect='.$redirectUrl
1333
                    );
1334
                }
1335
            }
1336
        }
1337
1338
        return $redirect;
1339
    }
1340
1341
    /**
1342
     * This method create the basic Game view
1343
     * @param \PlaygroundGame\Entity\Game $game
1344
     */
1345
    public function buildView($game)
1346
    {
1347
        if ($this->getRequest()->isXmlHttpRequest()) {
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Zend\Stdlib\RequestInterface as the method isXmlHttpRequest() does only exist in the following implementations of said interface: Zend\Http\PhpEnvironment\Request, Zend\Http\Request, Zend\Psr7Bridge\Zend\Request.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
1348
            $viewModel = new JsonModel();
1349
            if ($game) {
1350
                $view = $this->addAdditionalView($game);
1351
                if ($view && $view instanceof \Zend\View\Model\ViewModel) {
1352
                    $viewModel->setVariables($view->getVariables());
1353
                }
1354
            }
1355
        } else {
1356
            $viewModel = new ViewModel();
1357
1358
            if ($game) {
1359
                $this->addMetaTitle($game);
1360
                $this->addMetaBitly();
1361
                $this->addGaEvent($game);
1362
1363
                $this->customizeGameDesign($game);
1364
1365
                $view = $this->addAdditionalView($game);
1366
                if ($view && $view instanceof \Zend\View\Model\ViewModel) {
1367
                    $viewModel->addChild($view, 'additional');
1368
                } elseif ($view && $view instanceof \Zend\Http\PhpEnvironment\Response) {
1369
                    return $view;
1370
                }
1371
1372
                $this->layout()->setVariables(
0 ignored issues
show
Bug introduced by
The method setVariables does only exist in Zend\View\Model\ModelInterface, but not in Zend\Mvc\Controller\Plugin\Layout.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
1373
                    array(
1374
                        'action'        => $this->params('action'),
1375
                        'game'          => $game,
1376
                        'flashMessages' => $this->flashMessenger()->getMessages(),
0 ignored issues
show
Documentation Bug introduced by
The method flashMessenger does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
1377
1378
                    )
1379
                );
1380
1381
                $viewModel->setVariables($this->getShareData($game));
1382
                $viewModel->setVariables(array('game' => $game, 'user' => $this->user));
1383
            }
1384
        }
1385
1386
        return $viewModel;
1387
    }
1388
1389
    /**
1390
     * @param \PlaygroundGame\Entity\Game $game
1391
     */
1392
    public function addAdditionalView($game)
1393
    {
1394
        $view = false;
1395
1396
        $actionName = $this->getEvent()->getRouteMatch()->getParam('action', 'not-found');
1397
        $stepsViews = json_decode($game->getStepsViews(), true);
1398
        if ($stepsViews && isset($stepsViews[$actionName])) {
1399
            $beforeLayout = $this->layout()->getTemplate();
0 ignored issues
show
Bug introduced by
The method getTemplate does only exist in Zend\View\Model\ModelInterface, but not in Zend\Mvc\Controller\Plugin\Layout.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
1400
            $actionData   = $stepsViews[$actionName];
1401
            if (is_string($actionData)) {
1402
                $action     = $actionData;
1403
                $controller = $this->getEvent()->getRouteMatch()->getParam('controller', PlaygroundGame\Controller\Frontend\Game::class);
1404
                $view       = $this->forward()->dispatch(
1405
                    $controller,
1406
                    array(
1407
                        'action' => $action,
1408
                        'id'     => $game->getIdentifier()
1409
                    )
1410
                );
1411
            } elseif (is_array($actionData) && count($actionData) > 0) {
1412
                $action     = key($actionData);
1413
                $controller = $actionData[$action];
1414
                $view       = $this->forward()->dispatch(
1415
                    $controller,
1416
                    array(
1417
                        'action' => $action,
1418
                        'id'     => $game->getIdentifier()
1419
                    )
1420
                );
1421
            }
1422
            // suite au forward, le template de layout a changé, je dois le rétablir...
1423
            $this->layout()->setTemplate($beforeLayout);
1424
        }
1425
1426
        return $view;
1427
    }
1428
1429
    public function addMetaBitly()
1430
    {
1431
        $bitlyclient = $this->getOptions()->getBitlyUrl();
1432
        $bitlyuser   = $this->getOptions()->getBitlyUsername();
1433
        $bitlykey    = $this->getOptions()->getBitlyApiKey();
1434
1435
        $this->getViewHelper('HeadMeta')->setProperty('bt:client', $bitlyclient);
1436
        $this->getViewHelper('HeadMeta')->setProperty('bt:user', $bitlyuser);
1437
        $this->getViewHelper('HeadMeta')->setProperty('bt:key', $bitlykey);
1438
    }
1439
1440
    /**
1441
     * @param \PlaygroundGame\Entity\Game $game
1442
     */
1443
    public function addGaEvent($game)
1444
    {
1445
        // Google Analytics event
1446
        $ga    = $this->getServiceLocator()->get('google-analytics');
1447
        $event = new \PlaygroundCore\Analytics\Event($game->getClassType(), $this->params('action'));
1448
        $event->setLabel($game->getTitle());
1449
        $ga->addEvent($event);
1450
    }
1451
1452
    /**
1453
     * @param \PlaygroundGame\Entity\Game $game
1454
     */
1455
    public function addMetaTitle($game)
1456
    {
1457
        //$title = $this->translate($game->getTitle());
1458
        $title = $game->getTitle();
1459
        $this->getGameService()->getServiceManager()->get('ViewHelperManager')->get('HeadTitle')->set($title);
1460
        // Meta set in the layout
1461
        $this->layout()->setVariables(
0 ignored issues
show
Bug introduced by
The method setVariables does only exist in Zend\View\Model\ModelInterface, but not in Zend\Mvc\Controller\Plugin\Layout.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
1462
            array(
1463
                'breadcrumbTitle' => $title,
1464
                'currentPage'     => array(
1465
                    'pageGames'      => 'games',
1466
                    'pageWinners'    => '',
1467
                ),
1468
                'headParams'       => array(
1469
                    'headTitle'       => $title,
1470
                    'headDescription' => $title,
1471
                ),
1472
                'bodyCss' => $game->getIdentifier()
1473
            )
1474
        );
1475
    }
1476
1477
    /**
1478
     * @param \PlaygroundGame\Entity\Game $game
1479
     */
1480
    public function customizeGameDesign($game)
1481
    {
1482
        // If this game has a specific layout...
1483
        if ($game->getLayout()) {
1484
            $layoutViewModel = $this->layout();
1485
            $layoutViewModel->setTemplate($game->getLayout());
1486
        }
1487
1488
        // If this game has a specific stylesheet...
1489
        if ($game->getStylesheet()) {
1490
            $this->getViewHelper('HeadLink')->appendStylesheet(
1491
                $this->getRequest()->getBaseUrl().'/'.$game->getStylesheet()
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Zend\Stdlib\RequestInterface as the method getBaseUrl() does only exist in the following implementations of said interface: Zend\Http\PhpEnvironment\Request, Zend\Psr7Bridge\Zend\Request.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
1492
            );
1493
        }
1494
    }
1495
1496
    /**
1497
     * @param \PlaygroundGame\Entity\Game $game
1498
     */
1499
    public function getShareData($game)
1500
    {
1501
        $fo      = $this->getServiceLocator()->get('facebook-opengraph');
1502
        $session = new Container('facebook');
1503
1504
        // I change the fbappid if i'm in fb
1505
        if ($session->offsetExists('signed_request')) {
1506
            $fo->setId($game->getFbAppId());
1507
        }
1508
1509
        // If I want to add a share block in my view
1510 View Code Duplication
        if ($game->getFbShareMessage()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1511
            $fbShareMessage = $game->getFbShareMessage();
1512
        } else {
1513
            $fbShareMessage = str_replace(
1514
                '__placeholder__',
1515
                $game->getTitle(),
1516
                $this->getOptions()->getDefaultShareMessage()
1517
            );
1518
        }
1519
1520
        if ($game->getFbShareImage()) {
1521
            $fbShareImage = $this->frontendUrl()->fromRoute(
0 ignored issues
show
Documentation Bug introduced by
The method frontendUrl does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
1522
                '',
1523
                array(),
1524
                array('force_canonical' => true),
1525
                false
1526
            ).$game->getFbShareImage();
1527
        } else {
1528
            $fbShareImage = $this->frontendUrl()->fromRoute(
0 ignored issues
show
Documentation Bug introduced by
The method frontendUrl does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
1529
                '',
1530
                array(),
1531
                array('force_canonical' => true),
1532
                false
1533
            ).$game->getMainImage();
1534
        }
1535
1536
        $secretKey = strtoupper(substr(sha1(uniqid('pg_', true).'####'.time()), 0, 15));
1537
1538
        // Without bit.ly shortener
1539
        $socialLinkUrl = $this->frontendUrl()->fromRoute(
0 ignored issues
show
Documentation Bug introduced by
The method frontendUrl does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
1540
            $game->getClassType(),
1541
            array('id'              => $game->getIdentifier()),
1542
            array('force_canonical' => true)
1543
        );
1544
        // With core shortener helper
1545
        $socialLinkUrl = $this->shortenUrl()->shortenUrl($socialLinkUrl);
0 ignored issues
show
Documentation Bug introduced by
The method shortenUrl does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
1546
1547
        // FB Requests only work when it's a FB app
1548
        if ($game->getFbRequestMessage()) {
1549
            $fbRequestMessage = urlencode($game->getFbRequestMessage());
1550
        } else {
1551
            $fbRequestMessage = str_replace(
1552
                '__placeholder__',
1553
                $game->getTitle(),
1554
                $this->getOptions()->getDefaultShareMessage()
1555
            );
1556
        }
1557
1558 View Code Duplication
        if ($game->getTwShareMessage()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1559
            $twShareMessage = $game->getTwShareMessage().$socialLinkUrl;
1560
        } else {
1561
            $twShareMessage = str_replace(
1562
                '__placeholder__',
1563
                $game->getTitle(),
1564
                $this->getOptions()->getDefaultShareMessage()
1565
            ).$socialLinkUrl;
1566
        }
1567
1568
        $ogTitle = new \PlaygroundCore\Opengraph\Tag('og:title', $fbShareMessage);
1569
        $ogImage = new \PlaygroundCore\Opengraph\Tag('og:image', $fbShareImage);
1570
1571
        $fo->addTag($ogTitle);
1572
        $fo->addTag($ogImage);
1573
1574
        $data = array(
1575
            'socialLinkUrl'    => $socialLinkUrl,
1576
            'secretKey'        => $secretKey,
1577
            'fbShareMessage'   => $fbShareMessage,
1578
            'fbShareImage'     => $fbShareImage,
1579
            'fbRequestMessage' => $fbRequestMessage,
1580
            'twShareMessage'   => $twShareMessage,
1581
        );
1582
1583
        return $data;
1584
    }
1585
1586
    /**
1587
     * return ajax response in json format
1588
     *
1589
     * @param array $data
1590
     * @return \Zend\View\Model\JsonModel
1591
     */
1592 View Code Duplication
    protected function successJson($data = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1593
    {
1594
        $model = new JsonModel(array(
1595
                'success' => true,
1596
                'data'    => $data,
1597
            ));
1598
        return $model->setTerminal(true);
1599
    }
1600
1601
    /**
1602
     * return ajax response in json format
1603
     *
1604
     * @param string $message
1605
     * @return \Zend\View\Model\JsonModel
1606
     */
1607 View Code Duplication
    protected function errorJson($message = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1608
    {
1609
        $model = new JsonModel(array(
1610
                'success' => false,
1611
                'message' => $message,
1612
            ));
1613
        return $model->setTerminal(true);
1614
    }
1615
1616
    /**
1617
     * @param string $helperName
1618
     */
1619
    protected function getViewHelper($helperName)
1620
    {
1621
        return $this->getServiceLocator()->get('ViewHelperManager')->get($helperName);
1622
    }
1623
1624
    public function getGameService()
1625
    {
1626
        if (!$this->gameService) {
1627
            $this->gameService = $this->getServiceLocator()->get('playgroundgame_lottery_service');
1628
        }
1629
1630
        return $this->gameService;
1631
    }
1632
1633
    public function setGameService(GameService $gameService)
1634
    {
1635
        $this->gameService = $gameService;
1636
1637
        return $this;
1638
    }
1639
1640
    public function getPrizeService()
1641
    {
1642
        if (!$this->prizeService) {
1643
            $this->prizeService = $this->getServiceLocator()->get('playgroundgame_prize_service');
1644
        }
1645
1646
        return $this->prizeService;
1647
    }
1648
1649
    public function setPrizeService(PrizeService $prizeService)
1650
    {
1651
        $this->prizeService = $prizeService;
1652
1653
        return $this;
1654
    }
1655
1656
    public function getOptions()
1657
    {
1658
        if (!$this->options) {
1659
            $this->setOptions($this->getServiceLocator()->get('playgroundcore_module_options'));
1660
        }
1661
1662
        return $this->options;
1663
    }
1664
1665
    public function setOptions($options)
1666
    {
1667
        $this->options = $options;
1668
1669
        return $this;
1670
    }
1671
}
1672