Completed
Push — master ( 569171...b2f820 )
by greg
19:50 queued 10:54
created

GameController::ajaxforgotAction()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 18
Code Lines 11

Duplication

Lines 18
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 18
loc 18
rs 9.4285
cc 3
eloc 11
nc 2
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
        'prizes',
38
        'prize',
39
        'fangate',
40
        'share',
41
        'optin',
42
        'login',
43
        'ajaxforgot',
44
        'play',
45
        'result',
46
        'preview',
47
        'list'
48
    );
49
50
    protected $withOnlineGame = array(
51
        'leaderboard',
52
        'register',
53
        'bounce',
54
        'play',
55
        'result'
56
    );
57
58
    protected $withAnyUser = array(
59
        'share',
60
        'result',
61
        'play'
62
    );
63
64
    public function setEventManager(\Zend\EventManager\EventManagerInterface $events)
65
    {
66
        parent::setEventManager($events);
67
68
        $controller = $this;
69
        $events->attach('dispatch', function (\Zend\Mvc\MvcEvent $e) use ($controller) {
70
71
            $identifier = $e->getRouteMatch()->getParam('id');
72
            $controller->game = $controller->getGameService()->checkGame($identifier, false);
73
            if (!$controller->game &&
74
                in_array($controller->params('action'), $controller->withGame)
75
            ) {
76
                return $controller->notFoundAction();
77
            }
78
79
            if ($controller->game &&
80
                $controller->game->isClosed() &&
81
                in_array($controller->params('action'), $controller->withOnlineGame)
82
            ) {
83
                return $controller->notFoundAction();
84
            }
85
86
            if ($controller->game) {
87
                // this is possible to create a specific game design in /design/frontend/default/custom.
88
                //It will precede all others templates.
89
                $templatePathResolver = $controller->getServiceLocator()->get('Zend\View\Resolver\TemplatePathStack');
90
                $l = $templatePathResolver->getPaths();
91
                $templatePathResolver->addPath($l[0].'custom/'.$controller->game->getIdentifier());
92
            }
93
94
            $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...
95
            if ($controller->game &&
96
                !$controller->user &&
97
                !$controller->game->getAnonymousAllowed() &&
98
                in_array($controller->params('action'), $controller->withAnyUser)
99
            ) {
100
                $redirect = urlencode(
101
                    $controller->url()->fromRoute(
102
                        'frontend/'.$controller->game->getClassType() . '/' . $controller->params('action'),
103
                        array('id' => $controller->game->getIdentifier()),
104
                        array('force_canonical' => true)
105
                    )
106
                );
107
108
                $urlRegister = $controller->url()->fromRoute(
109
                    'frontend/zfcuser/register',
110
                    array(),
111
                    array('force_canonical' => true)
112
                ) . '?redirect='.$redirect;
113
114
                // code permettant d'identifier un custom game
115
                // ligne $config = $controller->getGameService()->getServiceManager()->get('config');
116
                // ligne $customUrl = str_replace('frontend.', '', $e->getRouteMatch()->getParam('area', ''));
117
                // ligne if ($config['custom_games'][$controller->game->getIdentifier()] &&
118
                // ligne    $controller->getRequest()->getUri()->getHost() === $customUrl
119
                // ligne ) {
120
                return $controller->redirect()->toUrl($urlRegister);
121
            }
122
123
            return;
124
        }, 100); // execute before executing action logic
125
    }
126
127
    /**
128
     * Action called if matched action does not exist
129
     * For this view not to be catched by Zend\Mvc\View\RouteNotFoundStrategy
130
     * it has to be rendered in the controller. Hence the code below.
131
     *
132
     * This action is injected as a catchall action for each custom_games definition
133
     * This way, when a custom_game is created, the 404 is it's responsability and the
134
     * view can be defined in design/frontend/default/custom/$slug/playground_game/$gametype/404.phtml
135
     *
136
     *
137
     * @return \Zend\Stdlib\ResponseInterface
138
     */
139
    public function notFoundAction()
140
    {
141
        $templatePathResolver = $this->getServiceLocator()->get('Zend\View\Resolver\TemplatePathStack');
142
143
        // I create a template path in which I can find a custom template
144
        $controller = explode('\\', get_class($this));
145
        $controllerPath = str_replace('Controller', '', end($controller));
146
        $controllerPath = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '-\\1', $controllerPath));
147
        $template = 'playground-game/'.$controllerPath . '/custom' .$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...
148
149
        if (false === $templatePathResolver->resolve($template)) {
150
            $viewRender     = $this->getServiceLocator()->get('ViewRenderer');
151
152
            $this->getEvent()->getRouteMatch()->setParam('action', 'not-found');
153
            $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...
154
155
            $res = 'error/404';
156
157
            $viewModel = $this->buildView($this->game);
158
            $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...
159
160
            $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...
161
            $this->response->setContent($viewRender->render($this->layout()));
162
163
            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...
164
        }
165
166
        $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 169 which is incompatible with the return type documented by PlaygroundGame\Controlle...troller::notFoundAction of type Zend\Stdlib\ResponseInterface.
Loading history...
167
        $viewModel->setTemplate($template);
168
169
        return $viewModel;
170
    }
171
172
    /**
173
     * This action acts as a hub : Depending on the first step of the game, it will forward the action to this step
174
     */
175
    public function homeAction()
