Completed
Push — develop ( ecef09...223ed6 )
by greg
03:06
created

GameController::getGameService()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
namespace PlaygroundGame\Controller\Frontend;
4
5
use PlaygroundGame\Service\GameService;
6
use PlaygroundGame\Service\Prize as PrizeService;
7
use Zend\Http\PhpEnvironment\Response;
8
use Zend\Mvc\Controller\AbstractActionController;
9
use Zend\ServiceManager\ServiceLocatorInterface;
10
use Zend\Session\Container;
11
use Zend\Stdlib\Parameters;
12
use Zend\View\Model\JsonModel;
13
use Zend\View\Model\ViewModel;
14
15
class GameController extends AbstractActionController
16
{
17
    /**
18
     * @var \PlaygroundGame\Service\GameService
19
     */
20
    protected $gameService;
21
22
    protected $prizeService;
23
24
    protected $options;
25
26
    protected $game;
27
28
    protected $user;
29
30
    protected $withGame = array(
31
        'home',
32
        'index',
33
        'terms',
34
        'conditions',
35
        'leaderboard',
36
        'register',
37
        'bounce',
38
        'createTeam',
39
        'inviteToTeam',
40
        'prizes',
41
        'prize',
42
        'fangate',
43
        'share',
44
        'optin',
45
        'login',
46
        'logout',
47
        'ajaxforgot',
48
        'play',
49
        'result',
50
        'preview',
51
        'list',
52
        'comments',
53
    );
54
55
    protected $withOnlineGame = array(
56
        'leaderboard',
57
        'register',
58
        'bounce',
59
        'play',
60
        'result',
61
    );
62
63
    protected $withAnyUser = array(
64
        'share',
65
        'result',
66
        'play',
67
        'logout',
68
        'createTeam',
69
        'inviteToTeam',
70
    );
71
72
    protected $isSoloGame = false;
73
74
    /**
75
     *
76
     * @var ServiceManager
77
     */
78
    protected $serviceLocator;
79
80
    public function __construct(ServiceLocatorInterface $locator)
81
    {
82
        $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...
83
    }
84
85
    public function getServiceLocator()
86
    {
87
        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...
88
    }
89
90
    public function setEventManager(\Zend\EventManager\EventManagerInterface $events)
91
    {
92
        parent::setEventManager($events);
93
94
        $controller = $this;
95
96
        $events->attach('dispatch', function (\Zend\Mvc\MvcEvent $e) use ($controller) {
97
            $identifier = $e->getRouteMatch()->getParam('id');
98
            $controller->game = $controller->getGameService()->checkGame($identifier, false);
99
100
            if (!$controller->game &&
101
                    in_array($controller->params('action'), $controller->withGame)
102
                ) {
103
                return $controller->notFoundAction();
104
            }
105
106
            if ($controller->game &&
107
                    $controller->game->isClosed() &&
108
                    in_array($controller->params('action'), $controller->withOnlineGame)
109
                ) {
110
                return $controller->notFoundAction();
111
            }
112
113
            $config = $this->getServiceLocator()->get('config');
114
            $customUrl = str_replace('frontend.', '', $e->getRouteMatch()->getMatchedRouteName());
115
            $customUrl = explode("/", $customUrl)[0];
116
117
            if (isset($config['custom_games']) && isset($config['custom_games'][$controller->game->getIdentifier()]) &&
118
                    $controller->getRequest()->getUri()->getHost() === $customUrl
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Zend\Stdlib\RequestInterface as the method getUri() does only exist in the following implementations of said interface: Zend\Http\PhpEnvironment\Request, Zend\Http\Request.

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...
119
                ) {
120
                $this->isSoloGame = true;
121
            }
122
123
            if ($controller->game) {
124
                // this is possible to create a specific game design in /design/frontend/default/custom.
125
                //It will precede all others templates.
126
                $templatePathResolver = $controller->getServiceLocator()->get('Zend\View\Resolver\TemplatePathStack');
127
                $l = $templatePathResolver->getPaths();
128
                $templatePathResolver->addPath($l[0].'custom/'.$controller->game->getIdentifier());
129
            }
130
131
                $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...
132
            if ($controller->game &&
133
                    !$controller->user &&
134
                    !$controller->game->getAnonymousAllowed() &&
135
                    in_array($controller->params('action'), $controller->withAnyUser)
136
                ) {
137
                $redirect = urlencode(
138
                    $controller->url()->fromRoute(
139
                        'frontend/'.$controller->game->getClassType().'/'.$controller->params('action'),
140
                        array('id'              => $controller->game->getIdentifier()),
141
                        array('force_canonical' => true)
142
                    )
143
                );
144
145
                if ($this->isSoloGame) {
146
                     $urlRegister = $controller->url()->fromRoute(
147
                         'frontend.'.$customUrl.'/'.$controller->game->getClassType().'/user-register',
148
                         array(),
149
                         array('force_canonical' => true)
150
                     ).'?redirect='.$redirect;
151
                } else {
152
                    $urlRegister = $controller->url()->fromRoute(
153
                        'frontend/zfcuser/register',
154
                        array(),
155
                        array('force_canonical' => true)
156
                    ).'?redirect='.$redirect;
157
                }
158
159
                // code permettant d'identifier un custom game
160
                // ligne $config = $controller->getGameService()->getServiceManager()->get('config');
161
                // ligne $customUrl = str_replace('frontend.', '', $e->getRouteMatch()->getParam('area', ''));
162
                // ligne if ($config['custom_games'][$controller->game->getIdentifier()] &&
163
                // ligne    $controller->getRequest()->getUri()->getHost() === $customUrl
164
                // ligne ) {
165
                return $controller->redirect()->toUrl($urlRegister);
166
            }
167
168
                return;
169
        }, 100);// execute before executing action logic
170
    }
171
172
    /**
173
     * Action called if matched action does not exist
174
     * For this view not to be catched by Zend\Mvc\View\RouteNotFoundStrategy
175
     * it has to be rendered in the controller. Hence the code below.
176
     *
177
     * This action is injected as a catchall action for each custom_games definition
178
     * This way, when a custom_game is created, the 404 is it's responsability and the
179
     * view can be defined in design/frontend/default/custom/$slug/playground_game/$gametype/404.phtml
180
     *
181
     *
182
     * @return \Zend\Stdlib\ResponseInterface
183
     */
184
    public function notFoundAction()
185
    {
186
        $templatePathResolver = $this->getServiceLocator()->get('Zend\View\Resolver\TemplatePathStack');
187
188
        // I create a template path in which I can find a custom template
189
        $controller     = explode('\\', get_class($this));
190
        $controllerPath = str_replace('Controller', '', end($controller));
191
        $controllerPath = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '-\\1', $controllerPath));
