Completed
Push — master ( b2f820...171548 )
by greg
07:21
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
        'logout',
44
        'ajaxforgot',
45
        'play',
46
        'result',
47
        'preview',
48
        'list'
49
    );
50
51
    protected $withOnlineGame = array(
52
        'leaderboard',
53
        'register',
54
        'bounce',
55
        'play',
56
        'result'
57
    );
58
59
    protected $withAnyUser = array(
60
        'share',
61
        'result',
62
        'play',
63
        'logout'
64
    );
65
66
    public function setEventManager(\Zend\EventManager\EventManagerInterface $events)
67
    {
68
        parent::setEventManager($events);
69
70
        $controller = $this;
71
        $events->attach('dispatch', function (\Zend\Mvc\MvcEvent $e) use ($controller) {
72
73
            $identifier = $e->getRouteMatch()->getParam('id');
74
            $controller->game = $controller->getGameService()->checkGame($identifier, false);
75
            if (!$controller->game &&
76
                in_array($controller->params('action'), $controller->withGame)
77
            ) {
78
                return $controller->notFoundAction();
79
            }
80
81
            if ($controller->game &&
82
                $controller->game->isClosed() &&
83
                in_array($controller->params('action'), $controller->withOnlineGame)
84
            ) {
85
                return $controller->notFoundAction();
86
            }
87
88
            if ($controller->game) {
89
                // this is possible to create a specific game design in /design/frontend/default/custom.
90
                //It will precede all others templates.
91
                $templatePathResolver = $controller->getServiceLocator()->get('Zend\View\Resolver\TemplatePathStack');
92
                $l = $templatePathResolver->getPaths();
93
                $templatePathResolver->addPath($l[0].'custom/'.$controller->game->getIdentifier());
94
            }
95
96
            $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...
97
            if ($controller->game &&
98
                !$controller->user &&
99
                !$controller->game->getAnonymousAllowed() &&
100
                in_array($controller->params('action'), $controller->withAnyUser)
101
            ) {
102
                $redirect = urlencode(
103
                    $controller->url()->fromRoute(
104
                        'frontend/'.$controller->game->getClassType() . '/' . $controller->params('action'),
105
                        array('id' => $controller->game->getIdentifier()),
106
                        array('force_canonical' => true)
107
                    )
108
                );
109
110
                $urlRegister = $controller->url()->fromRoute(
111
                    'frontend/zfcuser/register',
112
                    array(),
113
                    array('force_canonical' => true)
114
                ) . '?redirect='.$redirect;
115
116
                // code permettant d'identifier un custom game
117
                // ligne $config = $controller->getGameService()->getServiceManager()->get('config');
118
                // ligne $customUrl = str_replace('frontend.', '', $e->getRouteMatch()->getParam('area', ''));
119
                // ligne if ($config['custom_games'][$controller->game->getIdentifier()] &&
120
                // ligne    $controller->getRequest()->getUri()->getHost() === $customUrl
121
                // ligne ) {
122
                return $controller->redirect()->toUrl($urlRegister);
123
            }
124
125
            return;
126
        }, 100); // execute before executing action logic
127
    }
128
129
    /**
130
     * Action called if matched action does not exist
131
     * For this view not to be catched by Zend\Mvc\View\RouteNotFoundStrategy
132
     * it has to be rendered in the controller. Hence the code below.
133
     *
134
     * This action is injected as a catchall action for each custom_games definition
135
     * This way, when a custom_game is created, the 404 is it's responsability and the
136
     * view can be defined in design/frontend/default/custom/$slug/playground_game/$gametype/404.phtml
137
     *
138
     *
139
     * @return \Zend\Stdlib\ResponseInterface
140
     */
141
    public function notFoundAction()
142
    {
143
        $templatePathResolver = $this->getServiceLocator()->get('Zend\View\Resolver\TemplatePathStack');
144
145
        // I create a template path in which I can find a custom template
146
        $controller = explode('\\', get_class($this));
147
        $controllerPath = str_replace('Controller', '', end($controller));
148
        $controllerPath = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '-\\1', $controllerPath));
