Completed
Push — master ( d3983a...dfd1f2 )
by greg
15:51 queued 13:24
created

GameController::checkFbRegistration()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

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

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

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

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

Let’s take a look at an example:

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

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

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

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

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

Available Fixes

  1. Change the type-hint for the parameter:

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

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

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

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

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

class ParentClass {
    private $data = array();

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

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

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
145
            if ($controller->game &&
146
                    !$controller->user &&
147
                    !$controller->game->getAnonymousAllowed() &&
148
                    in_array($controller->params('action'), $controller->withAnyUser)
149
                ) {
150
                // if the current game runs under Facebook
151
                if ($session->offsetExists('signed_request')) {
152
                    // Let's start the FB registration dance !
153
                    $controller->forward()->dispatch(
154
                        'playgrounduser_user',
155
                        array(
156
                            'controller' => 'playgrounduser_user',
157
                            'action'     => 'registerFacebookUser',
158
                            'provider'   => 'facebook',
159
                            '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...
160
                        )
161
                    );
162
                }
163
                $redirect = urlencode(
164
                    $controller->url()->fromRoute(
165
                        'frontend/'.$controller->game->getClassType().'/'.$controller->params('action'),
166
                        array('id'              => $controller->game->getIdentifier()),
167
                        array('force_canonical' => true)
168
                    )
169
                );
170
171
                if ($this->isSoloGame) {
172
                     $urlRegister = $controller->url()->fromRoute(
173
                         'frontend.'.$customUrl.'/'.$controller->game->getClassType().'/user-register',
174
                         array(),
175
                         array('force_canonical' => true)
176
                     ).'?redirect='.$redirect;
177
                } else {
178
                    $urlRegister = $controller->url()->fromRoute(
179
                        'frontend/zfcuser/register',
180
                        array(),
181
                        array('force_canonical' => true)
182
                    ).'?redirect='.$redirect;
183
                }
184
185
                // code permettant d'identifier un custom game
186
                // ligne $config = $controller->getGameService()->getServiceManager()->get('config');
187
                // ligne $customUrl = str_replace('frontend.', '', $e->getRouteMatch()->getParam('area', ''));
188
                // ligne if ($config['custom_games'][$controller->game->getIdentifier()] &&
189
                // ligne    $controller->getRequest()->getUri()->getHost() === $customUrl
190
                // ligne ) {
191
                return $controller->redirect()->toUrl($urlRegister);
192
            }
193
194
                return;
195
        }, 100);// execute before executing action logic
196
    }
197
198
    /**
199
     * Action called if matched action does not exist
200
     * For this view not to be catched by Zend\Mvc\View\RouteNotFoundStrategy
201
     * it has to be rendered in the controller. Hence the code below.
202
     *
203
     * This action is injected as a catchall action for each custom_games definition
204
     * This way, when a custom_game is created, the 404 is it's responsability and the
205
     * view can be defined in design/frontend/default/custom/$slug/playground_game/$gametype/404.phtml
206
     *
207
     *
208
     * @return \Zend\Stdlib\ResponseInterface
209
     */
210
    public function notFoundAction()
211
    {
212
        $templatePathResolver = $this->getServiceLocator()->get('Zend\View\Resolver\TemplatePathStack');
213
214
        // I create a template path in which I can find a custom template
215
        $controller     = explode('\\', get_class($this));
216
        $controllerPath = str_replace('Controller', '', end($controller));
217
        $controllerPath = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '-\\1', $controllerPath));
218
        $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...
219
        if ($this->game) {
220
            $uri = str_replace($controllerPath.'/'.$this->game->getIdentifier().'/', '', $uri);
221
        }
222
        $uri      = str_replace("/".$this->getEvent()->getRouteMatch()->getParam('locale')."/", "/", $uri);
223
        $template = 'playground-game/'.$controllerPath.'/custom'.$uri;
224
225
        if (false === $templatePathResolver->resolve($template)) {
226
            $viewRender = $this->getServiceLocator()->get('ViewRenderer');
227
228
            $this->getEvent()->getRouteMatch()->setParam('action', 'not-found');
229
            $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...
230
231
            $res = 'error/404';
232
233
            $viewModel = $this->buildView($this->game);
234
            $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...
235
236
            $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...
237
            $this->response->setContent($viewRender->render($this->layout()));
238
239
            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...
240
        }
241
242
        $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 245 which is incompatible with the return type documented by PlaygroundGame\Controlle...troller::notFoundAction of type Zend\Stdlib\ResponseInterface.
Loading history...
243
        $viewModel->setTemplate($template);
244
245
        return $viewModel;
246
    }
247
248
    /**
249
     * This action acts as a hub : Depending on the first step of the game, it will forward the action to this step
250
     */
251
    public function homeAction()
252
    {
253
        // This fix exists only for safari in FB on Windows : we need to redirect the user to the page
254
        // outside of iframe for the cookie to be accepted. PlaygroundCore redirects to the FB Iframed page when
255
        // it discovers that the user arrives for the first time on the game in FB.
256
        // When core redirects, it adds a 'redir_fb_page_id' var in the querystring
257
        // Here, we test if this var exist, and then send the user back to the game in FB.
258
        // Now the cookie will be accepted by Safari...
259
        $pageId = $this->params()->fromQuery('redir_fb_page_id');
260
        if (!empty($pageId)) {
261
            $appId = 'app_'.$this->game->getFbAppId();
262
            $url   = '//www.facebook.com/pages/game/'.$pageId.'?sk='.$appId;
263
264
            return $this->redirect()->toUrl($url);
265
        }
266
267
        // If an entry has already been done during this session, I reset the anonymous_identifier cookie
268
        // so that another person can play the same game (if game conditions are fullfilled)
269
        $session = new Container('anonymous_identifier');
270
        if ($session->offsetExists('anonymous_identifier')) {
271
            $session->offsetUnset('anonymous_identifier');
272
        }
273
274
        $classGame = __NAMESPACE__ . '\\' . ucfirst($this->game->getClassType());
275
        return $this->forward()->dispatch(
276
            $classGame,
277
            array(
278
                'controller' => $classGame,
279
                'action'     => $this->game->firstStep(),
280
                'id'         => $this->game->getIdentifier()
281
            )
282
        );
283
    }
284
285
    /**
286
     * Homepage of the game
287
     */
288
    public function indexAction()
