Completed
Pull Request — master (#314)
by greg
03:20
created

GameController::fbrequestAction()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 22
rs 8.9197
cc 4
eloc 14
nc 4
nop 0
1
<?php
2
3
namespace PlaygroundGame\Controller\Frontend;
4
5
use Zend\Mvc\Controller\AbstractActionController;
6
use Zend\View\Model\ViewModel;
7
use Zend\Session\Container;
8
use PlaygroundGame\Service\GameService;
9
use PlaygroundGame\Service\Prize as PrizeService;
10
use Zend\View\Model\JsonModel;
11
use Zend\Http\PhpEnvironment\Response;
12
use Zend\Stdlib\Parameters;
13
14
class GameController extends AbstractActionController
15
{
16
    /**
17
     * @var \PlaygroundGame\Service\GameService
18
     */
19
    protected $gameService;
20
21
    protected $prizeService;
22
23
    protected $options;
24
25
    protected $game;
26
27
    protected $user;
28
29
    protected $withGame = array(
30
        'home',
31
        'index',
32
        'terms',
33
        'conditions',
34
        'leaderboard',
35
        'register',
36
        'bounce',
37
        'inviteToTeam',
38
        'prizes',
39
        'prize',
40
        'fangate',
41
        'share',
42
        'optin',
43
        'login',
44
        'logout',
45
        'ajaxforgot',
46
        'play',
47
        'result',
48
        'preview',
49
        'list'
50
    );
51
52
    protected $withOnlineGame = array(
53
        'leaderboard',
54
        'register',
55
        'bounce',
56
        'play',
57
        'result'
58
    );
59
60
    protected $withAnyUser = array(
61
        'share',
62
        'result',
63
        'play',
64
        'logout',
65
        'inviteToTeam'
66
    );
67
68
    public function setEventManager(\Zend\EventManager\EventManagerInterface $events)
69
    {
70
        parent::setEventManager($events);
71
72
        $controller = $this;
73
        $events->attach('dispatch', function (\Zend\Mvc\MvcEvent $e) use ($controller) {
74
75
            $identifier = $e->getRouteMatch()->getParam('id');
76
            $controller->game = $controller->getGameService()->checkGame($identifier, false);
77
            if (!$controller->game &&
78
                in_array($controller->params('action'), $controller->withGame)
79
            ) {
80
                return $controller->notFoundAction();
81
            }
82
83
            if ($controller->game &&
84
                $controller->game->isClosed() &&
85
                in_array($controller->params('action'), $controller->withOnlineGame)
86
            ) {
87
                return $controller->notFoundAction();
88
            }
89
90
            if ($controller->game) {
91
                // this is possible to create a specific game design in /design/frontend/default/custom.
92
                //It will precede all others templates.
93
                $templatePathResolver = $controller->getServiceLocator()->get('Zend\View\Resolver\TemplatePathStack');
94
                $l = $templatePathResolver->getPaths();
95
                $templatePathResolver->addPath($l[0].'custom/'.$controller->game->getIdentifier());
96
            }
97
98
            $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...
99
            if ($controller->game &&
100
                !$controller->user &&
101
                !$controller->game->getAnonymousAllowed() &&
102
                in_array($controller->params('action'), $controller->withAnyUser)
103
            ) {
104
                $redirect = urlencode(
105
                    $controller->url()->fromRoute(
106
                        'frontend/'.$controller->game->getClassType() . '/' . $controller->params('action'),
107
                        array('id' => $controller->game->getIdentifier()),
108
                        array('force_canonical' => true)
109
                    )
110
                );
111
112
                $urlRegister = $controller->url()->fromRoute(
113
                    'frontend/zfcuser/register',
114
                    array(),
115
                    array('force_canonical' => true)
116
                ) . '?redirect='.$redirect;
117
118
                // code permettant d'identifier un custom game
119
                // ligne $config = $controller->getGameService()->getServiceManager()->get('config');
120
                // ligne $customUrl = str_replace('frontend.', '', $e->getRouteMatch()->getParam('area', ''));
121
                // ligne if ($config['custom_games'][$controller->game->getIdentifier()] &&
122
                // ligne    $controller->getRequest()->getUri()->getHost() === $customUrl
123
                // ligne ) {
124
                return $controller->redirect()->toUrl($urlRegister);
125
            }
126
127
            return;
128
        }, 100); // execute before executing action logic
129
    }
130
131
    /**
132
     * Action called if matched action does not exist
133
     * For this view not to be catched by Zend\Mvc\View\RouteNotFoundStrategy
134
     * it has to be rendered in the controller. Hence the code below.
135
     *
136
     * This action is injected as a catchall action for each custom_games definition
137
     * This way, when a custom_game is created, the 404 is it's responsability and the
138
     * view can be defined in design/frontend/default/custom/$slug/playground_game/$gametype/404.phtml
139
     *
140
     *
141
     * @return \Zend\Stdlib\ResponseInterface
142
     */
143
    public function notFoundAction()
144
    {
145
        $templatePathResolver = $this->getServiceLocator()->get('Zend\View\Resolver\TemplatePathStack');
146
147
        // I create a template path in which I can find a custom template
148
        $controller = explode('\\', get_class($this));
149
        $controllerPath = str_replace('Controller', '', end($controller));
150
        $controllerPath = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '-\\1', $controllerPath));
151
        $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...
152
        if ($this->game) {
153
            $uri = str_replace($controllerPath.'/'.$this->game->getIdentifier().'/', '', $uri);
154
        }
155
        $uri = str_replace("/" . $this->getEvent()->getRouteMatch()->getParam('locale') . "/", "/", $uri);
156
        $template = 'playground-game/'.$controllerPath . '/custom' . $uri;
157
158
        if (false === $templatePathResolver->resolve($template)) {
159
            $viewRender     = $this->getServiceLocator()->get('ViewRenderer');
160
161
            $this->getEvent()->getRouteMatch()->setParam('action', 'not-found');
162
            $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...
163
164
            $res = 'error/404';
165
166
            $viewModel = $this->buildView($this->game);
167
            $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...
168
169
            $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...
170
            $this->response->setContent($viewRender->render($this->layout()));
171
172
            return $this->response;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->response; (Zend\Stdlib\ResponseInterface) is incompatible with the return type of the parent method Zend\Mvc\Controller\Abst...troller::notFoundAction of type array.

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

Let’s take a look at an example:

class Author {
    private $name;

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

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

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

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

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

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

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

Loading history...
173
        }
174
175
        $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 178 which is incompatible with the return type documented by PlaygroundGame\Controlle...troller::notFoundAction of type Zend\Stdlib\ResponseInterface.
Loading history...
176
        $viewModel->setTemplate($template);
177
178
        return $viewModel;
179
    }
180
181
    /**
182
     * This action acts as a hub : Depending on the first step of the game, it will forward the action to this step
183
     */
184
    public function homeAction()
185
    {
186
        // This fix exists only for safari in FB on Windows : we need to redirect the user to the page
187
        // outside of iframe for the cookie to be accepted. PlaygroundCore redirects to the FB Iframed page when
188
        // it discovers that the user arrives for the first time on the game in FB.
189
        // When core redirects, it adds a 'redir_fb_page_id' var in the querystring
190
        // Here, we test if this var exist, and then send the user back to the game in FB.
191
        // Now the cookie will be accepted by Safari...
192
        $pageId = $this->params()->fromQuery('redir_fb_page_id');
193
        if (!empty($pageId)) {
194
            $appId = 'app_'.$this->game->getFbAppId();
195
            $url = '//www.facebook.com/pages/game/'.$pageId.'?sk='.$appId;
196
197
            return $this->redirect()->toUrl($url);
198
        }
199
200
        // If an entry has already been done during this session, I reset the anonymous_identifier cookie
201
        // so that another person can play the same game (if game conditions are fullfilled)
202
        $session = new Container('anonymous_identifier');
203
        if ($session->offsetExists('anonymous_identifier')) {
204
            $session->offsetUnset('anonymous_identifier');
205
        }
206
        
207
        return $this->forward()->dispatch(
208
            'playgroundgame_'.$this->game->getClassType(),
209
            array(
210
                'controller' => 'playgroundgame_'.$this->game->getClassType(),
211
                'action' => $this->game->firstStep(),
212
                'id' => $this->game->getIdentifier()
213
            )
214
        );
215
    }
216
217
    /**
218
     * Homepage of the game
219
     */
220
    public function indexAction()
221
    {
222
        $isSubscribed = false;
223
224
        $entry = $this->getGameService()->checkExistingEntry($this->game, $this->user);
225
        if ($entry) {
226
            $isSubscribed = true;
227
        }
228
229
        $viewModel = $this->buildView($this->game);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->buildView($this->game); of type Zend\Http\PhpEnvironment...nd\View\Model\ViewModel adds the type Zend\Http\PhpEnvironment\Response to the return on line 234 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...
230
        $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...
231
            'isSubscribed' => $isSubscribed
232
        ));
