Completed
Pull Request — master (#279)
by greg
10:07 queued 04:42
created

GameController::userProfileAction()   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.4286
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
        'play',
44
        'result',
45
        'preview',
46
        'list'
47
    );
48
49
    protected $withOnlineGame = array(
50
        'leaderboard',
51
        'register',
52
        'bounce',
53
        'play',
54
        'result'
55
    );
56
57
    protected $withAnyUser = array(
58
        'share',
59
        'result',
60
        'play'
61
    );
62
63
    public function setEventManager(\Zend\EventManager\EventManagerInterface $events)
64
    {
65
        parent::setEventManager($events);
66
67
        $controller = $this;
68
        $events->attach('dispatch', function (\Zend\Mvc\MvcEvent $e) use ($controller) {
69
70
            $identifier = $e->getRouteMatch()->getParam('id');
71
            $controller->game = $controller->getGameService()->checkGame($identifier, false);
72
            if (!$controller->game &&
73
                in_array($controller->params('action'), $controller->withGame)
74
            ) {
75
                return $controller->notFoundAction();
76
            }
77
78
            if ($controller->game &&
79
                $controller->game->isClosed() &&
80
                in_array($controller->params('action'), $controller->withOnlineGame)
81
            ) {
82
                return $controller->notFoundAction();
83
            }
84
85
            if ($controller->game) {
86
                // this is possible to create a specific game design in /design/frontend/default/custom.
87
                //It will precede all others templates.
88
                $templatePathResolver = $controller->getServiceLocator()->get('Zend\View\Resolver\TemplatePathStack');
89
                $l = $templatePathResolver->getPaths();
90
                $templatePathResolver->addPath($l[0].'custom/'.$controller->game->getIdentifier());
91
            }
92
93
            $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...
94
            if ($controller->game &&
95
                !$controller->user &&
96
                !$controller->game->getAnonymousAllowed() &&
97
                in_array($controller->params('action'), $controller->withAnyUser)
98
            ) {
99
                $redirect = urlencode(
100
                    $controller->url()->fromRoute(
101
                        'frontend/'.$controller->game->getClassType() . '/' . $controller->params('action'),
102
                        array('id' => $controller->game->getIdentifier()),
103
                        array('force_canonical' => true)
104
                    )
105
                );
106
107
                $urlRegister = $controller->url()->fromRoute(
108
                    'frontend/zfcuser/register',
109
                    array(),
110
                    array('force_canonical' => true)
111
                ) . '?redirect='.$redirect;
112
113
                // code permettant d'identifier un custom game
114
                // ligne $config = $controller->getGameService()->getServiceManager()->get('config');
115
                // ligne $customUrl = str_replace('frontend.', '', $e->getRouteMatch()->getParam('area', ''));
116
                // ligne if ($config['custom_games'][$controller->game->getIdentifier()] &&
117
                // ligne    $controller->getRequest()->getUri()->getHost() === $customUrl
118
                // ligne ) {
119
                return $controller->redirect()->toUrl($urlRegister);
120
            }
121
122
            return;
123
        }, 100); // execute before executing action logic
124
    }
125
126
    /**
127
     * Action called if matched action does not exist
128
     * For this view not to be catched by Zend\Mvc\View\RouteNotFoundStrategy
129
     * it has to be rendered in the controller. Hence the code below.
130
     *
131
     * This action is injected as a catchall action for each custom_games definition
132
     * This way, when a custom_game is created, the 404 is it's responsability and the
133
     * view can be defined in design/frontend/default/custom/$slug/playground_game/$gametype/404.phtml
134
     *
135
     *
136
     * @return \Zend\Stdlib\ResponseInterface
137
     */
138
    public function notFoundAction()
139
    {
140
        $templatePathResolver = $this->getServiceLocator()->get('Zend\View\Resolver\TemplatePathStack');
141
142
        // Figuring out the template path name based on the controller name
143
        $controller = explode('\\', get_class($this));
144
        $controllerPath = str_replace('Controller', '', end($controller));
145
        $controllerPath = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '-\\1', $controllerPath));