149
        $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...
150
151
        if (false === $templatePathResolver->resolve($template)) {
152
            $viewRender     = $this->getServiceLocator()->get('ViewRenderer');
153
154
            $this->getEvent()->getRouteMatch()->setParam('action', 'not-found');
155
            $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...
156
157
            $res = 'error/404';
158
159
            $viewModel = $this->buildView($this->game);
160
            $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...
161
162
            $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...
163
            $this->response->setContent($viewRender->render($this->layout()));
164
165
            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...
166
        }
167
168
        $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 171 which is incompatible with the return type documented by PlaygroundGame\Controlle...troller::notFoundAction of type Zend\Stdlib\ResponseInterface.
Loading history...
169
        $viewModel->setTemplate($template);
170
171
        return $viewModel;
172
    }
173
174
    /**
175
     * This action acts as a hub : Depending on the first step of the game, it will forward the action to this step
176
     */
177
    public function homeAction()
178
    {
179
        // This fix exists only for safari in FB on Windows : we need to redirect the user to the page
180
        // outside of iframe for the cookie to be accepted. PlaygroundCore redirects to the FB Iframed page when
181
        // it discovers that the user arrives for the first time on the game in FB.
182
        // When core redirects, it adds a 'redir_fb_page_id' var in the querystring
183
        // Here, we test if this var exist, and then send the user back to the game in FB.
184
        // Now the cookie will be accepted by Safari...
185
        $pageId = $this->params()->fromQuery('redir_fb_page_id');
186
        if (!empty($pageId)) {
187
            $appId = 'app_'.$this->game->getFbAppId();
188
            $url = '//www.facebook.com/pages/game/'.$pageId.'?sk='.$appId;
189
190
            return $this->redirect()->toUrl($url);
191
        }
192
193
        // If an entry has already been done during this session, I reset the anonymous_identifier cookie
194
        // so that another person can play the same game (if game conditions are fullfilled)
195
        $session = new Container('anonymous_identifier');
196
        if ($session->offsetExists('anonymous_identifier')) {
197
            $session->offsetUnset('anonymous_identifier');
198
        }
199
        
200
        return $this->forward()->dispatch(
201
            'playgroundgame_'.$this->game->getClassType(),
202
            array(
203
                'controller' => 'playgroundgame_'.$this->game->getClassType(),
204
                'action' => $this->game->firstStep(),
205
                'id' => $this->game->getIdentifier()
206
            )
207
        );
208
    }
209
210
    /**
211
     * Homepage of the game
212
     */
213
    public function indexAction()
214
    {
215
        $isSubscribed = false;
216
217
        $entry = $this->getGameService()->checkExistingEntry($this->game, $this->user);
218
        if ($entry) {
219
            $isSubscribed = true;
220
        }
221
222
        $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 227 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...
223
        $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...
224
            'isSubscribed' => $isSubscribed
225
        ));
226
227
        return $viewModel;
228
    }
229
230
    /**
231
      * leaderboardAction
232
      *
233
      * @return ViewModel $viewModel
234
      */
235
    public function leaderboardAction()
236
    {
237
        $filter = $this->getEvent()->getRouteMatch()->getParam('filter');
238
        $p = $this->getEvent()->getRouteMatch()->getParam('p');
239
240
        $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...
241
        $subViewModel = $this->forward()->dispatch(
242
            'playgroundreward',
243
            array('action' => 'leaderboard', 'filter' => $filter, 'p' => $p)
244
        );
245
        
246
        // suite au forward, le template de layout a changé, je dois le rétablir...
247
        $this->layout()->setTemplate($beforeLayout);
248
249
        // give the ability to the game to have its customized look and feel.
250
        $templatePathResolver = $this->getServiceLocator()->get('Zend\View\Resolver\TemplatePathStack');
251
        $l = $templatePathResolver->getPaths();
252
253
        $templatePathResolver->addPath($l[0].'custom/'.$this->game->getIdentifier());
254
255
        return $subViewModel;
256
    }