289
    {
290
        $isSubscribed = false;
291
292
        $entry = $this->getGameService()->checkExistingEntry($this->game, $this->user);
293
        if ($entry) {
294
            $isSubscribed = true;
295
        }
296
297
        $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 302 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...
298
        $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...
299
            'isSubscribed' => $isSubscribed,
300
        ));
301
302
        return $viewModel;
303
    }
304
305
    /**
306
     * leaderboardAction
307
     *
308
     * @return ViewModel $viewModel
309
     */
310
    public function leaderboardAction()
311
    {
312
        $filter = $this->getEvent()->getRouteMatch()->getParam('filter');
313
        $p      = $this->getEvent()->getRouteMatch()->getParam('p');
314
315
        $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...
316
        $subViewModel = $this->forward()->dispatch(
317
            'playgroundreward',
318
            array('action' => 'leaderboard', 'filter' => $filter, 'p' => $p)
319
        );
320
321
        // suite au forward, le template de layout a changé, je dois le rétablir...
322
        $this->layout()->setTemplate($beforeLayout);
323
        $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...
324
            array(
325
                'action' => $this->params('action'),
326
                'game'   => $this->game,
327
            )
328
        );
329
330
        $subViewModel->setVariables($this->getShareData($this->game));
331
        $subViewModel->setVariables(array('game' => $this->game, 'user' => $this->user));
332
333
        return $subViewModel;
334
    }
335
336
    /**
337
     * This action has been designed to be called by other controllers
338
     * It gives the ability to display an information form and persist it in the game entry
339
     *
340
     * @return \Zend\View\Model\ViewModel
341
     */
342
    public function registerAction()
343
    {
344
        $formDef = $this->game->getPlayerForm();
345
        if ($formDef !== null) {
346
            $form = $this->getGameService()->createFormFromJson($formDef->getForm(), 'playerForm');
347
        } else {
348
            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...
349
        }
350
351
        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...
352
            // POST Request: Process form
353
            $data = array_merge_recursive(
354
                $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...
355
                $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...
356
            );
357
358
            $form->setData($data);
359
360
            if ($form->isValid()) {
361
                // steps of the game
362
                $steps = $this->game->getStepsArray();
363
                // sub steps of the game
364
                $viewSteps = $this->game->getStepsViewsArray();
365
366
                // register position
367
                $key = array_search($this->params('action'), $viewSteps);
368
                if (!$key) {
369
                    // register is not a substep of the game so it's a step
370
                    $key     = array_search($this->params('action'), $steps);
371
                    $keyStep = true;
372
                } else {
373
                    // register was a substep, i search the index of its parent
374
                    $key     = array_search($key, $steps);
375
                    $keyStep = false;
376
                }
377
378
                // play position
379
                $keyplay = array_search('play', $viewSteps);
380
381
                if (!$keyplay) {
382
                    // play is not a substep, so it's a step
383
                    $keyplay     = array_search('play', $steps);
384
                    $keyplayStep = true;
385
                } else {
386
                    // play is a substep so I search the index of its parent
387
                    $keyplay     = array_search($keyplay, $steps);
388
                    $keyplayStep = false;
389
                }
390
391
                // If register step before play, I don't have no entry yet. I have to create one
392
                // If register after play step, I search for the last entry created by play step.
393
394
                if ($key < $keyplay || ($keyStep && !$keyplayStep && $key <= $keyplay)) {
395
                    $entry = $this->getGameService()->play($this->game, $this->user);
396
                    if (!$entry) {
397
                        // the user has already taken part of this game and the participation limit has been reached
398
                        $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...
399
400
                        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...
401
                            $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...
402
                                $this->game->getClassType().'/result',
403
                                array(
404
                                    'id' => $this->game->getIdentifier(),
405
                                )
406
                            )
407
                        );
408
                    }
409
                } else {
410
                    // I'm looking for an entry without anonymousIdentifier (the active entry in fact).
411
                    $entry = $this->getGameService()->findLastEntry($this->game, $this->user);
412
                    if ($this->getGameService()->hasReachedPlayLimit($this->game, $this->user)) {
413
                        // the user has already taken part of this game and the participation limit has been reached
414
                        $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...
415
416
                        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...
417
                            $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...
418
                                $this->game->getClassType().'/result',
419
                                array(
420
                                    'id' => $this->game->getIdentifier(),
421
                                )
422
                            )
423
                        );
424
                    }
425
                }
426
427
                $this->getGameService()->updateEntryPlayerForm($form->getData(), $this->game, $this->user, $entry);
428
429
                if (!empty($this->game->nextStep($this->params('action')))) {
430
                    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...
431
                        $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...
432
                            $this->game->getClassType().'/'.$this->game->nextStep($this->params('action')),
433
                            array('id'              => $this->game->getIdentifier()),
434
                            array('force_canonical' => true)
435
                        )
436
                    );
437
                }
438
            }
439
        }
440
441
        $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 446 which is incompatible with the return type documented by PlaygroundGame\Controlle...troller::registerAction of type Zend\View\Model\ViewModel.
Loading history...
442
        $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...
443
                'form' => $form,
444
            ));
445
446
        return $viewModel;
447
    }
448
449
    /**
450
     * This action takes care of the terms of the game
451
     */
452
    public function termsAction()
453
    {
454
        $viewModel = $this->buildView($this->game);
455
456
        return $viewModel;
457
    }
458
459
    /**
460
     * This action takes care of the conditions of the game
461
     */
462
    public function conditionsAction()
463
    {
464
        $viewModel = $this->buildView($this->game);
465
466
        return $viewModel;
467
    }
468
469
    /**
470
     * This action takes care of bounce page of the game
471
     */
472
    public function bounceAction()
473
    {
474
        $availableGames = $this->getGameService()->getAvailableGames($this->user);
475
476
        $rssUrl = '';
477
        $config = $this->getGameService()->getServiceManager()->get('config');
478
        if (isset($config['rss']['url'])) {
479
            $rssUrl = $config['rss']['url'];
480
        }
481
482
        $viewModel = $this->buildView($this->game);
483
        $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...
484
                'rssUrl'         => $rssUrl,
485
                'user'           => $this->user,
486
                'availableGames' => $availableGames,
487
            ));
488
489
        return $viewModel;
490
    }
491
492
    /**
493
     * This action displays the Prizes page associated to the game
494
     */
