Completed
Push — master ( 437856...5fb154 )
by greg
03:04
created

GameController::getServiceLocator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace PlaygroundGame\Controller\Frontend;
4
5
use Zend\Mvc\Controller\AbstractActionController;
6
use Zend\View\Model\ViewModel;
7
use Zend\Session\Container;
8
use PlaygroundGame\Service\GameService;
9
use PlaygroundGame\Service\Prize as PrizeService;
10
use Zend\View\Model\JsonModel;
11
use Zend\Http\PhpEnvironment\Response;
12
use Zend\Stdlib\Parameters;
13
use Zend\ServiceManager\ServiceLocatorInterface;
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
        'inviteToTeam',
39
        'prizes',
40
        'prize',
41
        'fangate',
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
        'inviteToTeam'
68
    );
69
70
    /**
71
     *
72
     * @var ServiceManager
73
     */
74
    protected $serviceLocator;
75
76
    public function __construct(ServiceLocatorInterface $locator)
77
    {
78
        $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...
79
    }
80
81
    public function getServiceLocator()
82
    {
83
        
84
        return $this->serviceLocator;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->serviceLocator; (PlaygroundGame\Controller\Frontend\ServiceManager) is incompatible with the return type of the parent method Zend\Mvc\Controller\Abst...ller::getServiceLocator of type Zend\ServiceManager\ServiceLocatorInterface.

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...
85
    }
86
87
    public function setEventManager(\Zend\EventManager\EventManagerInterface $events)
88
    {
89
        parent::setEventManager($events);
90
91
        $controller = $this;
92
        $events->attach('dispatch', function (\Zend\Mvc\MvcEvent $e) use ($controller) {
93
94
            $identifier = $e->getRouteMatch()->getParam('id');
95
            $controller->game = $controller->getGameService()->checkGame($identifier, false);
96
            if (!$controller->game &&
97
                in_array($controller->params('action'), $controller->withGame)
98
            ) {
99
                return $controller->notFoundAction();
100
            }
101
102
            if ($controller->game &&
103
                $controller->game->isClosed() &&
104
                in_array($controller->params('action'), $controller->withOnlineGame)
105
            ) {
106
                return $controller->notFoundAction();
107
            }
108
109
            if ($controller->game) {
110
                // this is possible to create a specific game design in /design/frontend/default/custom.
111
                //It will precede all others templates.
112
                $templatePathResolver = $controller->getServiceLocator()->get('Zend\View\Resolver\TemplatePathStack');
113
                $l = $templatePathResolver->getPaths();
114
                $templatePathResolver->addPath($l[0].'custom/'.$controller->game->getIdentifier());
115
            }
116
117
            $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...
118
            if ($controller->game &&
119
                !$controller->user &&
120
                !$controller->game->getAnonymousAllowed() &&
121
                in_array($controller->params('action'), $controller->withAnyUser)
122
            ) {
123
                $redirect = urlencode(
124
                    $controller->url()->fromRoute(
125
                        'frontend/'.$controller->game->getClassType() . '/' . $controller->params('action'),
126
                        array('id' => $controller->game->getIdentifier()),
127
                        array('force_canonical' => true)
128
                    )
129
                );
130
131
                $urlRegister = $controller->url()->fromRoute(
132
                    'frontend/zfcuser/register',
133
                    array(),
134
                    array('force_canonical' => true)
135
                ) . '?redirect='.$redirect;
136
137
                // code permettant d'identifier un custom game
138
                // ligne $config = $controller->getGameService()->getServiceManager()->get('config');
139
                // ligne $customUrl = str_replace('frontend.', '', $e->getRouteMatch()->getParam('area', ''));
140
                // ligne if ($config['custom_games'][$controller->game->getIdentifier()] &&
141
                // ligne    $controller->getRequest()->getUri()->getHost() === $customUrl
142
                // ligne ) {
143
                return $controller->redirect()->toUrl($urlRegister);
144
            }
145
146
            return;
147
        }, 100); // execute before executing action logic
148
    }
149
150
    /**
151
     * Action called if matched action does not exist
152
     * For this view not to be catched by Zend\Mvc\View\RouteNotFoundStrategy
153
     * it has to be rendered in the controller. Hence the code below.
154
     *
155
     * This action is injected as a catchall action for each custom_games definition
156
     * This way, when a custom_game is created, the 404 is it's responsability and the
157
     * view can be defined in design/frontend/default/custom/$slug/playground_game/$gametype/404.phtml
158
     *
159
     *
160
     * @return \Zend\Stdlib\ResponseInterface
161
     */
162
    public function notFoundAction()
163
    {
164
        $templatePathResolver = $this->getServiceLocator()->get('Zend\View\Resolver\TemplatePathStack');
165
166
        // I create a template path in which I can find a custom template
167
        $controller = explode('\\', get_class($this));
168
        $controllerPath = str_replace('Controller', '', end($controller));
169
        $controllerPath = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '-\\1', $controllerPath));
170
        $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.

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...
171
        if ($this->game) {
172
            $uri = str_replace($controllerPath.'/'.$this->game->getIdentifier().'/', '', $uri);
173
        }
174
        $uri = str_replace("/" . $this->getEvent()->getRouteMatch()->getParam('locale') . "/", "/", $uri);
175
        $template = 'playground-game/'.$controllerPath . '/custom' . $uri;
176
177
        if (false === $templatePathResolver->resolve($template)) {
178
            $viewRender     = $this->getServiceLocator()->get('ViewRenderer');
179
180
            $this->getEvent()->getRouteMatch()->setParam('action', 'not-found');
181
            $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...
182
183
            $res = 'error/404';
184
185
            $viewModel = $this->buildView($this->game);
186
            $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...
187
188
            $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...
189
            $this->response->setContent($viewRender->render($this->layout()));
190
191
            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 array.

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...
192
        }
193
194
        $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 197 which is incompatible with the return type documented by PlaygroundGame\Controlle...troller::notFoundAction of type Zend\Stdlib\ResponseInterface.
Loading history...
195
        $viewModel->setTemplate($template);
196
197
        return $viewModel;
198
    }
199
200
    /**
201
     * This action acts as a hub : Depending on the first step of the game, it will forward the action to this step
202
     */
203
    public function homeAction()