176
    {
177
        // This fix exists only for safari in FB on Windows : we need to redirect the user to the page
178
        // outside of iframe for the cookie to be accepted. PlaygroundCore redirects to the FB Iframed page when
179
        // it discovers that the user arrives for the first time on the game in FB.
180
        // When core redirects, it adds a 'redir_fb_page_id' var in the querystring
181
        // Here, we test if this var exist, and then send the user back to the game in FB.
182
        // Now the cookie will be accepted by Safari...
183
        $pageId = $this->params()->fromQuery('redir_fb_page_id');
184
        if (!empty($pageId)) {
185
            $appId = 'app_'.$this->game->getFbAppId();
186
            $url = '//www.facebook.com/pages/game/'.$pageId.'?sk='.$appId;
187
188
            return $this->redirect()->toUrl($url);
189
        }
190
191
        // If an entry has already been done during this session, I reset the anonymous_identifier cookie
192
        // so that another person can play the same game (if game conditions are fullfilled)
193
        $session = new Container('anonymous_identifier');
194
        if ($session->offsetExists('anonymous_identifier')) {
195
            $session->offsetUnset('anonymous_identifier');
196
        }
197
        
198
        return $this->forward()->dispatch(
199
            'playgroundgame_'.$this->game->getClassType(),
200
            array(
201
                'controller' => 'playgroundgame_'.$this->game->getClassType(),
202
                'action' => $this->game->firstStep(),
203
                'id' => $this->game->getIdentifier()
204
            )
205
        );
206
    }
207
208
    /**
209
     * Homepage of the game
210
     */
211
    public function indexAction()
212
    {
213
        $isSubscribed = false;
214
215
        $entry = $this->getGameService()->checkExistingEntry($this->game, $this->user);
216
        if ($entry) {
217
            $isSubscribed = true;
218
        }
219
220
        $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 225 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...
221
        $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...
222
            'isSubscribed' => $isSubscribed
223
        ));
224
225
        return $viewModel;
226
    }
227
228
    /**
229
      * leaderboardAction
230
      *
231
      * @return ViewModel $viewModel
232
      */
233
    public function leaderboardAction()
234
    {
235
        $filter = $this->getEvent()->getRouteMatch()->getParam('filter');
236
        $p = $this->getEvent()->getRouteMatch()->getParam('p');
237
238
        $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...
239
        $subViewModel = $this->forward()->dispatch(
240
            'playgroundreward',
241
            array('action' => 'leaderboard', 'filter' => $filter, 'p' => $p)
242
        );
243
        
244
        // suite au forward, le template de layout a changé, je dois le rétablir...
245
        $this->layout()->setTemplate($beforeLayout);
246
247
        // give the ability to the game to have its customized look and feel.
248
        $templatePathResolver = $this->getServiceLocator()->get('Zend\View\Resolver\TemplatePathStack');
249
        $l = $templatePathResolver->getPaths();
250
251
        $templatePathResolver->addPath($l[0].'custom/'.$this->game->getIdentifier());
252
253
        return $subViewModel;
254
    }
255
256
    /**
257
     * This action has been designed to be called by other controllers
258
     * It gives the ability to display an information form and persist it in the game entry
259
     *
260
     * @return \Zend\View\Model\ViewModel
261
     */
262
    public function registerAction()
263
    {
264
        $form = $this->getGameService()->createFormFromJson($this->game->getPlayerForm()->getForm(), 'playerForm');
265
266
        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...
267
            // POST Request: Process form
268
            $data = array_merge_recursive(
269
                $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...
270
                $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...
271
            );
272
            
273
            $form->setData($data);
274
275
            if ($form->isValid()) {
276
                // steps of the game
277
                $steps = $this->game->getStepsArray();
278
                // sub steps of the game
279
                $viewSteps = $this->game->getStepsViewsArray();
280
281
                // register position
282
                $key = array_search($this->params('action'), $viewSteps);
283 View Code Duplication
                if (!$key) {
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...
284
                    // register is not a substep of the game so it's a step
285
                    $key = array_search($this->params('action'), $steps);
286
                    $keyStep = true;
287
                } else {
288
                    // register was a substep, i search the index of its parent
289
                    $key = array_search($key, $steps);
290
                    $keyStep = false;
291
                }
292
293
                // play position
294
                $keyplay = array_search('play', $viewSteps);
295
296 View Code Duplication
                if (!$keyplay) {
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...
297
                    // play is not a substep, so it's a step
298
                    $keyplay = array_search('play', $steps);
299
                    $keyplayStep = true;
300
                } else {
301
                    // play is a substep so I search the index of its parent
302
                    $keyplay = array_search($keyplay, $steps);
303
                    $keyplayStep = false;
304
                }
305
306
                // If register step before play, I don't have no entry yet. I have to create one
307
                // If register after play step, I search for the last entry created by play step.
308
309
                if ($key < $keyplay || ($keyStep && !$keyplayStep && $key <= $keyplay)) {
310
                    $entry = $this->getGameService()->play($this->game, $this->user);
311
                    if (!$entry) {
312
                        // the user has already taken part of this game and the participation limit has been reached
313
                        $this->flashMessenger()->addMessage('Vous avez déjà participé');
314
                    
315
                        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...
316
                            $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...
317
                                $this->game->getClassType().'/result',
318
                                array(
319
                                    'id' => $this->game->getIdentifier(),
320
                                    
321
                                )
322
                            )
323
                        );
324
                    }
325
                } else {
326
                    // I'm looking for an entry without anonymousIdentifier (the active entry in fact).
327
                    $entry = $this->getGameService()->findLastEntry($this->game, $this->user);
328
                    if ($this->getGameService()->hasReachedPlayLimit($this->game, $this->user)) {
329
                        // the user has already taken part of this game and the participation limit has been reached
330
                        $this->flashMessenger()->addMessage('Vous avez déjà participé');
331
                    
332
                        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...
333
                            $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...
334
                                $this->game->getClassType().'/result',
335
                                array(
336
                                    'id' => $this->game->getIdentifier(),
337
                                    
338
                                )
339
                            )
340
                        );
341
                    }
342
                }
343
344
                $this->getGameService()->updateEntryPlayerForm($form->getData(), $this->game, $this->user, $entry);
345
346
                if (!empty($this->game->nextStep($this->params('action')))) {
347
                    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...
348
                        $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...
349
                            $this->game->getClassType() .'/' . $this->game->nextStep($this->params('action')),
350
                            array('id' => $this->game->getIdentifier()),
351
                            array('force_canonical' => true)
352
                        )
353
                    );
354
                }
355
            }
356
        }