146
147
        $template = 'playground-game/'.$controllerPath . $this->getRequest()->getUri()->getPath();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Zend\Stdlib\RequestInterface as the method getUri() does only exist in the following implementations of said interface: Zend\Http\PhpEnvironment\Request, Zend\Http\Request.

Let’s take a look at an example:

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

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

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

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

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

Available Fixes

  1. Change the type-hint for the parameter:

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

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

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

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

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

class ParentClass {
    private $data = array();

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

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

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
729
                $this->game->getClassType().'/login',
730
                array('id' => $this->game->getIdentifier())
731
            )
732
        );
733
        $viewModel = $this->buildView($this->game);
734
        $viewModel->setVariables(array(
735
            'form' => $form,
736
            'flashMessages' => $this->flashMessenger()->getMessages(),
737
        ));
738
        return $viewModel;
739
    }
740
741
    public function userregisterAction()
742
    {
743
        $userOptions = $this->getServiceLocator()->get('zfcuser_module_options');
744
745
        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...
746
            return $this->redirect()->toUrl(
747
                $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...
748
                    $this->game->getClassType().'/'.$this->game->nextStep('index'),
749
                    array('id' => $this->game->getIdentifier())
750
                )
751
            );
752
        }
753
        $request = $this->getRequest();
754
        $service = $this->getServiceLocator()->get('zfcuser_user_service');
755
        $form = $this->getServiceLocator()->get('playgroundgame_register_form');
756
        $socialnetwork = $this->params()->fromRoute('socialnetwork', false);
757
        $form->setAttribute(
758
            'action',
759
            $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...
760
                $this->game->getClassType().'/user-register',
761
                array('id' => $this->game->getIdentifier())
762
            )
763
        );
764
        $params = array();
765
        $socialCredentials = array();
766
767
        if ($userOptions->getUseRedirectParameterIfPresent() && $request->getQuery()->get('redirect')) {
768
            $redirect = $request->getQuery()->get('redirect');
769
        } else {
770
            $redirect = false;
771
        }
772
773
        if ($socialnetwork) {
774
            $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...
775
776
            if (!empty($infoMe)) {
777
                $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...
778
                    $infoMe->identifier,
779
                    $socialnetwork
780
                );
781
782
                if ($user || $service->getOptions()->getCreateUserAutoSocial() === true) {
783
                    //on le dirige vers l'action d'authentification
784
                    if (! $redirect && $userOptions->getLoginRedirectRoute() != '') {
785
                        $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...
786
                            $this->game->getClassType().'/login',
787
                            array('id' => $this->game->getIdentifier())
788
                        );
789
                    }
790
                    $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...
791
                        $this->game->getClassType().'/login',
792
                        array('id' => $this->game->getIdentifier())
793
                    ) .'/' . $socialnetwork . ($redirect ? '?redirect=' . $redirect : '');
794
795
                    return $this->redirect()->toUrl($redir);
796
                }
797
798
                // Je retire la saisie du login/mdp
799
                $form->setAttribute(
800
                    'action',
801
                    $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...
802
                        $this->game->getClassType().'/user-register',
803
                        array(
804
                            'id' => $this->game->getIdentifier(),
805
                            'socialnetwork' => $socialnetwork,
806
                            
807
                        )
808
                    )
809
                );
810
                $form->remove('password');
811
                $form->remove('passwordVerify');
812
813
                $birthMonth = $infoMe->birthMonth;
814
                if (strlen($birthMonth) <= 1) {
815
                    $birthMonth = '0'.$birthMonth;
816
                }
817
                $birthDay = $infoMe->birthDay;
818
                if (strlen($birthDay) <= 1) {
819
                    $birthDay = '0'.$birthDay;
820
                }
821
822
                $gender = $infoMe->gender;
823
                if ($gender == 'female') {
824
                    $title = 'Me';
825
                } else {
826
                    $title = 'M';
827
                }