233
234
        return $viewModel;
235
    }
236
237
    /**
238
      * leaderboardAction
239
      *
240
      * @return ViewModel $viewModel
241
      */
242
    public function leaderboardAction()
243
    {
244
        $filter = $this->getEvent()->getRouteMatch()->getParam('filter');
245
        $p = $this->getEvent()->getRouteMatch()->getParam('p');
246
247
        $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...
248
        $subViewModel = $this->forward()->dispatch(
249
            'playgroundreward',
250
            array('action' => 'leaderboard', 'filter' => $filter, 'p' => $p)
251
        );
252
        
253
        // suite au forward, le template de layout a changé, je dois le rétablir...
254
        $this->layout()->setTemplate($beforeLayout);
255
        $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...
256
            array(
257
                'action' => $this->params('action'),
258
                'game' => $this->game,
259
            )
260
        );
261
        
262
        $subViewModel->setVariables($this->getShareData($this->game));
263
        $subViewModel->setVariables(array('game' => $this->game, 'user' => $this->user));
264
265
        return $subViewModel;
266
    }
267
268
    /**
269
     * This action has been designed to be called by other controllers
270
     * It gives the ability to display an information form and persist it in the game entry
271
     *
272
     * @return \Zend\View\Model\ViewModel
273
     */
274
    public function registerAction()