257
258
    /**
259
     * This action has been designed to be called by other controllers
260
     * It gives the ability to display an information form and persist it in the game entry
261
     *
262
     * @return \Zend\View\Model\ViewModel
263
     */
264
    public function registerAction()
265
    {
266
        $form = $this->getGameService()->createFormFromJson($this->game->getPlayerForm()->getForm(), 'playerForm');
267
268
        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...
269
            // POST Request: Process form
270
            $data = array_merge_recursive(
271
                $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...
272
                $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...
273
            );
274
            
275
            $form->setData($data);
276
277
            if ($form->isValid()) {
278
                // steps of the game
279
                $steps = $this->game->getStepsArray();
280
                // sub steps of the game
281
                $viewSteps = $this->game->getStepsViewsArray();
282
283
                // register position
284
                $key = array_search($this->params('action'), $viewSteps);
285 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...
286
                    // register is not a substep of the game so it's a step
287
                    $key = array_search($this->params('action'), $steps);
288
                    $keyStep = true;
289
                } else {
290
                    // register was a substep, i search the index of its parent
291
                    $key = array_search($key, $steps);
292
                    $keyStep = false;
293
                }
294
295
                // play position
296
                $keyplay = array_search('play', $viewSteps);
297
298 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...
299
                    // play is not a substep, so it's a step
300
                    $keyplay = array_search('play', $steps);
301
                    $keyplayStep = true;
302
                } else {
303
                    // play is a substep so I search the index of its parent
304
                    $keyplay = array_search($keyplay, $steps);
305
                    $keyplayStep = false;
306
                }
307
308
                // If register step before play, I don't have no entry yet. I have to create one
309
                // If register after play step, I search for the last entry created by play step.
310
311
                if ($key < $keyplay || ($keyStep && !$keyplayStep && $key <= $keyplay)) {
312
                    $entry = $this->getGameService()->play($this->game, $this->user);
313
                    if (!$entry) {
314
                        // the user has already taken part of this game and the participation limit has been reached
315
                        $this->flashMessenger()->addMessage('Vous avez déjà participé');
316
                    
317
                        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...
318
                            $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...
319
                                $this->game->getClassType().'/result',
320
                                array(
321
                                    'id' => $this->game->getIdentifier(),
322
                                    
323
                                )
324
                            )
325
                        );
326
                    }
327
                } else {
328
                    // I'm looking for an entry without anonymousIdentifier (the active entry in fact).
329
                    $entry = $this->getGameService()->findLastEntry($this->game, $this->user);
330
                    if ($this->getGameService()->hasReachedPlayLimit($this->game, $this->user)) {
331
                        // the user has already taken part of this game and the participation limit has been reached
332
                        $this->flashMessenger()->addMessage('Vous avez déjà participé');
333
                    
334
                        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...
335
                            $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...
336
                                $this->game->getClassType().'/result',
337
                                array(
338
                                    'id' => $this->game->getIdentifier(),
339
                                    
340
                                )
341
                            )
342
                        );
343
                    }
344
                }
345
346
                $this->getGameService()->updateEntryPlayerForm($form->getData(), $this->game, $this->user, $entry);
347
348
                if (!empty($this->game->nextStep($this->params('action')))) {
349
                    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...
350
                        $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...
351
                            $this->game->getClassType() .'/' . $this->game->nextStep($this->params('action')),
352
                            array('id' => $this->game->getIdentifier()),
353
                            array('force_canonical' => true)
354
                        )
355
                    );
356
                }
357
            }
358
        }
359
360
        $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 365 which is incompatible with the return type documented by PlaygroundGame\Controlle...troller::registerAction of type Zend\View\Model\ViewModel.
Loading history...
361
        $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...
362
            'form' => $form
363
        ));
364
365
        return $viewModel;
366
    }
367
368
    /**
369
     * This action takes care of the terms of the game
370
     */
371
    public function termsAction()
372
    {
373
        $viewModel = $this->buildView($this->game);
374
375
        return $viewModel;
376
    }