357
358
        $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 363 which is incompatible with the return type documented by PlaygroundGame\Controlle...troller::registerAction of type Zend\View\Model\ViewModel.
Loading history...
359
        $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...
360
            'form' => $form
361
        ));
362
363
        return $viewModel;
364
    }
365
366
    /**
367
     * This action takes care of the terms of the game
368
     */
369
    public function termsAction()
370
    {
371
        $viewModel = $this->buildView($this->game);
372
373
        return $viewModel;
374
    }
375
376
    /**
377
     * This action takes care of the conditions of the game
378
     */
379
    public function conditionsAction()
380
    {
381
        $viewModel = $this->buildView($this->game);
382
383
        return $viewModel;
384
    }
385
386
    /**
387
     * This action takes care of bounce page of the game
388
     */
389
    public function bounceAction()
390
    {
391
        $availableGames = $this->getGameService()->getAvailableGames($this->user);
392
393
        $rssUrl = '';
394
        $config = $this->getGameService()->getServiceManager()->get('config');
395
        if (isset($config['rss']['url'])) {
396
            $rssUrl = $config['rss']['url'];
397
        }
398
399
        $viewModel = $this->buildView($this->game);
400
        $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...
401
            'rssUrl'         => $rssUrl,
402
            'user'           => $this->user,
403
            'availableGames' => $availableGames,
404
        ));
405
406
        return $viewModel;
407
    }
408
409
410
    /**
411
     * This action displays the Prizes page associated to the game
412
     */
413
    public function prizesAction()
414
    {
415
        if (count($this->game->getPrizes()) == 0) {
416
            return $this->notFoundAction();
417
        }
418
419
        $viewModel = $this->buildView($this->game);
420
421
        return $viewModel;
422
    }
423
424
    /**
425
     * This action displays a specific Prize page among those associated to the game
426
     */
427
    public function prizeAction()
428
    {
429
        $prizeIdentifier = $this->getEvent()->getRouteMatch()->getParam('prize');
430
        $prize = $this->getPrizeService()->getPrizeMapper()->findByIdentifier($prizeIdentifier);
431
        
432
        if (!$prize) {
433
            return $this->notFoundAction();
434
        }
435
436
        $viewModel = $this->buildView($this->game);
437
        $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...
438
439
        return $viewModel;
440
    }
441
442
    public function gameslistAction()
443
    {
444
        $layoutViewModel = $this->layout();
445
446
        $slider = new ViewModel();
447
        $slider->setTemplate('playground-game/common/top_promo');
448
449
        $sliderItems = $this->getGameService()->getActiveSliderGames();
450
451
        $slider->setVariables(array('sliderItems' => $sliderItems));
452
453
        $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...
454
455
        $games = $this->getGameService()->getActiveGames(false, '', 'endDate');
456
        if (is_array($games)) {
457
            $paginator = new \Zend\Paginator\Paginator(new \Zend\Paginator\Adapter\ArrayAdapter($games));
458
        } else {
459
            $paginator = $games;
460
        }
461
462
        $paginator->setItemCountPerPage(7);
463
        $paginator->setCurrentPageNumber($this->getEvent()->getRouteMatch()->getParam('p'));
464
465
        $bitlyclient = $this->getOptions()->getBitlyUrl();
466
        $bitlyuser = $this->getOptions()->getBitlyUsername();
467
        $bitlykey = $this->getOptions()->getBitlyApiKey();
468
469
        $this->getViewHelper('HeadMeta')->setProperty('bt:client', $bitlyclient);
470
        $this->getViewHelper('HeadMeta')->setProperty('bt:user', $bitlyuser);
471
        $this->getViewHelper('HeadMeta')->setProperty('bt:key', $bitlykey);
472
473
        $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...
474
            array(
475
            'sliderItems'   => $sliderItems,
476
            'currentPage' => array(
477
                'pageGames' => 'games',
478
                'pageWinners' => ''
479
            ),
480
            )
481
        );
482
483
        return new ViewModel(
484
            array(
485
                'games' => $paginator
486
            )
487
        );
488
    }
489
490
    public function fangateAction()
491
    {
492
        $viewModel = $this->buildView($this->game);
493
494
        return $viewModel;
495
    }
496
    
497
    public function shareAction()
498
    {
499
        $statusMail = null;
500
        $lastEntry = null;
501
    
502
        // steps of the game
503
        $steps = $this->game->getStepsArray();
504
        // sub steps of the game
505
        $viewSteps = $this->game->getStepsViewsArray();
506
507
        // share position
508
        $key = array_search($this->params('action'), $viewSteps);
509 View Code Duplication
        if (!$key) {
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...
510
            // share is not a substep of the game so it's a step
511
            $key = array_search($this->params('action'), $steps);
512
            $keyStep = true;
0 ignored issues
show
Unused Code introduced by
$keyStep is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
513
        } else {
514
            // share was a substep, I search the index of its parent
515
            $key = array_search($key, $steps);
516
            $keyStep = false;
0 ignored issues
show
Unused Code introduced by
$keyStep is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
517
        }
518
519
        // play position
520
        $keyplay = array_search('play', $viewSteps);
521
522 View Code Duplication
        if (!$keyplay) {
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...
523
            // play is not a substep, so it's a step
524
            $keyplay = array_search('play', $steps);
525
            $keyplayStep = true;
0 ignored issues
show
Unused Code introduced by
$keyplayStep is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
526
        } else {
527
            // play is a substep so I search the index of its parent
528
            $keyplay = array_search($keyplay, $steps);
529
            $keyplayStep = false;
0 ignored issues
show
Unused Code introduced by
$keyplayStep is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
530
        }
531
532
        if ($key && $keyplay && $keyplay <= $key) {
533
            // Has the user finished the game ?
534
            $lastEntry = $this->getGameService()->findLastInactiveEntry($this->game, $this->user);
535
    
536 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...
537
                return $this->redirect()->toUrl(
538
                    $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...
539
                        $this->game->getClassType(),
540
                        array('id' => $this->game->getIdentifier())
541
                    )
542
                );
543
            }