204
    {
205
        // This fix exists only for safari in FB on Windows : we need to redirect the user to the page
206
        // outside of iframe for the cookie to be accepted. PlaygroundCore redirects to the FB Iframed page when
207
        // it discovers that the user arrives for the first time on the game in FB.
208
        // When core redirects, it adds a 'redir_fb_page_id' var in the querystring
209
        // Here, we test if this var exist, and then send the user back to the game in FB.
210
        // Now the cookie will be accepted by Safari...
211
        $pageId = $this->params()->fromQuery('redir_fb_page_id');
212
        if (!empty($pageId)) {
213
            $appId = 'app_'.$this->game->getFbAppId();
214
            $url = '//www.facebook.com/pages/game/'.$pageId.'?sk='.$appId;
215
216
            return $this->redirect()->toUrl($url);
217
        }
218
219
        // If an entry has already been done during this session, I reset the anonymous_identifier cookie
220
        // so that another person can play the same game (if game conditions are fullfilled)
221
        $session = new Container('anonymous_identifier');
222
        if ($session->offsetExists('anonymous_identifier')) {
223
            $session->offsetUnset('anonymous_identifier');
224
        }
225
        
226
        return $this->forward()->dispatch(
227
            'playgroundgame_'.$this->game->getClassType(),
228
            array(
229
                'controller' => 'playgroundgame_'.$this->game->getClassType(),
230
                'action' => $this->game->firstStep(),
231
                'id' => $this->game->getIdentifier()
232
            )
233
        );
234
    }
235
236
    /**
237
     * Homepage of the game
238
     */
239
    public function indexAction()
240
    {
241
        $isSubscribed = false;
242
243
        $entry = $this->getGameService()->checkExistingEntry($this->game, $this->user);
244
        if ($entry) {
245
            $isSubscribed = true;
246
        }
247
248
        $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 253 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...
249
        $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...
250
            'isSubscribed' => $isSubscribed
251
        ));
252
253
        return $viewModel;
254
    }
255
256
    /**
257
      * leaderboardAction
258
      *
259
      * @return ViewModel $viewModel
260
      */
261
    public function leaderboardAction()
262
    {
263
        $filter = $this->getEvent()->getRouteMatch()->getParam('filter');
264
        $p = $this->getEvent()->getRouteMatch()->getParam('p');
265
266
        $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...
267
        $subViewModel = $this->forward()->dispatch(
268
            'playgroundreward',
269
            array('action' => 'leaderboard', 'filter' => $filter, 'p' => $p)
270
        );
271
        
272
        // suite au forward, le template de layout a changé, je dois le rétablir...
273
        $this->layout()->setTemplate($beforeLayout);
274
        $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...
275
            array(
276
                'action' => $this->params('action'),
277
                'game' => $this->game,
278
            )
279
        );
280
        
281
        $subViewModel->setVariables($this->getShareData($this->game));
282
        $subViewModel->setVariables(array('game' => $this->game, 'user' => $this->user));
283
284
        return $subViewModel;
285
    }
286
287
    /**
288
     * This action has been designed to be called by other controllers
289
     * It gives the ability to display an information form and persist it in the game entry
290
     *
291
     * @return \Zend\View\Model\ViewModel
292
     */
293
    public function registerAction()
294
    {
295
        $form = $this->getGameService()->createFormFromJson($this->game->getPlayerForm()->getForm(), 'playerForm');
296
297
        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.

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...
298
            // POST Request: Process form
299
            $data = array_merge_recursive(
300
                $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.

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...
301
                $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.

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...
302
            );
303
            
304
            $form->setData($data);
305
306
            if ($form->isValid()) {
307
                // steps of the game
308
                $steps = $this->game->getStepsArray();
309
                // sub steps of the game
310
                $viewSteps = $this->game->getStepsViewsArray();
311
312
                // register position
313
                $key = array_search($this->params('action'), $viewSteps);
314
                if (!$key) {
315
                    // register is not a substep of the game so it's a step
316
                    $key = array_search($this->params('action'), $steps);
317
                    $keyStep = true;
318
                } else {
319
                    // register was a substep, i search the index of its parent
320
                    $key = array_search($key, $steps);
321
                    $keyStep = false;
322
                }
323
324
                // play position
325
                $keyplay = array_search('play', $viewSteps);
326
327
                if (!$keyplay) {
328
                    // play is not a substep, so it's a step
329
                    $keyplay = array_search('play', $steps);
330
                    $keyplayStep = true;
331
                } else {
332
                    // play is a substep so I search the index of its parent
333
                    $keyplay = array_search($keyplay, $steps);
334
                    $keyplayStep = false;
335
                }
336
337
                // If register step before play, I don't have no entry yet. I have to create one
338
                // If register after play step, I search for the last entry created by play step.
339
340
                if ($key < $keyplay || ($keyStep && !$keyplayStep && $key <= $keyplay)) {
341
                    $entry = $this->getGameService()->play($this->game, $this->user);
342 View Code Duplication
                    if (!$entry) {
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...
343
                        // the user has already taken part of this game and the participation limit has been reached
344
                        $this->flashMessenger()->addMessage('Vous avez déjà participé');
345
                    
346
                        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...
347
                            $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...
348
                                $this->game->getClassType().'/result',
349
                                array(
350
                                    'id' => $this->game->getIdentifier(),
351
                                    
352
                                )
353
                            )
354
                        );
355
                    }
356
                } else {
357
                    // I'm looking for an entry without anonymousIdentifier (the active entry in fact).
358
                    $entry = $this->getGameService()->findLastEntry($this->game, $this->user);
359
                    if ($this->getGameService()->hasReachedPlayLimit($this->game, $this->user)) {
360
                        // the user has already taken part of this game and the participation limit has been reached
361
                        $this->flashMessenger()->addMessage('Vous avez déjà participé');
362
                    
363
                        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...
364
                            $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...
365
                                $this->game->getClassType().'/result',
366
                                array(
367
                                    'id' => $this->game->getIdentifier(),
368
                                    
369
                                )
370
                            )
371
                        );
372
                    }
373
                }
374
375
                $this->getGameService()->updateEntryPlayerForm($form->getData(), $this->game, $this->user, $entry);
376
377
                if (!empty($this->game->nextStep($this->params('action')))) {
378
                    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...
379
                        $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...
380
                            $this->game->getClassType() .'/' . $this->game->nextStep($this->params('action')),
381
                            array('id' => $this->game->getIdentifier()),
382
                            array('force_canonical' => true)
383
                        )