377
378
    /**
379
     * This action takes care of the conditions of the game
380
     */
381
    public function conditionsAction()
382
    {
383
        $viewModel = $this->buildView($this->game);
384
385
        return $viewModel;
386
    }
387
388
    /**
389
     * This action takes care of bounce page of the game
390
     */
391
    public function bounceAction()
392
    {
393
        $availableGames = $this->getGameService()->getAvailableGames($this->user);
394
395
        $rssUrl = '';
396
        $config = $this->getGameService()->getServiceManager()->get('config');
397
        if (isset($config['rss']['url'])) {
398
            $rssUrl = $config['rss']['url'];
399
        }
400
401
        $viewModel = $this->buildView($this->game);
402
        $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...
403
            'rssUrl'         => $rssUrl,
404
            'user'           => $this->user,
405
            'availableGames' => $availableGames,
406
        ));
407
408
        return $viewModel;
409
    }
410
411
412
    /**
413
     * This action displays the Prizes page associated to the game
414
     */
415
    public function prizesAction()
416
    {
417
        if (count($this->game->getPrizes()) == 0) {
418
            return $this->notFoundAction();
419
        }
420
421
        $viewModel = $this->buildView($this->game);
422
423
        return $viewModel;
424
    }
425
426
    /**
427
     * This action displays a specific Prize page among those associated to the game
428
     */
429
    public function prizeAction()
430
    {
431
        $prizeIdentifier = $this->getEvent()->getRouteMatch()->getParam('prize');
432
        $prize = $this->getPrizeService()->getPrizeMapper()->findByIdentifier($prizeIdentifier);
433
        
434
        if (!$prize) {
435
            return $this->notFoundAction();
436
        }
437
438
        $viewModel = $this->buildView($this->game);
439
        $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...
440
441
        return $viewModel;
442
    }
443
444
    public function gameslistAction()
445
    {
446
        $layoutViewModel = $this->layout();
447
448
        $slider = new ViewModel();
449
        $slider->setTemplate('playground-game/common/top_promo');
450
451
        $sliderItems = $this->getGameService()->getActiveSliderGames();
452
453
        $slider->setVariables(array('sliderItems' => $sliderItems));
454
455
        $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...
456
457
        $games = $this->getGameService()->getActiveGames(false, '', 'endDate');
458
        if (is_array($games)) {
459
            $paginator = new \Zend\Paginator\Paginator(new \Zend\Paginator\Adapter\ArrayAdapter($games));
460
        } else {
461
            $paginator = $games;
462
        }
463
464
        $paginator->setItemCountPerPage(7);
465
        $paginator->setCurrentPageNumber($this->getEvent()->getRouteMatch()->getParam('p'));
466
467
        $bitlyclient = $this->getOptions()->getBitlyUrl();
468
        $bitlyuser = $this->getOptions()->getBitlyUsername();
469
        $bitlykey = $this->getOptions()->getBitlyApiKey();
470
471
        $this->getViewHelper('HeadMeta')->setProperty('bt:client', $bitlyclient);
472
        $this->getViewHelper('HeadMeta')->setProperty('bt:user', $bitlyuser);
473
        $this->getViewHelper('HeadMeta')->setProperty('bt:key', $bitlykey);
474
475
        $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...
476
            array(
477
            'sliderItems'   => $sliderItems,
478
            'currentPage' => array(
479
                'pageGames' => 'games',
480
                'pageWinners' => ''
481
            ),
482
            )
483
        );
484
485
        return new ViewModel(
486
            array(
487
                'games' => $paginator
488
            )
489
        );
490
    }
491
492
    public function fangateAction()
493
    {
494
        $viewModel = $this->buildView($this->game);
495
496
        return $viewModel;
497
    }
498
    
499
    public function shareAction()