275
    {
276
        $form = $this->getGameService()->createFormFromJson($this->game->getPlayerForm()->getForm(), 'playerForm');
277
278
        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...
279
            // POST Request: Process form
280
            $data = array_merge_recursive(
281
                $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...
282
                $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...
283
            );
284
            
285
            $form->setData($data);
286
287
            if ($form->isValid()) {
288
                // steps of the game
289
                $steps = $this->game->getStepsArray();
290
                // sub steps of the game
291
                $viewSteps = $this->game->getStepsViewsArray();
292
293
                // register position
294
                $key = array_search($this->params('action'), $viewSteps);
295
                if (!$key) {
296
                    // register is not a substep of the game so it's a step
297
                    $key = array_search($this->params('action'), $steps);
298
                    $keyStep = true;
299
                } else {
300
                    // register was a substep, i search the index of its parent
301
                    $key = array_search($key, $steps);
302
                    $keyStep = false;
303
                }
304
305
                // play position
306
                $keyplay = array_search('play', $viewSteps);
307
308
                if (!$keyplay) {
309
                    // play is not a substep, so it's a step
310
                    $keyplay = array_search('play', $steps);
311
                    $keyplayStep = true;
312
                } else {
313
                    // play is a substep so I search the index of its parent
314
                    $keyplay = array_search($keyplay, $steps);
315
                    $keyplayStep = false;
316
                }
317
318
                // If register step before play, I don't have no entry yet. I have to create one
319
                // If register after play step, I search for the last entry created by play step.
320
321
                if ($key < $keyplay || ($keyStep && !$keyplayStep && $key <= $keyplay)) {
322
                    $entry = $this->getGameService()->play($this->game, $this->user);
323 View Code Duplication
                    if (!$entry) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

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

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

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

Loading history...
545
                return $this->redirect()->toUrl(
546
                    $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...
547
                        $this->game->getClassType(),
548
                        array('id' => $this->game->getIdentifier())
549
                    )
550
                );
551
            }
552
        }
553
    
554
        $form = $this->getServiceLocator()->get('playgroundgame_sharemail_form');
555
        $form->setAttribute('method', 'post');
556
557
        // buildView must be before sendMail because it adds the game template path to the templateStack
558
        $viewModel = $this->buildView($this->game);
559
    
560
        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...
561
            $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...
562
            $form->setData($data);
563 View Code Duplication
            if ($form->isValid()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
564
                $result = $this->getGameService()->sendShareMail($data, $this->game, $this->user, $lastEntry);
565
                if ($result) {
566
                    $statusMail = true;
567
                }
568
            }
569
        }
570
571
        $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...
572
            'statusMail'       => $statusMail,
573
            'form'             => $form,
574
        ));
575
    
576
        return $viewModel;
577
    }
578
    
579
    public function inviteToTeamAction()
580
    {
581
        $statusMail = null;
582
        $message = '';
583
    
584
        $form = $this->getServiceLocator()->get('playgroundgame_sharemail_form');
585
        $form->setAttribute('method', 'post');
586
587
        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...
588
            $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...
589
            $form->setData($data);
590
            if ($form->isValid()) {
591
                $result = $this->getGameService()->inviteToTeam($data, $this->game, $this->user);
592
                if ($result['result']) {
593
                    $statusMail = true;
594
                } else {
595
                    $statusMail = false;
596
                    $message = $result['message'];
597
                }
598
            }
599
        }
600
601
        $viewModel = $this->buildView($this->game);
602
        $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...
603
            'message' => $message,
604
            'statusMail' => $statusMail,
605
            'form' => $form,
606
        ));
607
    
608
        return $viewModel;
609
    }
610
611 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...
612
    {
613
        $viewModel = new JsonModel();
614
        $viewModel->setTerminal(true);
615
        $fbId = $this->params()->fromQuery('fbId');
616
        if (!$this->game) {
617
            return $this->errorJson();
618
        }
619
        $entry = $this->getGameService()->checkExistingEntry($this->game, $this->user);
620
        if (! $entry) {
621
            return $this->errorJson();
622
        }
623
        if (!$fbId) {
624
            return $this->errorJson();
625
        }
626
    
627
        $this->getGameService()->postFbWall($fbId, $this->game, $this->user, $entry);
628
    
629
        return $this->successJson();
630
    }
631
    
632
    public function fbrequestAction()
633
    {
634
        $viewModel = new ViewModel();
635
        $viewModel->setTerminal(true);
636
        $fbId = $this->params()->fromQuery('fbId');
637
        $to = $this->params()->fromQuery('to');
638
    
639
        if (!$this->game) {
640
            return $this->errorJson();
641
        }
642
        $entry = $this->getGameService()->checkExistingEntry($this->game, $this->user);
643
        if (! $entry) {
644
            return $this->errorJson();
645
        }
646
        if (!$fbId) {
647
            return $this->errorJson();
648
        }
649
    
650
        $this->getGameService()->postFbRequest($fbId, $this->game, $this->user, $entry, $to);
651
    
652
        return $this->successJson();
653
    }
654
    
655
    public function tweetAction()
656
    {
657
        $tweetId = $this->params()->fromQuery('tweetId');
658
    
659
        if (!$this->game) {
660
            return $this->errorJson();
661
        }
662
        $entry = $this->getGameService()->checkExistingEntry($this->game, $this->user);
663
        if (! $entry) {
664
            return $this->errorJson();
665
        }
666
        if (!$tweetId) {
667
            return $this->errorJson();
668
        }
669
    
670
        $this->getGameService()->postTwitter($tweetId, $this->game, $this->user, $entry);
671
    
672
        return $this->successJson();
673
    }
674
    
675 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...
676
    {
677
        $viewModel = new ViewModel();
678
        $viewModel->setTerminal(true);
679
        $googleId = $this->params()->fromQuery('googleId');
680
681
        if (!$this->game) {
682
            return $this->errorJson();
683
        }
684
        $entry = $this->getGameService()->checkExistingEntry($this->game, $this->user);
685
        if (! $entry) {
686
            return $this->errorJson();
687
        }
688
        if (!$googleId) {
689
            return $this->errorJson();
690
        }
691
    
692
        $this->getGameService()->postGoogle($googleId, $this->game, $this->user, $entry);
693
    
694
        return $this->successJson();
695
    }
696
697
    public function optinAction()
