Completed
Push — master ( 467cb1...f6d530 )
by greg
57:09 queued 47:00
created

GameController::shareAction()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 29

Duplication

Lines 10
Ratio 34.48 %

Importance

Changes 0
Metric Value
dl 10
loc 29
rs 9.456
c 0
b 0
f 0
cc 4
nc 4
nop 0
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
    /**
63
     * These steps are available only when the game is started
64
     */
65
    protected $withStartedGame = array(
66
        'preview',
67
        'createTeam',
68
        'inviteToTeam',
69
        'register',
70
        'play',
71
    );
72
73
    protected $withAnyUser = array(
74
        'share',
75
        'result',
76
        'play',
77
        'logout',
78
        'createTeam',
79
        'inviteToTeam',
80
    );
81
82
    protected $isSoloGame = false;
83
84
    /**
85
     *
86
     * @var ServiceManager
87
     */
88
    protected $serviceLocator;
89
90
    public function __construct(ServiceLocatorInterface $locator)
91
    {
92
        $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...
93
    }
94
95
    public function getServiceLocator()
96
    {
97
        return $this->serviceLocator;
98
    }
99
100
    public function setEventManager(\Zend\EventManager\EventManagerInterface $events)
101
    {
102
        parent::setEventManager($events);
103
104
        $controller = $this;
105
106
        $events->attach('dispatch', function (\Zend\Mvc\MvcEvent $e) use ($controller) {
107
108
            $session = new Container('facebook');
109
            $identifier = $e->getRouteMatch()->getParam('id');
110
111
            // I set the right identifier if I come from FB
112
            // From FB, the games have all the same identifier. I use the FB Page Id to find the right game
113
            // So for 1 FB page, you can have only 1 game ;/
114
            if ($identifier === 'facebook' && $session->offsetExists('signed_request')) {
115
                $sr = $session->offsetGet('signed_request');
116
                $identifier = $controller->getGameService()->getGameIdentifierFromFacebook($sr['page']['id']);
117
            }
118
     
119
            $controller->game = $controller->getGameService()->checkGame($identifier, false);
120
121
            if (!$controller->game &&
122
                    in_array($controller->params('action'), $controller->withGame)
123
                ) {
124
                return $controller->notFoundAction();
125
            }
126
127
            if ($controller->game &&
128
                    $controller->game->isClosed() &&
129
                    in_array($controller->params('action'), $controller->withOnlineGame)
130
                ) {
131
                return $controller->notFoundAction();
132
            }
133
134
            $config = $this->getServiceLocator()->get('config');
135
            $customUrl = str_replace('frontend.', '', $e->getRouteMatch()->getMatchedRouteName());
136
            $customUrl = explode("/", $customUrl)[0];
137
138
            if (
139
                    isset($config['custom_games']) &&
140
                    $controller->game !== false &&
141
                    isset($config['custom_games'][$controller->game->getIdentifier()]) &&
142
                    $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...
143
                ) {
144
                $this->isSoloGame = true;
145
            }
146
147
            if ($controller->game) {
148
                // this is possible to create a specific game design in /design/frontend/default/custom.
149
                //It will precede all others templates.
150
                $templatePathResolver = $controller->getServiceLocator()->get('Zend\View\Resolver\TemplatePathStack');
151
                $l = $templatePathResolver->getPaths();
152
                $templatePathResolver->addPath($l[0].'custom/'.$controller->game->getIdentifier());
153
            }
154
155
            $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...
156
            if (
157
                    $controller->game &&
158
                    !$controller->user &&
159
                    !$controller->game->getAnonymousAllowed() &&
160
                    in_array($controller->params('action'), $controller->withAnyUser)
161
                ) {
162
                // if the current game runs under Facebook
163
                if ($session->offsetExists('signed_request')) {
164
                    $session->offsetSet('fb-redirect', $controller->getRequest()->getUri());
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...
165
                    // Let's start the FB registration dance !
166
                    $controller->forward()->dispatch(
167
                        'playgrounduser_user',
168
                        array(
169
                            'controller' => 'playgrounduser_user',
170
                            'action'     => 'registerFacebookUser',
171
                            'provider'   => 'facebook',
172
                        )
173
                    );
174
                }
175
                $redirect = urlencode(
176
                    $controller->url()->fromRoute(
177
                        'frontend/'.$controller->game->getClassType().'/'.$controller->params('action'),
178
                        array('id'              => $controller->game->getIdentifier()),
179
                        array('force_canonical' => true)
180
                    )
181
                );
182
183
                if ($this->isSoloGame) {
184
                     $urlRegister = $controller->url()->fromRoute(
185
                         'frontend.'.$customUrl.'/'.$controller->game->getClassType().'/user-register',
186
                         array(),
187
                         array('force_canonical' => true)
188
                     ).'?redirect='.$redirect;
189
                } else {
190
                    $urlRegister = $controller->url()->fromRoute(
191
                        'frontend/zfcuser/register',
192
                        array(),
193
                        array('force_canonical' => true)
194
                    ).'?redirect='.$redirect;
195
                }
196
197
                // code permettant d'identifier un custom game
198
                // ligne $config = $controller->getGameService()->getServiceManager()->get('config');
199
                // ligne $customUrl = str_replace('frontend.', '', $e->getRouteMatch()->getParam('area', ''));
200
                // ligne if ($config['custom_games'][$controller->game->getIdentifier()] &&
201
                // ligne    $controller->getRequest()->getUri()->getHost() === $customUrl
202
                // ligne ) {
203
                return $controller->redirect()->toUrl($urlRegister);
204
            }
205
206
            // If the game is finished, I redirect some actions to result (you can't play it anymore)
207
            if (
208
                $controller->game &&
209
                $controller->game->isFinished() &&
210
                in_array($controller->params('action'), $controller->withStartedGame)
211
            ) {
212
                if ($this->isSoloGame) {
213
                    $urlResult = $controller->url()->fromRoute(
214
                        'frontend.'.$customUrl.'/'.$controller->game->getClassType().'/result',
215
                        array('id' => $controller->game->getIdentifier()),
216
                        array('force_canonical' => true)
217
                    );
218
                } else {
219
                    $urlResult = $controller->url()->fromRoute(
220
                        'frontend/'.$controller->game->getClassType().'/result',
221
                        array('id' => $controller->game->getIdentifier()),
222
                        array('force_canonical' => true)
223
                    );
224
                }
225
                return $controller->redirect()->toUrl($urlResult);
226
            }
227
228
                return;
229
        }, 100);// execute before executing action logic
230
    }
231
232
    /**
233
     * Action called if matched action does not exist
234
     * For this view not to be catched by Zend\Mvc\View\RouteNotFoundStrategy
235
     * it has to be rendered in the controller. Hence the code below.
236
     *
237
     * This action is injected as a catchall action for each custom_games definition
238
     * This way, when a custom_game is created, the 404 is it's responsability and the
239
     * view can be defined in design/frontend/default/custom/$slug/playground_game/$gametype/404.phtml
240
     *
241
     *
242
     * @return \Zend\Stdlib\ResponseInterface
243
     */