384
                    );
385
                }
386
            }
387
        }
388
389
        $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 394 which is incompatible with the return type documented by PlaygroundGame\Controlle...troller::registerAction of type Zend\View\Model\ViewModel.
Loading history...
390
        $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...
391
            'form' => $form
392
        ));
393
394
        return $viewModel;
395
    }
396
397
    /**
398
     * This action takes care of the terms of the game
399
     */
400
    public function termsAction()
401
    {
402
        $viewModel = $this->buildView($this->game);
403
404
        return $viewModel;
405
    }
406
407
    /**
408
     * This action takes care of the conditions of the game
409
     */
410
    public function conditionsAction()
411
    {
412
        $viewModel = $this->buildView($this->game);
413
414
        return $viewModel;
415
    }
416
417
    /**
418
     * This action takes care of bounce page of the game
419
     */
420
    public function bounceAction()
421
    {
422
        $availableGames = $this->getGameService()->getAvailableGames($this->user);
423
424
        $rssUrl = '';
425
        $config = $this->getGameService()->getServiceManager()->get('config');
426
        if (isset($config['rss']['url'])) {
427
            $rssUrl = $config['rss']['url'];
428
        }
429
430
        $viewModel = $this->buildView($this->game);
431
        $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...
432
            'rssUrl'         => $rssUrl,
433
            'user'           => $this->user,
434
            'availableGames' => $availableGames,
435
        ));
436
437
        return $viewModel;
438
    }
439
440
441
    /**
442
     * This action displays the Prizes page associated to the game
443
     */
444
    public function prizesAction()
445
    {
446
        if (count($this->game->getPrizes()) == 0) {
447
            return $this->notFoundAction();
448
        }
449
450
        $viewModel = $this->buildView($this->game);
451
452
        return $viewModel;
453
    }
454
455
    /**
456
     * This action displays a specific Prize page among those associated to the game
457
     */
458
    public function prizeAction()
459
    {
460
        $prizeIdentifier = $this->getEvent()->getRouteMatch()->getParam('prize');
461
        $prize = $this->getPrizeService()->getPrizeMapper()->findByIdentifier($prizeIdentifier);
462
        
463
        if (!$prize) {
464
            return $this->notFoundAction();
465
        }
466
467
        $viewModel = $this->buildView($this->game);
468
        $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...
469
470
        return $viewModel;
471
    }
472
473
    public function gameslistAction()
474
    {
475
        $layoutViewModel = $this->layout();
476
477
        $slider = new ViewModel();
478
        $slider->setTemplate('playground-game/common/top_promo');
479
480
        $sliderItems = $this->getGameService()->getActiveSliderGames();
481
482
        $slider->setVariables(array('sliderItems' => $sliderItems));
483
484
        $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...
485
486
        $games = $this->getGameService()->getActiveGames(false, '', 'endDate');
487
        if (is_array($games)) {
488
            $paginator = new \Zend\Paginator\Paginator(new \Zend\Paginator\Adapter\ArrayAdapter($games));
489
        } else {
490
            $paginator = $games;
491
        }
492
493
        $paginator->setItemCountPerPage(7);
494
        $paginator->setCurrentPageNumber($this->getEvent()->getRouteMatch()->getParam('p'));
495
496
        $bitlyclient = $this->getOptions()->getBitlyUrl();
497
        $bitlyuser = $this->getOptions()->getBitlyUsername();
498
        $bitlykey = $this->getOptions()->getBitlyApiKey();
499
500
        $this->getViewHelper('HeadMeta')->setProperty('bt:client', $bitlyclient);
501
        $this->getViewHelper('HeadMeta')->setProperty('bt:user', $bitlyuser);
502
        $this->getViewHelper('HeadMeta')->setProperty('bt:key', $bitlykey);
503
504
        $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...
505
            array(
506
            'sliderItems'   => $sliderItems,
507
            'currentPage' => array(
508
                'pageGames' => 'games',
509
                'pageWinners' => ''
510
            ),
511
            )
512
        );
513
514
        return new ViewModel(
515
            array(
516
                'games' => $paginator
517
            )
518
        );
519
    }
520
521
    public function fangateAction()
522
    {
523
        $viewModel = $this->buildView($this->game);
524
525
        return $viewModel;
526
    }
527
    
528
    public function shareAction()
529
    {
530
        $statusMail = null;
531
        $lastEntry = null;
532
    
533
        // steps of the game
534
        $steps = $this->game->getStepsArray();
535
        // sub steps of the game
536
        $viewSteps = $this->game->getStepsViewsArray();
537
538
        // share position
539
        $key = array_search($this->params('action'), $viewSteps);
540
        if (!$key) {
541
            // share is not a substep of the game so it's a step
542
            $key = array_search($this->params('action'), $steps);
543
        } else {
544
            // share was a substep, I search the index of its parent
545
            $key = array_search($key, $steps);
546
        }
547
548
        // play position
549
        $keyplay = array_search('play', $viewSteps);
550
551
        if (!$keyplay) {
552
            // play is not a substep, so it's a step
553
            $keyplay = array_search('play', $steps);
554
        } else {
555
            // play is a substep so I search the index of its parent
556
            $keyplay = array_search($keyplay, $steps);
557
        }
558
559
        if ($key && $keyplay && $keyplay <= $key) {
560
            // Has the user finished the game ?
561
            $lastEntry = $this->getGameService()->findLastInactiveEntry($this->game, $this->user);
562
    
563 View Code Duplication
            if ($lastEntry === null) {
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...
564
                return $this->redirect()->toUrl(
565
                    $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...
566
                        $this->game->getClassType(),
567
                        array('id' => $this->game->getIdentifier())
568
                    )
569
                );
570
            }
571
        }
572
    
573
        $form = $this->getServiceLocator()->get('playgroundgame_sharemail_form');
574
        $form->setAttribute('method', 'post');
575
576
        // buildView must be before sendMail because it adds the game template path to the templateStack
577
        $viewModel = $this->buildView($this->game);
578
    
579
        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.

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...
580
            $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.

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...
581
            $form->setData($data);
582 View Code Duplication
            if ($form->isValid()) {
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...
583
                $result = $this->getGameService()->sendShareMail($data, $this->game, $this->user, $lastEntry);
584
                if ($result) {
585
                    $statusMail = true;
586
                }
587
            }
588
        }
589
590
        $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...