698
    {
699
        $userService = $this->getServiceLocator()->get('zfcuser_user_service');
700
701
        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...
702
            $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...
703
            $data['optinPartner'] = ($this->params()->fromPost('optinPartner'))? 1:0;
704
705
            $userService->updateNewsletter($data);
706
        }
707
708
        return $this->redirect()->toUrl(
709
            $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...
710
                $this->game->getClassType(),
711
                array('id' => $this->game->getIdentifier())
712
            )
713
        );
714
    }
715
    
716
    public function loginAction()
717
    {
718
        $request = $this->getRequest();
719
        $form = $this->getServiceLocator()->get('zfcuser_login_form');
720
    
721
        if ($request->isPost()) {
722
            $form->setData($request->getPost());
723
            
724
            if (!$form->isValid()) {
725
                $this->flashMessenger()->addMessage(
726
                    'Authentication failed. Please try again.'
727
                );
728
729
                $viewModel = $this->buildView($this->game);
730
                $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...
731
                    'form' => $form,
732
                    'flashMessages' => $this->flashMessenger()->getMessages(),
733
                ));
734
                
735
                return $viewModel;
736
            }
737
            
738
            // clear adapters
739
            $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...
740
            $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...
741
742
            $logged = $this->forward()->dispatch('playgrounduser_user', array('action' => 'ajaxauthenticate'));
743
744
            if (!$logged) {
745
                $this->flashMessenger()->addMessage(
746
                    'Authentication failed. Please try again.'
747
                );
748
                
749
                return $this->redirect()->toUrl(
750
                    $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...
751
                        $this->game->getClassType() . '/login',
752
                        array('id' => $this->game->getIdentifier())
753
                    )
754
                );
755
            } else {
756
                return $this->redirect()->toUrl(
757
                    $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...
758
                        $this->game->getClassType() . '/index',
759
                        array('id' => $this->game->getIdentifier())
760
                    )
761
                );
762
            }
763
        }
764
        
765
        $form->setAttribute(
766
            'action',
767
            $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...
768
                $this->game->getClassType().'/login',
769
                array('id' => $this->game->getIdentifier())
770
            )
771
        );
772
        $viewModel = $this->buildView($this->game);
773
        $viewModel->setVariables(array(
774
            'form' => $form,
775
            'flashMessages' => $this->flashMessenger()->getMessages(),
776
        ));
777
        return $viewModel;
778
    }
779
780 View Code Duplication
    public function logoutAction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
781
    {
782
        $viewModel = $this->forward()->dispatch(
783
            'playgrounduser_user',
784
            array(
785
                'controller' => 'playgrounduser_user',
786
                'action' => 'logout',
787
                'id' => $this->game->getIdentifier()
788
            )
789
        );
790
791
        if ($viewModel && $viewModel instanceof \Zend\View\Model\ViewModel) {
792
            $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...
793
            $viewModel->setVariables(array('game' => $this->game));
794
        }
795
796
        return $viewModel;
797
    }
798
799
    public function userregisterAction()
800
    {
801
        $userOptions = $this->getServiceLocator()->get('zfcuser_module_options');
802
803
        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...
804
            return $this->redirect()->toUrl(
805
                $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...
806
                    $this->game->getClassType().'/'.$this->game->nextStep('index'),
807
                    array('id' => $this->game->getIdentifier())
808
                )
809
            );
810
        }
811
        $request = $this->getRequest();
812
        $service = $this->getServiceLocator()->get('zfcuser_user_service');
813
        $form = $this->getServiceLocator()->get('playgroundgame_register_form');
814
        $socialnetwork = $this->params()->fromRoute('socialnetwork', false);
815
        $form->setAttribute(
816
            'action',
817
            $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...
818
                $this->game->getClassType().'/user-register',
819
                array('id' => $this->game->getIdentifier())
820
            )
821
        );
822
        $params = array();
823
        $socialCredentials = array();
824
825
        if ($userOptions->getUseRedirectParameterIfPresent() && $request->getQuery()->get('redirect')) {
826
            $redirect = $request->getQuery()->get('redirect');
827
        } else {
828
            $redirect = false;
829
        }
830
831
        if ($socialnetwork) {
832
            $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...
833
834
            if (!empty($infoMe)) {
835
                $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...
836
                    $infoMe->identifier,
837
                    $socialnetwork
838
                );
839
840
                if ($user || $service->getOptions()->getCreateUserAutoSocial() === true) {
841
                    //on le dirige vers l'action d'authentification
842
                    if (! $redirect && $userOptions->getLoginRedirectRoute() != '') {
843
                        $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...
844
                            $this->game->getClassType().'/login',
845
                            array('id' => $this->game->getIdentifier())
846
                        );
847
                    }
848
                    $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...
849
                        $this->game->getClassType().'/login',
850
                        array('id' => $this->game->getIdentifier())
851
                    ) .'/' . $socialnetwork . ($redirect ? '?redirect=' . $redirect : '');
852
853
                    return $this->redirect()->toUrl($redir);
854
                }
855
856
                // Je retire la saisie du login/mdp
857
                $form->setAttribute(
858
                    'action',
859
                    $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...
860
                        $this->game->getClassType().'/user-register',
861
                        array(
862
                            'id' => $this->game->getIdentifier(),
863
                            'socialnetwork' => $socialnetwork,
864
                            
865
                        )
866
                    )
867
                );
868
                $form->remove('password');
869
                $form->remove('passwordVerify');
870
871
                $birthMonth = $infoMe->birthMonth;
872
                if (strlen($birthMonth) <= 1) {
873
                    $birthMonth = '0'.$birthMonth;
874
                }
875
                $birthDay = $infoMe->birthDay;