244
    public function notFoundAction()
245
    {
246
        $templatePathResolver = $this->getServiceLocator()->get('Zend\View\Resolver\TemplatePathStack');
247
248
        // I create a template path in which I can find a custom template
249
        $controller     = explode('\\', get_class($this));
250
        $controllerPath = str_replace('Controller', '', end($controller));
251
        $controllerPath = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '-\\1', $controllerPath));
252
        $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...
253
        if ($this->game) {
254
            $uri = str_replace($controllerPath.'/'.$this->game->getIdentifier().'/', '', $uri);
255
        }
256
        $uri      = str_replace("/".$this->getEvent()->getRouteMatch()->getParam('locale')."/", "/", $uri);
257
        $template = 'playground-game/'.$controllerPath.'/custom'.$uri;
258
259
        if (false === $templatePathResolver->resolve($template)) {
260
            $viewRender = $this->getServiceLocator()->get('ViewRenderer');
261
262
            $this->getEvent()->getRouteMatch()->setParam('action', 'not-found');
263
            $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...
264
265
            $res = 'error/404';
266
267
            $viewModel = $this->buildView($this->game);
268
            $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...
269
270
            $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...
271
            $this->response->setContent($viewRender->render($this->layout()));
272
273
            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...
274
        }
275
276
        $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 279 which is incompatible with the return type documented by PlaygroundGame\Controlle...troller::notFoundAction of type Zend\Stdlib\ResponseInterface.
Loading history...
277
        $viewModel->setTemplate($template);
278
279
        return $viewModel;
280
    }
281
282
    /**
283
     * This action acts as a hub : Depending on the first step of the game, it will forward the action to this step
284
     */
285
    public function homeAction()
286
    {
287
        // This fix exists only for safari in FB on Windows : we need to redirect the user to the page
288
        // outside of iframe for the cookie to be accepted. PlaygroundCore redirects to the FB Iframed page when
289
        // it discovers that the user arrives for the first time on the game in FB.
290
        // When core redirects, it adds a 'redir_fb_page_id' var in the querystring
291
        // Here, we test if this var exist, and then send the user back to the game in FB.
292
        // Now the cookie will be accepted by Safari...
293
        $pageId = $this->params()->fromQuery('redir_fb_page_id');
294
        if (!empty($pageId)) {
295
            $appId = 'app_'.$this->game->getFbAppId();
296
            $url   = '//www.facebook.com/pages/game/'.$pageId.'?sk='.$appId;
297
298
            return $this->redirect()->toUrl($url);
299
        }
300
301
        // If an entry has already been done during this session, I reset the anonymous_identifier cookie
302
        // so that another person can play the same game (if game conditions are fullfilled)
303
        // or the same person can play another game
304
        $session = new Container('anonymous_identifier');
305
        if ($session->offsetExists('anonymous_identifier')) {
306
            $session->offsetUnset('anonymous_identifier');
307
        }
308
309
        $classGame = __NAMESPACE__ . '\\' . ucfirst($this->game->getClassType());
310
        return $this->forward()->dispatch(
311
            $classGame,
312
            array(
313
                'controller' => $classGame,
314
                'action'     => $this->game->firstStep(),
315
                'id'         => $this->game->getIdentifier()
316
            )
317
        );
318
    }
319
320
    /**
321
     * Homepage of the game
322
     */
323
    public function indexAction()
324
    {
325
        $isSubscribed = false;
326
327
        $entry = $this->getGameService()->checkExistingEntry($this->game, $this->user);
328
        if ($entry) {
329
            $isSubscribed = true;
330
        }
331
332
        $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 337 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...
333
        $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...
334
            'isSubscribed' => $isSubscribed,
335
        ));
336
337
        return $viewModel;
338
    }
339
340
    /**
341
     * leaderboardAction
342
     *
343
     * @return ViewModel $viewModel
344
     */
345
    public function leaderboardAction()
346
    {
347
        $filter = $this->getEvent()->getRouteMatch()->getParam('filter');
348
        $p      = $this->getEvent()->getRouteMatch()->getParam('p');
349
350
        $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...
351
        $subViewModel = $this->forward()->dispatch(
352
            'playgroundreward',
353
            array('action' => 'leaderboard', 'filter' => $filter, 'p' => $p)
354
        );
355
356
        // suite au forward, le template de layout a changé, je dois le rétablir...
357
        $this->layout()->setTemplate($beforeLayout);
358
        $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...
359
            array(
360
                'action' => $this->params('action'),
361
                'game'   => $this->game,
362
            )
363
        );
364
365
        $subViewModel->setVariables($this->getShareData($this->game));
366
        $subViewModel->setVariables(array('game' => $this->game, 'user' => $this->user));
367
368
        return $subViewModel;
369
    }
370
371
    /**
372
     * This action has been designed to be called by other controllers
373
     * It gives the ability to display an information form and persist it in the game entry
374
     *
375
     * @return \Zend\View\Model\ViewModel
376
     */
377
    public function registerAction()
378
    {
379
        $formDef = $this->game->getPlayerForm();
380
        if ($formDef !== null) {
381
            $form = $this->getGameService()->createFormFromJson($formDef->getForm(), 'playerForm');
382
        } else {
383
            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...
384
        }
385
386
        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...
387
            // POST Request: Process form
388
            $data = array_merge_recursive(
389
                $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...
390
                $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...
391
            );
392
393
            $form->setData($data);
394
395
            if ($form->isValid()) {
396
                // steps of the game
397
                $steps = $this->game->getStepsArray();
398
                // sub steps of the game
399
                $viewSteps = $this->game->getStepsViewsArray();
400
                $keyStep = false;
401
402
                // register position
403
                $key = array_search($this->params('action'), $viewSteps);
404
                if ($key === false) {
405
                    // register is not a substep of the game so it's a step
406
                    $key     = array_search($this->params('action'), $steps);
407
                    if ($key !== false) {
408
                        $keyStep = true;
409
                    } else {
410
                        $key = -1;
411
                    }
412
                } else {
413
                    // register was a substep, I search the index of its parent
414
                    $key     = array_search($key, $steps);
415
                }
416
417
                // play position
418
                $keyplay = array_search('play', $viewSteps);
419
420
                if (!$keyplay) {
421
                    // play is not a substep, so it's a step
422
                    $keyplay     = array_search('play', $steps);
423
                    $keyplayStep = true;
424
                } else {
425
                    // play is a substep so I search the index of its parent
426
                    $keyplay     = array_search($keyplay, $steps);
427
                    $keyplayStep = false;
428
                }
429
430
                // If register step before play, I don't have no entry yet. I have to create one
431
                // If register after play step, I search for the last entry created by play step.
432
                if ($key < $keyplay || ($keyStep && !$keyplayStep && $key <= $keyplay)) {
433
                    // I need to check if this anonymous user has already played. This one is transmitted through
434
                    // a cookie... so I need to fill in this cookie if it's not already updated.
435
                    if ($this->game->getAnonymousAllowed() &&
436
                        $this->game->getAnonymousIdentifier() &&
437
                        isset($data[$this->game->getAnonymousIdentifier()])
438
                    ) {
439
                        $session = new \Zend\Session\Container('anonymous_identifier');
440
                        if (empty($session->offsetGet('anonymous_identifier'))) {
441
                            $anonymousIdentifier = $data[$this->game->getAnonymousIdentifier()];
442
                        
443
                            // I must transmit this info during the whole game workflow
444
                            $session->offsetSet('anonymous_identifier', $anonymousIdentifier);
445
                        }
446
                    }
447
                    $entry = $this->getGameService()->play($this->game, $this->user);
448
                    if (!$entry) {
449
                        // the user has already taken part to this game and the participation limit has been reached
450
                        $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...
451
452
                        return $this->redirect()->toUrl(
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->redirect()...'?playLimitReached=1'); (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...
453
                            $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...
454
                                $this->game->getClassType().'/result',
455
                                array(
456
                                    'id' => $this->game->getIdentifier(),
457
                                )
458
                            ) .'?playLimitReached=1'
459
                        );
460
                    }
461
                } else {
462
                    // I'm looking for an entry without anonymousIdentifier (the active entry in fact).
463
                    $entry = $this->getGameService()->findLastEntry($this->game, $this->user);
464
                    if ($this->getGameService()->hasReachedPlayLimit($this->game, $this->user)) {
465
                        // the user has already taken part of this game and the participation limit has been reached
466
                        $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...
467
468
                        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...
469
                            $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...
470
                                $this->game->getClassType().'/result',
471
                                array(
472
                                    'id' => $this->game->getIdentifier(),
473
                                )
474
                            )
475
                        );
476
                    }