500
    {
501
        $statusMail = null;
502
        $lastEntry = null;
503
    
504
        // steps of the game
505
        $steps = $this->game->getStepsArray();
506
        // sub steps of the game
507
        $viewSteps = $this->game->getStepsViewsArray();
508
509
        // share position
510
        $key = array_search($this->params('action'), $viewSteps);
511 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...
512
            // share is not a substep of the game so it's a step
513
            $key = array_search($this->params('action'), $steps);
514
            $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...
515
        } else {
516
            // share was a substep, I search the index of its parent
517
            $key = array_search($key, $steps);
518
            $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...
519
        }
520
521
        // play position
522
        $keyplay = array_search('play', $viewSteps);
523
524 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...
525
            // play is not a substep, so it's a step
526
            $keyplay = array_search('play', $steps);
527
            $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...
528
        } else {
529
            // play is a substep so I search the index of its parent
530
            $keyplay = array_search($keyplay, $steps);
531
            $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...
532
        }
533
534
        if ($key && $keyplay && $keyplay <= $key) {
535
            // Has the user finished the game ?
536
            $lastEntry = $this->getGameService()->findLastInactiveEntry($this->game, $this->user);
537
    
538 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...
539
                return $this->redirect()->toUrl(
540
                    $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...
541
                        $this->game->getClassType(),
542
                        array('id' => $this->game->getIdentifier())
543
                    )
544
                );
545
            }
546
        }
547
    
548
        $form = $this->getServiceLocator()->get('playgroundgame_sharemail_form');
549
        $form->setAttribute('method', 'post');
550
551
        // buildView must be before sendMail because it adds the game template path to the templateStack
552
        $viewModel = $this->buildView($this->game);
553
    
554
        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...
555
            $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...
556
            $form->setData($data);
557 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...
558
                $result = $this->getGameService()->sendShareMail($data, $this->game, $this->user, $lastEntry);
559
                if ($result) {
560
                    $statusMail = true;
561
                }
562
            }
563
        }
564
565
        $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...
566
            'statusMail'       => $statusMail,
567
            'form'             => $form,
568
        ));
569
    
570
        return $viewModel;
571
    }
572
    
573 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...
574
    {
575
        $viewModel = new JsonModel();
576
        $viewModel->setTerminal(true);
577
        $fbId = $this->params()->fromQuery('fbId');
578
        if (!$this->game) {
579
            return $this->errorJson();
580
        }
581
        $entry = $this->getGameService()->checkExistingEntry($this->game, $this->user);
582
        if (! $entry) {
583
            return $this->errorJson();
584
        }
585
        if (!$fbId) {
586
            return $this->errorJson();
587
        }
588
    
589
        $this->getGameService()->postFbWall($fbId, $this->game, $this->user, $entry);
590
    
591
        return $this->successJson();
592
    }
593
    
594
    public function fbrequestAction()
595
    {
596
        $viewModel = new ViewModel();
597
        $viewModel->setTerminal(true);
598
        $fbId = $this->params()->fromQuery('fbId');
599
        $to = $this->params()->fromQuery('to');
600
    
601
        if (!$this->game) {
602
            return $this->errorJson();
603
        }
604
        $entry = $this->getGameService()->checkExistingEntry($this->game, $this->user);
605
        if (! $entry) {
606
            return $this->errorJson();
607
        }
608
        if (!$fbId) {
609
            return $this->errorJson();
610
        }
611
    
612
        $this->getGameService()->postFbRequest($fbId, $this->game, $this->user, $entry, $to);
613
    
614
        return $this->successJson();
615
    }
616
    
617
    public function tweetAction()
618
    {
619
        $tweetId = $this->params()->fromQuery('tweetId');
620
    
621
        if (!$this->game) {
622
            return $this->errorJson();
623
        }
624
        $entry = $this->getGameService()->checkExistingEntry($this->game, $this->user);
625
        if (! $entry) {
626
            return $this->errorJson();
627
        }
628
        if (!$tweetId) {
629
            return $this->errorJson();
630
        }
631
    
632
        $this->getGameService()->postTwitter($tweetId, $this->game, $this->user, $entry);
633
    
634
        return $this->successJson();
635
    }
636
    