876
                if (strlen($birthDay) <= 1) {
877
                    $birthDay = '0'.$birthDay;
878
                }
879
880
                $gender = $infoMe->gender;
881
                if ($gender == 'female') {
882
                    $title = 'Me';
883
                } else {
884
                    $title = 'M';
885
                }
886
887
                $params = array(
888
                    //'birth_year'  => $infoMe->birthYear,
889
                    'title'      => $title,
890
                    'dob'      => $birthDay.'/'.$birthMonth.'/'.$infoMe->birthYear,
891
                    'firstname'   => $infoMe->firstName,
892
                    'lastname'    => $infoMe->lastName,
893
                    'email'       => $infoMe->email,
894
                    'postalCode' => $infoMe->zip,
895
                );
896
                $socialCredentials = array(
897
                    'socialNetwork' => strtolower($socialnetwork),
898
                    'socialId'      => $infoMe->identifier,
899
                );
900
            }
901
        }
902
903
        $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...
904
            $this->game->getClassType().'/user-register',
905
            array('id' => $this->game->getIdentifier())
906
        ) .($socialnetwork ? '/' . $socialnetwork : ''). ($redirect ? '?redirect=' . $redirect : '');
907
        $prg = $this->prg($redirectUrl, true);
908
909
        if ($prg instanceof Response) {
910
            return $prg;
911
        } elseif ($prg === false) {
912
            $form->setData($params);
913
            $viewModel = $this->buildView($this->game);
914
            $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...
915
                'registerForm' => $form,
916
                'enableRegistration' => $userOptions->getEnableRegistration(),
917
                'redirect' => $redirect,
918
            ));
919
            return $viewModel;
920
        }
921
922
        $post = $prg;
923
        $post = array_merge(
924
            $post,
925
            $socialCredentials
926
        );
927
928
        if ($this->game->getOnInvitation()) {
929
            $credential = trim(
930
                $post[$this->getGameService()->getOptions()->getOnInvitationField()]
931
            );
932
            if (!$credential) {
933
                $credential = $this->params()->fromQuery(
934
                    $this->getGameService()->getOptions()->getOnInvitationField()
935
                );
936
            }
937
            $found = $this->getGameService()->getInvitationMapper()->findOneBy(array('requestKey'=>$credential));
938
939
            if (!$found || !empty($found->getUser())) {
940
                $this->flashMessenger()->addMessage(
941
                    'Authentication failed. Please try again.'
942
                );
943
                $form->setData($post);
944
                $viewModel = $this->buildView($this->game);
945
                $viewModel->setVariables(array(
946
                    'registerForm' => $form,
947
                    'enableRegistration' => $userOptions->getEnableRegistration(),
948
                    'redirect' => $redirect,
949
                    'flashMessages'    => $this->flashMessenger()->getMessages(),
950
                    'flashErrors'      => $this->flashMessenger()->getErrorMessages(),
951
                ));
952
953
                return $viewModel;
954
            }
955
        }
956
957
        $user = $service->register($post, 'playgroundgame_register_form');
958
959
        if (! $user) {
960
            $viewModel = $this->buildView($this->game);
961
            $viewModel->setVariables(array(
962
                'registerForm' => $form,
963
                'enableRegistration' => $userOptions->getEnableRegistration(),
964
                'redirect' => $redirect,
965
                'flashMessages'    => $this->flashMessenger()->getMessages(),
966
                'flashErrors'      => $this->flashMessenger()->getErrorMessages(),
967
            ));
968
            
969
            return $viewModel;
970
        }
971
972
        if ($this->game->getOnInvitation()) {
973
            // user has been created, associate the code with the userId
974
            $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...
975
            $this->getGameService()->getInvitationMapper()->update($found);
976
        }
977
978
        if ($service->getOptions()->getEmailVerification()) {
979
            $vm = new ViewModel(array('userEmail' => $user->getEmail()));
980
            $vm->setTemplate('playground-user/register/registermail');
981
982
            return $vm;
983
        } elseif ($service->getOptions()->getLoginAfterRegistration()) {
984
            $identityFields = $service->getOptions()->getAuthIdentityFields();
985
            if (in_array('email', $identityFields)) {
986
                $post['identity'] = $user->getEmail();
987
            } elseif (in_array('username', $identityFields)) {
988
                $post['identity'] = $user->getUsername();
989
            }
990
            $post['credential'] = isset($post['password'])?$post['password']:'';
991
            $request->setPost(new Parameters($post));
992
993
            // clear adapters
994
            $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...
995
            $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...
996
997
            $logged = $this->forward()->dispatch('playgrounduser_user', array('action' => 'ajaxauthenticate'));
998
999
            if ($logged) {
1000
                return $this->redirect()->toUrl(
1001
                    $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...
1002
                        $this->game->getClassType(),
1003
                        array('id' => $this->game->getIdentifier())
1004
                    )
1005
                );
1006
            } else {
1007
                $this->flashMessenger()->setNamespace('zfcuser-login-form')->addMessage(
1008
                    'Authentication failed. Please try again.'
1009
                );
1010
                return $this->redirect()->toUrl(
1011
                    $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...
1012
                        $this->game->getClassType() . '/login',
1013
                        array('id' => $this->game->getIdentifier())
1014
                    )
1015
                );
1016
            }
1017
        }
1018
1019
        $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...
1020
            $this->game->getClassType().'/login',
1021
            array('id' => $this->game->getIdentifier())
1022
        ) . ($socialnetwork ? '/' . $socialnetwork : ''). ($redirect ? '?redirect=' . $redirect : '');
1023
1024
        return $this->redirect()->toUrl($redirect);
1025
    }