477
                }
478
479
                $this->getGameService()->updateEntryPlayerForm($form->getData(), $this->game, $this->user, $entry);
480
481
                if (!empty($this->game->nextStep($this->params('action')))) {
482
                    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...
483
                        $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...
484
                            $this->game->getClassType().'/'.$this->game->nextStep($this->params('action')),
485
                            array('id'              => $this->game->getIdentifier()),
486
                            array('force_canonical' => true)
487
                        )
488
                    );
489
                }
490
            }
491
        }
492
493
        $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 498 which is incompatible with the return type documented by PlaygroundGame\Controlle...troller::registerAction of type Zend\View\Model\ViewModel.
Loading history...
494
        $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...
495
                'form' => $form,
496
            ));
497
498
        return $viewModel;
499
    }
500
501
    /**
502
     * This action takes care of the terms of the game
503
     */
504
    public function termsAction()
505
    {
506
        $viewModel = $this->buildView($this->game);
507
508
        return $viewModel;
509
    }
510
511
    /**
512
     * This action takes care of the conditions of the game
513
     */
514
    public function conditionsAction()
515
    {
516
        $viewModel = $this->buildView($this->game);
517
518
        return $viewModel;
519
    }
520
521
    /**
522
     * This action takes care of bounce page of the game
523
     */
524
    public function bounceAction()
525
    {
526
        $availableGames = $this->getGameService()->getAvailableGames($this->user);
527
528
        $rssUrl = '';
529
        $config = $this->getGameService()->getServiceManager()->get('config');
530
        if (isset($config['rss']['url'])) {
531
            $rssUrl = $config['rss']['url'];
532
        }
533
534
        $viewModel = $this->buildView($this->game);
535
        $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...
536
                'rssUrl'         => $rssUrl,
537
                'user'           => $this->user,
538
                'availableGames' => $availableGames,
539
            ));
540
541
        return $viewModel;
542
    }
543
544
    /**
545
     * This action displays the Prizes page associated to the game
546
     */
547
    public function prizesAction()
548
    {
549
        if (count($this->game->getPrizes()) == 0) {
550
            return $this->notFoundAction();
551
        }
552
553
        $viewModel = $this->buildView($this->game);
554
555
        return $viewModel;
556
    }
557
558
    /**
559
     * This action displays a specific Prize page among those associated to the game
560
     */
561
    public function prizeAction()
562
    {
563
        $prizeIdentifier = $this->getEvent()->getRouteMatch()->getParam('prize');
564
        $prize           = $this->getPrizeService()->getPrizeMapper()->findByIdentifier($prizeIdentifier);
565
566
        if (!$prize) {
567
            return $this->notFoundAction();
568
        }
569
570
        $viewModel = $this->buildView($this->game);
571
        $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...
572
573
        return $viewModel;
574
    }
575
576
    public function gameslistAction()
577
    {
578
        $layoutViewModel = $this->layout();
579
580
        $slider = new ViewModel();
581
        $slider->setTemplate('playground-game/common/top_promo');
582
583
        $sliderItems = $this->getGameService()->getActiveSliderGames();
584
585
        $slider->setVariables(array('sliderItems' => $sliderItems));
586
587
        $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...
588
589
        $games = $this->getGameService()->getActiveGames(false, '', 'endDate');
590
        if (is_array($games)) {
591
            $paginator = new \Zend\Paginator\Paginator(new \Zend\Paginator\Adapter\ArrayAdapter($games));
592
        } else {
593
            $paginator = $games;
594
        }
595
596
        $paginator->setItemCountPerPage(7);
597
        $paginator->setCurrentPageNumber($this->getEvent()->getRouteMatch()->getParam('p'));
598
599
        $bitlyclient = $this->getOptions()->getBitlyUrl();
600
        $bitlyuser   = $this->getOptions()->getBitlyUsername();
601
        $bitlykey    = $this->getOptions()->getBitlyApiKey();
602
603
        $this->getViewHelper('HeadMeta')->setProperty('bt:client', $bitlyclient);
604
        $this->getViewHelper('HeadMeta')->setProperty('bt:user', $bitlyuser);
605
        $this->getViewHelper('HeadMeta')->setProperty('bt:key', $bitlykey);
606
607
        $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...
608
            array(
609
                'sliderItems'  => $sliderItems,
610
                'currentPage'  => array(
611
                    'pageGames'   => 'games',
612
                    'pageWinners' => '',
613
                ),
614
            )
615
        );
616
617
        return new ViewModel(
618
            array(
619
                'games' => $paginator,
620
            )
621
        );
622
    }
623
624
    public function shareAction()
625
    {
626
        $statusMail = null;
627
        $lastEntry = $this->getGameService()->findLastInactiveEntry($this->game, $this->user);
628
629
        $form = $this->getServiceLocator()->get('playgroundgame_sharemail_form');
630
        $form->setAttribute('method', 'post');
631
632
        // buildView must be before sendMail because it adds the game template path to the templateStack
633
        $viewModel = $this->buildView($this->game);
634
635 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...
636
            $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...
637
            $form->setData($data);
638
            if ($form->isValid()) {
639
                $result = $this->getGameService()->sendShareMail($data, $this->game, $this->user, $lastEntry);
640
                if ($result) {
641
                    $statusMail = true;
642
                }
643
            }
644
        }