192
        $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...
193
        if ($this->game) {
194
            $uri = str_replace($controllerPath.'/'.$this->game->getIdentifier().'/', '', $uri);
195
        }
196
        $uri      = str_replace("/".$this->getEvent()->getRouteMatch()->getParam('locale')."/", "/", $uri);
197
        $template = 'playground-game/'.$controllerPath.'/custom'.$uri;
198
199
        if (false === $templatePathResolver->resolve($template)) {
200
            $viewRender = $this->getServiceLocator()->get('ViewRenderer');
201
202
            $this->getEvent()->getRouteMatch()->setParam('action', 'not-found');
203
            $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...
204
205
            $res = 'error/404';
206
207
            $viewModel = $this->buildView($this->game);
208
            $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...
209
210
            $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...
211
            $this->response->setContent($viewRender->render($this->layout()));
212
213
            return $this->response;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->response; (Zend\Stdlib\ResponseInterface) is incompatible with the return type of the parent method Zend\Mvc\Controller\Abst...troller::notFoundAction of type Zend\View\Model\ViewMode...View\Model\ConsoleModel.

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

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

Let’s take a look at an example:

class Author {
    private $name;

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

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

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

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

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

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

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

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

Let’s take a look at an example:

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

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

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

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

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

Available Fixes

  1. Change the type-hint for the parameter:

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

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

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

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

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

Loading history...
605
            $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...
606
            $form->setData($data);
607
            if ($form->isValid()) {
608
                $result = $this->getGameService()->sendShareMail($data, $this->game, $this->user, $lastEntry);
609
                if ($result) {
610
                    $statusMail = true;
611
                }
612
            }
613
        }
614
615
        $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...
616
                'statusMail' => $statusMail,
617
                'form'       => $form,
618
            ));
619
620
        return $viewModel;
621
    }
622
623
    public function inviteToTeamAction()
624
    {
625
626 View Code Duplication
        if (count($this->user->getTeams()) == 0) {
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...
627
            return $this->redirect()->toUrl(
628
                $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...
629
                    $this->game->getClassType().'/create-team',
630
                    array('id' => $this->game->getIdentifier())
631
                )
632
            );
633
        }
634
635
        $team = $this->user->getTeams()->first(); 
636
        $invitationMapper = $this->getServiceLocator()->get('playgroundgame_invitation_mapper');
637
        $invitations = $invitationMapper->findBy(array('host' => $this->user, 'game' => $this->game));
638
        $statusMail = null;
639
        $message = '';
640
        $isHost = ($this->user->getId() === $team->getHost()->getId()) ? true : false;
641
642
        $form = $this->getServiceLocator()->get('playgroundgame_sharemail_form');
643
        $form->setAttribute('method', 'post');
644
645
        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...
646
            $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...
647
            $form->setData($data);
648
            if ($form->isValid()) {
649
                $result = $this->getGameService()->inviteToTeam($data, $this->game, $this->user);
650
                if ($result['result']) {
651
                    $statusMail = true;
652
                } else {
653
                    $statusMail = false;
654
                    $message    = $result['message'];
655
                }
656
            }
657
        }
658
659
        $viewModel = $this->buildView($this->game);
660
        $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...
661
            'team'       => $team,
662
            'invitations'=> $invitations,
663
            'message'    => $message,
664
            'statusMail' => $statusMail,
665
            'form'       => $form,
666
            'isHost'     => $isHost,
667
        ));
668
669
        return $viewModel;
670
    }
671
672
    public function createTeamAction()
673
    {
674 View Code Duplication
        if (count($this->user->getTeams()) > 0) {
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...
675
            return $this->redirect()->toUrl(
676
                $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...
677
                    $this->game->getClassType().'/invite-to-team',
678
                    array('id' => $this->game->getIdentifier())
679
                )
680
            );
681
        }
682
683
        $form = $this->getServiceLocator()->get('playgroundgame_createteam_form');
684
        $form->setAttribute('method', 'post');
685
686
        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...
687
            $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...
688
            $form->setData($data);
689
            if ($form->isValid()) {
690
                $teamMapper = $this->getServiceLocator()->get('playgrounduser_team_mapper');
691
                $users = new \Doctrine\Common\Collections\ArrayCollection();
692
                $users->add($this->user);
693
                $teamName = $data['name'];
694
                $slugify = new \PlaygroundCore\Filter\Slugify;
695
696
                $team = new \PlaygroundUser\Entity\Team();
697
                $team->setName($teamName);
698
                $team->setIdentifier($slugify($teamName));
699
                $team->setHost($this->user);
0 ignored issues
show
Bug introduced by
The method setHost() does not seem to exist on object<PlaygroundUser\Entity\Team>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
700
                $team->addUsers($users);
701
702
                $teamMapper->insert($team);
703
704
                return $this->redirect()->toUrl(
705
                    $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...
706
                        $this->game->getClassType().'/invite-to-team',
707
                        array('id' => $this->game->getIdentifier())
708
                    )
709
                );