495
    public function prizesAction()
496
    {
497
        if (count($this->game->getPrizes()) == 0) {
498
            return $this->notFoundAction();
499
        }
500
501
        $viewModel = $this->buildView($this->game);
502
503
        return $viewModel;
504
    }
505
506
    /**
507
     * This action displays a specific Prize page among those associated to the game
508
     */
509
    public function prizeAction()
510
    {
511
        $prizeIdentifier = $this->getEvent()->getRouteMatch()->getParam('prize');
512
        $prize           = $this->getPrizeService()->getPrizeMapper()->findByIdentifier($prizeIdentifier);
513
514
        if (!$prize) {
515
            return $this->notFoundAction();
516
        }
517
518
        $viewModel = $this->buildView($this->game);
519
        $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...
520
521
        return $viewModel;
522
    }
523
524
    public function gameslistAction()
525
    {
526
        $layoutViewModel = $this->layout();
527
528
        $slider = new ViewModel();
529
        $slider->setTemplate('playground-game/common/top_promo');
530
531
        $sliderItems = $this->getGameService()->getActiveSliderGames();
532
533
        $slider->setVariables(array('sliderItems' => $sliderItems));
534
535
        $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...
536
537
        $games = $this->getGameService()->getActiveGames(false, '', 'endDate');
538
        if (is_array($games)) {
539
            $paginator = new \Zend\Paginator\Paginator(new \Zend\Paginator\Adapter\ArrayAdapter($games));
540
        } else {
541
            $paginator = $games;
542
        }
543
544
        $paginator->setItemCountPerPage(7);
545
        $paginator->setCurrentPageNumber($this->getEvent()->getRouteMatch()->getParam('p'));
546
547
        $bitlyclient = $this->getOptions()->getBitlyUrl();
548
        $bitlyuser   = $this->getOptions()->getBitlyUsername();
549
        $bitlykey    = $this->getOptions()->getBitlyApiKey();
550
551
        $this->getViewHelper('HeadMeta')->setProperty('bt:client', $bitlyclient);
552
        $this->getViewHelper('HeadMeta')->setProperty('bt:user', $bitlyuser);
553
        $this->getViewHelper('HeadMeta')->setProperty('bt:key', $bitlykey);
554
555
        $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...
556
            array(
557
                'sliderItems'  => $sliderItems,
558
                'currentPage'  => array(
559
                    'pageGames'   => 'games',
560
                    'pageWinners' => '',
561
                ),
562
            )
563
        );
564
565
        return new ViewModel(
566
            array(
567
                'games' => $paginator,
568
            )
569
        );
570
    }
571
572
    public function shareAction()
573
    {
574
        $statusMail = null;
575
        $lastEntry  = null;
576
577
        // steps of the game
578
        $steps = $this->game->getStepsArray();
579
        // sub steps of the game
580
        $viewSteps = $this->game->getStepsViewsArray();
581
582
        // share position
583
        $key = array_search($this->params('action'), $viewSteps);
584
        if (!$key) {
585
            // share is not a substep of the game so it's a step
586
            $key = array_search($this->params('action'), $steps);
587
        } else {
588
            // share was a substep, I search the index of its parent
589
            $key = array_search($key, $steps);
590
        }
591
592
        // play position
593
        $keyplay = array_search('play', $viewSteps);
594
595
        if (!$keyplay) {
596
            // play is not a substep, so it's a step
597
            $keyplay = array_search('play', $steps);
598
        } else {
599
            // play is a substep so I search the index of its parent
600
            $keyplay = array_search($keyplay, $steps);
601
        }
602
603
        if ($key && $keyplay && $keyplay <= $key) {
604
            // Has the user finished the game ?
605
            $lastEntry = $this->getGameService()->findLastInactiveEntry($this->game, $this->user);
606
607
            if ($lastEntry === null) {
608
                return $this->redirect()->toUrl(
609
                    $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...
610
                        $this->game->getClassType(),
611
                        array('id' => $this->game->getIdentifier())
612
                    )
613
                );
614
            }
615
        }
616
617
        $form = $this->getServiceLocator()->get('playgroundgame_sharemail_form');
618
        $form->setAttribute('method', 'post');
619
620
        // buildView must be before sendMail because it adds the game template path to the templateStack
621
        $viewModel = $this->buildView($this->game);
622
623 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...
624
            $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...
625
            $form->setData($data);
626
            if ($form->isValid()) {
627
                $result = $this->getGameService()->sendShareMail($data, $this->game, $this->user, $lastEntry);
628
                if ($result) {
629
                    $statusMail = true;
630
                }
631
            }
632
        }
633
634
        $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...
635
                'statusMail' => $statusMail,
636
                'form'       => $form,
637
            ));
638
639
        return $viewModel;
640
    }
641
642
    public function inviteToTeamAction()
643
    {
644
645
        if (count($this->user->getTeams()) == 0) {
646
            return $this->redirect()->toUrl(
647
                $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...
648
                    $this->game->getClassType().'/create-team',
649
                    array('id' => $this->game->getIdentifier())
650
                )
651
            );
652
        }
653
654
        $team = $this->user->getTeams()->first(); 
655
        $invitationMapper = $this->getServiceLocator()->get('playgroundgame_invitation_mapper');
656
        $invitations = $invitationMapper->findBy(array('host' => $this->user, 'game' => $this->game));
657
        $statusMail = null;
658
        $message = '';
659
        $isHost = ($this->user->getId() === $team->getHost()->getId()) ? true : false;
660
661
        $form = $this->getServiceLocator()->get('playgroundgame_sharemail_form');
662
        $form->setAttribute('method', 'post');
663
664
        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...
665
            $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...
666
            $form->setData($data);
667
            if ($form->isValid()) {
668
                $result = $this->getGameService()->inviteToTeam($data, $this->game, $this->user);
669
                if ($result['result']) {
670
                    $statusMail = true;
671
                } else {
672
                    $statusMail = false;
673
                    $message    = $result['message'];
674
                }
675
            }
676
        }
677
678
        $viewModel = $this->buildView($this->game);
679
        $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...
680
            'team'       => $team,
681
            'invitations'=> $invitations,
682
            'message'    => $message,
683
            'statusMail' => $statusMail,
684
            'form'       => $form,
685
            'isHost'     => $isHost,
686
        ));
687
688
        return $viewModel;
689
    }