544
        }
545
    
546
        $form = $this->getServiceLocator()->get('playgroundgame_sharemail_form');
547
        $form->setAttribute('method', 'post');
548
549
        // buildView must be before sendMail because it adds the game template path to the templateStack
550
        $viewModel = $this->buildView($this->game);
551
    
552
        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...
553
            $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...
554
            $form->setData($data);
555 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...
556
                $result = $this->getGameService()->sendShareMail($data, $this->game, $this->user, $lastEntry);
557
                if ($result) {
558
                    $statusMail = true;
559
                }
560
            }
561
        }
562
563
        $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...
564
            'statusMail'       => $statusMail,
565
            'form'             => $form,
566
        ));
567
    
568
        return $viewModel;
569
    }
570
    
571 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...
572
    {
573
        $viewModel = new JsonModel();
574
        $viewModel->setTerminal(true);
575
        $fbId = $this->params()->fromQuery('fbId');
576
        if (!$this->game) {
577
            return $this->errorJson();
578
        }
579
        $entry = $this->getGameService()->checkExistingEntry($this->game, $this->user);
580
        if (! $entry) {
581
            return $this->errorJson();
582
        }
583
        if (!$fbId) {
584
            return $this->errorJson();
585
        }
586
    
587
        $this->getGameService()->postFbWall($fbId, $this->game, $this->user, $entry);
588
    
589
        return $this->successJson();
590
    }
591
    
592
    public function fbrequestAction()
593
    {
594
        $viewModel = new ViewModel();
595
        $viewModel->setTerminal(true);
596
        $fbId = $this->params()->fromQuery('fbId');
597
        $to = $this->params()->fromQuery('to');
598
    
599
        if (!$this->game) {
600
            return $this->errorJson();
601
        }
602
        $entry = $this->getGameService()->checkExistingEntry($this->game, $this->user);
603
        if (! $entry) {
604
            return $this->errorJson();
605
        }
606
        if (!$fbId) {
607
            return $this->errorJson();
608
        }
609
    
610
        $this->getGameService()->postFbRequest($fbId, $this->game, $this->user, $entry, $to);
611
    
612
        return $this->successJson();
613
    }
614
    
615
    public function tweetAction()
616
    {
617
        $tweetId = $this->params()->fromQuery('tweetId');
618
    
619
        if (!$this->game) {
620
            return $this->errorJson();
621
        }
622
        $entry = $this->getGameService()->checkExistingEntry($this->game, $this->user);
623
        if (! $entry) {
624
            return $this->errorJson();
625
        }
626
        if (!$tweetId) {
627
            return $this->errorJson();
628
        }
629
    
630
        $this->getGameService()->postTwitter($tweetId, $this->game, $this->user, $entry);
631
    
632
        return $this->successJson();
633
    }
634
    
635 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...
636
    {
637
        $viewModel = new ViewModel();
638
        $viewModel->setTerminal(true);
639
        $googleId = $this->params()->fromQuery('googleId');
640
641
        if (!$this->game) {
642
            return $this->errorJson();
643
        }
644
        $entry = $this->getGameService()->checkExistingEntry($this->game, $this->user);
645
        if (! $entry) {
646
            return $this->errorJson();
647
        }
648
        if (!$googleId) {
649
            return $this->errorJson();
650
        }
651
    
652
        $this->getGameService()->postGoogle($googleId, $this->game, $this->user, $entry);
653
    
654
        return $this->successJson();
655
    }
656
657
    public function optinAction()
658
    {
659
        $userService = $this->getServiceLocator()->get('zfcuser_user_service');
660
661
        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...
662
            $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...
663
            $data['optinPartner'] = ($this->params()->fromPost('optinPartner'))? 1:0;
664
665
            $userService->updateNewsletter($data);
666
        }
667
668
        return $this->redirect()->toUrl(
669
            $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...
670
                'frontend/' . $this->game->getClassType() . '/index',
671
                array('id' => $this->game->getIdentifier())
672
            )
673
        );
674
    }
675
    
676
    public function loginAction()
677
    {
678
        $request = $this->getRequest();
679
        $form = $this->getServiceLocator()->get('zfcuser_login_form');
680
    
681
        if ($request->isPost()) {
682
            $form->setData($request->getPost());
683
            
684
            if (!$form->isValid()) {
685
                $this->flashMessenger()->addMessage(
686
                    'Authentication failed. Please try again.'
687
                );
688
689
                $viewModel = $this->buildView($this->game);
690
                $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...
691
                    'form' => $form,
692
                    'flashMessages' => $this->flashMessenger()->getMessages(),
693
                ));
694
                
695
                return $viewModel;
696
            }
697
            
698
            // clear adapters
699
            $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...
700
            $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...
701
702
            $logged = $this->forward()->dispatch('playgrounduser_user', array('action' => 'ajaxauthenticate'));
703
704
            if (!$logged) {
705
                $this->flashMessenger()->addMessage(
706
                    'Authentication failed. Please try again.'
707
                );
708
                
709
                return $this->redirect()->toUrl(
710
                    $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...
711
                        $this->game->getClassType() . '/login',
712
                        array('id' => $this->game->getIdentifier())
713
                    )
714
                );
715
            } else {
716
                return $this->redirect()->toUrl(
717
                    $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...
718
                        $this->game->getClassType() . '/index',
719
                        array('id' => $this->game->getIdentifier())
720
                    )
721
                );
722
            }
723
        }
724
        
725
        $form->setAttribute(
726
            'action',
727
            $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...
728
                $this->game->getClassType().'/login',
729
                array('id' => $this->game->getIdentifier())
730
            )
731
        );
732
        $viewModel = $this->buildView($this->game);
733
        $viewModel->setVariables(array(
734
            'form' => $form,
735
            'flashMessages' => $this->flashMessenger()->getMessages(),
736
        ));
737
        return $viewModel;
738
    }
739
740
    public function userregisterAction()