710
            }
711
        }
712
713
        $viewModel = $this->buildView($this->game);
714
        $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...
715
            'form'       => $form,
716
        ));
717
718
        return $viewModel;
719
    }
720
721 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...
722
    {
723
        $viewModel = new JsonModel();
724
        $viewModel->setTerminal(true);
725
        $fbId = $this->params()->fromQuery('fbId');
726
        if (!$this->game) {
727
            return $this->errorJson();
728
        }
729
        $entry = $this->getGameService()->checkExistingEntry($this->game, $this->user);
730
        if (!$entry) {
731
            return $this->errorJson();
732
        }
733
        if (!$fbId) {
734
            return $this->errorJson();
735
        }
736
737
        $this->getGameService()->postFbWall($fbId, $this->game, $this->user, $entry);
738
739
        return $this->successJson();
740
    }
741
742
    public function fbrequestAction()
743
    {
744
        $viewModel = new ViewModel();
745
        $viewModel->setTerminal(true);
746
        $fbId = $this->params()->fromQuery('fbId');
747
        $to   = $this->params()->fromQuery('to');
748
749
        if (!$this->game) {
750
            return $this->errorJson();
751
        }
752
        $entry = $this->getGameService()->checkExistingEntry($this->game, $this->user);
753
        if (!$entry) {
754
            return $this->errorJson();
755
        }
756
        if (!$fbId) {
757
            return $this->errorJson();
758
        }
759
760
        $this->getGameService()->postFbRequest($fbId, $this->game, $this->user, $entry, $to);
761
762
        return $this->successJson();
763
    }
764
765
    public function tweetAction()
766
    {
767
        $tweetId = $this->params()->fromQuery('tweetId');
768
769
        if (!$this->game) {
770
            return $this->errorJson();
771
        }
772
        $entry = $this->getGameService()->checkExistingEntry($this->game, $this->user);
773
        if (!$entry) {
774
            return $this->errorJson();
775
        }
776
        if (!$tweetId) {
777
            return $this->errorJson();
778
        }
779
780
        $this->getGameService()->postTwitter($tweetId, $this->game, $this->user, $entry);
781
782
        return $this->successJson();
783
    }
784
785 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...
786
    {
787
        $viewModel = new ViewModel();
788
        $viewModel->setTerminal(true);
789
        $googleId = $this->params()->fromQuery('googleId');
790
791
        if (!$this->game) {
792
            return $this->errorJson();
793
        }
794
        $entry = $this->getGameService()->checkExistingEntry($this->game, $this->user);
795
        if (!$entry) {
796
            return $this->errorJson();
797
        }
798
        if (!$googleId) {
799
            return $this->errorJson();
800
        }
801
802
        $this->getGameService()->postGoogle($googleId, $this->game, $this->user, $entry);
803
804
        return $this->successJson();
805
    }
806
807
    public function optinAction()
808
    {
809
        $userService = $this->getServiceLocator()->get('zfcuser_user_service');
810
811
        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...
812
            $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...
813
            $data['optinPartner'] = ($this->params()->fromPost('optinPartner'))?1:0;
814
815
            $userService->updateNewsletter($data);
816
        }
817
818
        return $this->redirect()->toUrl(
819
            $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...
820
                $this->game->getClassType(),
821
                array('id' => $this->game->getIdentifier())
822
            )
823
        );
824
    }
825
826
    public function loginAction()
827
    {
828
        $request = $this->getRequest();
829
        $form    = $this->getServiceLocator()->get('zfcuser_login_form');
830
831
        if ($request->isPost()) {
832
            $form->setData($request->getPost());
833
834
            if (!$form->isValid()) {
835
                $this->flashMessenger()->addMessage(
836
                    'Authentication failed. Please try again.'
837
                );
838
839
                $viewModel = $this->buildView($this->game);
840
                $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...
841
                        'form'          => $form,
842
                        'flashMessages' => $this->flashMessenger()->getMessages(),
843
                    ));
844
845
                return $viewModel;
846
            }
847
848
            // clear adapters
849
            $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...
850
            $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...
851
852
            $logged = $this->forward()->dispatch('playgrounduser_user', array('action' => 'ajaxauthenticate'));
853
854 View Code Duplication
            if (!$logged) {
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...
855
                $this->flashMessenger()->addMessage(
856
                    'Authentication failed. Please try again.'
857
                );
858
859
                return $this->redirect()->toUrl(
860
                    $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...
861
                        $this->game->getClassType().'/login',
862
                        array('id' => $this->game->getIdentifier())
863
                    )
864
                );
865
            } else {
866
                return $this->redirect()->toUrl(
867
                    $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().'/'.$this->game->nextStep('index'),
869
                        array('id' => $this->game->getIdentifier())
870
                    )
871
                );
872
            }
873
        }
874
875
        $form->setAttribute(
876
            'action',
877
            $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...
878
                $this->game->getClassType().'/login',
879
                array('id' => $this->game->getIdentifier())
880
            )
881
        );
882
        $viewModel = $this->buildView($this->game);
883
        $viewModel->setVariables(array(
884
                'form'          => $form,
885
                'flashMessages' => $this->flashMessenger()->getMessages(),
886
            ));
887
        return $viewModel;
888
    }