828
829
                $params = array(
830
                    //'birth_year'  => $infoMe->birthYear,
831
                    'title'      => $title,
832
                    'dob'      => $birthDay.'/'.$birthMonth.'/'.$infoMe->birthYear,
833
                    'firstname'   => $infoMe->firstName,
834
                    'lastname'    => $infoMe->lastName,
835
                    'email'       => $infoMe->email,
836
                    'postalCode' => $infoMe->zip,
837
                );
838
                $socialCredentials = array(
839
                    'socialNetwork' => strtolower($socialnetwork),
840
                    'socialId'      => $infoMe->identifier,
841
                );
842
            }
843
        }
844
845
        $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...
846
            $this->game->getClassType().'/user-register',
847
            array('id' => $this->game->getIdentifier())
848
        ) .($socialnetwork ? '/' . $socialnetwork : ''). ($redirect ? '?redirect=' . $redirect : '');
849
        $prg = $this->prg($redirectUrl, true);
850
851
        if ($prg instanceof Response) {
852
            return $prg;
853
        } elseif ($prg === false) {
854
            $form->setData($params);
855
            $viewModel = $this->buildView($this->game);
856
            $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...
857
                'registerForm' => $form,
858
                'enableRegistration' => $userOptions->getEnableRegistration(),
859
                'redirect' => $redirect,
860
            ));
861
            return $viewModel;
862
        }
863
864
        $post = $prg;
865
        $post = array_merge(
866
            $post,
867
            $socialCredentials
868
        );
869
870
        if ($this->game->getOnInvitation()) {
871
            $credential = trim(
872
                $post[$this->getGameService()->getOptions()->getOnInvitationField()]
873
            );
874
            if (!$credential) {
875
                $credential = $this->params()->fromQuery(
876
                    $this->getGameService()->getOptions()->getOnInvitationField()
877
                );
878
            }
879
            $found = $this->getGameService()->getInvitationMapper()->findOneBy(array('requestKey'=>$credential));
880
881
            if (!$found || !empty($found->getUser())) {
882
                $this->flashMessenger()->addMessage(
883
                    'Authentication failed. Please try again.'
884
                );
885
                $form->setData($post);
886
                $viewModel = $this->buildView($this->game);
887
                $viewModel->setVariables(array(
888
                    'registerForm' => $form,
889
                    'enableRegistration' => $userOptions->getEnableRegistration(),
890
                    'redirect' => $redirect,
891
                    'flashMessages'    => $this->flashMessenger()->getMessages(),
892
                    'flashErrors'      => $this->flashMessenger()->getErrorMessages(),
893
                ));
894
895
                return $viewModel;
896
            }
897
        }
898
899
        $user = $service->register($post, 'playgroundgame_register_form');
900
901
        if (! $user) {
902
            $viewModel = $this->buildView($this->game);
903
            $viewModel->setVariables(array(
904
                'registerForm' => $form,
905
                'enableRegistration' => $userOptions->getEnableRegistration(),
906
                'redirect' => $redirect,
907
            ));
908
            
909
            return $viewModel;
910
        }
911
912
        if ($this->game->getOnInvitation()) {
913
            // user has been created, associate the code with the userId
914
            $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...
915
            $this->getGameService()->getInvitationMapper()->update($found);
916
        }