591
            'statusMail'       => $statusMail,
592
            'form'             => $form,
593
        ));
594
    
595
        return $viewModel;
596
    }
597
    
598
    public function inviteToTeamAction()
599
    {
600
        $statusMail = null;
601
        $message = '';
602
    
603
        $form = $this->getServiceLocator()->get('playgroundgame_sharemail_form');
604
        $form->setAttribute('method', 'post');
605
606
        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.

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...
607
            $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.

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...
608
            $form->setData($data);
609
            if ($form->isValid()) {
610
                $result = $this->getGameService()->inviteToTeam($data, $this->game, $this->user);
611
                if ($result['result']) {
612
                    $statusMail = true;
613
                } else {
614
                    $statusMail = false;
615
                    $message = $result['message'];
616
                }
617
            }
618
        }
619
620
        $viewModel = $this->buildView($this->game);
621
        $viewModel->setVariables(array(
0 ignored issues
show
Bug introduced by
The method setVariables does only exist in Zend\View\Model\ViewModel, but not in Zend\Http\PhpEnvironment\Response.

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

Let’s take a look at an example:

class A
{
    public function foo() { }
}

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

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

Available Fixes

  1. Add an additional type-check:

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

    function someFunction(B $x) { /** ... */ }
    
Loading history...
622
            'message' => $message,
623
            'statusMail' => $statusMail,
624
            'form' => $form,
625
        ));
626
    
627
        return $viewModel;
628
    }
629
630 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...
631
    {
632
        $viewModel = new JsonModel();
633
        $viewModel->setTerminal(true);
634
        $fbId = $this->params()->fromQuery('fbId');
635
        if (!$this->game) {
636
            return $this->errorJson();
637
        }
638
        $entry = $this->getGameService()->checkExistingEntry($this->game, $this->user);
639
        if (! $entry) {
640
            return $this->errorJson();
641
        }
642
        if (!$fbId) {
643
            return $this->errorJson();
644
        }
645
    
646
        $this->getGameService()->postFbWall($fbId, $this->game, $this->user, $entry);
647
    
648
        return $this->successJson();
649
    }
650
    
651
    public function fbrequestAction()
652
    {
653
        $viewModel = new ViewModel();
654
        $viewModel->setTerminal(true);
655
        $fbId = $this->params()->fromQuery('fbId');
656
        $to = $this->params()->fromQuery('to');
657
    
658
        if (!$this->game) {
659
            return $this->errorJson();
660
        }
661
        $entry = $this->getGameService()->checkExistingEntry($this->game, $this->user);
662
        if (! $entry) {
663
            return $this->errorJson();
664
        }
665
        if (!$fbId) {
666
            return $this->errorJson();
667
        }
668
    
669
        $this->getGameService()->postFbRequest($fbId, $this->game, $this->user, $entry, $to);
670
    
671
        return $this->successJson();
672
    }
673
    
674
    public function tweetAction()
675
    {
676
        $tweetId = $this->params()->fromQuery('tweetId');
677
    
678
        if (!$this->game) {
679
            return $this->errorJson();
680
        }
681
        $entry = $this->getGameService()->checkExistingEntry($this->game, $this->user);
682
        if (! $entry) {
683
            return $this->errorJson();
684
        }
685
        if (!$tweetId) {
686
            return $this->errorJson();
687
        }
688
    
689
        $this->getGameService()->postTwitter($tweetId, $this->game, $this->user, $entry);
690
    
691
        return $this->successJson();
692
    }
693
    
694 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...
695
    {
696
        $viewModel = new ViewModel();
697
        $viewModel->setTerminal(true);
698
        $googleId = $this->params()->fromQuery('googleId');
699
700
        if (!$this->game) {
701
            return $this->errorJson();
702
        }
703
        $entry = $this->getGameService()->checkExistingEntry($this->game, $this->user);
704
        if (! $entry) {
705
            return $this->errorJson();
706
        }
707
        if (!$googleId) {
708
            return $this->errorJson();
709
        }
710
    
711
        $this->getGameService()->postGoogle($googleId, $this->game, $this->user, $entry);
712
    
713
        return $this->successJson();
714
    }
715
716
    public function optinAction()
717
    {
718
        $userService = $this->getServiceLocator()->get('zfcuser_user_service');
719
720
        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.

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...
721
            $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...
722
            $data['optinPartner'] = ($this->params()->fromPost('optinPartner'))? 1:0;
723
724
            $userService->updateNewsletter($data);
725
        }
726
727
        return $this->redirect()->toUrl(
728
            $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...
729
                $this->game->getClassType(),
730
                array('id' => $this->game->getIdentifier())
731
            )
732
        );
733
    }
734
    
735
    public function loginAction()
736
    {
737
        $request = $this->getRequest();
738
        $form = $this->getServiceLocator()->get('zfcuser_login_form');
739
    
740
        if ($request->isPost()) {
741
            $form->setData($request->getPost());
742
            
743
            if (!$form->isValid()) {
744
                $this->flashMessenger()->addMessage(
745
                    'Authentication failed. Please try again.'
746
                );
747
748
                $viewModel = $this->buildView($this->game);
749
                $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...
750
                    'form' => $form,
751
                    'flashMessages' => $this->flashMessenger()->getMessages(),
752
                ));
753
                
754
                return $viewModel;
755
            }
756
            
757
            // clear adapters
758
            $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...
759
            $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...
760
761
            $logged = $this->forward()->dispatch('playgrounduser_user', array('action' => 'ajaxauthenticate'));
762
763
            if (!$logged) {
764
                $this->flashMessenger()->addMessage(
765
                    'Authentication failed. Please try again.'
766
                );
767
                
768
                return $this->redirect()->toUrl(
769
                    $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...
770
                        $this->game->getClassType() . '/login',
771
                        array('id' => $this->game->getIdentifier())
772
                    )
773
                );
774
            } else {
775
                return $this->redirect()->toUrl(
776
                    $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...
777
                        $this->game->getClassType() . '/index',
778
                        array('id' => $this->game->getIdentifier())
779
                    )
780
                );
781
            }
782
        }
783
        
784
        $form->setAttribute(
785
            'action',
786
            $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...
787
                $this->game->getClassType().'/login',
788
                array('id' => $this->game->getIdentifier())
789
            )
790
        );
791
        $viewModel = $this->buildView($this->game);