889
890
    public function logoutAction()
891
    {
892
        $viewModel = $this->forward()->dispatch(
893
            'playgrounduser_user',
894
            array(
895
                'controller' => 'playgrounduser_user',
896
                'action'     => 'logout',
897
                'id'         => $this->game->getIdentifier()
898
            )
899
        );
900
901
        if ($viewModel && $viewModel instanceof \Zend\View\Model\ViewModel) {
902
            $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...
903
            $viewModel->setVariables(array('game'      => $this->game));
904
        }
905
906
        return $viewModel;
907
    }
908
909
    public function userregisterAction()
910
    {
911
        $pguserOptions = $this->getServiceLocator()->get('playgrounduser_module_options');
912
        $userOptions = $this->getServiceLocator()->get('zfcuser_module_options');
913
914
        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...
915
            return $this->redirect()->toUrl(
916
                $this->frontendUrl()->fromRoute(
0 ignored issues
show
Documentation Bug introduced by
The method frontendUrl does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

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

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

class ParentClass {
    private $data = array();

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

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

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
917
                    $this->game->getClassType().'/'.$this->game->nextStep('index'),
918
                    array('id' => $this->game->getIdentifier())
919
                )
920
            );
921
        }
922
        $request       = $this->getRequest();
923
        $service       = $this->getServiceLocator()->get('zfcuser_user_service');
924
        $form          = $this->getServiceLocator()->get('playgroundgame_register_form');
925
        $socialnetwork = $this->params()->fromRoute('socialnetwork', false);
926
        $form->setAttribute(
927
            'action',
928
            $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...
929
                $this->game->getClassType().'/user-register',
930
                array('id' => $this->game->getIdentifier())
931
            )
932
        );
933
        $params            = array();
934
        $socialCredentials = array();
935
936
        if ($userOptions->getUseRedirectParameterIfPresent() && $request->getQuery()->get('redirect')) {
937
            $redirect = $request->getQuery()->get('redirect');
938
        } else {
939
            $redirect = false;
940
        }
941
942
        if ($socialnetwork) {
943
            $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...
944
945
            if (!empty($infoMe)) {
946
                $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...
947
                    $infoMe->identifier,
948
                    $socialnetwork
949
                );
950
951
                if ($user || $service->getOptions()->getCreateUserAutoSocial() === true) {
952
                    //on le dirige vers l'action d'authentification
953
                    if (!$redirect && $userOptions->getLoginRedirectRoute() != '') {
954
                        $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...
955
                            $this->game->getClassType().'/login',
956
                            array('id' => $this->game->getIdentifier())
957
                        );
958
                    }
959
                    $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...
960
                        $this->game->getClassType().'/login',
961
                        array('id' => $this->game->getIdentifier())
962
                    ).'/'.$socialnetwork.($redirect?'?redirect='.$redirect:'');
963
964
                    return $this->redirect()->toUrl($redir);
965
                }
966
967
                // Je retire la saisie du login/mdp
968
                $form->setAttribute(
969
                    'action',
970
                    $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...
971
                        $this->game->getClassType().'/user-register',
972
                        array(
973
                            'id'            => $this->game->getIdentifier(),
974
                            'socialnetwork' => $socialnetwork,
975
976
                        )
977
                    )
978
                );
979
                $form->remove('password');
980
                $form->remove('passwordVerify');
981
982
                $birthMonth = $infoMe->birthMonth;
983
                if (strlen($birthMonth) <= 1) {
984
                    $birthMonth = '0'.$birthMonth;
985
                }
986
                $birthDay = $infoMe->birthDay;
987
                if (strlen($birthDay) <= 1) {
988
                    $birthDay = '0'.$birthDay;
989
                }
990
991
                $gender = $infoMe->gender;
992
                if ($gender == 'female') {
993
                    $title = 'Me';
994
                } else {
995
                    $title = 'M';
996
                }
997
998
                $params = array(
999
                    //'birth_year'  => $infoMe->birthYear,
1000
                    'title'      => $title,
1001
                    'dob'        => $birthDay.'/'.$birthMonth.'/'.$infoMe->birthYear,
1002
                    'firstname'  => $infoMe->firstName,
1003
                    'lastname'   => $infoMe->lastName,
1004
                    'email'      => $infoMe->email,
1005
                    'postalCode' => $infoMe->zip,
1006
                );
1007
                $socialCredentials = array(
1008
                    'socialNetwork' => strtolower($socialnetwork),
1009
                    'socialId'      => $infoMe->identifier,
1010
                );
1011
            }
1012
        }
1013
1014
        $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...
1015
            $this->game->getClassType().'/user-register',
1016
            array('id' => $this->game->getIdentifier())
1017
        ).($socialnetwork?'/'.$socialnetwork:'').($redirect?'?redirect='.$redirect:'');
1018
        $prg = $this->prg($redirectUrl, true);
1019
1020
        if ($prg instanceof Response) {
1021
            return $prg;
1022
        } elseif ($prg === false) {
1023
            $form->setData($params);
1024
            $viewModel = $this->buildView($this->game);
1025
            $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...
1026
                'registerForm'       => $form,
1027
                'enableRegistration' => $userOptions->getEnableRegistration(),
1028
                'redirect'           => $redirect,
1029
            ));
1030
            return $viewModel;
1031
        }
1032
1033
        $post = $prg;
1034
        if (isset($post['optin'])) {
1035
            $post['optin'] = 1;
1036
        }
1037
        if (isset($post['optinPartner'])) {
1038
            $post['optinPartner'] = 1;
1039
        }
1040
        $post = array_merge(
1041
            $post,
1042
            $socialCredentials
1043
        );