645
646
        $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...
647
                'statusMail' => $statusMail,
648
                'form'       => $form,
649
            ));
650
651
        return $viewModel;
652
    }
653
654
    public function inviteToTeamAction()
655
    {
656
657
        if (count($this->user->getTeams()) == 0) {
658
            return $this->redirect()->toUrl(
659
                $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...
660
                    $this->game->getClassType().'/create-team',
661
                    array('id' => $this->game->getIdentifier())
662
                )
663
            );
664
        }
665
666
        $team = $this->user->getTeams()->first(); 
667
        $invitationMapper = $this->getServiceLocator()->get('playgroundgame_invitation_mapper');
668
        $invitations = $invitationMapper->findBy(array('host' => $this->user, 'game' => $this->game));
669
        $statusMail = null;
670
        $message = '';
671
        $isHost = ($this->user->getId() === $team->getHost()->getId()) ? true : false;
672
673
        $form = $this->getServiceLocator()->get('playgroundgame_sharemail_form');
674
        $form->setAttribute('method', 'post');
675
676
        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...
677
            $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...
678
            $form->setData($data);
679
            if ($form->isValid()) {
680
                $result = $this->getGameService()->inviteToTeam($data, $this->game, $this->user);
681
                if ($result['result']) {
682
                    $statusMail = true;
683
                } else {
684
                    $statusMail = false;
685
                    $message    = $result['message'];
686
                }
687
            }
688
        }
689
690
        $viewModel = $this->buildView($this->game);
691
        $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...
692
            'team'       => $team,
693
            'invitations'=> $invitations,
694
            'message'    => $message,
695
            'statusMail' => $statusMail,
696
            'form'       => $form,
697
            'isHost'     => $isHost,
698
        ));
699
700
        return $viewModel;
701
    }
702
703
    public function createTeamAction()
704
    {
705
        if (count($this->user->getTeams()) > 0) {
706
            return $this->redirect()->toUrl(
707
                $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...
708
                    $this->game->getClassType().'/invite-to-team',
709
                    array('id' => $this->game->getIdentifier())
710
                )
711
            );
712
        }
713
714
        $form = $this->getServiceLocator()->get('playgroundgame_createteam_form');
715
        $form->setAttribute('method', 'post');
716
717
        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...
718
            $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...
719
            $form->setData($data);
720
            if ($form->isValid()) {
721
                $teamMapper = $this->getServiceLocator()->get('playgrounduser_team_mapper');
722
                $users = new \Doctrine\Common\Collections\ArrayCollection();
723
                $users->add($this->user);
724
                $teamName = $data['name'];
725
                $slugify = new \PlaygroundCore\Filter\Slugify;
726
727
                $team = new \PlaygroundUser\Entity\Team();
728
                $team->setName($teamName);
729
                $team->setIdentifier($slugify($teamName));
730
                $team->setHost($this->user);
731
                $team->addUsers($users);
732
733
                $teamMapper->insert($team);
734
735
                return $this->redirect()->toUrl(
736
                    $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...
737
                        $this->game->getClassType().'/invite-to-team',
738
                        array('id' => $this->game->getIdentifier())
739
                    )
740
                );
741
            }
742
        }
743
744
        $viewModel = $this->buildView($this->game);
745
        $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...
746
            'form'       => $form,
747
        ));
748
749
        return $viewModel;
750
    }
751
752 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...
753
    {
754
        $viewModel = new JsonModel();
755
        $viewModel->setTerminal(true);
756
        $fbId = $this->params()->fromQuery('fbId');
757
        if (!$this->game) {
758
            return $this->errorJson();
759
        }
760
        $entry = $this->getGameService()->checkExistingEntry($this->game, $this->user);
761
        if (!$entry) {
762
            return $this->errorJson();
763
        }
764
        if (!$fbId) {
765
            return $this->errorJson();
766
        }
767
768
        $this->getGameService()->postFbWall($fbId, $this->game, $this->user, $entry);
769
770
        return $this->successJson();
771
    }
772
773
    public function fbrequestAction()
774
    {
775
        $viewModel = new ViewModel();
776
        $viewModel->setTerminal(true);
777
        $fbId = $this->params()->fromQuery('fbId');
778
        $to   = $this->params()->fromQuery('to');
779
780
        if (!$this->game) {
781
            return $this->errorJson();
782
        }
783
        $entry = $this->getGameService()->checkExistingEntry($this->game, $this->user);
784
        if (!$entry) {
785
            return $this->errorJson();
786
        }
787
        if (!$fbId) {
788
            return $this->errorJson();
789
        }
790
791
        $this->getGameService()->postFbRequest($fbId, $this->game, $this->user, $entry, $to);
792
793
        return $this->successJson();
794
    }
795
796
    public function tweetAction()
797
    {
798
        $tweetId = $this->params()->fromQuery('tweetId');
799
800
        if (!$this->game) {
801
            return $this->errorJson();
802
        }
803
        $entry = $this->getGameService()->checkExistingEntry($this->game, $this->user);
804
        if (!$entry) {
805
            return $this->errorJson();
806
        }
807
        if (!$tweetId) {
808
            return $this->errorJson();
809
        }
810
811
        $this->getGameService()->postTwitter($tweetId, $this->game, $this->user, $entry);
812
813
        return $this->successJson();
814
    }
815
816 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...
817
    {
818
        $viewModel = new ViewModel();
819
        $viewModel->setTerminal(true);
820
        $googleId = $this->params()->fromQuery('googleId');
821
822
        if (!$this->game) {
823
            return $this->errorJson();
824
        }
825
        $entry = $this->getGameService()->checkExistingEntry($this->game, $this->user);
826
        if (!$entry) {
827
            return $this->errorJson();
828
        }
829
        if (!$googleId) {
830
            return $this->errorJson();
831
        }
832
833
        $this->getGameService()->postGoogle($googleId, $this->game, $this->user, $entry);
834
835
        return $this->successJson();
836
    }
837
838
    public function optinAction()
839
    {
840
        $userService = $this->getServiceLocator()->get('zfcuser_user_service');
841
842
        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...
843
            $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...
844
            $data['optinPartner'] = ($this->params()->fromPost('optinPartner'))?1:0;
845
846
            $userService->updateNewsletter($data);
847
        }
848
849
        return $this->redirect()->toUrl(
850
            $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...
851
                $this->game->getClassType(),
852
                array('id' => $this->game->getIdentifier())
853
            )
854
        );
855
    }
856
857
    public function loginAction()
858
    {
859
        $request = $this->getRequest();
860
        $redirect = "";
861
        if ($request->getQuery()->get('redirect') != '') {
862
            $redirect = $request->getQuery()->get('redirect');
863
        }
864
        $form    = $this->getServiceLocator()->get('zfcuser_login_form');
865
866
        if ($request->isPost()) {
867
            $form->setData($request->getPost());
868
869
            if (!$form->isValid()) {
870
                $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...
871
                    'Authentication failed. Please try again.'
872
                );
873
874
                $viewModel = $this->buildView($this->game);
875
                $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...
876
                        'form'          => $form,
877
                        '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...
878
                    ));