792
        $viewModel->setVariables(array(
793
            'form' => $form,
794
            'flashMessages' => $this->flashMessenger()->getMessages(),
795
        ));
796
        return $viewModel;
797
    }
798
799 View Code Duplication
    public function logoutAction()
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...
800
    {
801
        $viewModel = $this->forward()->dispatch(
802
            'playgrounduser_user',
803
            array(
804
                'controller' => 'playgrounduser_user',
805
                'action' => 'logout',
806
                'id' => $this->game->getIdentifier()
807
            )
808
        );
809
810
        if ($viewModel && $viewModel instanceof \Zend\View\Model\ViewModel) {
811
            $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...
812
            $viewModel->setVariables(array('game' => $this->game));
813
        }
814
815
        return $viewModel;
816
    }
817
818
    public function userregisterAction()
819
    {
820
        $userOptions = $this->getServiceLocator()->get('zfcuser_module_options');
821
822
        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...
823
            return $this->redirect()->toUrl(
824
                $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...
825
                    $this->game->getClassType().'/'.$this->game->nextStep('index'),
826
                    array('id' => $this->game->getIdentifier())
827
                )
828
            );
829
        }
830
        $request = $this->getRequest();
831
        $service = $this->getServiceLocator()->get('zfcuser_user_service');
832
        $form = $this->getServiceLocator()->get('playgroundgame_register_form');
833
        $socialnetwork = $this->params()->fromRoute('socialnetwork', false);
834
        $form->setAttribute(
835
            'action',
836
            $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...
837
                $this->game->getClassType().'/user-register',
838
                array('id' => $this->game->getIdentifier())
839
            )
840
        );
841
        $params = array();
842
        $socialCredentials = array();
843
844
        if ($userOptions->getUseRedirectParameterIfPresent() && $request->getQuery()->get('redirect')) {
845
            $redirect = $request->getQuery()->get('redirect');
846
        } else {
847
            $redirect = false;
848
        }
849
850
        if ($socialnetwork) {
851
            $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...
852
853
            if (!empty($infoMe)) {
854
                $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...
855
                    $infoMe->identifier,
856
                    $socialnetwork
857
                );
858
859
                if ($user || $service->getOptions()->getCreateUserAutoSocial() === true) {
860
                    //on le dirige vers l'action d'authentification
861
                    if (! $redirect && $userOptions->getLoginRedirectRoute() != '') {
862
                        $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...
863
                            $this->game->getClassType().'/login',
864
                            array('id' => $this->game->getIdentifier())
865
                        );
866
                    }
867
                    $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...
868
                        $this->game->getClassType().'/login',
869
                        array('id' => $this->game->getIdentifier())
870
                    ) .'/' . $socialnetwork . ($redirect ? '?redirect=' . $redirect : '');
871
872
                    return $this->redirect()->toUrl($redir);
873
                }
874
875
                // Je retire la saisie du login/mdp
876
                $form->setAttribute(
877
                    'action',
878
                    $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...
879
                        $this->game->getClassType().'/user-register',
880
                        array(
881
                            'id' => $this->game->getIdentifier(),
882
                            'socialnetwork' => $socialnetwork,
883
                            
884
                        )
885
                    )
886
                );
887
                $form->remove('password');
888
                $form->remove('passwordVerify');
889
890
                $birthMonth = $infoMe->birthMonth;
891
                if (strlen($birthMonth) <= 1) {
892
                    $birthMonth = '0'.$birthMonth;
893
                }
894
                $birthDay = $infoMe->birthDay;
895
                if (strlen($birthDay) <= 1) {
896
                    $birthDay = '0'.$birthDay;
897
                }
898
899
                $gender = $infoMe->gender;
900
                if ($gender == 'female') {
901
                    $title = 'Me';
902
                } else {
903
                    $title = 'M';
904
                }
905
906
                $params = array(
907
                    //'birth_year'  => $infoMe->birthYear,
908
                    'title'      => $title,
909
                    'dob'      => $birthDay.'/'.$birthMonth.'/'.$infoMe->birthYear,
910
                    'firstname'   => $infoMe->firstName,
911
                    'lastname'    => $infoMe->lastName,
912
                    'email'       => $infoMe->email,
913
                    'postalCode' => $infoMe->zip,
914
                );
915
                $socialCredentials = array(
916
                    'socialNetwork' => strtolower($socialnetwork),
917
                    'socialId'      => $infoMe->identifier,
918
                );
919
            }
920
        }
921
922
        $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...
923
            $this->game->getClassType().'/user-register',
924
            array('id' => $this->game->getIdentifier())
925
        ) .($socialnetwork ? '/' . $socialnetwork : ''). ($redirect ? '?redirect=' . $redirect : '');
926
        $prg = $this->prg($redirectUrl, true);
927
928
        if ($prg instanceof Response) {
929
            return $prg;
930
        } elseif ($prg === false) {
931
            $form->setData($params);
932
            $viewModel = $this->buildView($this->game);
933
            $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...
934
                'registerForm' => $form,
935
                'enableRegistration' => $userOptions->getEnableRegistration(),
936
                'redirect' => $redirect,
937
            ));
938
            return $viewModel;
939
        }
940
941
        $post = $prg;
942
        $post = array_merge(
943
            $post,
944
            $socialCredentials
945
        );
946
947
        if ($this->game->getOnInvitation()) {
948
            $credential = trim(
949
                $post[$this->getGameService()->getOptions()->getOnInvitationField()]
950
            );
951
            if (!$credential) {
952
                $credential = $this->params()->fromQuery(
953
                    $this->getGameService()->getOptions()->getOnInvitationField()
954
                );
955
            }
956
            $found = $this->getGameService()->getInvitationMapper()->findOneBy(array('requestKey'=>$credential));
957
958
            if (!$found || !empty($found->getUser())) {
959
                $this->flashMessenger()->addMessage(
960
                    'Authentication failed. Please try again.'
961
                );
962
                $form->setData($post);
963
                $viewModel = $this->buildView($this->game);
964
                $viewModel->setVariables(array(
965
                    'registerForm' => $form,
966
                    'enableRegistration' => $userOptions->getEnableRegistration(),
967
                    'redirect' => $redirect,
968
                    'flashMessages'    => $this->flashMessenger()->getMessages(),
969
                    'flashErrors'      => $this->flashMessenger()->getErrorMessages(),
970
                ));
971
972
                return $viewModel;
973
            }
974
        }