1044
1045
        if ($pguserOptions->getUseRecaptcha()) {
1046
            if (!isset($post['g-recaptcha-response']) || $post['g-recaptcha-response'] == '' || !$this->recaptcha()->recaptcha($post['g-recaptcha-response'])) {
0 ignored issues
show
Documentation Bug introduced by
The method recaptcha does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

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

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

class ParentClass {
    private $data = array();

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

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

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
1047
                $this->flashMessenger()->addErrorMessage('Invalid Captcha. Please try again.');
1048
                $form->setData($post);
1049
                $viewModel = $this->buildView($this->game);
1050
                $viewModel->setVariables(array(
1051
                        'registerForm'       => $form,
1052
                        'enableRegistration' => $userOptions->getEnableRegistration(),
1053
                        'redirect'           => $redirect,
1054
                        'bah'                => 'coco',
1055
                        'flashMessages'      => $this->flashMessenger()->getMessages(),
1056
                        'flashErrors'        => $this->flashMessenger()->getErrorMessages(),
1057
                    ));
1058
1059
                return $viewModel;
1060
            }
1061
        }
1062
1063
        if ($this->game->getOnInvitation()) {
1064
            $credential = trim(
1065
                $post[$this->getGameService()->getOptions()->getOnInvitationField()]
1066
            );
1067
            if (!$credential) {
1068
                $credential = $this->params()->fromQuery(
1069
                    $this->getGameService()->getOptions()->getOnInvitationField()
1070
                );
1071
            }
1072
            $found = $this->getGameService()->getInvitationMapper()->findOneBy(array('requestKey' => $credential));
1073
1074
            if (!$found || !empty($found->getUser())) {
1075
                $this->flashMessenger()->addMessage(
1076
                    'Authentication failed. Please try again.'
1077
                );
1078
                $form->setData($post);
1079
                $viewModel = $this->buildView($this->game);
1080
                $viewModel->setVariables(array(
1081
                        'registerForm'       => $form,
1082
                        'enableRegistration' => $userOptions->getEnableRegistration(),
1083
                        'redirect'           => $redirect,
1084
                        'flashMessages'      => $this->flashMessenger()->getMessages(),
1085
                        'flashErrors'        => $this->flashMessenger()->getErrorMessages(),
1086
                    ));
1087
1088
                return $viewModel;
1089
            }
1090
        }
1091
1092
        $user = $service->register($post, 'playgroundgame_register_form');
1093
1094
        if (!$user) {
1095
            $viewModel = $this->buildView($this->game);
1096
            $viewModel->setVariables(array(
1097
                    'registerForm'       => $form,
1098
                    'enableRegistration' => $userOptions->getEnableRegistration(),
1099
                    'redirect'           => $redirect,
1100
                    'flashMessages'      => $this->flashMessenger()->getMessages(),
1101
                    'flashErrors'        => $this->flashMessenger()->getErrorMessages(),
1102
                ));
1103
1104
            return $viewModel;
1105
        }
1106
1107
        if ($this->game->getOnInvitation()) {
1108
            // user has been created, associate the code with the userId
1109
            $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...
1110
            $this->getGameService()->getInvitationMapper()->update($found);
1111
        }
1112
1113
        if ($service->getOptions()->getEmailVerification()) {
1114
            $vm = new ViewModel(array('userEmail' => $user->getEmail()));
1115
            $vm->setTemplate('playground-user/register/registermail');
1116
1117
            return $vm;
1118
        } elseif ($service->getOptions()->getLoginAfterRegistration()) {
1119
            $identityFields = $service->getOptions()->getAuthIdentityFields();
1120
            if (in_array('email', $identityFields)) {
1121
                $post['identity'] = $user->getEmail();
1122
            } elseif (in_array('username', $identityFields)) {
1123
                $post['identity'] = $user->getUsername();
1124
            }
1125
            $post['credential'] = isset($post['password'])?$post['password']:'';
1126
            $request->setPost(new Parameters($post));
1127
1128
            // clear adapters
1129
            $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...
1130
            $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...
1131
1132
            $logged = $this->forward()->dispatch('playgrounduser_user', array('action' => 'ajaxauthenticate'));
1133
1134 View Code Duplication
            if ($logged) {
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...
1135
                return $this->redirect()->toUrl(
1136
                    $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...
1137
                        $this->game->getClassType().'/'.$this->game->nextStep('index'),
1138
                        array('id' => $this->game->getIdentifier())
1139
                    )
1140
                );
1141
            } else {
1142
                $this->flashMessenger()->setNamespace('zfcuser-login-form')->addMessage(
1143
                    'Authentication failed. Please try again.'
1144
                );
1145
                return $this->redirect()->toUrl(
1146
                    $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...
1147
                        $this->game->getClassType().'/login',
1148
                        array('id' => $this->game->getIdentifier())
1149
                    )
1150
                );
1151
            }
1152
        }
1153
1154
        $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...
1155
            $this->game->getClassType().'/login',
1156
            array('id' => $this->game->getIdentifier())
1157
        ).($socialnetwork?'/'.$socialnetwork:'').($redirect?'?redirect='.$redirect:'');
1158
1159
        return $this->redirect()->toUrl($redirect);
1160
    }
1161
1162 View Code Duplication
    public function checkTokenAction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
1163
    {
1164
        $viewModel = $this->forward()->dispatch(
1165
            'playgrounduser_user',
1166
            array(
1167
                'controller' => 'playgrounduser_user',
1168
                'action' => 'check-token',
1169
                'id' => $this->game->getIdentifier(),
1170
                'token' => $this->params()->fromRoute('token', null)
1171
            )
1172
        );
1173
1174
        if ($viewModel && $viewModel instanceof \Zend\View\Model\ViewModel) {
1175
            $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...
1176
            $viewModel->setVariables(array('game' => $this->game));
1177
        }
1178
1179
        return $viewModel;
1180
    }