637 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...
638
    {
639
        $viewModel = new ViewModel();
640
        $viewModel->setTerminal(true);
641
        $googleId = $this->params()->fromQuery('googleId');
642
643
        if (!$this->game) {
644
            return $this->errorJson();
645
        }
646
        $entry = $this->getGameService()->checkExistingEntry($this->game, $this->user);
647
        if (! $entry) {
648
            return $this->errorJson();
649
        }
650
        if (!$googleId) {
651
            return $this->errorJson();
652
        }
653
    
654
        $this->getGameService()->postGoogle($googleId, $this->game, $this->user, $entry);
655
    
656
        return $this->successJson();
657
    }
658
659
    public function optinAction()
660
    {
661
        $userService = $this->getServiceLocator()->get('zfcuser_user_service');
662
663
        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...
664
            $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...
665
            $data['optinPartner'] = ($this->params()->fromPost('optinPartner'))? 1:0;
666
667
            $userService->updateNewsletter($data);
668
        }
669
670
        return $this->redirect()->toUrl(
671
            $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...
672
                'frontend/' . $this->game->getClassType() . '/index',
673
                array('id' => $this->game->getIdentifier())
674
            )
675
        );
676
    }
677
    
678
    public function loginAction()
679
    {
680
        $request = $this->getRequest();
681
        $form = $this->getServiceLocator()->get('zfcuser_login_form');
682
    
683
        if ($request->isPost()) {
684
            $form->setData($request->getPost());
685
            
686
            if (!$form->isValid()) {
687
                $this->flashMessenger()->addMessage(
688
                    'Authentication failed. Please try again.'
689
                );
690
691
                $viewModel = $this->buildView($this->game);
692
                $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...
693
                    'form' => $form,
694
                    'flashMessages' => $this->flashMessenger()->getMessages(),
695
                ));
696
                
697
                return $viewModel;
698
            }
699
            
700
            // clear adapters
701
            $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...
702
            $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...
703
704
            $logged = $this->forward()->dispatch('playgrounduser_user', array('action' => 'ajaxauthenticate'));
705
706
            if (!$logged) {
707
                $this->flashMessenger()->addMessage(
708
                    'Authentication failed. Please try again.'
709
                );
710
                
711
                return $this->redirect()->toUrl(
712
                    $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...
713
                        $this->game->getClassType() . '/login',
714
                        array('id' => $this->game->getIdentifier())
715
                    )
716
                );
717
            } else {
718
                return $this->redirect()->toUrl(
719
                    $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...
720
                        $this->game->getClassType() . '/index',
721
                        array('id' => $this->game->getIdentifier())
722
                    )
723
                );
724
            }
725
        }
726
        
727
        $form->setAttribute(
728
            'action',
729
            $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...
730
                $this->game->getClassType().'/login',
731
                array('id' => $this->game->getIdentifier())
732
            )
733
        );
734
        $viewModel = $this->buildView($this->game);
735
        $viewModel->setVariables(array(
736
            'form' => $form,
737
            'flashMessages' => $this->flashMessenger()->getMessages(),
738
        ));
739
        return $viewModel;
740
    }
741
742 View Code Duplication
    public function logoutAction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
743
    {
744
        $viewModel = $this->forward()->dispatch(
745
            'playgrounduser_user',
746
            array(
747
                'controller' => 'playgrounduser_user',
748
                'action' => 'logout',
749
                'id' => $this->game->getIdentifier()
750
            )
751
        );
752
753
        if ($viewModel && $viewModel instanceof \Zend\View\Model\ViewModel) {
754
            $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...
755
            $viewModel->setVariables(array('game' => $this->game));
756
        }
757
758
        return $viewModel;
759
    }
760
761
    public function userregisterAction()