879
880
                return $viewModel;
881
            }
882
883
            // clear adapters
884
            $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...
885
            $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...
886
887
            $logged = $this->forward()->dispatch('playgrounduser_user', array('action' => 'ajaxauthenticate'));
888
889
            if (!$logged) {
890
                $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...
891
                    'Authentication failed. Please try again.'
892
                );
893
894
                return $this->redirect()->toUrl(
895
                    $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...
896
                        $this->game->getClassType().'/login',
897
                        array('id' => $this->game->getIdentifier())
898
                    )
899
                );
900
            } else {
901
                if ($redirect != "") {
902
                    return $this->redirect()->toUrl($redirect);
903
                } else {
904
                    return $this->redirect()->toUrl(
905
                        $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...
906
                            $this->game->getClassType().'/'.$this->game->nextStep('index'),
907
                            array('id' => $this->game->getIdentifier())
908
                        )
909
                    );
910
                }
911
            }
912
        }
913
914
        $form->setAttribute(
915
            'action',
916
            $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...
917
                $this->game->getClassType().'/login',
918
                array('id' => $this->game->getIdentifier())
919
            )
920
        );
921
        $viewModel = $this->buildView($this->game);
922
        $viewModel->setVariables(array(
923
                'form'          => $form,
924
                '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...
925
            ));
926
        return $viewModel;
927
    }
928
929
    public function logoutAction()
930
    {
931
        $viewModel = $this->forward()->dispatch(
932
            'playgrounduser_user',
933
            array(
934
                'controller' => 'playgrounduser_user',
935
                'action'     => 'logout',
936
                'id'         => $this->game->getIdentifier()
937
            )
938
        );
939
940
        if ($viewModel && $viewModel instanceof \Zend\View\Model\ViewModel) {
941
            $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...
942
            $viewModel->setVariables(array('game'      => $this->game));
943
        }
944
945
        return $viewModel;
946
    }
947
948
    public function userregisterAction()
949
    {
950
        $pguserOptions = $this->getServiceLocator()->get('playgrounduser_module_options');
951
        $userOptions = $this->getServiceLocator()->get('zfcuser_module_options');
952
953
        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...
954
            return $this->redirect()->toUrl(
955
                $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...
956
                    $this->game->getClassType().'/'.$this->game->nextStep('index'),
957
                    array('id' => $this->game->getIdentifier())
958
                )
959
            );
960
        }
961
        $request       = $this->getRequest();
962
        $service       = $this->getServiceLocator()->get('zfcuser_user_service');
963
        $form          = $this->getServiceLocator()->get('playgroundgame_register_form');
964
        $socialnetwork = $this->params()->fromRoute('socialnetwork', false);
965
        $form->setAttribute(
966
            'action',
967
            $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...
968
                $this->game->getClassType().'/user-register',
969
                array('id' => $this->game->getIdentifier())
970
            )
971
        );
972
        $params            = array();
973
        $socialCredentials = array();
974
975
        if ($userOptions->getUseRedirectParameterIfPresent() && $request->getQuery()->get('redirect')) {
976
            $redirect = $request->getQuery()->get('redirect');
977
        } else {
978
            $redirect = false;
979
        }
980
981
        if ($socialnetwork) {
982
            $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...
983
984
            if (!empty($infoMe)) {
985
                $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...
986
                    $infoMe->identifier,
987
                    $socialnetwork
988
                );
989
990
                if ($user || $service->getOptions()->getCreateUserAutoSocial() === true) {
991
                    //on le dirige vers l'action d'authentification
992
                    if (!$redirect && $userOptions->getLoginRedirectRoute() != '') {
993
                        $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...
994
                            $this->game->getClassType().'/login',
995
                            array('id' => $this->game->getIdentifier())
996
                        );
997
                    }
998
                    $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...
999
                        $this->game->getClassType().'/login',
1000
                        array('id' => $this->game->getIdentifier())
1001
                    ).'/'.$socialnetwork.($redirect?'?redirect='.$redirect:'');
1002
1003
                    return $this->redirect()->toUrl($redir);
1004
                }
1005
1006
                // Je retire la saisie du login/mdp
1007
                $form->setAttribute(
1008
                    'action',
1009
                    $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...
1010
                        $this->game->getClassType().'/user-register',
1011
                        array(
1012
                            'id'            => $this->game->getIdentifier(),
1013
                            'socialnetwork' => $socialnetwork,
1014
1015
                        )
1016
                    )
1017
                );
1018
                $form->remove('password');
1019
                $form->remove('passwordVerify');
1020
1021
                $birthMonth = $infoMe->birthMonth;
1022
                if (strlen($birthMonth) <= 1) {
1023
                    $birthMonth = '0'.$birthMonth;
1024
                }
1025
                $birthDay = $infoMe->birthDay;
1026
                if (strlen($birthDay) <= 1) {
1027
                    $birthDay = '0'.$birthDay;
1028
                }
1029
1030
                $gender = $infoMe->gender;
1031
                if ($gender == 'female') {
1032
                    $title = 'Me';
1033
                } else {
1034
                    $title = 'M';
1035
                }
1036
1037
                $params = array(
1038
                    //'birth_year'  => $infoMe->birthYear,
1039
                    'title'      => $title,
1040
                    'dob'        => $birthDay.'/'.$birthMonth.'/'.$infoMe->birthYear,
1041
                    'firstname'  => $infoMe->firstName,
1042
                    'lastname'   => $infoMe->lastName,
1043
                    'email'      => $infoMe->email,
1044
                    'postalCode' => $infoMe->zip,
1045
                );
1046
                $socialCredentials = array(
1047
                    'socialNetwork' => strtolower($socialnetwork),
1048
                    'socialId'      => $infoMe->identifier,
1049
                );
1050
            }
1051
        }
1052
1053
        $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...
1054
            $this->game->getClassType().'/user-register',
1055
            array('id' => $this->game->getIdentifier())
1056
        ).($socialnetwork?'/'.$socialnetwork:'').($redirect?'?redirect='.$redirect:'');
1057
        $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...
1058
1059
        if ($prg instanceof Response) {
1060
            return $prg;
1061
        } elseif ($prg === false) {
1062
            $form->setData($params);
1063
            $viewModel = $this->buildView($this->game);
1064
            $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...
1065
                'registerForm'       => $form,
1066
                'enableRegistration' => $userOptions->getEnableRegistration(),
1067
                'redirect'           => $redirect,
1068
            ));
1069
            return $viewModel;
1070
        }
1071
1072
        $post = $prg;
1073
        if (isset($post['optin'])) {
1074
            $post['optin'] = 1;
1075
        }
1076
        if (isset($post['optinPartner'])) {
1077
            $post['optinPartner'] = 1;
1078
        }