1181
1182
    public function userProfileAction()
1183
    {
1184
        $viewModel = $this->forward()->dispatch(
1185
            'playgrounduser_user',
1186
            array(
1187
                'controller' => 'playgrounduser_user',
1188
                'action'     => 'profile',
1189
                'id'         => $this->game->getIdentifier()
1190
            )
1191
        );
1192
1193
        if ($viewModel && $viewModel instanceof \Zend\View\Model\ViewModel) {
1194
            $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...
1195
            $viewModel->setVariables(array('game'      => $this->game));
1196
        }
1197
1198
        return $viewModel;
1199
    }
1200
1201
    public function userresetAction()
1202
    {
1203
        $viewModel = $this->forward()->dispatch(
1204
            'playgrounduser_forgot',
1205
            array(
1206
                'controller' => 'playgrounduser_forgot',
1207
                'action'     => 'reset',
1208
                'id'         => $this->game->getIdentifier(),
1209
                'userId'     => $this->params()->fromRoute('userId', null),
1210
                'token'      => $this->params()->fromRoute('token', null),
1211
            )
1212
        );
1213
1214
        if ($viewModel && $viewModel instanceof \Zend\View\Model\ViewModel) {
1215
            $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...
1216
            $viewModel->setVariables(array('game'      => $this->game));
1217
        }
1218
1219
        return $viewModel;
1220
    }
1221
1222
    public function ajaxforgotAction()
1223
    {
1224
        $view = $this->forward()->dispatch(
1225
            'playgrounduser_forgot',
1226
            array(
1227
                'controller' => 'playgrounduser_forgot',
1228
                'action'     => 'ajaxforgot',
1229
                'id'         => $this->game->getIdentifier()
1230
            )
1231
        );
1232
1233
        if ($view && $view instanceof \Zend\View\Model\ViewModel) {
1234
            $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...
1235
            $view->setVariables(array('game'           => $this->game));
1236
        }
1237
1238
        return $view;
1239
    }
1240
1241 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...
1242
    {
1243
        $viewModel = $this->forward()->dispatch(
1244
            'playgroundcms',
1245
            array(
1246
                'controller' => 'playgroundcms',
1247
                'action'     => 'index',
1248
                'id'         => $this->game->getIdentifier(),
1249
                'pid'        => $this->getEvent()->getRouteMatch()->getParam('pid')
1250
            )
1251
        );
1252
1253
        if ($viewModel && $viewModel instanceof \Zend\View\Model\ViewModel) {
1254
            $this->layout()->setVariables(array('game' => $this->game));
0 ignored issues
show
Bug introduced by
The method setVariables does only exist in Zend\View\Model\ModelInterface, but not in Zend\Mvc\Controller\Plugin\Layout.

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

Let’s take a look at an example:

class A
{
    public function foo() { }
}

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

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

Available Fixes

  1. Add an additional type-check:

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

    function someFunction(B $x) { /** ... */ }
    
Loading history...
1255
            $viewModel->setVariables(array('game'      => $this->game));
1256
        }
1257
1258
        return $viewModel;
1259
    }
1260
1261 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...
1262
    {
1263
        $viewModel = $this->forward()->dispatch(
1264
            'playgroundcms',
1265
            array(
1266
                'controller' => 'playgroundcms',
1267
                'action'     => 'list',
1268
                'id'         => $this->game->getIdentifier(),
1269
                'category'   => $this->game->getIdentifier()
1270
            )
1271
        );
1272
1273
        if ($viewModel && $viewModel instanceof \Zend\View\Model\ViewModel) {
1274
            $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...
1275
            $viewModel->setVariables(array('game'      => $this->game));
1276
        }
1277
1278
        return $viewModel;
1279
    }
1280
1281
    /**
1282
     *
1283
     * @param \PlaygroundGame\Entity\Game $game
1284
     * @param \PlaygroundUser\Entity\User $user
1285
     */
1286
    public function checkFbRegistration($user, $game)
1287
    {
1288
        $redirect = false;
1289
        $session  = new Container('facebook');
1290
        if ($session->offsetExists('signed_request')) {
1291
            if (!$user) {
1292
                // Get Playground user from Facebook info
1293
                $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...
1294
                $view         = $this->forward()->dispatch(
1295
                    'playgrounduser_user',
1296
                    array(
1297
                        'controller' => 'playgrounduser_user',
1298
                        'action'     => 'registerFacebookUser',
1299
                        'provider'   => 'facebook',
1300
                    )
1301
                );
1302
1303
                $this->layout()->setTemplate($beforeLayout);
1304
                $user = $view->user;
1305
1306
                // If the user can not be created/retrieved from Facebook info, redirect to login/register form
1307
                if (!$user) {
1308
                    $redirectUrl = urlencode(
1309
                        $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...
1310
                            $game->getClassType().'/play',
1311
                            array('id'              => $game->getIdentifier()),
1312
                            array('force_canonical' => true)
1313
                        )
1314
                    );
1315
                    $redirect = $this->redirect()->toUrl(
1316
                        $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...
1317
                            'zfcuser/register'
1318
                        ).'?redirect='.$redirectUrl
1319
                    );
1320
                }
1321
            }
1322
1323
            if ($game->getFbFan()) {
1324
                if ($this->getGameService()->checkIsFan($game) === false) {
1325
                    $redirect = $this->redirect()->toRoute(
1326
                        $game->getClassType().'/fangate',
1327
                        array('id' => $game->getIdentifier())
1328
                    );
1329
                }
1330
            }