917
918
        if ($service->getOptions()->getEmailVerification()) {
919
            $vm = new ViewModel(array('userEmail' => $user->getEmail()));
920
            $vm->setTemplate('playground-user/register/registermail');
921
922
            return $vm;
923
        } elseif ($service->getOptions()->getLoginAfterRegistration()) {
924
            $identityFields = $service->getOptions()->getAuthIdentityFields();
925
            if (in_array('email', $identityFields)) {
926
                $post['identity'] = $user->getEmail();
927
            } elseif (in_array('username', $identityFields)) {
928
                $post['identity'] = $user->getUsername();
929
            }
930
            $post['credential'] = isset($post['password'])?$post['password']:'';
931
            $request->setPost(new Parameters($post));
932
933
            // clear adapters
934
            $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...
935
            $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...
936
937
            $logged = $this->forward()->dispatch('playgrounduser_user', array('action' => 'ajaxauthenticate'));
938
939
            if ($logged) {
940
                return $this->redirect()->toUrl(
941
                    $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...
942
                        $this->game->getClassType(),
943
                        array('id' => $this->game->getIdentifier())
944
                    )
945
                );
946
            } else {
947
                $this->flashMessenger()->setNamespace('zfcuser-login-form')->addMessage(
948
                    'Authentication failed. Please try again.'
949
                );
950
                return $this->redirect()->toUrl(
951
                    $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...
952
                        $this->game->getClassType() . '/login',
953
                        array('id' => $this->game->getIdentifier())
954
                    )
955
                );
956
            }
957
        }
958
959
        $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...
960
            $this->game->getClassType().'/login',
961
            array(
962
                'id' => $this->game->getIdentifier(),
963
                
964
            )
965
        ) . ($socialnetwork ? '/' . $socialnetwork : ''). ($redirect ? '?redirect=' . $redirect : '');
966
967
        return $this->redirect()->toUrl($redirect);
968
    }
969
970 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...
971
    {
972
        $viewModel = $this->forward()->dispatch(
973
            'playgrounduser_user',
974
            array(
975
                'controller' => 'playgrounduser_user',
976
                'action' => 'profile',
977
                'id' => $this->game->getIdentifier()
978
            )
979
        );
980
981
        if ($viewModel && $viewModel instanceof \Zend\View\Model\ViewModel) {
982
            $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...
983
            $viewModel->setVariables(array('game' => $this->game));
984
        }
985
986
        return $viewModel;
987
    }
988
989 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...
990
    {
991
        $viewModel = $this->forward()->dispatch(
992
            'playgroundcms',
993
            array(
994
                'controller' => 'playgroundcms',
995
                'action' => 'index',
996
                'id' => $this->game->getIdentifier(),
997
                'pid' => $this->getEvent()->getRouteMatch()->getParam('pid')
998
            )
999
        );
1000
1001
        if ($viewModel && $viewModel instanceof \Zend\View\Model\ViewModel) {
1002
            $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...
1003
            $viewModel->setVariables(array('game' => $this->game));
1004
        }
1005
1006
        return $viewModel;
1007
    }