1079
        $post = array_merge(
1080
            $post,
1081
            $socialCredentials
1082
        );
1083
1084
        if ($pguserOptions->getUseRecaptcha()) {
1085
            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...
1086
                $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...
1087
                $form->setData($post);
1088
                $viewModel = $this->buildView($this->game);
1089
                $viewModel->setVariables(array(
1090
                        'registerForm'       => $form,
1091
                        'enableRegistration' => $userOptions->getEnableRegistration(),
1092
                        'redirect'           => $redirect,
1093
                        'bah'                => 'coco',
1094
                        '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...
1095
                        '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...
1096
                    ));
1097
1098
                return $viewModel;
1099
            }
1100
        }
1101
1102
        if ($this->game->getOnInvitation()) {
1103
            $credential = trim(
1104
                $post[$this->getGameService()->getOptions()->getOnInvitationField()]
1105
            );
1106
            if (!$credential) {
1107
                $credential = $this->params()->fromQuery(
1108
                    $this->getGameService()->getOptions()->getOnInvitationField()
1109
                );
1110
            }
1111
            $found = $this->getGameService()->getInvitationMapper()->findOneBy(array('requestKey' => $credential));
1112
1113
            if (!$found || !empty($found->getUser())) {
1114
                $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...
1115
                    'Authentication failed. Please try again.'
1116
                );
1117
                $form->setData($post);
1118
                $viewModel = $this->buildView($this->game);
1119
                $viewModel->setVariables(array(
1120
                        'registerForm'       => $form,
1121
                        'enableRegistration' => $userOptions->getEnableRegistration(),
1122
                        'redirect'           => $redirect,
1123
                        '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...
1124
                        '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...
1125
                    ));
1126
1127
                return $viewModel;
1128
            }
1129
        }
1130
1131
        $user = $service->register($post, 'playgroundgame_register_form');
1132
1133
        if (!$user) {
1134
            $viewModel = $this->buildView($this->game);
1135
            $viewModel->setVariables(array(
1136
                    'registerForm'       => $form,
1137
                    'enableRegistration' => $userOptions->getEnableRegistration(),
1138
                    'redirect'           => $redirect,
1139
                    '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...
1140
                    '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...
1141
                ));
1142
1143
            return $viewModel;
1144
        }
1145
1146
        if ($this->game->getOnInvitation()) {
1147
            // user has been created, associate the code with the userId
1148
            $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...
1149
            $this->getGameService()->getInvitationMapper()->update($found);
1150
        }
1151
1152
        if ($service->getOptions()->getEmailVerification()) {
1153
            $vm = new ViewModel(array('userEmail' => $user->getEmail()));
1154
            $vm->setTemplate('playground-user/register/registermail');
1155
1156
            return $vm;
1157
        } elseif ($service->getOptions()->getLoginAfterRegistration()) {
1158
            $identityFields = $service->getOptions()->getAuthIdentityFields();
1159
            if (in_array('email', $identityFields)) {
1160
                $post['identity'] = $user->getEmail();
1161
            } elseif (in_array('username', $identityFields)) {
1162
                $post['identity'] = $user->getUsername();
1163
            }
1164
            $post['credential'] = isset($post['password'])?$post['password']:'';
1165
            $request->setPost(new Parameters($post));
1166
1167
            // clear adapters
1168
            $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...
1169
            $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...
1170
1171
            $logged = $this->forward()->dispatch('playgrounduser_user', array('action' => 'ajaxauthenticate'));
1172
1173
            if ($logged) {
1174
                return $this->redirect()->toUrl(
1175
                    $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...
1176
                        $this->game->getClassType().'/'.$this->game->nextStep('index'),
1177
                        array('id' => $this->game->getIdentifier())
1178
                    )
1179
                );
1180 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...
1181
                $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...
1182
                    'Authentication failed. Please try again.'
1183
                );
1184
                return $this->redirect()->toUrl(
1185
                    $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...
1186
                        $this->game->getClassType().'/login',
1187
                        array('id' => $this->game->getIdentifier())
1188
                    )
1189
                );
1190
            }
1191
        }
1192
1193
        $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...
1194
            $this->game->getClassType().'/login',
1195
            array('id' => $this->game->getIdentifier())
1196
        ).($socialnetwork?'/'.$socialnetwork:'').($redirect?'?redirect='.$redirect:'');
1197
1198
        return $this->redirect()->toUrl($redirect);
1199
    }
1200
1201 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...
1202
    {
1203
        $viewModel = $this->forward()->dispatch(
1204
            'playgrounduser_user',
1205
            array(
1206
                'controller' => 'playgrounduser_user',
1207
                'action' => 'check-token',
1208
                'id' => $this->game->getIdentifier(),
1209
                'token' => $this->params()->fromRoute('token', null)
1210
            )
1211
        );
1212
1213
        if ($viewModel && $viewModel instanceof \Zend\View\Model\ViewModel) {
1214
            $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...
1215
            $viewModel->setVariables(array('game' => $this->game));
1216
        }
1217
1218
        return $viewModel;
1219
    }
1220
1221
    public function userProfileAction()
1222
    {
1223
        $viewModel = $this->forward()->dispatch(
1224
            'playgrounduser_user',
1225
            array(
1226
                'controller' => 'playgrounduser_user',
1227
                'action'     => 'profile',
1228
                'id'         => $this->game->getIdentifier()
1229
            )
1230
        );
1231
1232
        if ($viewModel && $viewModel instanceof \Zend\View\Model\ViewModel) {
1233
            $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...
1234
            $viewModel->setVariables(array('game'      => $this->game));
1235
        }
1236
1237
        return $viewModel;
1238
    }
1239
1240
    public function userresetAction()
1241
    {
1242
        $viewModel = $this->forward()->dispatch(
1243
            'playgrounduser_forgot',
1244
            array(
1245
                'controller' => 'playgrounduser_forgot',
1246
                'action'     => 'reset',
1247
                'id'         => $this->game->getIdentifier(),
1248
                'userId'     => $this->params()->fromRoute('userId', null),
1249
                'token'      => $this->params()->fromRoute('token', null),
1250
            )
1251
        );
1252
1253
        if ($viewModel && $viewModel instanceof \Zend\View\Model\ViewModel) {
1254
            $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...
1255
            $viewModel->setVariables(array('game'      => $this->game));
1256
        }
1257
1258
        return $viewModel;
1259
    }
1260
1261
    public function ajaxforgotAction()
1262
    {
1263
        $view = $this->forward()->dispatch(
1264
            'playgrounduser_forgot',
1265
            array(
1266
                'controller' => 'playgrounduser_forgot',
1267
                'action'     => 'ajaxforgot',
1268
                'id'         => $this->game->getIdentifier()
1269
            )
1270
        );
1271
1272
        if ($view && $view instanceof \Zend\View\Model\ViewModel) {
1273
            $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...
1274
            $view->setVariables(array('game'           => $this->game));
1275
        }
1276
1277
        return $view;
1278
    }