975
976
        $user = $service->register($post, 'playgroundgame_register_form');
977
978
        if (! $user) {
979
            $viewModel = $this->buildView($this->game);
980
            $viewModel->setVariables(array(
981
                'registerForm' => $form,
982
                'enableRegistration' => $userOptions->getEnableRegistration(),
983
                'redirect' => $redirect,
984
                'flashMessages'    => $this->flashMessenger()->getMessages(),
985
                'flashErrors'      => $this->flashMessenger()->getErrorMessages(),
986
            ));
987
            
988
            return $viewModel;
989
        }
990
991
        if ($this->game->getOnInvitation()) {
992
            // user has been created, associate the code with the userId
993
            $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...
994
            $this->getGameService()->getInvitationMapper()->update($found);
995
        }
996
997
        if ($service->getOptions()->getEmailVerification()) {
998
            $vm = new ViewModel(array('userEmail' => $user->getEmail()));
999
            $vm->setTemplate('playground-user/register/registermail');
1000
1001
            return $vm;
1002
        } elseif ($service->getOptions()->getLoginAfterRegistration()) {
1003
            $identityFields = $service->getOptions()->getAuthIdentityFields();
1004
            if (in_array('email', $identityFields)) {
1005
                $post['identity'] = $user->getEmail();
1006
            } elseif (in_array('username', $identityFields)) {
1007
                $post['identity'] = $user->getUsername();
1008
            }
1009
            $post['credential'] = isset($post['password'])?$post['password']:'';
1010
            $request->setPost(new Parameters($post));
1011
1012
            // clear adapters
1013
            $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...
1014
            $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...
1015
1016
            $logged = $this->forward()->dispatch('playgrounduser_user', array('action' => 'ajaxauthenticate'));
1017
1018
            if ($logged) {
1019
                return $this->redirect()->toUrl(
1020
                    $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...
1021
                        $this->game->getClassType(),
1022
                        array('id' => $this->game->getIdentifier())
1023
                    )
1024
                );
1025
            } else {
1026
                $this->flashMessenger()->setNamespace('zfcuser-login-form')->addMessage(
1027
                    'Authentication failed. Please try again.'
1028
                );
1029
                return $this->redirect()->toUrl(
1030
                    $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...
1031
                        $this->game->getClassType() . '/login',
1032
                        array('id' => $this->game->getIdentifier())
1033
                    )
1034
                );
1035
            }
1036
        }
1037
1038
        $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...
1039
            $this->game->getClassType().'/login',
1040
            array('id' => $this->game->getIdentifier())
1041
        ) . ($socialnetwork ? '/' . $socialnetwork : ''). ($redirect ? '?redirect=' . $redirect : '');
1042
1043
        return $this->redirect()->toUrl($redirect);
1044
    }
1045
1046 View Code Duplication
    public function userProfileAction()
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...
1047
    {
1048
        $viewModel = $this->forward()->dispatch(
1049
            'playgrounduser_user',
1050
            array(
1051
                'controller' => 'playgrounduser_user',
1052
                'action' => 'profile',
1053
                'id' => $this->game->getIdentifier()
1054
            )
1055
        );
1056
1057
        if ($viewModel && $viewModel instanceof \Zend\View\Model\ViewModel) {
1058
            $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...
1059
            $viewModel->setVariables(array('game' => $this->game));
1060
        }
1061
1062
        return $viewModel;
1063
    }
1064
1065
    public function userresetAction()
1066
    {
1067
        $viewModel = $this->forward()->dispatch(
1068
            'playgrounduser_forgot',
1069
            array(
1070
                'controller' => 'playgrounduser_forgot',
1071
                'action' => 'reset',
1072
                'id' => $this->game->getIdentifier(),
1073
                'userId' => $this->params()->fromRoute('userId', null),
1074
                'token' => $this->params()->fromRoute('token', null),
1075
            )
1076
        );
1077
1078
        if ($viewModel && $viewModel instanceof \Zend\View\Model\ViewModel) {
1079
            $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...
1080
            $viewModel->setVariables(array('game' => $this->game));
1081
        }
1082
1083
        return $viewModel;
1084
    }
1085
1086 View Code Duplication
    public function ajaxforgotAction()
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...
1087
    {
1088
        $view = $this->forward()->dispatch(
1089
            'playgrounduser_forgot',
1090
            array(
1091
                'controller' => 'playgrounduser_forgot',
1092
                'action' => 'ajaxforgot',
1093
                'id' => $this->game->getIdentifier()
1094
            )
1095
        );
1096
1097
        if ($view && $view instanceof \Zend\View\Model\ViewModel) {
1098
            $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...
1099
            $view->setVariables(array('game' => $this->game));
1100
        }
1101
1102
        return $view;
1103
    }
1104
1105 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...
1106
    {
1107
        $viewModel = $this->forward()->dispatch(
1108
            'playgroundcms',
1109
            array(
1110
                'controller' => 'playgroundcms',
1111
                'action' => 'index',
1112
                'id' => $this->game->getIdentifier(),
1113
                'pid' => $this->getEvent()->getRouteMatch()->getParam('pid')
1114
            )
1115
        );
1116
1117
        if ($viewModel && $viewModel instanceof \Zend\View\Model\ViewModel) {
1118
            $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...
1119
            $viewModel->setVariables(array('game' => $this->game));
1120
        }
1121
1122
        return $viewModel;
1123
    }
1124
1125 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...
1126
    {
1127
        $viewModel = $this->forward()->dispatch(
1128
            'playgroundcms',
1129
            array(
1130
                'controller' => 'playgroundcms',
1131
                'action' => 'list',
1132
                'id' => $this->game->getIdentifier(),
1133
                'category' => $this->game->getIdentifier()
1134
            )
1135
        );
1136
1137
        if ($viewModel && $viewModel instanceof \Zend\View\Model\ViewModel) {
1138
            $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...
1139
            $viewModel->setVariables(array('game' => $this->game));
1140
        }
1141
1142
        return $viewModel;
1143
    }
1144
1145
    /**
1146
     *
1147
     * @param \PlaygroundGame\Entity\Game $game
1148
     * @param \PlaygroundUser\Entity\User $user
1149
     */
1150
    public function checkFbRegistration($user, $game)