1008
1009 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...
1010
    {
1011
        $viewModel = $this->forward()->dispatch(
1012
            'playgroundcms',
1013
            array(
1014
                'controller' => 'playgroundcms',
1015
                'action' => 'list',
1016
                'id' => $this->game->getIdentifier(),
1017
                'category' => $this->game->getIdentifier()
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
    /**
1030
     *
1031
     * @param \PlaygroundGame\Entity\Game $game
1032
     * @param \PlaygroundUser\Entity\User $user
1033
     */
1034
    public function checkFbRegistration($user, $game)
1035
    {
1036
        $redirect = false;
1037
        $session = new Container('facebook');
1038
        if ($session->offsetExists('signed_request')) {
1039
            if (!$user) {
1040
                // Get Playground user from Facebook info
1041
                $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...
1042
                $view = $this->forward()->dispatch(
1043
                    'playgrounduser_user',
1044
                    array(
1045
                        'controller' => 'playgrounduser_user',
1046
                        'action' => 'registerFacebookUser',
1047
                        'provider' => 'facebook'
1048
                    )
1049
                );
1050
1051
                $this->layout()->setTemplate($beforeLayout);
1052
                $user = $view->user;
1053
1054
                // If the user can not be created/retrieved from Facebook info, redirect to login/register form
1055
                if (!$user) {
1056
                    $redirectUrl = urlencode(
1057
                        $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...
1058
                            $game->getClassType() .'/play',
1059
                            array('id' => $game->getIdentifier()),
1060
                            array('force_canonical' => true)
1061
                        )
1062
                    );
1063
                    $redirect =  $this->redirect()->toUrl(
1064
                        $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...
1065
                            'zfcuser/register'
1066
                        ) . '?redirect='.$redirectUrl
1067
                    );
1068
                }
1069
            }
1070
1071
            if ($game->getFbFan()) {
1072
                if ($this->getGameService()->checkIsFan($game) === false) {
1073
                    $redirect =  $this->redirect()->toRoute(
1074
                        $game->getClassType().'/fangate',
1075
                        array('id' => $game->getIdentifier())
1076
                    );
1077
                }
1078
            }
1079
        }
1080
1081
        return $redirect;
1082
    }
1083
1084
    /**
1085
     * This method create the basic Game view
1086
     * @param \PlaygroundGame\Entity\Game $game
1087
     */
1088
    public function buildView($game)
1089
    {
1090
        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...
1091
            $viewModel = new JsonModel();
1092
            if ($game) {
1093
                $view = $this->addAdditionalView($game);
1094
                if ($view && $view instanceof \Zend\View\Model\ViewModel) {
1095
                    $viewModel->setVariables($view->getVariables());
1096
                }
1097
            }
1098
        } else {
1099
            $viewModel = new ViewModel();
1100
1101
            if ($game) {
1102
                $this->addMetaTitle($game);
1103
                $this->addMetaBitly();
1104
                $this->addGaEvent($game);
1105
1106
                $this->customizeGameDesign($game);
1107
                
1108
                $view = $this->addAdditionalView($game);
1109
                if ($view && $view instanceof \Zend\View\Model\ViewModel) {
1110
                    $viewModel->addChild($view, 'additional');
1111
                } elseif ($view && $view instanceof \Zend\Http\PhpEnvironment\Response) {
1112
                    return $view;
1113
                }
1114
1115
                $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...
1116
                    array(
1117
                        'action' => $this->params('action'),
1118
                        'game' => $game,
1119
                        'flashMessages'    => $this->flashMessenger()->getMessages(),
1120
                        
1121
                    )
1122
                );
1123
            }
1124
        }
1125
        
1126
        if ($game) {
1127
            $viewModel->setVariables($this->getShareData($game));
1128
            $viewModel->setVariables(array('game' => $game, 'user' => $this->user));
1129
        }
1130
1131
        return $viewModel;
1132
    }
1133
1134
    /**
1135
     * @param \PlaygroundGame\Entity\Game $game
1136
     */
1137
    public function addAdditionalView($game)
1138
    {
1139
        $view = false;
1140
1141
        $actionName = $this->getEvent()->getRouteMatch()->getParam('action', 'not-found');
1142
        $stepsViews = json_decode($game->getStepsViews(), true);
1143
        if ($stepsViews && isset($stepsViews[$actionName])) {
1144
            $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...
1145
            $actionData = $stepsViews[$actionName];
1146
            if (is_string($actionData)) {
1147
                $action = $actionData;
1148
                $controller = $this->getEvent()->getRouteMatch()->getParam('controller', 'playgroundgame_game');
1149
                $view = $this->forward()->dispatch(
1150
                    $controller,
1151
                    array(
1152
                        'action' => $action,
1153
                        'id' => $game->getIdentifier()
1154
                    )
1155
                );
1156
            } elseif (is_array($actionData) && count($actionData)>0) {
1157
                $action = key($actionData);
1158
                $controller = $actionData[$action];
1159
                $view = $this->forward()->dispatch(
1160
                    $controller,
1161
                    array(
1162
                        'action' => $action,
1163
                        'id' => $game->getIdentifier()
1164
                    )
1165
                );
1166
            }
1167
            // suite au forward, le template de layout a changé, je dois le rétablir...
1168
            $this->layout()->setTemplate($beforeLayout);
1169
        }
1170
1171
        return $view;
1172
    }
1173
1174
    public function addMetaBitly()