1279
1280 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...
1281
    {
1282
        $viewModel = $this->forward()->dispatch(
1283
            'playgroundcms',
1284
            array(
1285
                'controller' => 'playgroundcms',
1286
                'action'     => 'index',
1287
                'id'         => $this->game->getIdentifier(),
1288
                'pid'        => $this->getEvent()->getRouteMatch()->getParam('pid')
1289
            )
1290
        );
1291
1292
        if ($viewModel && $viewModel instanceof \Zend\View\Model\ViewModel) {
1293
            $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...
1294
            $viewModel->setVariables(array('game'      => $this->game));
1295
        }
1296
1297
        return $viewModel;
1298
    }
1299
1300 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...
1301
    {
1302
        $viewModel = $this->forward()->dispatch(
1303
            'playgroundcms',
1304
            array(
1305
                'controller' => 'playgroundcms',
1306
                'action'     => 'list',
1307
                'id'         => $this->game->getIdentifier(),
1308
                'category'   => $this->game->getIdentifier()
1309
            )
1310
        );
1311
1312
        if ($viewModel && $viewModel instanceof \Zend\View\Model\ViewModel) {
1313
            $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...
1314
            $viewModel->setVariables(array('game'      => $this->game));
1315
        }
1316
1317
        return $viewModel;
1318
    }
1319
1320
    /**
1321
     * This method create the basic Game view
1322
     * @param \PlaygroundGame\Entity\Game $game
1323
     */
1324
    public function buildView($game)
1325
    {
1326
        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...
1327
            $viewModel = new JsonModel();
1328
            if ($game) {
1329
                $view = $this->addAdditionalView($game);
1330
                if ($view && $view instanceof \Zend\View\Model\ViewModel) {
1331
                    $viewModel->setVariables($view->getVariables());
1332
                }
1333
            }
1334
        } else {
1335
            $viewModel = new ViewModel();
1336
1337
            if ($game) {
1338
                $this->addMetaTitle($game);
1339
                //$this->addMetaBitly();
1340
                $this->addGaEvent($game);
1341
1342
                $this->customizeGameDesign($game);
1343
1344
                $view = $this->addAdditionalView($game);
1345
                if ($view && $view instanceof \Zend\View\Model\ViewModel) {
1346
                    $viewModel->addChild($view, 'additional');
1347
                } elseif ($view && $view instanceof \Zend\Http\PhpEnvironment\Response) {
1348
                    return $view;
1349
                }
1350
1351
                $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...
1352
                    array(
1353
                        'action'        => $this->params('action'),
1354
                        'game'          => $game,
1355
                        '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...
1356
                    )
1357
                );
1358
1359
                $viewModel->setVariables($this->getShareData($game));
1360
                $viewModel->setVariables(
1361
                    array(
1362
                        'game' => $game,
1363
                        'user' => $this->user
1364
                    )
1365
                );
1366
            }
1367
        }
1368
1369
        return $viewModel;
1370
    }
1371
1372
    /**
1373
     * @param \PlaygroundGame\Entity\Game $game
1374
     */
1375
    public function addAdditionalView($game)
1376
    {
1377
        $view = false;
1378
1379
        $actionName = $this->getEvent()->getRouteMatch()->getParam('action', 'not-found');
1380
        $stepsViews = json_decode($game->getStepsViews(), true);
1381
        if ($stepsViews && isset($stepsViews[$actionName])) {
1382
            $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...
1383
            $actionData   = $stepsViews[$actionName];
1384
            if (is_string($actionData)) {
1385
                $action     = $actionData;
1386
                $classGame = __NAMESPACE__ . '\\' . ucfirst($this->game->getClassType());
1387
                $controller = $this->getEvent()->getRouteMatch()->getParam('controller', $classGame);
1388
                $view       = $this->forward()->dispatch(
1389
                    $controller,
1390
                    array(
1391
                        'action' => $action,
1392
                        'id'     => $game->getIdentifier()
1393
                    )
1394
                );
1395
            } elseif (is_array($actionData) && count($actionData) > 0) {
1396
                $action     = key($actionData);
1397
                $controller = __NAMESPACE__ . '\\' . ucfirst($actionData[$action]);
1398
                $view       = $this->forward()->dispatch(
1399
                    $controller,
1400
                    array(
1401
                        'action' => $action,
1402
                        'id'     => $game->getIdentifier()
1403
                    )
1404
                );
1405
            }
1406
            // suite au forward, le template de layout a changé, je dois le rétablir...
1407
            $this->layout()->setTemplate($beforeLayout);
1408
        }
1409
1410
        return $view;
1411
    }
1412
1413
    public function addMetaBitly()
1414
    {
1415
        $bitlyclient = $this->getOptions()->getBitlyUrl();
1416
        $bitlyuser   = $this->getOptions()->getBitlyUsername();
1417
        $bitlykey    = $this->getOptions()->getBitlyApiKey();
1418
1419
        $this->getViewHelper('HeadMeta')->setProperty('bt:client', $bitlyclient);
1420
        $this->getViewHelper('HeadMeta')->setProperty('bt:user', $bitlyuser);
1421
        $this->getViewHelper('HeadMeta')->setProperty('bt:key', $bitlykey);
1422
    }
1423
1424
    /**
1425
     * @param \PlaygroundGame\Entity\Game $game
1426
     */
1427
    public function addGaEvent($game)
1428
    {
1429
        // Google Analytics event
1430
        $ga    = $this->getServiceLocator()->get('google-analytics');
1431
        $event = new \PlaygroundCore\Analytics\Event($game->getClassType(), $this->params('action'));
1432
        $event->setLabel(str_replace("'", "\'", $game->getTitle()));
1433
        $ga->addEvent($event);
1434
    }
1435
1436
    /**
1437
     * @param \PlaygroundGame\Entity\Game $game
1438
     */
1439
    public function addMetaTitle($game)
1440
    {
1441
        $title = $game->getTitle();
1442
        $this->getGameService()->getServiceManager()->get('ViewHelperManager')->get('HeadTitle')->set($title);
1443
        // Meta set in the layout
1444
        $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...
1445
            array(
1446
                'breadcrumbTitle' => $title,
1447
                'currentPage'     => array(
1448
                    'pageGames'      => 'games',
1449
                    'pageWinners'    => '',
1450
                ),
1451
                'headParams'       => array(
1452
                    'headTitle'       => $title,
1453
                    'headDescription' => $title,
1454
                ),
1455
                'bodyCss' => $game->getIdentifier()
1456
            )
1457
        );
1458
    }
1459
1460
    /**
1461
     * @param \PlaygroundGame\Entity\Game $game
1462
     */
1463
    public function customizeGameDesign($game)
1464
    {
1465
        // If this game has a specific layout...
1466
        if ($game->getLayout()) {
1467
            $layoutViewModel = $this->layout();
1468
            $layoutViewModel->setTemplate($game->getLayout());
1469
        }
1470
1471
        // If this game has a specific stylesheet...
1472
        if ($game->getStylesheet()) {
1473
            $this->getViewHelper('HeadLink')->appendStylesheet(
1474
                $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...
1475
            );
1476
        }
1477
    }