690
691
    public function createTeamAction()
692
    {
693
        if (count($this->user->getTeams()) > 0) {
694
            return $this->redirect()->toUrl(
695
                $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...
696
                    $this->game->getClassType().'/invite-to-team',
697
                    array('id' => $this->game->getIdentifier())
698
                )
699
            );
700
        }
701
702
        $form = $this->getServiceLocator()->get('playgroundgame_createteam_form');
703
        $form->setAttribute('method', 'post');
704
705
        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...
706
            $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...
707
            $form->setData($data);
708
            if ($form->isValid()) {
709
                $teamMapper = $this->getServiceLocator()->get('playgrounduser_team_mapper');
710
                $users = new \Doctrine\Common\Collections\ArrayCollection();
711
                $users->add($this->user);
712
                $teamName = $data['name'];
713
                $slugify = new \PlaygroundCore\Filter\Slugify;
714
715
                $team = new \PlaygroundUser\Entity\Team();
716
                $team->setName($teamName);
717
                $team->setIdentifier($slugify($teamName));
718
                $team->setHost($this->user);
719
                $team->addUsers($users);
720
721
                $teamMapper->insert($team);
722
723
                return $this->redirect()->toUrl(
724
                    $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...
725
                        $this->game->getClassType().'/invite-to-team',
726
                        array('id' => $this->game->getIdentifier())
727
                    )
728
                );
729
            }
730
        }
731
732
        $viewModel = $this->buildView($this->game);
733
        $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...
734
            'form'       => $form,
735
        ));
736
737
        return $viewModel;
738
    }
739
740 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...
741
    {
742
        $viewModel = new JsonModel();
743
        $viewModel->setTerminal(true);
744
        $fbId = $this->params()->fromQuery('fbId');
745
        if (!$this->game) {
746
            return $this->errorJson();
747
        }
748
        $entry = $this->getGameService()->checkExistingEntry($this->game, $this->user);
749
        if (!$entry) {
750
            return $this->errorJson();
751
        }
752
        if (!$fbId) {
753
            return $this->errorJson();
754
        }
755
756
        $this->getGameService()->postFbWall($fbId, $this->game, $this->user, $entry);
757
758
        return $this->successJson();
759
    }
760
761
    public function fbrequestAction()
762
    {
763
        $viewModel = new ViewModel();
764
        $viewModel->setTerminal(true);
765
        $fbId = $this->params()->fromQuery('fbId');
766
        $to   = $this->params()->fromQuery('to');
767
768
        if (!$this->game) {
769
            return $this->errorJson();
770
        }
771
        $entry = $this->getGameService()->checkExistingEntry($this->game, $this->user);
772
        if (!$entry) {
773
            return $this->errorJson();
774
        }
775
        if (!$fbId) {
776
            return $this->errorJson();
777
        }
778
779
        $this->getGameService()->postFbRequest($fbId, $this->game, $this->user, $entry, $to);
780
781
        return $this->successJson();
782
    }
783
784
    public function tweetAction()
785
    {
786
        $tweetId = $this->params()->fromQuery('tweetId');
787
788
        if (!$this->game) {
789
            return $this->errorJson();
790
        }
791
        $entry = $this->getGameService()->checkExistingEntry($this->game, $this->user);
792
        if (!$entry) {
793
            return $this->errorJson();
794
        }
795
        if (!$tweetId) {
796
            return $this->errorJson();
797
        }
798
799
        $this->getGameService()->postTwitter($tweetId, $this->game, $this->user, $entry);
800
801
        return $this->successJson();
802
    }
803
804 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...
805
    {
806
        $viewModel = new ViewModel();
807
        $viewModel->setTerminal(true);
808
        $googleId = $this->params()->fromQuery('googleId');
809
810
        if (!$this->game) {
811
            return $this->errorJson();
812
        }
813
        $entry = $this->getGameService()->checkExistingEntry($this->game, $this->user);
814
        if (!$entry) {
815
            return $this->errorJson();
816
        }
817
        if (!$googleId) {
818
            return $this->errorJson();
819
        }
820
821
        $this->getGameService()->postGoogle($googleId, $this->game, $this->user, $entry);
822
823
        return $this->successJson();
824
    }
825
826
    public function optinAction()
827
    {
828
        $userService = $this->getServiceLocator()->get('zfcuser_user_service');
829
830
        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...
831
            $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...
832
            $data['optinPartner'] = ($this->params()->fromPost('optinPartner'))?1:0;
833
834
            $userService->updateNewsletter($data);
835
        }
836
837
        return $this->redirect()->toUrl(
838
            $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...
839
                $this->game->getClassType(),
840
                array('id' => $this->game->getIdentifier())
841
            )
842
        );
843
    }
844
845
    public function loginAction()
846
    {
847
        $request = $this->getRequest();
848
        $redirect = "";
849
        if ($request->getQuery()->get('redirect') != '') {
850
            $redirect = $request->getQuery()->get('redirect');
851
        }
852
        $form    = $this->getServiceLocator()->get('zfcuser_login_form');
853
854
        if ($request->isPost()) {
855
            $form->setData($request->getPost());
856
857
            if (!$form->isValid()) {
858
                $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...
859
                    'Authentication failed. Please try again.'
860
                );
861
862
                $viewModel = $this->buildView($this->game);
863
                $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...
864
                        'form'          => $form,
865
                        '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...
866
                    ));
867
868
                return $viewModel;
869
            }
870
871
            // clear adapters
872
            $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...
873
            $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...
874
875
            $logged = $this->forward()->dispatch('playgrounduser_user', array('action' => 'ajaxauthenticate'));
876
877
            if (!$logged) {
878
                $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...
879
                    'Authentication failed. Please try again.'
880
                );
881
882
                return $this->redirect()->toUrl(
883
                    $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...
884
                        $this->game->getClassType().'/login',
885
                        array('id' => $this->game->getIdentifier())
886
                    )
887
                );
888 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...
889
                if ($redirect != "") {
890
                    return $this->redirect()->toUrl($redirect);
891
                } else {
892
                    return $this->redirect()->toUrl(
893
                        $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...
894
                            $this->game->getClassType().'/'.$this->game->nextStep('index'),
895
                            array('id' => $this->game->getIdentifier())
896
                        )
897
                    );
898
                }
899
            }
900
        }