741
    {
742
        $userOptions = $this->getServiceLocator()->get('zfcuser_module_options');
743
744
        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...
745
            return $this->redirect()->toUrl(
746
                $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...
747
                    $this->game->getClassType().'/'.$this->game->nextStep('index'),
748
                    array('id' => $this->game->getIdentifier())
749
                )
750
            );
751
        }
752
        $request = $this->getRequest();
753
        $service = $this->getServiceLocator()->get('zfcuser_user_service');
754
        $form = $this->getServiceLocator()->get('playgroundgame_register_form');
755
        $socialnetwork = $this->params()->fromRoute('socialnetwork', false);
756
        $form->setAttribute(
757
            'action',
758
            $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...
759
                $this->game->getClassType().'/user-register',
760
                array('id' => $this->game->getIdentifier())
761
            )
762
        );
763
        $params = array();
764
        $socialCredentials = array();
765
766
        if ($userOptions->getUseRedirectParameterIfPresent() && $request->getQuery()->get('redirect')) {
767
            $redirect = $request->getQuery()->get('redirect');
768
        } else {
769
            $redirect = false;
770
        }
771
772
        if ($socialnetwork) {
773
            $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...
774
775
            if (!empty($infoMe)) {
776
                $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...
777
                    $infoMe->identifier,
778
                    $socialnetwork
779
                );
780
781
                if ($user || $service->getOptions()->getCreateUserAutoSocial() === true) {
782
                    //on le dirige vers l'action d'authentification
783
                    if (! $redirect && $userOptions->getLoginRedirectRoute() != '') {
784
                        $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...
785
                            $this->game->getClassType().'/login',
786
                            array('id' => $this->game->getIdentifier())
787
                        );
788
                    }
789
                    $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...
790
                        $this->game->getClassType().'/login',
791
                        array('id' => $this->game->getIdentifier())
792
                    ) .'/' . $socialnetwork . ($redirect ? '?redirect=' . $redirect : '');
793
794
                    return $this->redirect()->toUrl($redir);
795
                }
796
797
                // Je retire la saisie du login/mdp
798
                $form->setAttribute(
799
                    'action',
800
                    $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...
801
                        $this->game->getClassType().'/user-register',
802
                        array(
803
                            'id' => $this->game->getIdentifier(),
804
                            'socialnetwork' => $socialnetwork,
805
                            
806
                        )
807
                    )
808
                );
809
                $form->remove('password');
810
                $form->remove('passwordVerify');
811
812
                $birthMonth = $infoMe->birthMonth;
813
                if (strlen($birthMonth) <= 1) {
814
                    $birthMonth = '0'.$birthMonth;
815
                }
816
                $birthDay = $infoMe->birthDay;
817
                if (strlen($birthDay) <= 1) {
818
                    $birthDay = '0'.$birthDay;
819
                }
820
821
                $gender = $infoMe->gender;
822
                if ($gender == 'female') {
823
                    $title = 'Me';
824
                } else {
825
                    $title = 'M';
826
                }
827
828
                $params = array(
829
                    //'birth_year'  => $infoMe->birthYear,
830
                    'title'      => $title,
831
                    'dob'      => $birthDay.'/'.$birthMonth.'/'.$infoMe->birthYear,
832
                    'firstname'   => $infoMe->firstName,
833
                    'lastname'    => $infoMe->lastName,
834
                    'email'       => $infoMe->email,
835
                    'postalCode' => $infoMe->zip,
836
                );
837
                $socialCredentials = array(
838
                    'socialNetwork' => strtolower($socialnetwork),
839
                    'socialId'      => $infoMe->identifier,
840
                );
841
            }
842
        }
843
844
        $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...
845
            $this->game->getClassType().'/user-register',
846
            array('id' => $this->game->getIdentifier())
847
        ) .($socialnetwork ? '/' . $socialnetwork : ''). ($redirect ? '?redirect=' . $redirect : '');
848
        $prg = $this->prg($redirectUrl, true);
849
850
        if ($prg instanceof Response) {
851
            return $prg;
852
        } elseif ($prg === false) {
853
            $form->setData($params);
854
            $viewModel = $this->buildView($this->game);
855
            $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...
856
                'registerForm' => $form,
857
                'enableRegistration' => $userOptions->getEnableRegistration(),
858
                'redirect' => $redirect,
859
            ));
860
            return $viewModel;
861
        }
862
863
        $post = $prg;
864
        $post = array_merge(
865
            $post,
866
            $socialCredentials
867
        );
868
869
        if ($this->game->getOnInvitation()) {
870
            $credential = trim(
871
                $post[$this->getGameService()->getOptions()->getOnInvitationField()]
872
            );
873
            if (!$credential) {
874
                $credential = $this->params()->fromQuery(
875
                    $this->getGameService()->getOptions()->getOnInvitationField()
876
                );
877
            }
878
            $found = $this->getGameService()->getInvitationMapper()->findOneBy(array('requestKey'=>$credential));
879
880
            if (!$found || !empty($found->getUser())) {
881
                $this->flashMessenger()->addMessage(
882
                    'Authentication failed. Please try again.'
883
                );
884
                $form->setData($post);
885
                $viewModel = $this->buildView($this->game);
886
                $viewModel->setVariables(array(
887
                    'registerForm' => $form,
888
                    'enableRegistration' => $userOptions->getEnableRegistration(),
889
                    'redirect' => $redirect,
890
                    'flashMessages'    => $this->flashMessenger()->getMessages(),
891
                    'flashErrors'      => $this->flashMessenger()->getErrorMessages(),
892
                ));
893
894
                return $viewModel;
895
            }
896
        }
897
898
        $user = $service->register($post, 'playgroundgame_register_form');
899
900
        if (! $user) {
901
            $viewModel = $this->buildView($this->game);
902
            $viewModel->setVariables(array(
903
                'registerForm' => $form,
904
                'enableRegistration' => $userOptions->getEnableRegistration(),
905
                'redirect' => $redirect,
906
                'flashMessages'    => $this->flashMessenger()->getMessages(),
907
                'flashErrors'      => $this->flashMessenger()->getErrorMessages(),
908
            ));
909
            
910
            return $viewModel;
911
        }