1151
    {
1152
        $redirect = false;
1153
        $session = new Container('facebook');
1154
        if ($session->offsetExists('signed_request')) {
1155
            if (!$user) {
1156
                // Get Playground user from Facebook info
1157
                $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...
1158
                $view = $this->forward()->dispatch(
1159
                    'playgrounduser_user',
1160
                    array(
1161
                        'controller' => 'playgrounduser_user',
1162
                        'action' => 'registerFacebookUser',
1163
                        'provider' => 'facebook'
1164
                    )
1165
                );
1166
1167
                $this->layout()->setTemplate($beforeLayout);
1168
                $user = $view->user;
1169
1170
                // If the user can not be created/retrieved from Facebook info, redirect to login/register form
1171
                if (!$user) {
1172
                    $redirectUrl = urlencode(
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
                            $game->getClassType() .'/play',
1175
                            array('id' => $game->getIdentifier()),
1176
                            array('force_canonical' => true)
1177
                        )
1178
                    );
1179
                    $redirect =  $this->redirect()->toUrl(
1180
                        $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...
1181
                            'zfcuser/register'
1182
                        ) . '?redirect='.$redirectUrl
1183
                    );
1184
                }
1185
            }
1186
1187
            if ($game->getFbFan()) {
1188
                if ($this->getGameService()->checkIsFan($game) === false) {
1189
                    $redirect =  $this->redirect()->toRoute(
1190
                        $game->getClassType().'/fangate',
1191
                        array('id' => $game->getIdentifier())
1192
                    );
1193
                }
1194
            }
1195
        }
1196
1197
        return $redirect;
1198
    }
1199
1200
    /**
1201
     * This method create the basic Game view
1202
     * @param \PlaygroundGame\Entity\Game $game
1203
     */
1204
    public function buildView($game)
1205
    {
1206
        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.

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...
1207
            $viewModel = new JsonModel();
1208
            if ($game) {
1209
                $view = $this->addAdditionalView($game);
1210
                if ($view && $view instanceof \Zend\View\Model\ViewModel) {
1211
                    $viewModel->setVariables($view->getVariables());
1212
                }
1213
            }
1214
        } else {
1215
            $viewModel = new ViewModel();
1216
1217
            if ($game) {
1218
                $this->addMetaTitle($game);
1219
                $this->addMetaBitly();
1220
                $this->addGaEvent($game);
1221
1222
                $this->customizeGameDesign($game);
1223
                
1224
                $view = $this->addAdditionalView($game);
1225
                if ($view && $view instanceof \Zend\View\Model\ViewModel) {
1226
                    $viewModel->addChild($view, 'additional');
1227
                } elseif ($view && $view instanceof \Zend\Http\PhpEnvironment\Response) {
1228
                    return $view;
1229
                }
1230
1231
                $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...
1232
                    array(
1233
                        'action' => $this->params('action'),
1234
                        'game' => $game,
1235
                        'flashMessages'    => $this->flashMessenger()->getMessages(),
1236
                        
1237
                    )
1238
                );
1239
1240
                $viewModel->setVariables($this->getShareData($game));
1241
                $viewModel->setVariables(array('game' => $game, 'user' => $this->user));
1242
            }
1243
        }
1244
1245
        return $viewModel;
1246
    }
1247
1248
    /**
1249
     * @param \PlaygroundGame\Entity\Game $game
1250
     */
1251
    public function addAdditionalView($game)
1252
    {
1253
        $view = false;
1254
1255
        $actionName = $this->getEvent()->getRouteMatch()->getParam('action', 'not-found');
1256
        $stepsViews = json_decode($game->getStepsViews(), true);
1257
        if ($stepsViews && isset($stepsViews[$actionName])) {
1258
            $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...
1259
            $actionData = $stepsViews[$actionName];
1260
            if (is_string($actionData)) {
1261
                $action = $actionData;
1262
                $controller = $this->getEvent()->getRouteMatch()->getParam('controller', 'playgroundgame_game');
1263
                $view = $this->forward()->dispatch(
1264
                    $controller,
1265
                    array(
1266
                        'action' => $action,
1267
                        'id' => $game->getIdentifier()
1268
                    )
1269
                );
1270
            } elseif (is_array($actionData) && count($actionData)>0) {
1271
                $action = key($actionData);
1272
                $controller = $actionData[$action];
1273
                $view = $this->forward()->dispatch(
1274
                    $controller,
1275
                    array(
1276
                        'action' => $action,
1277
                        'id' => $game->getIdentifier()
1278
                    )
1279
                );
1280
            }
1281
            // suite au forward, le template de layout a changé, je dois le rétablir...
1282
            $this->layout()->setTemplate($beforeLayout);
1283
        }
1284
1285
        return $view;
1286
    }
1287
1288
    public function addMetaBitly()
1289
    {
1290
        $bitlyclient = $this->getOptions()->getBitlyUrl();
1291
        $bitlyuser = $this->getOptions()->getBitlyUsername();
1292
        $bitlykey = $this->getOptions()->getBitlyApiKey();
1293
1294
        $this->getViewHelper('HeadMeta')->setProperty('bt:client', $bitlyclient);
1295
        $this->getViewHelper('HeadMeta')->setProperty('bt:user', $bitlyuser);
1296
        $this->getViewHelper('HeadMeta')->setProperty('bt:key', $bitlykey);
1297
    }
1298
1299
    /**
1300
     * @param \PlaygroundGame\Entity\Game $game
1301
     */
1302
    public function addGaEvent($game)
1303
    {
1304
        // Google Analytics event
1305
        $ga = $this->getServiceLocator()->get('google-analytics');
1306
        $event = new \PlaygroundCore\Analytics\Event($game->getClassType(), $this->params('action'));
1307
        $event->setLabel($game->getTitle());
1308
        $ga->addEvent($event);
1309
    }
1310
1311
    /**
1312
     * @param \PlaygroundGame\Entity\Game $game
1313
     */
1314
    public function addMetaTitle($game)
1315
    {
1316
        $title = $this->translate($game->getTitle());
0 ignored issues
show
Documentation Bug introduced by
The method translate 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...
1317
        $this->getGameService()->getServiceManager()->get('ViewHelperManager')->get('HeadTitle')->set($title);
1318
        // Meta set in the layout
1319
        $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...
1320
            array(
1321
                'breadcrumbTitle' => $title,
1322
                'currentPage' => array(
1323
                    'pageGames' => 'games',
1324
                    'pageWinners' => ''
1325
                ),
1326
                'headParams' => array(
1327
                    'headTitle' => $title,
1328
                    'headDescription' => $title,
1329
                ),
1330
                'bodyCss' => $game->getIdentifier()
1331
            )
1332
        );