901
902
        $form->setAttribute(
903
            'action',
904
            $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...
905
                $this->game->getClassType().'/login',
906
                array('id' => $this->game->getIdentifier())
907
            )
908
        );
909
        $viewModel = $this->buildView($this->game);
910
        $viewModel->setVariables(array(
911
                'form'          => $form,
912
                '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...
913
            ));
914
        return $viewModel;
915
    }
916
917
    public function logoutAction()
918
    {
919
        $viewModel = $this->forward()->dispatch(
920
            'playgrounduser_user',
921
            array(
922
                'controller' => 'playgrounduser_user',
923
                'action'     => 'logout',
924
                'id'         => $this->game->getIdentifier()
925
            )
926
        );
927
928
        if ($viewModel && $viewModel instanceof \Zend\View\Model\ViewModel) {
929
            $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...
930
            $viewModel->setVariables(array('game'      => $this->game));
931
        }
932
933
        return $viewModel;
934
    }
935
936
    public function userregisterAction()
937
    {
938
        $pguserOptions = $this->getServiceLocator()->get('playgrounduser_module_options');
939
        $userOptions = $this->getServiceLocator()->get('zfcuser_module_options');
940
941 View Code Duplication
        if ($this->zfcUserAuthentication()->hasIdentity()) {
0 ignored issues
show
Documentation Bug introduced by
The method zfcUserAuthentication does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

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

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

class ParentClass {
    private $data = array();

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

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

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

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

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

Loading history...
942
            return $this->redirect()->toUrl(
943
                $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...
944
                    $this->game->getClassType().'/'.$this->game->nextStep('index'),
945
                    array('id' => $this->game->getIdentifier())
946
                )
947
            );
948
        }
949
        $request       = $this->getRequest();
950
        $service       = $this->getServiceLocator()->get('zfcuser_user_service');
951
        $form          = $this->getServiceLocator()->get('playgroundgame_register_form');
952
        $socialnetwork = $this->params()->fromRoute('socialnetwork', false);
953
        $form->setAttribute(
954
            'action',
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().'/user-register',
957
                array('id' => $this->game->getIdentifier())
958
            )
959
        );
960
        $params            = array();
961
        $socialCredentials = array();
962
963
        if ($userOptions->getUseRedirectParameterIfPresent() && $request->getQuery()->get('redirect')) {
964
            $redirect = $request->getQuery()->get('redirect');
965
        } else {
966
            $redirect = false;
967
        }
968
969
        if ($socialnetwork) {
970
            $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...
971
972
            if (!empty($infoMe)) {
973
                $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...
974
                    $infoMe->identifier,
975
                    $socialnetwork
976
                );
977
978
                if ($user || $service->getOptions()->getCreateUserAutoSocial() === true) {
979
                    //on le dirige vers l'action d'authentification
980
                    if (!$redirect && $userOptions->getLoginRedirectRoute() != '') {
981
                        $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...
982
                            $this->game->getClassType().'/login',
983
                            array('id' => $this->game->getIdentifier())
984
                        );
985
                    }
986
                    $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...
987
                        $this->game->getClassType().'/login',
988
                        array('id' => $this->game->getIdentifier())
989
                    ).'/'.$socialnetwork.($redirect?'?redirect='.$redirect:'');
990
991
                    return $this->redirect()->toUrl($redir);
992
                }
993
994
                // Je retire la saisie du login/mdp
995
                $form->setAttribute(
996
                    'action',
997
                    $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...
998
                        $this->game->getClassType().'/user-register',
999
                        array(
1000
                            'id'            => $this->game->getIdentifier(),
1001
                            'socialnetwork' => $socialnetwork,
1002
1003
                        )
1004
                    )
1005
                );
1006
                $form->remove('password');
1007
                $form->remove('passwordVerify');
1008
1009
                $birthMonth = $infoMe->birthMonth;
1010
                if (strlen($birthMonth) <= 1) {
1011
                    $birthMonth = '0'.$birthMonth;
1012
                }
1013
                $birthDay = $infoMe->birthDay;
1014
                if (strlen($birthDay) <= 1) {
1015
                    $birthDay = '0'.$birthDay;
1016
                }
1017
1018
                $gender = $infoMe->gender;
1019
                if ($gender == 'female') {
1020
                    $title = 'Me';
1021
                } else {
1022
                    $title = 'M';
1023
                }
1024
1025
                $params = array(
1026
                    //'birth_year'  => $infoMe->birthYear,
1027
                    'title'      => $title,
1028
                    'dob'        => $birthDay.'/'.$birthMonth.'/'.$infoMe->birthYear,
1029
                    'firstname'  => $infoMe->firstName,
1030
                    'lastname'   => $infoMe->lastName,
1031
                    'email'      => $infoMe->email,
1032
                    'postalCode' => $infoMe->zip,
1033
                );
1034
                $socialCredentials = array(
1035
                    'socialNetwork' => strtolower($socialnetwork),
1036
                    'socialId'      => $infoMe->identifier,
1037
                );
1038
            }
1039
        }
1040
1041
        $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...
1042
            $this->game->getClassType().'/user-register',
1043
            array('id' => $this->game->getIdentifier())
1044
        ).($socialnetwork?'/'.$socialnetwork:'').($redirect?'?redirect='.$redirect:'');
1045
        $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...
1046
1047
        if ($prg instanceof Response) {
1048
            return $prg;
1049
        } elseif ($prg === false) {
1050
            $form->setData($params);
1051
            $viewModel = $this->buildView($this->game);
1052
            $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...
1053
                'registerForm'       => $form,
1054
                'enableRegistration' => $userOptions->getEnableRegistration(),
1055
                'redirect'           => $redirect,
1056
            ));
1057
            return $viewModel;
1058
        }
1059
1060
        $post = $prg;
1061
        if (isset($post['optin'])) {
1062
            $post['optin'] = 1;
1063
        }
1064
        if (isset($post['optinPartner'])) {
1065
            $post['optinPartner'] = 1;
1066
        }
1067
        $post = array_merge(
1068
            $post,
1069
            $socialCredentials
1070
        );
1071
1072
        if ($pguserOptions->getUseRecaptcha()) {
1073
            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...
1074
                $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...
1075
                $form->setData($post);
1076
                $viewModel = $this->buildView($this->game);
1077
                $viewModel->setVariables(array(
1078
                        'registerForm'       => $form,
1079
                        'enableRegistration' => $userOptions->getEnableRegistration(),
1080
                        'redirect'           => $redirect,
1081
                        'bah'                => 'coco',
1082
                        '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...
1083
                        '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...
1084
                    ));
1085
1086
                return $viewModel;
1087
            }