1026
1027 View Code Duplication
    public function userProfileAction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
1028
    {
1029
        $viewModel = $this->forward()->dispatch(
1030
            'playgrounduser_user',
1031
            array(
1032
                'controller' => 'playgrounduser_user',
1033
                'action' => 'profile',
1034
                'id' => $this->game->getIdentifier()
1035
            )
1036
        );
1037
1038
        if ($viewModel && $viewModel instanceof \Zend\View\Model\ViewModel) {
1039
            $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...
1040
            $viewModel->setVariables(array('game' => $this->game));
1041
        }
1042
1043
        return $viewModel;
1044
    }
1045
1046
    public function userresetAction()
1047
    {
1048
        $viewModel = $this->forward()->dispatch(
1049
            'playgrounduser_forgot',
1050
            array(
1051
                'controller' => 'playgrounduser_forgot',
1052
                'action' => 'reset',
1053
                'id' => $this->game->getIdentifier(),
1054
                'userId' => $this->params()->fromRoute('userId', null),
1055
                'token' => $this->params()->fromRoute('token', null),
1056
            )
1057
        );
1058
1059
        if ($viewModel && $viewModel instanceof \Zend\View\Model\ViewModel) {
1060
            $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...
1061
            $viewModel->setVariables(array('game' => $this->game));
1062
        }
1063
1064
        return $viewModel;
1065
    }
1066
1067 View Code Duplication
    public function ajaxforgotAction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
1068
    {
1069
        $view = $this->forward()->dispatch(
1070
            'playgrounduser_forgot',
1071
            array(
1072
                'controller' => 'playgrounduser_forgot',
1073
                'action' => 'ajaxforgot',
1074
                'id' => $this->game->getIdentifier()
1075
            )
1076
        );
1077
1078
        if ($view && $view instanceof \Zend\View\Model\ViewModel) {
1079
            $this->layout()->setVariables(array('game' => $this->game));
0 ignored issues
show
Bug introduced by
The method setVariables does only exist in Zend\View\Model\ModelInterface, but not in Zend\Mvc\Controller\Plugin\Layout.

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

Let’s take a look at an example:

class A
{
    public function foo() { }
}

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

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

Available Fixes

  1. Add an additional type-check:

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

    function someFunction(B $x) { /** ... */ }
    
Loading history...
1080
            $view->setVariables(array('game' => $this->game));
1081
        }
1082
1083
        return $view;
1084
    }
1085
1086 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...
1087
    {
1088
        $viewModel = $this->forward()->dispatch(
1089
            'playgroundcms',
1090
            array(
1091
                'controller' => 'playgroundcms',
1092
                'action' => 'index',
1093
                'id' => $this->game->getIdentifier(),
1094
                'pid' => $this->getEvent()->getRouteMatch()->getParam('pid')
1095
            )
1096
        );
1097
1098
        if ($viewModel && $viewModel instanceof \Zend\View\Model\ViewModel) {
1099
            $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...
1100
            $viewModel->setVariables(array('game' => $this->game));
1101
        }
1102
1103
        return $viewModel;
1104
    }
1105
1106 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...
1107
    {
1108
        $viewModel = $this->forward()->dispatch(
1109
            'playgroundcms',
1110
            array(
1111
                'controller' => 'playgroundcms',
1112
                'action' => 'list',
1113
                'id' => $this->game->getIdentifier(),
1114
                'category' => $this->game->getIdentifier()
1115
            )
1116
        );
1117
1118
        if ($viewModel && $viewModel instanceof \Zend\View\Model\ViewModel) {
1119
            $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...
1120
            $viewModel->setVariables(array('game' => $this->game));
1121
        }
1122
1123
        return $viewModel;
1124
    }
1125
1126
    /**
1127
     *
1128
     * @param \PlaygroundGame\Entity\Game $game
1129
     * @param \PlaygroundUser\Entity\User $user
1130
     */
1131
    public function checkFbRegistration($user, $game)
1132
    {
1133
        $redirect = false;
1134
        $session = new Container('facebook');
1135
        if ($session->offsetExists('signed_request')) {
1136
            if (!$user) {
1137
                // Get Playground user from Facebook info
1138
                $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...
1139
                $view = $this->forward()->dispatch(
1140
                    'playgrounduser_user',
1141
                    array(
1142
                        'controller' => 'playgrounduser_user',
1143
                        'action' => 'registerFacebookUser',
1144
                        'provider' => 'facebook'
1145
                    )
1146
                );
1147
1148
                $this->layout()->setTemplate($beforeLayout);
1149
                $user = $view->user;
1150
1151
                // If the user can not be created/retrieved from Facebook info, redirect to login/register form
1152
                if (!$user) {
1153
                    $redirectUrl = urlencode(
1154
                        $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
                            $game->getClassType() .'/play',
1156
                            array('id' => $game->getIdentifier()),
1157
                            array('force_canonical' => true)
1158
                        )
1159
                    );
1160
                    $redirect =  $this->redirect()->toUrl(
1161
                        $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...
1162
                            'zfcuser/register'
1163
                        ) . '?redirect='.$redirectUrl
1164
                    );
1165
                }
1166
            }
1167
1168
            if ($game->getFbFan()) {
1169
                if ($this->getGameService()->checkIsFan($game) === false) {
1170
                    $redirect =  $this->redirect()->toRoute(
1171
                        $game->getClassType().'/fangate',
1172
                        array('id' => $game->getIdentifier())
1173
                    );
1174
                }
1175
            }
1176
        }
1177
1178
        return $redirect;
1179
    }