912
913
        if ($this->game->getOnInvitation()) {
914
            // user has been created, associate the code with the userId
915
            $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...
916
            $this->getGameService()->getInvitationMapper()->update($found);
917
        }
918
919
        if ($service->getOptions()->getEmailVerification()) {
920
            $vm = new ViewModel(array('userEmail' => $user->getEmail()));
921
            $vm->setTemplate('playground-user/register/registermail');
922
923
            return $vm;
924
        } elseif ($service->getOptions()->getLoginAfterRegistration()) {
925
            $identityFields = $service->getOptions()->getAuthIdentityFields();
926
            if (in_array('email', $identityFields)) {
927
                $post['identity'] = $user->getEmail();
928
            } elseif (in_array('username', $identityFields)) {
929
                $post['identity'] = $user->getUsername();
930
            }
931
            $post['credential'] = isset($post['password'])?$post['password']:'';
932
            $request->setPost(new Parameters($post));
933
934
            // clear adapters
935
            $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...
936
            $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...
937
938
            $logged = $this->forward()->dispatch('playgrounduser_user', array('action' => 'ajaxauthenticate'));
939
940
            if ($logged) {
941
                return $this->redirect()->toUrl(
942
                    $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...
943
                        $this->game->getClassType(),
944
                        array('id' => $this->game->getIdentifier())
945
                    )
946
                );
947
            } else {
948
                $this->flashMessenger()->setNamespace('zfcuser-login-form')->addMessage(
949
                    'Authentication failed. Please try again.'
950
                );
951
                return $this->redirect()->toUrl(
952
                    $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...
953
                        $this->game->getClassType() . '/login',
954
                        array('id' => $this->game->getIdentifier())
955
                    )
956
                );
957
            }
958
        }
959
960
        $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...
961
            $this->game->getClassType().'/login',
962
            array('id' => $this->game->getIdentifier())
963
        ) . ($socialnetwork ? '/' . $socialnetwork : ''). ($redirect ? '?redirect=' . $redirect : '');
964
965
        return $this->redirect()->toUrl($redirect);
966
    }
967
968 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...
969
    {
970
        $viewModel = $this->forward()->dispatch(
971
            'playgrounduser_user',
972
            array(
973
                'controller' => 'playgrounduser_user',
974
                'action' => 'profile',
975
                'id' => $this->game->getIdentifier()
976
            )
977
        );
978
979
        if ($viewModel && $viewModel instanceof \Zend\View\Model\ViewModel) {
980
            $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...
981
            $viewModel->setVariables(array('game' => $this->game));
982
        }
983
984
        return $viewModel;
985
    }
986
987
    public function userresetAction()
988
    {
989
        $viewModel = $this->forward()->dispatch(
990
            'playgrounduser_forgot',
991
            array(
992
                'controller' => 'playgrounduser_forgot',
993
                'action' => 'reset',
994
                'id' => $this->game->getIdentifier(),
995
                'userId' => $this->params()->fromRoute('userId', null),
996
                'token' => $this->params()->fromRoute('token', null),
997
            )
998
        );
999
1000
        if ($viewModel && $viewModel instanceof \Zend\View\Model\ViewModel) {
1001
            $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...
1002
            $viewModel->setVariables(array('game' => $this->game));
1003
        }
1004
1005
        return $viewModel;
1006
    }
1007
1008 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...
1009
    {
1010
        $view = $this->forward()->dispatch(
1011
            'playgrounduser_forgot',
1012
            array(
1013
                'controller' => 'playgrounduser_forgot',
1014
                'action' => 'ajaxforgot',
1015
                'id' => $this->game->getIdentifier()
1016
            )
1017
        );
1018
1019
        if ($view && $view instanceof \Zend\View\Model\ViewModel) {
1020
            $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...
1021
            $view->setVariables(array('game' => $this->game));
1022
        }
1023
1024
        return $view;
1025
    }
1026
1027 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...
1028
    {
1029
        $viewModel = $this->forward()->dispatch(
1030
            'playgroundcms',
1031
            array(
1032
                'controller' => 'playgroundcms',
1033
                'action' => 'index',
1034
                'id' => $this->game->getIdentifier(),
1035
                'pid' => $this->getEvent()->getRouteMatch()->getParam('pid')
1036
            )
1037
        );
1038
1039
        if ($viewModel && $viewModel instanceof \Zend\View\Model\ViewModel) {
1040
            $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...
1041
            $viewModel->setVariables(array('game' => $this->game));
1042
        }
1043
1044
        return $viewModel;
1045
    }
