Completed
Push — master ( c66de5...21ba74 )
by greg
10:56 queued 08:43
created

GameController::setOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace PlaygroundGame\Controller\Frontend;
4
5
use PlaygroundGame\Service\GameService;
6
use PlaygroundGame\Service\Prize as PrizeService;
7
use Zend\Http\PhpEnvironment\Response;
8
use Zend\Mvc\Controller\AbstractActionController;
9
use Zend\ServiceManager\ServiceLocatorInterface;
10
use Zend\Session\Container;
11
use Zend\Stdlib\Parameters;
12
use Zend\View\Model\JsonModel;
13
use Zend\View\Model\ViewModel;
14
15
class GameController extends AbstractActionController {
16
	/**
17
	 * @var \PlaygroundGame\Service\GameService
18
	 */
19
	protected $gameService;
20
21
	protected $prizeService;
22
23
	protected $options;
24
25
	protected $game;
26
27
	protected $user;
28
29
	protected $withGame = array(
30
		'home',
31
		'index',
32
		'terms',
33
		'conditions',
34
		'leaderboard',
35
		'register',
36
		'bounce',
37
		'inviteToTeam',
38
		'prizes',
39
		'prize',
40
		'fangate',
41
		'share',
42
		'optin',
43
		'login',
44
		'logout',
45
		'ajaxforgot',
46
		'play',
47
		'result',
48
		'preview',
49
		'list',
50
		'comments',
51
	);
52
53
	protected $withOnlineGame = array(
54
		'leaderboard',
55
		'register',
56
		'bounce',
57
		'play',
58
		'result',
59
	);
60
61
	protected $withAnyUser = array(
62
		'share',
63
		'result',
64
		'play',
65
		'logout',
66
		'inviteToTeam',
67
	);
68
69
	/**
70
	 *
71
	 * @var ServiceManager
72
	 */
73
	protected $serviceLocator;
74
75
	public function __construct(ServiceLocatorInterface $locator) {
76
		$this->serviceLocator = $locator;
0 ignored issues
show
Documentation Bug introduced by
It seems like $locator of type object<Zend\ServiceManag...erviceLocatorInterface> is incompatible with the declared type object<PlaygroundGame\Co...rontend\ServiceManager> of property $serviceLocator.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
77
	}
78
79
	public function getServiceLocator() {
80
		return $this->serviceLocator;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->serviceLocator; (PlaygroundGame\Controller\Frontend\ServiceManager) is incompatible with the return type of the parent method Zend\Mvc\Controller\Abst...ller::getServiceLocator of type Zend\ServiceManager\ServiceLocatorInterface.

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

Let’s take a look at an example:

class Author {
    private $name;

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

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

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

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

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

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

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

Loading history...
81
	}
82
83
	public function setEventManager(\Zend\EventManager\EventManagerInterface $events) {
84
		parent::setEventManager($events);
85
86
		$controller = $this;
87
		$events->attach('dispatch', function (\Zend\Mvc\MvcEvent $e) use ($controller) {
88
				$identifier = $e->getRouteMatch()->getParam('id');
89
				$controller->game = $controller->getGameService()->checkGame($identifier, false);
90
				if (!$controller->game &&
91
					in_array($controller->params('action'), $controller->withGame)
92
				) {
93
					return $controller->notFoundAction();
94
				}
95
96
				if ($controller->game &&
97
					$controller->game->isClosed() &&
98
					in_array($controller->params('action'), $controller->withOnlineGame)
99
				) {
100
					return $controller->notFoundAction();
101
				}
102
103
				if ($controller->game) {
104
					// this is possible to create a specific game design in /design/frontend/default/custom.
105
					//It will precede all others templates.
106
					$templatePathResolver = $controller->getServiceLocator()->get('Zend\View\Resolver\TemplatePathStack');
107
					$l = $templatePathResolver->getPaths();
108
					$templatePathResolver->addPath($l[0].'custom/'.$controller->game->getIdentifier());
109
				}
110
111
				$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...
112
				if ($controller->game &&
113
					!$controller->user &&
114
					!$controller->game->getAnonymousAllowed() &&
115
					in_array($controller->params('action'), $controller->withAnyUser)
116
				) {
117
					$redirect = urlencode(
118
						$controller->url()->fromRoute(
119
							'frontend/'.$controller->game->getClassType().'/'.$controller->params('action'),
120
							array('id'              => $controller->game->getIdentifier()),
121
							array('force_canonical' => true)
122
						)
123
					);
124
125
					// code permettant d'identifier un custom game
126
					$config = $controller->getGameService()->getServiceManager()->get('config');
127
					$customUrl = str_replace('frontend.', '', $e->getRouteMatch()->getMatchedRouteName());
128
					$customUrl = explode("/", $customUrl)[0];
129
130
					if ($config['custom_games'][$controller->game->getIdentifier()] &&
131
						$controller->getRequest()->getUri()->getHost() === $customUrl
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Zend\Stdlib\RequestInterface as the method getUri() does only exist in the following implementations of said interface: Zend\Http\PhpEnvironment\Request, Zend\Http\Request.

Let’s take a look at an example:

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

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

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

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

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

Available Fixes

  1. Change the type-hint for the parameter:

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

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

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
132
					) {
133
						$urlRegister = $controller->url()->fromRoute(
134
							'frontend.'.$customUrl.'/'.$controller->game->getClassType().'/user-register',
135
							array(),
136
							array('force_canonical' => true)
137
						).'?redirect='.$redirect;
138
					} else {
139
						$urlRegister = $controller->url()->fromRoute(
140
							'frontend/zfcuser/register',
141
							array(),
142
							array('force_canonical' => true)
143
						).'?redirect='.$redirect;
144
					}
145
					return $controller->redirect()->toUrl($urlRegister);
146
				}
147
148
				return;
149
			}, 100);// execute before executing action logic
150
	}
151
152
	/**
153
	 * Action called if matched action does not exist
154
	 * For this view not to be catched by Zend\Mvc\View\RouteNotFoundStrategy
155
	 * it has to be rendered in the controller. Hence the code below.
156
	 *
157
	 * This action is injected as a catchall action for each custom_games definition
158
	 * This way, when a custom_game is created, the 404 is it's responsability and the
159
	 * view can be defined in design/frontend/default/custom/$slug/playground_game/$gametype/404.phtml
160
	 *
161
	 *
162
	 * @return \Zend\Stdlib\ResponseInterface
163
	 */
164
	public function notFoundAction() {
165
		$templatePathResolver = $this->getServiceLocator()->get('Zend\View\Resolver\TemplatePathStack');
166
167
		// I create a template path in which I can find a custom template
168
		$controller     = explode('\\', get_class($this));
169
		$controllerPath = str_replace('Controller', '', end($controller));
170
		$controllerPath = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '-\\1', $controllerPath));
171
		$uri            = $this->getRequest()->getUri()->getPath();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Zend\Stdlib\RequestInterface as the method getUri() does only exist in the following implementations of said interface: Zend\Http\PhpEnvironment\Request, Zend\Http\Request.

Let’s take a look at an example:

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

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

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

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

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

Available Fixes