1088
        }
1089
1090
        if ($this->game->getOnInvitation()) {
1091
            $credential = trim(
1092
                $post[$this->getGameService()->getOptions()->getOnInvitationField()]
1093
            );
1094
            if (!$credential) {
1095
                $credential = $this->params()->fromQuery(
1096
                    $this->getGameService()->getOptions()->getOnInvitationField()
1097
                );
1098
            }
1099
            $found = $this->getGameService()->getInvitationMapper()->findOneBy(array('requestKey' => $credential));
1100
1101
            if (!$found || !empty($found->getUser())) {
1102
                $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...
1103
                    'Authentication failed. Please try again.'
1104
                );
1105
                $form->setData($post);
1106
                $viewModel = $this->buildView($this->game);
1107
                $viewModel->setVariables(array(
1108
                        'registerForm'       => $form,
1109
                        'enableRegistration' => $userOptions->getEnableRegistration(),
1110
                        'redirect'           => $redirect,
1111
                        '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...
1112
                        '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...
1113
                    ));
1114
1115
                return $viewModel;
1116
            }
1117
        }
1118
1119
        $user = $service->register($post, 'playgroundgame_register_form');
1120
1121
        if (!$user) {
1122
            $viewModel = $this->buildView($this->game);
1123
            $viewModel->setVariables(array(
1124
                    'registerForm'       => $form,
1125
                    'enableRegistration' => $userOptions->getEnableRegistration(),
1126
                    'redirect'           => $redirect,
1127
                    '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...
1128
                    '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...
1129
                ));
1130
1131
            return $viewModel;
1132
        }
1133
1134
        if ($this->game->getOnInvitation()) {
1135
            // user has been created, associate the code with the userId
1136
            $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...
1137
            $this->getGameService()->getInvitationMapper()->update($found);
1138
        }
1139
1140
        if ($service->getOptions()->getEmailVerification()) {
1141
            $vm = new ViewModel(array('userEmail' => $user->getEmail()));
1142
            $vm->setTemplate('playground-user/register/registermail');
1143
1144
            return $vm;
1145
        } elseif ($service->getOptions()->getLoginAfterRegistration()) {
1146
            $identityFields = $service->getOptions()->getAuthIdentityFields();
1147
            if (in_array('email', $identityFields)) {
1148
                $post['identity'] = $user->getEmail();
1149
            } elseif (in_array('username', $identityFields)) {
1150
                $post['identity'] = $user->getUsername();
1151
            }
1152
            $post['credential'] = isset($post['password'])?$post['password']:'';
1153
            $request->setPost(new Parameters($post));
1154
1155
            // clear adapters
1156
            $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...
1157
            $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...
1158
1159
            $logged = $this->forward()->dispatch('playgrounduser_user', array('action' => 'ajaxauthenticate'));
1160
1161
            if ($logged) {
1162
                return $this->redirect()->toUrl(
1163
                    $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...
1164
                        $this->game->getClassType().'/'.$this->game->nextStep('index'),
1165
                        array('id' => $this->game->getIdentifier())
1166
                    )
1167
                );
1168 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...
1169
                $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...
1170
                    'Authentication failed. Please try again.'
1171
                );
1172
                return $this->redirect()->toUrl(
1173
                    $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...
1174
                        $this->game->getClassType().'/login',
1175
                        array('id' => $this->game->getIdentifier())
1176
                    )
1177
                );
1178
            }
1179
        }
1180
1181
        $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...
1182
            $this->game->getClassType().'/login',
1183
            array('id' => $this->game->getIdentifier())
1184
        ).($socialnetwork?'/'.$socialnetwork:'').($redirect?'?redirect='.$redirect:'');
1185
1186
        return $this->redirect()->toUrl($redirect);
1187
    }
1188
1189 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...
1190
    {
1191
        $viewModel = $this->forward()->dispatch(
1192
            'playgrounduser_user',
1193
            array(
1194
                'controller' => 'playgrounduser_user',
1195
                'action' => 'check-token',
1196
                'id' => $this->game->getIdentifier(),
1197
                'token' => $this->params()->fromRoute('token', null)
1198
            )
1199
        );
1200
1201
        if ($viewModel && $viewModel instanceof \Zend\View\Model\ViewModel) {
1202
            $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...
1203
            $viewModel->setVariables(array('game' => $this->game));
1204
        }
1205
1206
        return $viewModel;
1207
    }
1208
1209
    public function userProfileAction()
1210
    {
1211
        $viewModel = $this->forward()->dispatch(
1212
            'playgrounduser_user',
1213
            array(
1214
                'controller' => 'playgrounduser_user',
1215
                'action'     => 'profile',
1216
                'id'         => $this->game->getIdentifier()
1217
            )
1218
        );
1219
1220
        if ($viewModel && $viewModel instanceof \Zend\View\Model\ViewModel) {
1221
            $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...
1222
            $viewModel->setVariables(array('game'      => $this->game));
1223
        }
1224
1225
        return $viewModel;
1226
    }
1227
1228
    public function userresetAction()
1229
    {
1230
        $viewModel = $this->forward()->dispatch(
1231
            'playgrounduser_forgot',
1232
            array(
1233
                'controller' => 'playgrounduser_forgot',
1234
                'action'     => 'reset',
1235
                'id'         => $this->game->getIdentifier(),
1236
                'userId'     => $this->params()->fromRoute('userId', null),
1237
                'token'      => $this->params()->fromRoute('token', null),
1238
            )
1239
        );
1240
1241
        if ($viewModel && $viewModel instanceof \Zend\View\Model\ViewModel) {
1242
            $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...
1243
            $viewModel->setVariables(array('game'      => $this->game));
1244
        }
1245
1246
        return $viewModel;
1247
    }
1248
1249
    public function ajaxforgotAction()
1250
    {
1251
        $view = $this->forward()->dispatch(
1252
            'playgrounduser_forgot',
1253
            array(
1254
                'controller' => 'playgrounduser_forgot',
1255
                'action'     => 'ajaxforgot',
1256
                'id'         => $this->game->getIdentifier()
1257
            )
1258
        );
1259
1260
        if ($view && $view instanceof \Zend\View\Model\ViewModel) {
1261
            $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...
1262
            $view->setVariables(array('game'           => $this->game));
1263
        }
1264
1265
        return $view;
1266
    }