762
    {
763
        $userOptions = $this->getServiceLocator()->get('zfcuser_module_options');
764
765
        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...
766
            return $this->redirect()->toUrl(
767
                $this->frontendUrl()->fromRoute(
0 ignored issues
show
Documentation Bug introduced by
The method frontendUrl does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

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

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

class ParentClass {
    private $data = array();

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

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

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
768
                    $this->game->getClassType().'/'.$this->game->nextStep('index'),
769
                    array('id' => $this->game->getIdentifier())
770
                )
771
            );
772
        }
773
        $request = $this->getRequest();
774
        $service = $this->getServiceLocator()->get('zfcuser_user_service');
775
        $form = $this->getServiceLocator()->get('playgroundgame_register_form');
776
        $socialnetwork = $this->params()->fromRoute('socialnetwork', false);
777
        $form->setAttribute(
778
            'action',
779
            $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...
780
                $this->game->getClassType().'/user-register',
781
                array('id' => $this->game->getIdentifier())
782
            )
783
        );
784
        $params = array();
785
        $socialCredentials = array();
786
787
        if ($userOptions->getUseRedirectParameterIfPresent() && $request->getQuery()->get('redirect')) {
788
            $redirect = $request->getQuery()->get('redirect');
789
        } else {
790
            $redirect = false;
791
        }
792
793
        if ($socialnetwork) {
794
            $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...
795
796
            if (!empty($infoMe)) {
797
                $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...
798
                    $infoMe->identifier,
799
                    $socialnetwork
800
                );
801
802
                if ($user || $service->getOptions()->getCreateUserAutoSocial() === true) {
803
                    //on le dirige vers l'action d'authentification
804
                    if (! $redirect && $userOptions->getLoginRedirectRoute() != '') {
805
                        $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...
806
                            $this->game->getClassType().'/login',
807
                            array('id' => $this->game->getIdentifier())
808
                        );
809
                    }
810
                    $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...
811
                        $this->game->getClassType().'/login',
812
                        array('id' => $this->game->getIdentifier())
813
                    ) .'/' . $socialnetwork . ($redirect ? '?redirect=' . $redirect : '');
814
815
                    return $this->redirect()->toUrl($redir);
816
                }
817
818
                // Je retire la saisie du login/mdp
819
                $form->setAttribute(
820
                    'action',
821
                    $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...
822
                        $this->game->getClassType().'/user-register',
823
                        array(
824
                            'id' => $this->game->getIdentifier(),
825
                            'socialnetwork' => $socialnetwork,
826
                            
827
                        )
828
                    )
829
                );
830
                $form->remove('password');
831
                $form->remove('passwordVerify');
832
833
                $birthMonth = $infoMe->birthMonth;
834
                if (strlen($birthMonth) <= 1) {
835
                    $birthMonth = '0'.$birthMonth;
836
                }
837
                $birthDay = $infoMe->birthDay;
838
                if (strlen($birthDay) <= 1) {
839
                    $birthDay = '0'.$birthDay;
840
                }
841
842
                $gender = $infoMe->gender;
843
                if ($gender == 'female') {
844
                    $title = 'Me';
845
                } else {
846
                    $title = 'M';
847
                }
848
849
                $params = array(
850
                    //'birth_year'  => $infoMe->birthYear,
851
                    'title'      => $title,
852
                    'dob'      => $birthDay.'/'.$birthMonth.'/'.$infoMe->birthYear,
853
                    'firstname'   => $infoMe->firstName,
854
                    'lastname'    => $infoMe->lastName,
855
                    'email'       => $infoMe->email,
856
                    'postalCode' => $infoMe->zip,
857
                );
858
                $socialCredentials = array(
859
                    'socialNetwork' => strtolower($socialnetwork),
860
                    'socialId'      => $infoMe->identifier,
861
                );
862
            }
863
        }
864
865
        $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...
866
            $this->game->getClassType().'/user-register',
867
            array('id' => $this->game->getIdentifier())
868
        ) .($socialnetwork ? '/' . $socialnetwork : ''). ($redirect ? '?redirect=' . $redirect : '');
869
        $prg = $this->prg($redirectUrl, true);
870
871
        if ($prg instanceof Response) {
872
            return $prg;
873
        } elseif ($prg === false) {
874
            $form->setData($params);
875
            $viewModel = $this->buildView($this->game);
876
            $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...
877
                'registerForm' => $form,
878
                'enableRegistration' => $userOptions->getEnableRegistration(),
879
                'redirect' => $redirect,
880
            ));