  1. Change the type-hint for the parameter:

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

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

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
172
		if ($this->game) {
173
			$uri = str_replace($controllerPath.'/'.$this->game->getIdentifier().'/', '', $uri);
174
		}
175
		$uri      = str_replace("/".$this->getEvent()->getRouteMatch()->getParam('locale')."/", "/", $uri);
176
		$template = 'playground-game/'.$controllerPath.'/custom'.$uri;
177
178
		if (false === $templatePathResolver->resolve($template)) {
179
			$viewRender = $this->getServiceLocator()->get('ViewRenderer');
180
181
			$this->getEvent()->getRouteMatch()->setParam('action', 'not-found');
182
			$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...
183
184
			$res = 'error/404';
185
186
			$viewModel = $this->buildView($this->game);
187
			$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...
188
189
			$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...
190
			$this->response->setContent($viewRender->render($this->layout()));
191
192
			return $this->response;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->response; (Zend\Stdlib\ResponseInterface) is incompatible with the return type of the parent method Zend\Mvc\Controller\Abst...troller::notFoundAction of type Zend\View\Model\ViewMode...View\Model\ConsoleModel.

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

Let’s take a look at an example:

class Author {
    private $name;

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

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

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

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

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

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

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

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

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

Let’s take a look at an example:

class Author {
    private $name;

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

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

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

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

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

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

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

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

Let’s take a look at an example:

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

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

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

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

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

Available Fixes

  1. Change the type-hint for the parameter:

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

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

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

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

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

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

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

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

Loading history...
748
				$this->flashMessenger()->addMessage(
749
					'Authentication failed. Please try again.'
750
				);
751
752
				return $this->redirect()->toUrl(
753
					$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...
754
						$this->game->getClassType().'/login',
755
						array('id' => $this->game->getIdentifier())
756
					)
757
				);
758
			} else {
759
				return $this->redirect()->toUrl(
760
					$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...
761
						$this->game->getClassType().'/index',
762
						array('id' => $this->game->getIdentifier())
763
					)
764
				);
765
			}
766
		}