1331
        }
1332
1333
        return $redirect;
1334
    }
1335
1336
    /**
1337
     * This method create the basic Game view
1338
     * @param \PlaygroundGame\Entity\Game $game
1339
     */
1340
    public function buildView($game)
1341
    {
1342
        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...
1343
            $viewModel = new JsonModel();
1344
            if ($game) {
1345
                $view = $this->addAdditionalView($game);
1346
                if ($view && $view instanceof \Zend\View\Model\ViewModel) {
1347
                    $viewModel->setVariables($view->getVariables());
1348
                }
1349
            }
1350
        } else {
1351
            $viewModel = new ViewModel();
1352
1353
            if ($game) {
1354
                $this->addMetaTitle($game);
1355
                $this->addMetaBitly();
1356
                $this->addGaEvent($game);
1357
1358
                $this->customizeGameDesign($game);
1359
1360
                $view = $this->addAdditionalView($game);
1361
                if ($view && $view instanceof \Zend\View\Model\ViewModel) {
1362
                    $viewModel->addChild($view, 'additional');
1363
                } elseif ($view && $view instanceof \Zend\Http\PhpEnvironment\Response) {
1364
                    return $view;
1365
                }
1366
1367
                $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...
1368
                    array(
1369
                        'action'        => $this->params('action'),
1370
                        'game'          => $game,
1371
                        'flashMessages' => $this->flashMessenger()->getMessages(),
1372
1373
                    )
1374
                );
1375
1376
                $viewModel->setVariables($this->getShareData($game));
1377
                $viewModel->setVariables(array('game' => $game, 'user' => $this->user));
1378
            }
1379
        }
1380
1381
        return $viewModel;
1382
    }
1383
1384
    /**
1385
     * @param \PlaygroundGame\Entity\Game $game
1386
     */
1387
    public function addAdditionalView($game)
1388
    {
1389
        $view = false;
1390
1391
        $actionName = $this->getEvent()->getRouteMatch()->getParam('action', 'not-found');
1392
        $stepsViews = json_decode($game->getStepsViews(), true);
1393
        if ($stepsViews && isset($stepsViews[$actionName])) {
1394
            $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...
1395
            $actionData   = $stepsViews[$actionName];
1396
            if (is_string($actionData)) {
1397
                $action     = $actionData;
1398
                $controller = $this->getEvent()->getRouteMatch()->getParam('controller', PlaygroundGame\Controller\Frontend\Game::class);
1399
                $view       = $this->forward()->dispatch(
1400
                    $controller,
1401
                    array(
1402
                        'action' => $action,
1403
                        'id'     => $game->getIdentifier()
1404
                    )
1405
                );
1406
            } elseif (is_array($actionData) && count($actionData) > 0) {
1407
                $action     = key($actionData);
1408
                $controller = $actionData[$action];
1409
                $view       = $this->forward()->dispatch(
1410
                    $controller,
1411
                    array(
1412
                        'action' => $action,
1413
                        'id'     => $game->getIdentifier()
1414
                    )
1415
                );
1416
            }
1417
            // suite au forward, le template de layout a changé, je dois le rétablir...
1418
            $this->layout()->setTemplate($beforeLayout);
1419
        }
1420
1421
        return $view;
1422
    }
1423
1424
    public function addMetaBitly()
1425
    {
1426
        $bitlyclient = $this->getOptions()->getBitlyUrl();
1427
        $bitlyuser   = $this->getOptions()->getBitlyUsername();
1428
        $bitlykey    = $this->getOptions()->getBitlyApiKey();
1429
1430
        $this->getViewHelper('HeadMeta')->setProperty('bt:client', $bitlyclient);
1431
        $this->getViewHelper('HeadMeta')->setProperty('bt:user', $bitlyuser);
1432
        $this->getViewHelper('HeadMeta')->setProperty('bt:key', $bitlykey);
1433
    }
1434
1435
    /**
1436
     * @param \PlaygroundGame\Entity\Game $game
1437
     */
1438
    public function addGaEvent($game)
1439
    {
1440
        // Google Analytics event
1441
        $ga    = $this->getServiceLocator()->get('google-analytics');
1442
        $event = new \PlaygroundCore\Analytics\Event($game->getClassType(), $this->params('action'));
1443
        $event->setLabel($game->getTitle());
1444
        $ga->addEvent($event);
1445
    }
1446
1447
    /**
1448
     * @param \PlaygroundGame\Entity\Game $game
1449
     */
1450
    public function addMetaTitle($game)
1451
    {
1452
        $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...
1453
        $this->getGameService()->getServiceManager()->get('ViewHelperManager')->get('HeadTitle')->set($title);
1454
        // Meta set in the layout
1455
        $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...
1456
            array(
1457
                'breadcrumbTitle' => $title,
1458
                'currentPage'     => array(
1459
                    'pageGames'      => 'games',
1460
                    'pageWinners'    => '',
1461
                ),
1462
                'headParams'       => array(
1463
                    'headTitle'       => $title,
1464
                    'headDescription' => $title,
1465
                ),
1466
                'bodyCss' => $game->getIdentifier()
1467
            )
1468
        );
1469
    }
1470
1471
    /**
1472
     * @param \PlaygroundGame\Entity\Game $game
1473
     */
1474
    public function customizeGameDesign($game)
1475
    {
1476
        // If this game has a specific layout...
1477
        if ($game->getLayout()) {
1478
            $layoutViewModel = $this->layout();
1479
            $layoutViewModel->setTemplate($game->getLayout());
1480
        }
1481
1482
        // If this game has a specific stylesheet...
1483
        if ($game->getStylesheet()) {
1484
            $this->getViewHelper('HeadLink')->appendStylesheet(
1485
                $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...
1486
            );
1487
        }
1488
    }