1180
1181
    /**
1182
     * This method create the basic Game view
1183
     * @param \PlaygroundGame\Entity\Game $game
1184
     */
1185
    public function buildView($game)
1186
    {
1187
        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...
1188
            $viewModel = new JsonModel();
1189
            if ($game) {
1190
                $view = $this->addAdditionalView($game);
1191
                if ($view && $view instanceof \Zend\View\Model\ViewModel) {
1192
                    $viewModel->setVariables($view->getVariables());
1193
                }
1194
            }
1195
        } else {
1196
            $viewModel = new ViewModel();
1197
1198
            if ($game) {
1199
                $this->addMetaTitle($game);
1200
                $this->addMetaBitly();
1201
                $this->addGaEvent($game);
1202
1203
                $this->customizeGameDesign($game);
1204
                
1205
                $view = $this->addAdditionalView($game);
1206
                if ($view && $view instanceof \Zend\View\Model\ViewModel) {
1207
                    $viewModel->addChild($view, 'additional');
1208
                } elseif ($view && $view instanceof \Zend\Http\PhpEnvironment\Response) {
1209
                    return $view;
1210
                }
1211
1212
                $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...
1213
                    array(
1214
                        'action' => $this->params('action'),
1215
                        'game' => $game,
1216
                        'flashMessages'    => $this->flashMessenger()->getMessages(),
1217
                        
1218
                    )
1219
                );
1220
1221
                $viewModel->setVariables($this->getShareData($game));
1222
                $viewModel->setVariables(array('game' => $game, 'user' => $this->user));
1223
            }
1224
        }
1225
1226
        return $viewModel;
1227
    }
1228
1229
    /**
1230
     * @param \PlaygroundGame\Entity\Game $game
1231
     */
1232
    public function addAdditionalView($game)
1233
    {
1234
        $view = false;
1235
1236
        $actionName = $this->getEvent()->getRouteMatch()->getParam('action', 'not-found');
1237
        $stepsViews = json_decode($game->getStepsViews(), true);
1238
        if ($stepsViews && isset($stepsViews[$actionName])) {
1239
            $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...
1240
            $actionData = $stepsViews[$actionName];
1241
            if (is_string($actionData)) {
1242
                $action = $actionData;
1243
                $controller = $this->getEvent()->getRouteMatch()->getParam('controller', 'playgroundgame_game');
1244
                $view = $this->forward()->dispatch(
1245
                    $controller,
1246
                    array(
1247
                        'action' => $action,
1248
                        'id' => $game->getIdentifier()
1249
                    )
1250
                );
1251
            } elseif (is_array($actionData) && count($actionData)>0) {
1252
                $action = key($actionData);
1253
                $controller = $actionData[$action];
1254
                $view = $this->forward()->dispatch(
1255
                    $controller,
1256
                    array(
1257
                        'action' => $action,
1258
                        'id' => $game->getIdentifier()
1259
                    )
1260
                );
1261
            }
1262
            // suite au forward, le template de layout a changé, je dois le rétablir...
1263
            $this->layout()->setTemplate($beforeLayout);
1264
        }
1265
1266
        return $view;
1267
    }
1268
1269
    public function addMetaBitly()
1270
    {
1271
        $bitlyclient = $this->getOptions()->getBitlyUrl();
1272
        $bitlyuser = $this->getOptions()->getBitlyUsername();
1273
        $bitlykey = $this->getOptions()->getBitlyApiKey();
1274
1275
        $this->getViewHelper('HeadMeta')->setProperty('bt:client', $bitlyclient);
1276
        $this->getViewHelper('HeadMeta')->setProperty('bt:user', $bitlyuser);
1277
        $this->getViewHelper('HeadMeta')->setProperty('bt:key', $bitlykey);
1278
    }
1279
1280
    /**
1281
     * @param \PlaygroundGame\Entity\Game $game
1282
     */
1283
    public function addGaEvent($game)
1284
    {
1285
        // Google Analytics event
1286
        $ga = $this->getServiceLocator()->get('google-analytics');
1287
        $event = new \PlaygroundCore\Analytics\Event($game->getClassType(), $this->params('action'));
1288
        $event->setLabel($game->getTitle());
1289
        $ga->addEvent($event);
1290
    }
1291
1292
    /**
1293
     * @param \PlaygroundGame\Entity\Game $game
1294
     */
1295
    public function addMetaTitle($game)
1296
    {
1297
        $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...
1298
        $this->getGameService()->getServiceManager()->get('ViewHelperManager')->get('HeadTitle')->set($title);
1299
        // Meta set in the layout
1300
        $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...
1301
            array(
1302
                'breadcrumbTitle' => $title,
1303
                'currentPage' => array(
1304
                    'pageGames' => 'games',
1305
                    'pageWinners' => ''
1306
                ),
1307
                'headParams' => array(
1308
                    'headTitle' => $title,
1309
                    'headDescription' => $title,
1310
                ),
1311
                'bodyCss' => $game->getIdentifier()
1312
            )
1313
        );
1314
    }
1315
1316
    /**
1317
     * @param \PlaygroundGame\Entity\Game $game
1318
     */
1319
    public function customizeGameDesign($game)
1320
    {
1321
        // If this game has a specific layout...
1322
        if ($game->getLayout()) {
1323
            $layoutViewModel = $this->layout();
1324
            $layoutViewModel->setTemplate($game->getLayout());
1325
        }
1326
1327
        // If this game has a specific stylesheet...
1328
        if ($game->getStylesheet()) {
1329
            $this->getViewHelper('HeadLink')->appendStylesheet(
1330
                $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...
1331
            );
1332
        }
1333
    }