1046
1047 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...
1048
    {
1049
        $viewModel = $this->forward()->dispatch(
1050
            'playgroundcms',
1051
            array(
1052
                'controller' => 'playgroundcms',
1053
                'action' => 'list',
1054
                'id' => $this->game->getIdentifier(),
1055
                'category' => $this->game->getIdentifier()
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
    /**
1068
     *
1069
     * @param \PlaygroundGame\Entity\Game $game
1070
     * @param \PlaygroundUser\Entity\User $user
1071
     */
1072
    public function checkFbRegistration($user, $game)
1073
    {
1074
        $redirect = false;
1075
        $session = new Container('facebook');
1076
        if ($session->offsetExists('signed_request')) {
1077
            if (!$user) {
1078
                // Get Playground user from Facebook info
1079
                $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...
1080
                $view = $this->forward()->dispatch(
1081
                    'playgrounduser_user',
1082
                    array(
1083
                        'controller' => 'playgrounduser_user',
1084
                        'action' => 'registerFacebookUser',
1085
                        'provider' => 'facebook'
1086
                    )
1087
                );
1088
1089
                $this->layout()->setTemplate($beforeLayout);
1090
                $user = $view->user;
1091
1092
                // If the user can not be created/retrieved from Facebook info, redirect to login/register form
1093
                if (!$user) {
1094
                    $redirectUrl = urlencode(
1095
                        $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...
1096
                            $game->getClassType() .'/play',
1097
                            array('id' => $game->getIdentifier()),
1098
                            array('force_canonical' => true)
1099
                        )
1100
                    );
1101
                    $redirect =  $this->redirect()->toUrl(
1102
                        $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...
1103
                            'zfcuser/register'
1104
                        ) . '?redirect='.$redirectUrl
1105
                    );
1106
                }
1107
            }
1108
1109
            if ($game->getFbFan()) {
1110
                if ($this->getGameService()->checkIsFan($game) === false) {
1111
                    $redirect =  $this->redirect()->toRoute(
1112
                        $game->getClassType().'/fangate',
1113
                        array('id' => $game->getIdentifier())
1114
                    );
1115
                }
1116
            }
1117
        }
1118
1119
        return $redirect;
1120
    }
1121
1122
    /**
1123
     * This method create the basic Game view
1124
     * @param \PlaygroundGame\Entity\Game $game
1125
     */
1126
    public function buildView($game)
1127
    {
1128
        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...
1129
            $viewModel = new JsonModel();
1130
            if ($game) {
1131
                $view = $this->addAdditionalView($game);
1132
                if ($view && $view instanceof \Zend\View\Model\ViewModel) {
1133
                    $viewModel->setVariables($view->getVariables());
1134
                }
1135
            }
1136
        } else {
1137
            $viewModel = new ViewModel();
1138
1139
            if ($game) {
1140
                $this->addMetaTitle($game);
1141
                $this->addMetaBitly();
1142
                $this->addGaEvent($game);
1143
1144
                $this->customizeGameDesign($game);
1145
                
1146
                $view = $this->addAdditionalView($game);
1147
                if ($view && $view instanceof \Zend\View\Model\ViewModel) {
1148
                    $viewModel->addChild($view, 'additional');
1149
                } elseif ($view && $view instanceof \Zend\Http\PhpEnvironment\Response) {
1150
                    return $view;
1151
                }
1152
1153
                $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...
1154
                    array(
1155
                        'action' => $this->params('action'),
1156
                        'game' => $game,
1157
                        'flashMessages'    => $this->flashMessenger()->getMessages(),
1158
                        
1159
                    )
1160
                );
1161
            }
1162
        }
1163
        
1164
        if ($game) {
1165
            $viewModel->setVariables($this->getShareData($game));
1166
            $viewModel->setVariables(array('game' => $game, 'user' => $this->user));
1167
        }
1168
1169
        return $viewModel;
1170
    }
1171
1172
    /**
1173
     * @param \PlaygroundGame\Entity\Game $game
1174
     */
1175
    public function addAdditionalView($game)
1176
    {
1177
        $view = false;
1178
1179
        $actionName = $this->getEvent()->getRouteMatch()->getParam('action', 'not-found');
1180
        $stepsViews = json_decode($game->getStepsViews(), true);
1181
        if ($stepsViews && isset($stepsViews[$actionName])) {
1182
            $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...
1183
            $actionData = $stepsViews[$actionName];
1184
            if (is_string($actionData)) {
1185
                $action = $actionData;
1186
                $controller = $this->getEvent()->getRouteMatch()->getParam('controller', 'playgroundgame_game');
1187
                $view = $this->forward()->dispatch(
1188
                    $controller,
1189
                    array(
1190
                        'action' => $action,
1191
                        'id' => $game->getIdentifier()
1192
                    )
1193
                );
1194
            } elseif (is_array($actionData) && count($actionData)>0) {
1195
                $action = key($actionData);
1196
                $controller = $actionData[$action];
1197
                $view = $this->forward()->dispatch(
1198
                    $controller,
1199
                    array(
1200
                        'action' => $action,
1201
                        'id' => $game->getIdentifier()
1202
                    )
1203
                );
1204
            }
1205
            // suite au forward, le template de layout a changé, je dois le rétablir...
1206
            $this->layout()->setTemplate($beforeLayout);
1207
        }
1208
1209
        return $view;
1210
    }
1211
1212
    public function addMetaBitly()
1213
    {
1214
        $bitlyclient = $this->getOptions()->getBitlyUrl();
1215
        $bitlyuser = $this->getOptions()->getBitlyUsername();
1216
        $bitlykey = $this->getOptions()->getBitlyApiKey();
1217
1218
        $this->getViewHelper('HeadMeta')->setProperty('bt:client', $bitlyclient);
1219
        $this->getViewHelper('HeadMeta')->setProperty('bt:user', $bitlyuser);
1220
        $this->getViewHelper('HeadMeta')->setProperty('bt:key', $bitlykey);
1221
    }
1222
1223
    /**
1224
     * @param \PlaygroundGame\Entity\Game $game
1225
     */
1226
    public function addGaEvent($game)
1227
    {
1228
        // Google Analytics event
1229
        $ga = $this->getServiceLocator()->get('google-analytics');
1230
        $event = new \PlaygroundCore\Analytics\Event($game->getClassType(), $this->params('action'));
1231
        $event->setLabel($game->getTitle());
1232
        $ga->addEvent($event);
1233
    }
1234
1235
    /**
1236
     * @param \PlaygroundGame\Entity\Game $game
1237
     */
1238
    public function addMetaTitle($game)
1239
    {
1240
        $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...
1241
        $this->getGameService()->getServiceManager()->get('ViewHelperManager')->get('HeadTitle')->set($title);
1242
        // Meta set in the layout
1243
        $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...
1244
            array(
1245
                'breadcrumbTitle' => $title,
1246
                'currentPage' => array(
1247
                    'pageGames' => 'games',
1248
                    'pageWinners' => ''
1249
                ),
1250
                'headParams' => array(
1251
                    'headTitle' => $title,
1252
                    'headDescription' => $title,
1253
                ),
1254
                'bodyCss' => $game->getIdentifier()
1255
            )
1256
        );
1257
    }