1489
1490
    /**
1491
     * @param \PlaygroundGame\Entity\Game $game
1492
     */
1493
    public function getShareData($game)
1494
    {
1495
        $fo      = $this->getServiceLocator()->get('facebook-opengraph');
1496
        $session = new Container('facebook');
1497
1498
        // I change the fbappid if i'm in fb
1499
        if ($session->offsetExists('signed_request')) {
1500
            $fo->setId($game->getFbAppId());
1501
        }
1502
1503
        // If I want to add a share block in my view
1504 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...
1505
            $fbShareMessage = $game->getFbShareMessage();
1506
        } else {
1507
            $fbShareMessage = str_replace(
1508
                '__placeholder__',
1509
                $game->getTitle(),
1510
                $this->getOptions()->getDefaultShareMessage()
1511
            );
1512
        }
1513
1514
        if ($game->getFbShareImage()) {
1515
            $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...
1516
                '',
1517
                array(),
1518
                array('force_canonical' => true),
1519
                false
1520
            ).$game->getFbShareImage();
1521
        } else {
1522
            $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...
1523
                '',
1524
                array(),
1525
                array('force_canonical' => true),
1526
                false
1527
            ).$game->getMainImage();
1528
        }
1529
1530
        $secretKey = strtoupper(substr(sha1(uniqid('pg_', true).'####'.time()), 0, 15));
1531
1532
        // Without bit.ly shortener
1533
        $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...
1534
            $game->getClassType(),
1535
            array('id'              => $game->getIdentifier()),
1536
            array('force_canonical' => true)
1537
        );
1538
        // With core shortener helper
1539
        $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...
1540
1541
        // FB Requests only work when it's a FB app
1542
        if ($game->getFbRequestMessage()) {
1543
            $fbRequestMessage = urlencode($game->getFbRequestMessage());
1544
        } else {
1545
            $fbRequestMessage = str_replace(
1546
                '__placeholder__',
1547
                $game->getTitle(),
1548
                $this->getOptions()->getDefaultShareMessage()
1549
            );
1550
        }
1551
1552 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...
1553
            $twShareMessage = $game->getTwShareMessage().$socialLinkUrl;
1554
        } else {
1555
            $twShareMessage = str_replace(
1556
                '__placeholder__',
1557
                $game->getTitle(),
1558
                $this->getOptions()->getDefaultShareMessage()
1559
            ).$socialLinkUrl;
1560
        }
1561
1562
        $ogTitle = new \PlaygroundCore\Opengraph\Tag('og:title', $fbShareMessage);
1563
        $ogImage = new \PlaygroundCore\Opengraph\Tag('og:image', $fbShareImage);
1564
1565
        $fo->addTag($ogTitle);
1566
        $fo->addTag($ogImage);
1567
1568
        $data = array(
1569
            'socialLinkUrl'    => $socialLinkUrl,
1570
            'secretKey'        => $secretKey,
1571
            'fbShareMessage'   => $fbShareMessage,
1572
            'fbShareImage'     => $fbShareImage,
1573
            'fbRequestMessage' => $fbRequestMessage,
1574
            'twShareMessage'   => $twShareMessage,
1575
        );
1576
1577
        return $data;
1578
    }
1579
1580
    /**
1581
     * return ajax response in json format
1582
     *
1583
     * @param array $data
1584
     * @return \Zend\View\Model\JsonModel
1585
     */
1586 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...
1587
    {
1588
        $model = new JsonModel(array(
1589
                'success' => true,
1590
                'data'    => $data,
1591
            ));
1592
        return $model->setTerminal(true);
1593
    }
1594
1595
    /**
1596
     * return ajax response in json format
1597
     *
1598
     * @param string $message
1599
     * @return \Zend\View\Model\JsonModel
1600
     */
1601 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...
1602
    {
1603
        $model = new JsonModel(array(
1604
                'success' => false,
1605
                'message' => $message,
1606
            ));
1607
        return $model->setTerminal(true);
1608
    }
1609
1610
    /**
1611
     * @param string $helperName
1612
     */
1613
    protected function getViewHelper($helperName)
1614
    {
1615
        return $this->getServiceLocator()->get('viewhelpermanager')->get($helperName);
1616
    }
1617
1618
    public function getGameService()
1619
    {
1620
        if (!$this->gameService) {
1621
            $this->gameService = $this->getServiceLocator()->get('playgroundgame_lottery_service');
1622
        }
1623
1624
        return $this->gameService;
1625
    }
1626
1627
    public function setGameService(GameService $gameService)
1628
    {
1629
        $this->gameService = $gameService;
1630
1631
        return $this;
1632
    }
1633
1634
    public function getPrizeService()
1635
    {
1636
        if (!$this->prizeService) {
1637
            $this->prizeService = $this->getServiceLocator()->get('playgroundgame_prize_service');
1638
        }
1639
1640
        return $this->prizeService;
1641
    }
1642
1643
    public function setPrizeService(PrizeService $prizeService)
1644
    {
1645
        $this->prizeService = $prizeService;
1646
1647
        return $this;
1648
    }
1649
1650
    public function getOptions()
1651
    {
1652
        if (!$this->options) {
1653
            $this->setOptions($this->getServiceLocator()->get('playgroundcore_module_options'));
1654
        }
1655
1656
        return $this->options;
1657
    }
1658
1659
    public function setOptions($options)
1660
    {
1661
        $this->options = $options;
1662
1663
        return $this;
1664
    }
1665
}
1666