767
768
		$form->setAttribute(
769
			'action',
770
			$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...
771
				$this->game->getClassType().'/login',
772
				array('id' => $this->game->getIdentifier())
773
			)
774
		);
775
		$viewModel = $this->buildView($this->game);
776
		$viewModel->setVariables(array(
777
				'form'          => $form,
778
				'flashMessages' => $this->flashMessenger()->getMessages(),
779
			));
780
		return $viewModel;
781
	}
782
783
	public function logoutAction() {
784
		$viewModel = $this->forward()->dispatch(
785
			'playgrounduser_user',
786
			array(
787
				'controller' => 'playgrounduser_user',
788
				'action'     => 'logout',
789
				'id'         => $this->game->getIdentifier()
790
			)
791
		);
792
793
		if ($viewModel && $viewModel instanceof \Zend\View\Model\ViewModel) {
794
			$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...
795
			$viewModel->setVariables(array('game'      => $this->game));
796
		}
797
798
		return $viewModel;
799
	}
800
801
	public function userregisterAction() {
802
		$userOptions = $this->getServiceLocator()->get('zfcuser_module_options');
803
804
		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...
805
			return $this->redirect()->toUrl(
806
				$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...
807
					$this->game->getClassType().'/'.$this->game->nextStep('index'),
808
					array('id' => $this->game->getIdentifier())
809
				)
810
			);
811
		}
812
		$request       = $this->getRequest();
813
		$service       = $this->getServiceLocator()->get('zfcuser_user_service');
814
		$form          = $this->getServiceLocator()->get('playgroundgame_register_form');
815
		$socialnetwork = $this->params()->fromRoute('socialnetwork', false);
816
		$form->setAttribute(
817
			'action',
818
			$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...
819
				$this->game->getClassType().'/user-register',
820
				array('id' => $this->game->getIdentifier())
821
			)
822
		);
823
		$params            = array();
824
		$socialCredentials = array();
825
826
		if ($userOptions->getUseRedirectParameterIfPresent() && $request->getQuery()->get('redirect')) {
827
			$redirect = $request->getQuery()->get('redirect');
828
		} else {
829
			$redirect = false;
830
		}