1175
    {
1176
        $bitlyclient = $this->getOptions()->getBitlyUrl();
1177
        $bitlyuser = $this->getOptions()->getBitlyUsername();
1178
        $bitlykey = $this->getOptions()->getBitlyApiKey();
1179
1180
        $this->getViewHelper('HeadMeta')->setProperty('bt:client', $bitlyclient);
1181
        $this->getViewHelper('HeadMeta')->setProperty('bt:user', $bitlyuser);
1182
        $this->getViewHelper('HeadMeta')->setProperty('bt:key', $bitlykey);
1183
    }
1184
1185
    /**
1186
     * @param \PlaygroundGame\Entity\Game $game
1187
     */
1188
    public function addGaEvent($game)
1189
    {
1190
        // Google Analytics event
1191
        $ga = $this->getServiceLocator()->get('google-analytics');
1192
        $event = new \PlaygroundCore\Analytics\Event($game->getClassType(), $this->params('action'));
1193
        $event->setLabel($game->getTitle());
1194
        $ga->addEvent($event);
1195
    }
1196
1197
    /**
1198
     * @param \PlaygroundGame\Entity\Game $game
1199
     */
1200
    public function addMetaTitle($game)
1201
    {
1202
        $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...
1203
        $this->getGameService()->getServiceManager()->get('ViewHelperManager')->get('HeadTitle')->set($title);
1204
        // Meta set in the layout
1205
        $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...
1206
            array(
1207
                'breadcrumbTitle' => $title,
1208
                'currentPage' => array(
1209
                    'pageGames' => 'games',
1210
                    'pageWinners' => ''
1211
                ),
1212
                'headParams' => array(
1213
                    'headTitle' => $title,
1214
                    'headDescription' => $title,
1215
                ),
1216
                'bodyCss' => $game->getIdentifier()
1217
            )
1218
        );
1219
    }
1220
1221
    /**
1222
     * @param \PlaygroundGame\Entity\Game $game
1223
     */
1224
    public function customizeGameDesign($game)
1225
    {
1226
        // If this game has a specific layout...
1227
        if ($game->getLayout()) {
1228
            $layoutViewModel = $this->layout();
1229
            $layoutViewModel->setTemplate($game->getLayout());
1230
        }
1231
1232
        // If this game has a specific stylesheet...
1233
        if ($game->getStylesheet()) {
1234
            $this->getViewHelper('HeadLink')->appendStylesheet(
1235
                $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...
1236
            );
1237
        }
1238
    }
1239
1240
    /**
1241
     * @param \PlaygroundGame\Entity\Game $game
1242
     */
1243
    public function getShareData($game)
1244
    {
1245
        $fo = $this->getServiceLocator()->get('facebook-opengraph');
1246
        $session = new Container('facebook');
1247
1248
        // I change the fbappid if i'm in fb
1249
        if ($session->offsetExists('signed_request')) {
1250
            $fo->setId($game->getFbAppId());
1251
        }
1252
1253
        // If I want to add a share block in my view
1254 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...
1255
            $fbShareMessage = $game->getFbShareMessage();
1256
        } else {
1257
            $fbShareMessage = str_replace(
1258
                '__placeholder__',
1259
                $game->getTitle(),
1260
                $this->getOptions()->getDefaultShareMessage()
1261
            );
1262
        }
1263
1264
        if ($game->getFbShareImage()) {
1265
            $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...
1266
                '',
1267
                array(),
1268
                array('force_canonical' => true),
1269
                false
1270
            ) . $game->getFbShareImage();
1271
        } else {
1272
            $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...
1273
                '',
1274
                array(),
1275
                array('force_canonical' => true),
1276
                false
1277
            ) . $game->getMainImage();
1278
        }
1279
1280
        $secretKey = strtoupper(substr(sha1(uniqid('pg_', true).'####'.time()), 0, 15));
1281
1282
        // Without bit.ly shortener
1283
        $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...
1284
            $game->getClassType(),