1478
1479
    /**
1480
     * @param \PlaygroundGame\Entity\Game $game
1481
     */
1482
    public function getShareData($game)
1483
    {
1484
        $fo      = $this->getServiceLocator()->get('facebook-opengraph');
1485
        $session = new Container('facebook');
1486
1487
        // I change the fbappid if i'm in fb
1488
        if ($session->offsetExists('signed_request')) {
1489
            $fo->setId($game->getFbAppId());
1490
        }
1491
1492
        $fbShareDescription = $game->getFbShareDescription();
1493
1494
        if ($game->getFbShareImage()) {
1495
            $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...
1496
                '',
1497
                array(),
1498
                array('force_canonical' => true),
1499
                false
1500
            ).$game->getFbShareImage();
1501
        } else {
1502
            $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...
1503
                '',
1504
                array(),
1505
                array('force_canonical' => true),
1506
                false
1507
            ).$game->getMainImage();
1508
        }
1509
1510
        $secretKey = strtoupper(substr(sha1(uniqid('pg_', true).'####'.time()), 0, 15));
1511
        $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...
1512
            $game->getClassType(),
1513
            array('id' => $this->game->getIdentifier()),
1514
            array('force_canonical' => true)
1515
        ).'?key='.$secretKey;
1516
        // With core shortener helper
1517
        $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...
1518
1519
        $fbShareUrl = $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...
1520
            $game->getClassType().'/fbshare',
1521
            array('id' => $this->game->getIdentifier()),
1522
            array('force_canonical' => true)
1523
        ).'?fbId='.$secretKey;
1524
1525
        $twShareUrl = $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...
1526
            $game->getClassType().'/tweet',
1527
            array('id' => $this->game->getIdentifier()),
1528
            array('force_canonical' => true)
1529
        ).'?fbId='.$secretKey;
1530
1531
        // FB Requests only work when it's a FB app
1532
        if ($game->getFbRequestMessage()) {
1533
            $fbRequestMessage = urlencode($game->getFbRequestMessage());
1534
        } else {
1535
            $fbRequestMessage = str_replace(
1536
                '__placeholder__',
1537
                $game->getTitle(),
1538
                $this->getOptions()->getDefaultShareMessage()
1539
            );
1540
        }
1541
1542
        $twShareMessage = $game->getTwShareMessage().$socialLinkUrl;
1543
1544
        // I add OG tags to the meta
1545
        $ogTitle = new \PlaygroundCore\Opengraph\Tag('og:title', $game->getTitle());
1546
        $ogDescription = new \PlaygroundCore\Opengraph\Tag('og:description', $fbShareDescription);
1547
        $ogImage = new \PlaygroundCore\Opengraph\Tag('og:image', $fbShareImage);
1548
        $twTitle = new \PlaygroundCore\Opengraph\Tag('twitter:title', $game->getTitle());
1549
        $twDescription =  new \PlaygroundCore\Opengraph\Tag('twitter:description', $this->game->getTwShareMessage());
1550
        $twImage =  new \PlaygroundCore\Opengraph\Tag('twitter:image', $fbShareImage);
1551
        $twUrl = new \PlaygroundCore\Opengraph\Tag('twitter:url', $socialLinkUrl);
1552
1553
        $fo->addTag($ogTitle);
1554
        $fo->addTag($ogDescription);
1555
        $fo->addTag($ogImage);
1556
        $fo->addTag($twTitle);
1557
        $fo->addTag($twDescription);
1558
        $fo->addTag($twImage);
1559
        $fo->addTag($twUrl);
1560
        
1561
        // I add variables + js to make the share easy
1562
        $renderer = $this->serviceLocator->get('Zend\View\Renderer\RendererInterface');
1563
        $headScript = $this->getServiceLocator()->get('ViewHelperManager')->get('HeadScript');
1564
        $headScript->appendScript("var pgGameUrl = '" . $socialLinkUrl . "';\nvar pgFbShareUrl = '" . $fbShareUrl . "';\nvar pgTwShareUrl = '" . $twShareUrl . "';");
1565
        $headScript->appendFile($renderer->frontendAssetPath() . '/js/pg/share.js');
1566
1567
        $data = array(
1568
            'socialLinkUrl'         => $socialLinkUrl,
1569
            'secretKey'             => $secretKey,
1570
            'fbShareDescription'    => $fbShareDescription,
1571
            'fbShareImage'          => $fbShareImage,
1572
            'fbRequestMessage'      => $fbRequestMessage,
1573
            'twShareMessage'        => $twShareMessage,
1574
        );
1575
1576
        return $data;
1577
    }
1578
1579
    /**
1580
     * return ajax response in json format
1581
     *
1582
     * @param array $data
1583
     * @return \Zend\View\Model\JsonModel
1584
     */
1585 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...
1586
    {
1587
        $model = new JsonModel(array(
1588
                'success' => true,
1589
                'data'    => $data,
1590
            ));
1591
        return $model->setTerminal(true);
1592
    }
1593
1594
    /**
1595
     * return ajax response in json format
1596
     *
1597
     * @param string $message
1598
     * @return \Zend\View\Model\JsonModel
1599
     */
1600 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...
1601
    {
1602
        $model = new JsonModel(array(
1603
                'success' => false,
1604
                'message' => $message,
1605
            ));
1606
        return $model->setTerminal(true);
1607
    }
1608
1609
    /**
1610
     * @param string $helperName
1611
     */
1612
    protected function getViewHelper($helperName)
1613
    {
1614
        return $this->getServiceLocator()->get('ViewHelperManager')->get($helperName);
1615
    }
1616
1617
    public function getGameService()
1618
    {
1619
        if (!$this->gameService) {
1620
            $this->gameService = $this->getServiceLocator()->get('playgroundgame_lottery_service');
1621
        }
1622
1623
        return $this->gameService;
1624
    }
1625
1626
    public function setGameService(GameService $gameService)
1627
    {
1628
        $this->gameService = $gameService;
1629
1630
        return $this;
1631
    }
1632
1633
    public function getPrizeService()
1634
    {
1635
        if (!$this->prizeService) {
1636
            $this->prizeService = $this->getServiceLocator()->get('playgroundgame_prize_service');
1637
        }
1638
1639
        return $this->prizeService;
1640
    }
1641
1642
    public function setPrizeService(PrizeService $prizeService)
1643
    {
1644
        $this->prizeService = $prizeService;
1645
1646
        return $this;
1647
    }
1648
1649
    public function getOptions()
1650
    {
1651
        if (!$this->options) {
1652
            $this->setOptions($this->getServiceLocator()->get('playgroundcore_module_options'));
1653
        }
1654
1655
        return $this->options;
1656
    }
1657
1658
    public function setOptions($options)
1659
    {
1660
        $this->options = $options;
1661
1662
        return $this;
1663
    }
1664
}
1665