1333
    }
1334
1335
    /**
1336
     * @param \PlaygroundGame\Entity\Game $game
1337
     */
1338
    public function customizeGameDesign($game)
1339
    {
1340
        // If this game has a specific layout...
1341
        if ($game->getLayout()) {
1342
            $layoutViewModel = $this->layout();
1343
            $layoutViewModel->setTemplate($game->getLayout());
1344
        }
1345
1346
        // If this game has a specific stylesheet...
1347
        if ($game->getStylesheet()) {
1348
            $this->getViewHelper('HeadLink')->appendStylesheet(
1349
                $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.

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...
1350
            );
1351
        }
1352
    }
1353
1354
    /**
1355
     * @param \PlaygroundGame\Entity\Game $game
1356
     */
1357
    public function getShareData($game)
1358
    {
1359
        $fo = $this->getServiceLocator()->get('facebook-opengraph');
1360
        $session = new Container('facebook');
1361
1362
        // I change the fbappid if i'm in fb
1363
        if ($session->offsetExists('signed_request')) {
1364
            $fo->setId($game->getFbAppId());
1365
        }
1366
1367
        // If I want to add a share block in my view
1368 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...
1369
            $fbShareMessage = $game->getFbShareMessage();
1370
        } else {
1371
            $fbShareMessage = str_replace(
1372
                '__placeholder__',
1373
                $game->getTitle(),
1374
                $this->getOptions()->getDefaultShareMessage()
1375
            );
1376
        }
1377
1378
        if ($game->getFbShareImage()) {
1379
            $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...
1380
                '',
1381
                array(),
1382
                array('force_canonical' => true),
1383
                false
1384
            ) . $game->getFbShareImage();
1385
        } else {
1386
            $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...
1387
                '',
1388
                array(),
1389
                array('force_canonical' => true),
1390
                false
1391
            ) . $game->getMainImage();
1392
        }
1393
1394
        $secretKey = strtoupper(substr(sha1(uniqid('pg_', true).'####'.time()), 0, 15));
1395
1396
        // Without bit.ly shortener
1397
        $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...
1398
            $game->getClassType(),
1399
            array('id' => $game->getIdentifier()),
1400
            array('force_canonical' => true)
1401
        );
1402
        // With core shortener helper
1403
        $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...
1404
1405
        // FB Requests only work when it's a FB app
1406
        if ($game->getFbRequestMessage()) {
1407
            $fbRequestMessage = urlencode($game->getFbRequestMessage());
1408
        } else {
1409
            $fbRequestMessage = str_replace(
1410
                '__placeholder__',
1411
                $game->getTitle(),
1412
                $this->getOptions()->getDefaultShareMessage()
1413
            );
1414
        }
1415
1416 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...
1417
            $twShareMessage = $game->getTwShareMessage() . $socialLinkUrl;
1418
        } else {
1419
            $twShareMessage = str_replace(
1420
                '__placeholder__',
1421
                $game->getTitle(),
1422
                $this->getOptions()->getDefaultShareMessage()
1423
            ) . $socialLinkUrl;
1424
        }
1425
1426
        $ogTitle = new \PlaygroundCore\Opengraph\Tag('og:title', $fbShareMessage);
1427
        $ogImage = new \PlaygroundCore\Opengraph\Tag('og:image', $fbShareImage);
1428
        
1429
        $fo->addTag($ogTitle);
1430
        $fo->addTag($ogImage);
1431
        
1432
        $data = array(
1433
            'socialLinkUrl'       => $socialLinkUrl,
1434
            'secretKey'           => $secretKey,
1435
            'fbShareMessage'      => $fbShareMessage,
1436
            'fbShareImage'        => $fbShareImage,
1437
            'fbRequestMessage'    => $fbRequestMessage,
1438
            'twShareMessage'      => $twShareMessage,
1439
        );
1440
1441
        return $data;
1442
    }
1443
    
1444
    /**
1445
     * return ajax response in json format
1446
     *
1447
     * @param array $data
1448
     * @return \Zend\View\Model\JsonModel
1449
     */
1450 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...
1451
    {
1452
        $model = new JsonModel(array(
1453
            'success' => true,
1454
            'data' => $data
1455
        ));
1456
        return $model->setTerminal(true);
1457
    }
1458
    
1459
    /**
1460
     * return ajax response in json format
1461
     *
1462
     * @param string $message
1463
     * @return \Zend\View\Model\JsonModel
1464
     */
1465 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...
1466
    {
1467
        $model = new JsonModel(array(
1468
            'success' => false,
1469
            'message' => $message
1470
        ));
1471
        return $model->setTerminal(true);
1472
    }
1473
1474
    /**
1475
     * @param string $helperName
1476
     */
1477
    protected function getViewHelper($helperName)
1478
    {
1479
        return $this->getServiceLocator()->get('viewhelpermanager')->get($helperName);
1480
    }
1481
1482
    public function getGameService()
1483
    {
1484
        if (!$this->gameService) {
1485
            $this->gameService = $this->getServiceLocator()->get('playgroundgame_lottery_service');
1486
        }
1487
1488
        return $this->gameService;
1489
    }
1490
1491
    public function setGameService(GameService $gameService)
1492
    {
1493
        $this->gameService = $gameService;
1494
1495
        return $this;
1496
    }
1497
1498
    public function getPrizeService()
1499
    {
1500
        if (!$this->prizeService) {
1501
            $this->prizeService = $this->getServiceLocator()->get('playgroundgame_prize_service');
1502
        }
1503
1504
        return $this->prizeService;
1505
    }
1506
1507
    public function setPrizeService(PrizeService $prizeService)
1508
    {
1509
        $this->prizeService = $prizeService;
1510
1511
        return $this;
1512
    }
1513
1514
    public function getOptions()
1515
    {
1516
        if (!$this->options) {
1517
            $this->setOptions($this->getServiceLocator()->get('playgroundcore_module_options'));
1518
        }
1519
1520
        return $this->options;
1521
    }
1522
1523
    public function setOptions($options)
1524
    {
1525
        $this->options = $options;
1526
1527
        return $this;
1528
    }
1529
}
1530