831
832
		if ($socialnetwork) {
833
			$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...
834
835
			if (!empty($infoMe)) {
836
				$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...
837
					$infoMe->identifier,
838
					$socialnetwork
839
				);
840
841
				if ($user || $service->getOptions()->getCreateUserAutoSocial() === true) {
842
					//on le dirige vers l'action d'authentification
843
					if (!$redirect && $userOptions->getLoginRedirectRoute() != '') {
844
						$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...
845
							$this->game->getClassType().'/login',
846
							array('id' => $this->game->getIdentifier())
847
						);
848
					}
849
					$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...
850
						$this->game->getClassType().'/login',
851
						array('id' => $this->game->getIdentifier())
852
					).'/'.$socialnetwork.($redirect?'?redirect='.$redirect:'');
853
854
					return $this->redirect()->toUrl($redir);
855
				}
856
857
				// Je retire la saisie du login/mdp
858
				$form->setAttribute(
859
					'action',
860
					$this->frontendUrl()->fromRoute(
0 ignored issues
show
Documentation Bug introduced by
The method frontendUrl does not exist on object<PlaygroundGame\Co...rontend\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

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

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

class ParentClass {
    private $data = array();

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

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

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
861
						$this->game->getClassType().'/user-register',
862
						array(
863
							'id'            => $this->game->getIdentifier(),
864
							'socialnetwork' => $socialnetwork,
865
866
						)
867
					)
868
				);
869
				$form->remove('password');
870
				$form->remove('passwordVerify');
871
872
				$birthMonth = $infoMe->birthMonth;
873
				if (strlen($birthMonth) <= 1) {
874
					$birthMonth = '0'.$birthMonth;
875
				}
876
				$birthDay = $infoMe->birthDay;
877
				if (strlen($birthDay) <= 1) {
878
					$birthDay = '0'.$birthDay;
879
				}
880
881
				$gender = $infoMe->gender;
882
				if ($gender == 'female') {
883
					$title = 'Me';
884
				} else {
885
					$title = 'M';
886
				}
887
888
				$params = array(
889
					//'birth_year'  => $infoMe->birthYear,
890
					'title'      => $title,
891
					'dob'        => $birthDay.'/'.$birthMonth.'/'.$infoMe->birthYear,
892
					'firstname'  => $infoMe->firstName,
893
					'lastname'   => $infoMe->lastName,
894
					'email'      => $infoMe->email,
895
					'postalCode' => $infoMe->zip,
896
				);
897
				$socialCredentials = array(
898
					'socialNetwork' => strtolower($socialnetwork),
899
					'socialId'      => $infoMe->identifier,
900
				);
901
			}
902
		}
903
904
		$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...
905
			$this->game->getClassType().'/user-register',
906
			array('id' => $this->game->getIdentifier())
907
		).($socialnetwork?'/'.$socialnetwork:'').($redirect?'?redirect='.$redirect:'');
908
		$prg = $this->prg($redirectUrl, true);
909
910
		if ($prg instanceof Response) {
911
			return $prg;
912
		} elseif ($prg === false) {
913
			$form->setData($params);
914
			$viewModel = $this->buildView($this->game);
915
			$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...
916
					'registerForm'       => $form,
917
					'enableRegistration' => $userOptions->getEnableRegistration(),
918
					'redirect'           => $redirect,
919
				));
920
			return $viewModel;
921
		}
922
923
		$post = $prg;
924
		$post = array_merge(
925
			$post,
926
			$socialCredentials
927
		);
928
929
		if ($this->game->getOnInvitation()) {
930
			$credential = trim(
931
				$post[$this->getGameService()->getOptions()->getOnInvitationField()]
932
			);
933
			if (!$credential) {
934
				$credential = $this->params()->fromQuery(
935
					$this->getGameService()->getOptions()->getOnInvitationField()
936
				);
937
			}
938
			$found = $this->getGameService()->getInvitationMapper()->findOneBy(array('requestKey' => $credential));
939
940
			if (!$found || !empty($found->getUser())) {
941
				$this->flashMessenger()->addMessage(
942
					'Authentication failed. Please try again.'
943
				);
944
				$form->setData($post);
945
				$viewModel = $this->buildView($this->game);
946
				$viewModel->setVariables(array(
947
						'registerForm'       => $form,
948
						'enableRegistration' => $userOptions->getEnableRegistration(),
949
						'redirect'           => $redirect,
950
						'flashMessages'      => $this->flashMessenger()->getMessages(),
951
						'flashErrors'        => $this->flashMessenger()->getErrorMessages(),
952
					));
953
954
				return $viewModel;
955
			}
956
		}