1267
1268 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...
1269
    {
1270
        $viewModel = $this->forward()->dispatch(
1271
            'playgroundcms',
1272
            array(
1273
                'controller' => 'playgroundcms',
1274
                'action'     => 'index',
1275
                'id'         => $this->game->getIdentifier(),
1276
                'pid'        => $this->getEvent()->getRouteMatch()->getParam('pid')
1277
            )
1278
        );
1279
1280
        if ($viewModel && $viewModel instanceof \Zend\View\Model\ViewModel) {
1281
            $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...
1282
            $viewModel->setVariables(array('game'      => $this->game));
1283
        }
1284
1285
        return $viewModel;
1286
    }
1287
1288 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...
1289
    {
1290
        $viewModel = $this->forward()->dispatch(
1291
            'playgroundcms',
1292
            array(
1293
                'controller' => 'playgroundcms',
1294
                'action'     => 'list',
1295
                'id'         => $this->game->getIdentifier(),
1296
                'category'   => $this->game->getIdentifier()
1297
            )
1298
        );
1299
1300
        if ($viewModel && $viewModel instanceof \Zend\View\Model\ViewModel) {
1301
            $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...
1302
            $viewModel->setVariables(array('game'      => $this->game));
1303
        }
1304
1305
        return $viewModel;
1306
    }
1307
1308
    /**
1309
     * This method create the basic Game view
1310
     * @param \PlaygroundGame\Entity\Game $game
1311
     */
1312
    public function buildView($game)
1313
    {
1314
        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...
1315
            $viewModel = new JsonModel();
1316
            if ($game) {
1317
                $view = $this->addAdditionalView($game);
1318
                if ($view && $view instanceof \Zend\View\Model\ViewModel) {
1319
                    $viewModel->setVariables($view->getVariables());
1320
                }
1321
            }
1322
        } else {
1323
            $viewModel = new ViewModel();
1324
1325
            if ($game) {
1326
                $this->addMetaTitle($game);
1327
                $this->addMetaBitly();
1328
                $this->addGaEvent($game);
1329
1330
                $this->customizeGameDesign($game);
1331
1332
                $view = $this->addAdditionalView($game);
1333
                if ($view && $view instanceof \Zend\View\Model\ViewModel) {
1334
                    $viewModel->addChild($view, 'additional');
1335
                } elseif ($view && $view instanceof \Zend\Http\PhpEnvironment\Response) {
1336
                    return $view;
1337
                }
1338
1339
                $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...
1340
                    array(
1341
                        'action'        => $this->params('action'),
1342
                        'game'          => $game,
1343
                        '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...
1344
1345
                    )
1346
                );
1347
1348
                $viewModel->setVariables($this->getShareData($game));
1349
                $viewModel->setVariables(array('game' => $game, 'user' => $this->user));
1350
            }
1351
        }
1352
1353
        return $viewModel;
1354
    }
1355
1356
    /**
1357
     * @param \PlaygroundGame\Entity\Game $game
1358
     */
1359
    public function addAdditionalView($game)
1360
    {
1361
        $view = false;
1362
1363
        $actionName = $this->getEvent()->getRouteMatch()->getParam('action', 'not-found');
1364
        $stepsViews = json_decode($game->getStepsViews(), true);
1365
        if ($stepsViews && isset($stepsViews[$actionName])) {
1366
            $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...
1367
            $actionData   = $stepsViews[$actionName];
1368
            if (is_string($actionData)) {
1369
                $action     = $actionData;
1370
                $controller = $this->getEvent()->getRouteMatch()->getParam('controller', PlaygroundGame\Controller\Frontend\Game::class);
1371
                $view       = $this->forward()->dispatch(
1372
                    $controller,
1373
                    array(
1374
                        'action' => $action,
1375
                        'id'     => $game->getIdentifier()
1376
                    )
1377
                );
1378
            } elseif (is_array($actionData) && count($actionData) > 0) {
1379
                $action     = key($actionData);
1380
                $controller = $actionData[$action];
1381
                $view       = $this->forward()->dispatch(
1382
                    $controller,
1383
                    array(
1384
                        'action' => $action,
1385
                        'id'     => $game->getIdentifier()
1386
                    )
1387
                );
1388
            }
1389
            // suite au forward, le template de layout a changé, je dois le rétablir...
1390
            $this->layout()->setTemplate($beforeLayout);
1391
        }
1392
1393
        return $view;
1394
    }
1395
1396
    public function addMetaBitly()
1397
    {
1398
        $bitlyclient = $this->getOptions()->getBitlyUrl();
1399
        $bitlyuser   = $this->getOptions()->getBitlyUsername();
1400
        $bitlykey    = $this->getOptions()->getBitlyApiKey();
1401
1402
        $this->getViewHelper('HeadMeta')->setProperty('bt:client', $bitlyclient);
1403
        $this->getViewHelper('HeadMeta')->setProperty('bt:user', $bitlyuser);
1404
        $this->getViewHelper('HeadMeta')->setProperty('bt:key', $bitlykey);
1405
    }
1406
1407
    /**
1408
     * @param \PlaygroundGame\Entity\Game $game
1409
     */
1410
    public function addGaEvent($game)
1411
    {
1412
        // Google Analytics event
1413
        $ga    = $this->getServiceLocator()->get('google-analytics');
1414
        $event = new \PlaygroundCore\Analytics\Event($game->getClassType(), $this->params('action'));
1415
        $event->setLabel($game->getTitle());
1416
        $ga->addEvent($event);
1417
    }
1418
1419
    /**
1420
     * @param \PlaygroundGame\Entity\Game $game
1421
     */
1422
    public function addMetaTitle($game)
1423
    {
1424
        //$title = $this->translate($game->getTitle());
1425
        $title = $game->getTitle();
1426
        $this->getGameService()->getServiceManager()->get('ViewHelperManager')->get('HeadTitle')->set($title);
1427
        // Meta set in the layout
1428
        $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...
1429
            array(
1430
                'breadcrumbTitle' => $title,
1431
                'currentPage'     => array(
1432
                    'pageGames'      => 'games',
1433
                    'pageWinners'    => '',
1434
                ),
1435
                'headParams'       => array(
1436
                    'headTitle'       => $title,
1437
                    'headDescription' => $title,
1438
                ),
1439
                'bodyCss' => $game->getIdentifier()
1440
            )
1441
        );