1334
1335
    /**
1336
     * @param \PlaygroundGame\Entity\Game $game
1337
     */
1338
    public function getShareData($game)
1339
    {
1340
        $fo = $this->getServiceLocator()->get('facebook-opengraph');
1341
        $session = new Container('facebook');
1342
1343
        // I change the fbappid if i'm in fb
1344
        if ($session->offsetExists('signed_request')) {
1345
            $fo->setId($game->getFbAppId());
1346
        }
1347
1348
        // If I want to add a share block in my view
1349 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...
1350
            $fbShareMessage = $game->getFbShareMessage();
1351
        } else {
1352
            $fbShareMessage = str_replace(
1353
                '__placeholder__',
1354
                $game->getTitle(),
1355
                $this->getOptions()->getDefaultShareMessage()
1356
            );
1357
        }
1358
1359
        if ($game->getFbShareImage()) {
1360
            $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...
1361
                '',
1362
                array(),
1363
                array('force_canonical' => true),
1364
                false
1365
            ) . $game->getFbShareImage();
1366
        } else {
1367
            $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...
1368
                '',
1369
                array(),
1370
                array('force_canonical' => true),
1371
                false
1372
            ) . $game->getMainImage();
1373
        }
1374
1375
        $secretKey = strtoupper(substr(sha1(uniqid('pg_', true).'####'.time()), 0, 15));
1376
1377
        // Without bit.ly shortener
1378
        $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...
1379
            $game->getClassType(),
1380
            array('id' => $game->getIdentifier()),
1381
            array('force_canonical' => true)
1382
        );
1383
        // With core shortener helper
1384
        $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...
1385
1386
        // FB Requests only work when it's a FB app
1387
        if ($game->getFbRequestMessage()) {
1388
            $fbRequestMessage = urlencode($game->getFbRequestMessage());
1389
        } else {
1390
            $fbRequestMessage = str_replace(
1391
                '__placeholder__',
1392
                $game->getTitle(),
1393
                $this->getOptions()->getDefaultShareMessage()
1394
            );
1395
        }
1396
1397 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...
1398
            $twShareMessage = $game->getTwShareMessage() . $socialLinkUrl;
1399
        } else {
1400
            $twShareMessage = str_replace(
1401
                '__placeholder__',
1402
                $game->getTitle(),
1403
                $this->getOptions()->getDefaultShareMessage()
1404
            ) . $socialLinkUrl;
1405
        }
1406
1407
        $ogTitle = new \PlaygroundCore\Opengraph\Tag('og:title', $fbShareMessage);
1408
        $ogImage = new \PlaygroundCore\Opengraph\Tag('og:image', $fbShareImage);
1409
        
1410
        $fo->addTag($ogTitle);
1411
        $fo->addTag($ogImage);
1412
        
1413
        $data = array(
1414
            'socialLinkUrl'       => $socialLinkUrl,
1415
            'secretKey'           => $secretKey,
1416
            'fbShareMessage'      => $fbShareMessage,
1417
            'fbShareImage'        => $fbShareImage,
1418
            'fbRequestMessage'    => $fbRequestMessage,
1419
            'twShareMessage'      => $twShareMessage,
1420
        );
1421
1422
        return $data;
1423
    }
1424
    
1425
    /**
1426
     * return ajax response in json format
1427
     *
1428
     * @param array $data
1429
     * @return \Zend\View\Model\JsonModel
1430
     */
1431 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...
1432
    {
1433
        $model = new JsonModel(array(
1434
            'success' => true,
1435
            'data' => $data
1436
        ));
1437
        return $model->setTerminal(true);
1438
    }
1439
    
1440
    /**
1441
     * return ajax response in json format
1442
     *
1443
     * @param string $message
1444
     * @return \Zend\View\Model\JsonModel
1445
     */
1446 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...
1447
    {
1448
        $model = new JsonModel(array(
1449
            'success' => false,
1450
            'message' => $message
1451
        ));
1452
        return $model->setTerminal(true);
1453
    }
1454
1455
    /**
1456
     * @param string $helperName
1457
     */
1458
    protected function getViewHelper($helperName)
1459
    {
1460
        return $this->getServiceLocator()->get('viewhelpermanager')->get($helperName);
1461
    }
1462
1463
    public function getGameService()
1464
    {
1465
        if (!$this->gameService) {
1466
            $this->gameService = $this->getServiceLocator()->get('playgroundgame_lottery_service');
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getServiceLocator...dgame_lottery_service') can also be of type array. However, the property $gameService is declared as type object<PlaygroundGame\Service\GameService>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

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

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
1467
        }
1468
1469
        return $this->gameService;
1470
    }
1471
1472
    public function setGameService(GameService $gameService)
1473
    {
1474
        $this->gameService = $gameService;
1475
1476
        return $this;
1477
    }
1478
1479
    public function getPrizeService()
1480
    {
1481
        if (!$this->prizeService) {
1482
            $this->prizeService = $this->getServiceLocator()->get('playgroundgame_prize_service');
1483
        }
1484
1485
        return $this->prizeService;
1486
    }
1487
1488
    public function setPrizeService(PrizeService $prizeService)
1489
    {
1490
        $this->prizeService = $prizeService;
1491
1492
        return $this;
1493
    }
1494
1495
    public function getOptions()
1496
    {
1497
        if (!$this->options) {
1498
            $this->setOptions($this->getServiceLocator()->get('playgroundcore_module_options'));
1499
        }
1500
1501
        return $this->options;
1502
    }
1503
1504
    public function setOptions($options)
1505
    {
1506
        $this->options = $options;
1507
1508
        return $this;
1509
    }
1510
}
1511