957
958
		$user = $service->register($post, 'playgroundgame_register_form');
959
960
		if (!$user) {
961
			$viewModel = $this->buildView($this->game);
962
			$viewModel->setVariables(array(
963
					'registerForm'       => $form,
964
					'enableRegistration' => $userOptions->getEnableRegistration(),
965
					'redirect'           => $redirect,
966
					'flashMessages'      => $this->flashMessenger()->getMessages(),
967
					'flashErrors'        => $this->flashMessenger()->getErrorMessages(),
968
				));
969
970
			return $viewModel;
971
		}
972
973
		if ($this->game->getOnInvitation()) {
974
			// user has been created, associate the code with the userId
975
			$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...
976
			$this->getGameService()->getInvitationMapper()->update($found);
977
		}
978
979
		if ($service->getOptions()->getEmailVerification()) {
980
			$vm = new ViewModel(array('userEmail' => $user->getEmail()));
981
			$vm->setTemplate('playground-user/register/registermail');
982
983
			return $vm;
984
		} elseif ($service->getOptions()->getLoginAfterRegistration()) {
985
			$identityFields = $service->getOptions()->getAuthIdentityFields();
986
			if (in_array('email', $identityFields)) {
987
				$post['identity'] = $user->getEmail();
988
			} elseif (in_array('username', $identityFields)) {
989
				$post['identity'] = $user->getUsername();
990
			}
991
			$post['credential'] = isset($post['password'])?$post['password']:'';
992
			$request->setPost(new Parameters($post));
993
994
			// clear adapters
995
			$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...
996
			$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...
997
998
			$logged = $this->forward()->dispatch('playgrounduser_user', array('action' => 'ajaxauthenticate'));
999
1000 View Code Duplication
			if ($logged) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
1001
				return $this->redirect()->toUrl(
1002
					$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...
1003
						$this->game->getClassType(),
1004
						array('id' => $this->game->getIdentifier())
1005
					)
1006
				);
1007
			} else {
1008
				$this->flashMessenger()->setNamespace('zfcuser-login-form')->addMessage(
1009
					'Authentication failed. Please try again.'
1010
				);
1011
				return $this->redirect()->toUrl(
1012
					$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...
1013
						$this->game->getClassType().'/login',
1014
						array('id' => $this->game->getIdentifier())
1015
					)
1016
				);
1017
			}
1018
		}
1019
1020
		$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...
1021
			$this->game->getClassType().'/login',
1022
			array('id' => $this->game->getIdentifier())
1023
		).($socialnetwork?'/'.$socialnetwork:'').($redirect?'?redirect='.$redirect:'');
1024
1025
		return $this->redirect()->toUrl($redirect);
1026
	}
1027
1028
	public function userProfileAction() {
1029
		$viewModel = $this->forward()->dispatch(
1030
			'playgrounduser_user',
1031
			array(
1032
				'controller' => 'playgrounduser_user',
1033
				'action'     => 'profile',
1034
				'id'         => $this->game->getIdentifier()
1035
			)
1036
		);
1037
1038
		if ($viewModel && $viewModel instanceof \Zend\View\Model\ViewModel) {
1039
			$this->layout()->setVariables(array('game' => $this->game));
0 ignored issues
show
Bug introduced by
The method setVariables does only exist in Zend\View\Model\ModelInterface, but not in Zend\Mvc\Controller\Plugin\Layout.

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

Let’s take a look at an example:

class A
{
    public function foo() { }
}

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

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

Available Fixes

  1. Add an additional type-check:

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

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