1442
    }
1443
1444
    /**
1445
     * @param \PlaygroundGame\Entity\Game $game
1446
     */
1447
    public function customizeGameDesign($game)
1448
    {
1449
        // If this game has a specific layout...
1450
        if ($game->getLayout()) {
1451
            $layoutViewModel = $this->layout();
1452
            $layoutViewModel->setTemplate($game->getLayout());
1453
        }
1454
1455
        // If this game has a specific stylesheet...
1456
        if ($game->getStylesheet()) {
1457
            $this->getViewHelper('HeadLink')->appendStylesheet(
1458
                $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...
1459
            );
1460
        }
1461
    }
1462
1463
    /**
1464
     * @param \PlaygroundGame\Entity\Game $game
1465
     */
1466
    public function getShareData($game)
1467
    {
1468
        $fo      = $this->getServiceLocator()->get('facebook-opengraph');
1469
        $session = new Container('facebook');
1470
1471
        // I change the fbappid if i'm in fb
1472
        if ($session->offsetExists('signed_request')) {
1473
            $fo->setId($game->getFbAppId());
1474
        }
1475
1476
        // If I want to add a share block in my view
1477 View Code Duplication
        if ($game->getFbShareMessage()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
1478
            $fbShareMessage = $game->getFbShareMessage();
1479
        } else {
1480
            $fbShareMessage = str_replace(
1481
                '__placeholder__',
1482
                $game->getTitle(),
1483
                $this->getOptions()->getDefaultShareMessage()
1484
            );
1485
        }
1486
1487
        if ($game->getFbShareImage()) {
1488
            $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...
1489
                '',
1490
                array(),
1491
                array('force_canonical' => true),
1492
                false
1493
            ).$game->getFbShareImage();
1494
        } else {
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->getMainImage();
1501
        }
1502
1503
        $secretKey = strtoupper(substr(sha1(uniqid('pg_', true).'####'.time()), 0, 15));
1504
1505
        // Without bit.ly shortener
1506
        $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...
1507
            $game->getClassType(),
1508
            array('id'              => $game->getIdentifier()),
1509
            array('force_canonical' => true)
1510
        );
1511
        // With core shortener helper
1512
        $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...
1513
1514
        // FB Requests only work when it's a FB app
1515
        if ($game->getFbRequestMessage()) {
1516
            $fbRequestMessage = urlencode($game->getFbRequestMessage());
1517
        } else {
1518
            $fbRequestMessage = str_replace(
1519
                '__placeholder__',
1520
                $game->getTitle(),
1521
                $this->getOptions()->getDefaultShareMessage()
1522
            );
1523
        }
1524
1525 View Code Duplication
        if ($game->getTwShareMessage()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
1526
            $twShareMessage = $game->getTwShareMessage().$socialLinkUrl;
1527
        } else {
1528
            $twShareMessage = str_replace(
1529
                '__placeholder__',
1530
                $game->getTitle(),
1531
                $this->getOptions()->getDefaultShareMessage()
1532
            ).$socialLinkUrl;
1533
        }
1534
1535
        $ogTitle = new \PlaygroundCore\Opengraph\Tag('og:title', $fbShareMessage);
1536
        $ogImage = new \PlaygroundCore\Opengraph\Tag('og:image', $fbShareImage);
1537
1538
        $fo->addTag($ogTitle);
1539
        $fo->addTag($ogImage);
1540
1541
        $data = array(
1542
            'socialLinkUrl'    => $socialLinkUrl,
1543
            'secretKey'        => $secretKey,
1544
            'fbShareMessage'   => $fbShareMessage,
1545
            'fbShareImage'     => $fbShareImage,
1546
            'fbRequestMessage' => $fbRequestMessage,
1547
            'twShareMessage'   => $twShareMessage,
1548
        );
1549
1550
        return $data;
1551
    }
1552
1553
    /**
1554
     * return ajax response in json format
1555
     *
1556
     * @param array $data
1557
     * @return \Zend\View\Model\JsonModel
1558
     */
1559 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...
1560
    {
1561
        $model = new JsonModel(array(
1562
                'success' => true,
1563
                'data'    => $data,
1564
            ));
1565
        return $model->setTerminal(true);
1566
    }
1567
1568
    /**
1569
     * return ajax response in json format
1570
     *
1571
     * @param string $message
1572
     * @return \Zend\View\Model\JsonModel
1573
     */
1574 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...
1575
    {
1576
        $model = new JsonModel(array(
1577
                'success' => false,
1578
                'message' => $message,
1579
            ));
1580
        return $model->setTerminal(true);
1581
    }
1582
1583
    /**
1584
     * @param string $helperName
1585
     */
1586
    protected function getViewHelper($helperName)
1587
    {
1588
        return $this->getServiceLocator()->get('ViewHelperManager')->get($helperName);
1589
    }
1590
1591
    public function getGameService()
1592
    {
1593
        if (!$this->gameService) {
1594
            $this->gameService = $this->getServiceLocator()->get('playgroundgame_lottery_service');
1595
        }
1596
1597
        return $this->gameService;
1598
    }
1599
1600
    public function setGameService(GameService $gameService)
1601
    {
1602
        $this->gameService = $gameService;
1603
1604
        return $this;
1605
    }
1606
1607
    public function getPrizeService()
1608
    {
1609
        if (!$this->prizeService) {
1610
            $this->prizeService = $this->getServiceLocator()->get('playgroundgame_prize_service');
1611
        }
1612
1613
        return $this->prizeService;
1614
    }
1615
1616
    public function setPrizeService(PrizeService $prizeService)
1617
    {
1618
        $this->prizeService = $prizeService;
1619
1620
        return $this;
1621
    }
1622
1623
    public function getOptions()
1624
    {
1625
        if (!$this->options) {
1626
            $this->setOptions($this->getServiceLocator()->get('playgroundcore_module_options'));
1627
        }
1628
1629
        return $this->options;
1630
    }
1631
1632
    public function setOptions($options)
1633
    {
1634
        $this->options = $options;
1635
1636
        return $this;
1637
    }
1638
}
1639