1285
            array('id' => $game->getIdentifier()),
1286
            array('force_canonical' => true)
1287
        );
1288
        // With core shortener helper
1289
        $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...
1290
1291
        // FB Requests only work when it's a FB app
1292
        if ($game->getFbRequestMessage()) {
1293
            $fbRequestMessage = urlencode($game->getFbRequestMessage());
1294
        } else {
1295
            $fbRequestMessage = str_replace(
1296
                '__placeholder__',
1297
                $game->getTitle(),
1298
                $this->getOptions()->getDefaultShareMessage()
1299
            );
1300
        }
1301
1302 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...
1303
            $twShareMessage = $game->getTwShareMessage() . $socialLinkUrl;
1304
        } else {
1305
            $twShareMessage = str_replace(
1306
                '__placeholder__',
1307
                $game->getTitle(),
1308
                $this->getOptions()->getDefaultShareMessage()
1309
            ) . $socialLinkUrl;
1310
        }
1311
1312
        $ogTitle = new \PlaygroundCore\Opengraph\Tag('og:title', $fbShareMessage);
1313
        $ogImage = new \PlaygroundCore\Opengraph\Tag('og:image', $fbShareImage);
1314
        
1315
        $fo->addTag($ogTitle);
1316
        $fo->addTag($ogImage);
1317
        
1318
        $data = array(
1319
            'socialLinkUrl'       => $socialLinkUrl,
1320
            'secretKey'           => $secretKey,
1321
            'fbShareMessage'      => $fbShareMessage,
1322
            'fbShareImage'        => $fbShareImage,
1323
            'fbRequestMessage'    => $fbRequestMessage,
1324
            'twShareMessage'      => $twShareMessage,
1325
        );
1326
1327
        return $data;
1328
    }
1329
    
1330
    /**
1331
     * return ajax response in json format
1332
     *
1333
     * @param array $data
1334
     * @return \Zend\View\Model\JsonModel
1335
     */
1336 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...
1337
    {
1338
        $model = new JsonModel(array(
1339
            'success' => true,
1340
            'data' => $data
1341
        ));
1342
        return $model->setTerminal(true);
1343
    }
1344
    
1345
    /**
1346
     * return ajax response in json format
1347
     *
1348
     * @param string $message
1349
     * @return \Zend\View\Model\JsonModel
1350
     */
1351 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...
1352
    {
1353
        $model = new JsonModel(array(
1354
            'success' => false,
1355
            'message' => $message
1356
        ));
1357
        return $model->setTerminal(true);
1358
    }
1359
1360
    /**
1361
     * @param string $helperName
1362
     */
1363
    protected function getViewHelper($helperName)
1364
    {
1365
        return $this->getServiceLocator()->get('viewhelpermanager')->get($helperName);
1366
    }
1367
1368
    public function getGameService()
1369
    {
1370
        if (!$this->gameService) {
1371
            $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...
1372
        }
1373
1374
        return $this->gameService;
1375
    }
1376
1377
    public function setGameService(GameService $gameService)
1378
    {
1379
        $this->gameService = $gameService;
1380
1381
        return $this;
1382
    }
1383
1384
    public function getPrizeService()
1385
    {
1386
        if (!$this->prizeService) {
1387
            $this->prizeService = $this->getServiceLocator()->get('playgroundgame_prize_service');
1388
        }
1389
1390
        return $this->prizeService;
1391
    }
1392
1393
    public function setPrizeService(PrizeService $prizeService)
1394
    {
1395
        $this->prizeService = $prizeService;
1396
1397
        return $this;
1398
    }
1399
1400
    public function getOptions()
1401
    {
1402
        if (!$this->options) {
1403
            $this->setOptions($this->getServiceLocator()->get('playgroundcore_module_options'));
1404
        }
1405
1406
        return $this->options;
1407
    }
1408
1409
    public function setOptions($options)
1410
    {
1411
        $this->options = $options;
1412
1413
        return $this;
1414
    }
1415
}
1416