881
            return $viewModel;
882
        }
883
884
        $post = $prg;
885
        $post = array_merge(
886
            $post,
887
            $socialCredentials
888
        );
889
890
        if ($this->game->getOnInvitation()) {
891
            $credential = trim(
892
                $post[$this->getGameService()->getOptions()->getOnInvitationField()]
893
            );
894
            if (!$credential) {
895
                $credential = $this->params()->fromQuery(
896
                    $this->getGameService()->getOptions()->getOnInvitationField()
897
                );
898
            }
899
            $found = $this->getGameService()->getInvitationMapper()->findOneBy(array('requestKey'=>$credential));
900
901
            if (!$found || !empty($found->getUser())) {
902
                $this->flashMessenger()->addMessage(
903
                    'Authentication failed. Please try again.'
904
                );
905
                $form->setData($post);
906
                $viewModel = $this->buildView($this->game);
907
                $viewModel->setVariables(array(
908
                    'registerForm' => $form,
909
                    'enableRegistration' => $userOptions->getEnableRegistration(),
910
                    'redirect' => $redirect,
911
                    'flashMessages'    => $this->flashMessenger()->getMessages(),
912
                    'flashErrors'      => $this->flashMessenger()->getErrorMessages(),
913
                ));
914
915
                return $viewModel;
916
            }
917
        }
918
919
        $user = $service->register($post, 'playgroundgame_register_form');
920
921
        if (! $user) {
922
            $viewModel = $this->buildView($this->game);
923
            $viewModel->setVariables(array(
924
                'registerForm' => $form,
925
                'enableRegistration' => $userOptions->getEnableRegistration(),
926
                'redirect' => $redirect,
927
                'flashMessages'    => $this->flashMessenger()->getMessages(),
928
                'flashErrors'      => $this->flashMessenger()->getErrorMessages(),
929
            ));
930
            
931
            return $viewModel;
932
        }
933
934
        if ($this->game->getOnInvitation()) {
935
            // user has been created, associate the code with the userId
936
            $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...
937
            $this->getGameService()->getInvitationMapper()->update($found);
938
        }
939
940
        if ($service->getOptions()->getEmailVerification()) {
941
            $vm = new ViewModel(array('userEmail' => $user->getEmail()));
942
            $vm->setTemplate('playground-user/register/registermail');
943
944
            return $vm;
945
        } elseif ($service->getOptions()->getLoginAfterRegistration()) {
946
            $identityFields = $service->getOptions()->getAuthIdentityFields();
947
            if (in_array('email', $identityFields)) {
948
                $post['identity'] = $user->getEmail();
949
            } elseif (in_array('username', $identityFields)) {
950
                $post['identity'] = $user->getUsername();
951
            }
952
            $post['credential'] = isset($post['password'])?$post['password']:'';
953
            $request->setPost(new Parameters($post));
954
955
            // clear adapters
956
            $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...
957
            $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...
958
959
            $logged = $this->forward()->dispatch('playgrounduser_user', array('action' => 'ajaxauthenticate'));
960
961
            if ($logged) {
962
                return $this->redirect()->toUrl(
963
                    $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...
964
                        $this->game->getClassType(),
965
                        array('id' => $this->game->getIdentifier())
966
                    )
967
                );
968
            } else {
969
                $this->flashMessenger()->setNamespace('zfcuser-login-form')->addMessage(
970
                    'Authentication failed. Please try again.'
971
                );
972
                return $this->redirect()->toUrl(
973
                    $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...
974
                        $this->game->getClassType() . '/login',
975
                        array('id' => $this->game->getIdentifier())
976
                    )
977
                );
978
            }
979
        }
980
981
        $redirect = $this->frontendUrl()->fromRoute(
0 ignored issues
show
Documentation Bug introduced by
The method frontendUrl does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

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

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

class ParentClass {
    private $data = array();

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

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

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