1258
1259
    /**
1260
     * @param \PlaygroundGame\Entity\Game $game
1261
     */
1262
    public function customizeGameDesign($game)
1263
    {
1264
        // If this game has a specific layout...
1265
        if ($game->getLayout()) {
1266
            $layoutViewModel = $this->layout();
1267
            $layoutViewModel->setTemplate($game->getLayout());
1268
        }
1269
1270
        // If this game has a specific stylesheet...
1271
        if ($game->getStylesheet()) {
1272
            $this->getViewHelper('HeadLink')->appendStylesheet(
1273
                $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...
1274
            );
1275
        }
1276
    }
1277
1278
    /**
1279
     * @param \PlaygroundGame\Entity\Game $game
1280
     */
1281
    public function getShareData($game)
1282
    {
1283
        $fo = $this->getServiceLocator()->get('facebook-opengraph');
1284
        $session = new Container('facebook');
1285
1286
        // I change the fbappid if i'm in fb
1287
        if ($session->offsetExists('signed_request')) {
1288
            $fo->setId($game->getFbAppId());
1289
        }
1290
1291
        // If I want to add a share block in my view
1292 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...
1293
            $fbShareMessage = $game->getFbShareMessage();
1294
        } else {
1295
            $fbShareMessage = str_replace(
1296
                '__placeholder__',
1297
                $game->getTitle(),
1298
                $this->getOptions()->getDefaultShareMessage()
1299
            );
1300
        }
1301
1302
        if ($game->getFbShareImage()) {
1303
            $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...
1304
                '',
1305
                array(),
1306
                array('force_canonical' => true),
1307
                false
1308
            ) . $game->getFbShareImage();
1309
        } else {
1310
            $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...
1311
                '',
1312
                array(),
1313
                array('force_canonical' => true),
1314
                false
1315
            ) . $game->getMainImage();
1316
        }
1317
1318
        $secretKey = strtoupper(substr(sha1(uniqid('pg_', true).'####'.time()), 0, 15));
1319
1320
        // Without bit.ly shortener
1321
        $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...
1322
            $game->getClassType(),
1323
            array('id' => $game->getIdentifier()),
1324
            array('force_canonical' => true)
1325
        );
1326
        // With core shortener helper
1327
        $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...
1328
1329
        // FB Requests only work when it's a FB app
1330
        if ($game->getFbRequestMessage()) {
1331
            $fbRequestMessage = urlencode($game->getFbRequestMessage());
1332
        } else {
1333
            $fbRequestMessage = str_replace(
1334
                '__placeholder__',
1335
                $game->getTitle(),
1336
                $this->getOptions()->getDefaultShareMessage()
1337
            );
1338
        }
1339
1340 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...
1341
            $twShareMessage = $game->getTwShareMessage() . $socialLinkUrl;
1342
        } else {
1343
            $twShareMessage = str_replace(
1344
                '__placeholder__',
1345
                $game->getTitle(),
1346
                $this->getOptions()->getDefaultShareMessage()
1347
            ) . $socialLinkUrl;
1348
        }
1349
1350
        $ogTitle = new \PlaygroundCore\Opengraph\Tag('og:title', $fbShareMessage);
1351
        $ogImage = new \PlaygroundCore\Opengraph\Tag('og:image', $fbShareImage);
1352
        
1353
        $fo->addTag($ogTitle);
1354
        $fo->addTag($ogImage);
1355
        
1356
        $data = array(
1357
            'socialLinkUrl'       => $socialLinkUrl,
1358
            'secretKey'           => $secretKey,
1359
            'fbShareMessage'      => $fbShareMessage,
1360
            'fbShareImage'        => $fbShareImage,
1361
            'fbRequestMessage'    => $fbRequestMessage,
1362
            'twShareMessage'      => $twShareMessage,
1363
        );
1364
1365
        return $data;
1366
    }
1367
    
1368
    /**
1369
     * return ajax response in json format
1370
     *
1371
     * @param array $data
1372
     * @return \Zend\View\Model\JsonModel
1373
     */
1374 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...
1375
    {
1376
        $model = new JsonModel(array(
1377
            'success' => true,
1378
            'data' => $data
1379
        ));
1380
        return $model->setTerminal(true);
1381
    }
1382
    
1383
    /**
1384
     * return ajax response in json format
1385
     *
1386
     * @param string $message
1387
     * @return \Zend\View\Model\JsonModel
1388
     */
1389 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...
1390
    {
1391
        $model = new JsonModel(array(
1392
            'success' => false,
1393
            'message' => $message
1394
        ));
1395
        return $model->setTerminal(true);
1396
    }
1397
1398
    /**
1399
     * @param string $helperName
1400
     */
1401
    protected function getViewHelper($helperName)
1402
    {
1403
        return $this->getServiceLocator()->get('viewhelpermanager')->get($helperName);
1404
    }
1405
1406
    public function getGameService()
1407
    {
1408
        if (!$this->gameService) {
1409
            $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...
1410
        }
1411
1412
        return $this->gameService;
1413
    }
1414
1415
    public function setGameService(GameService $gameService)
1416
    {
1417
        $this->gameService = $gameService;
1418
1419
        return $this;
1420
    }
1421
1422
    public function getPrizeService()
1423
    {
1424
        if (!$this->prizeService) {
1425
            $this->prizeService = $this->getServiceLocator()->get('playgroundgame_prize_service');
1426
        }
1427
1428
        return $this->prizeService;
1429
    }
1430
1431
    public function setPrizeService(PrizeService $prizeService)
1432
    {
1433
        $this->prizeService = $prizeService;
1434
1435
        return $this;
1436
    }
1437
1438
    public function getOptions()
1439
    {
1440
        if (!$this->options) {
1441
            $this->setOptions($this->getServiceLocator()->get('playgroundcore_module_options'));
1442
        }
1443
1444
        return $this->options;
1445
    }
1446
1447
    public function setOptions($options)
1448
    {
1449
        $this->options = $options;
1450
1451
        return $this;
1452
    }
1453
}
1454