Completed
Push — develop ( b8dca6...12df67 )
by greg
02:59
created

GameController::entryAction()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 91

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 91
rs 8.1963
c 0
b 0
f 0
cc 1
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace PlaygroundGame\Controller\Admin;
4
5
use PlaygroundGame\Service\Game as AdminGameService;
6
use Zend\Mvc\Controller\AbstractActionController;
7
use Zend\View\Model\ViewModel;
8
use PlaygroundGame\Options\ModuleOptions;
9
use Zend\Paginator\Paginator;
10
use DoctrineORMModule\Paginator\Adapter\DoctrinePaginator as DoctrineAdapter;
11
use PlaygroundCore\ORM\Pagination\LargeTablePaginator;
12
use Doctrine\ORM\Tools\Pagination\Paginator as ORMPaginator;
13
use Zend\Stdlib\ErrorHandler;
14
use Zend\ServiceManager\ServiceLocatorInterface;
15
use Zend\Session\Container;
16
use ZfcDatagrid\Column;
17
use ZfcDatagrid\Action;
18
use ZfcDatagrid\Column\Formatter;
19
use ZfcDatagrid\Column\Type;
20
use ZfcDatagrid\Column\Style;
21
use ZfcDatagrid\Filter;
22
23
class GameController extends AbstractActionController
24
{
25
    protected $options;
26
27
    /**
28
     * @var \PlaygroundGame\Service\Game
29
     */
30
    protected $adminGameService;
31
32
    protected $game;
33
34
    /**
35
     *
36
     * @var ServiceManager
37
     */
38
    protected $serviceLocator;
39
40
    public function __construct(ServiceLocatorInterface $locator)
41
    {
42
        $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...r\Admin\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...
43
    }
44
45
    public function getServiceLocator()
46
    {
47
        return $this->serviceLocator;
48
    }
49
50
    public function checkGame()
51
    {
52
        $gameId = $this->getEvent()->getRouteMatch()->getParam('gameId');
53
        if (!$gameId) {
54
            return $this->redirect()->toUrl($this->adminUrl()->fromRoute('playgroundgame/list'));
0 ignored issues
show
Documentation Bug introduced by
The method adminUrl does not exist on object<PlaygroundGame\Co...r\Admin\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...
55
        }
56
        
57
        $game = $this->getAdminGameService()->getGameMapper()->findById($gameId);
58
        if (!$game) {
59
            return $this->redirect()->toUrl($this->adminUrl()->fromRoute('playgroundgame/list'));
0 ignored issues
show
Documentation Bug introduced by
The method adminUrl does not exist on object<PlaygroundGame\Co...r\Admin\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...
60
        }
61
        $this->game = $game;
62
    }
63
64
    public function createForm($form)
65
    {
66
        // I use the wonderful Form Generator to create the Player form
67
        $this->forward()->dispatch(
68
            'playgroundcore_admin_formgen',
69
            array(
70
                'controller' => 'playgroundcore_admin_formgen',
71
                'action' => 'create'
72
            )
73
        );
74
75
        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, Zend\Psr7Bridge\Zend\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...
76
            $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, Zend\Psr7Bridge\Zend\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...
77
            $form = $this->getAdminGameService()->createForm($data, $this->game, $form);
78
            if ($form) {
79
                $this->flashMessenger()->setNamespace('playgroundgame')->addMessage('The form was created');
0 ignored issues
show
Documentation Bug introduced by
The method flashMessenger does not exist on object<PlaygroundGame\Co...r\Admin\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...
80
            }
81
        }
82
        $formTemplate='';
83
        if ($form) {
84
            $formTemplate = $form->getFormTemplate();
85
        }
86
87
        return array(
88
            'form' => $form,
89
            'formTemplate' => $formTemplate,
90
            'gameId' => $this->game->getId(),
91
            'game' => $this->game,
92
        );
93
    }
94
95
    /**
96
     * @param string $templatePath
97
     * @param string $formId
98
     */
99
    public function editGame($templatePath, $formId)
100
    {
101
        // We try to get FB pages from the logged in user
102
        $session = new Container('facebook');
103
        $config = $this->getServiceLocator()->get('config');
104
        $appsArray = [];
105
        $platformFbAppId = '';
106
        
107
        if (isset($config['facebook'])) {
108
            $platformFbAppId     = $config['facebook']['fb_appid'];
109
            $platformFbAppSecret = $config['facebook']['fb_secret'];
110
        }
111
        $fb = new \Facebook\Facebook([
112
            'app_id' => $platformFbAppId,
113
            'app_secret' => $platformFbAppSecret,
0 ignored issues
show
Bug introduced by
The variable $platformFbAppSecret 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...
114
            'default_graph_version' => 'v3.1',
115
        ]);
116
117
        $helper = $fb->getRedirectLoginHelper();
118
        $fb_args_param = array('req_perms' => 'manage_pages,publish_pages');
119
        $fb_login_url = $helper->getLoginUrl($this->adminUrl()->fromRoute(
0 ignored issues
show
Documentation Bug introduced by
The method adminUrl does not exist on object<PlaygroundGame\Co...r\Admin\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...
120
            'playgroundgame/list',
121
            array(),
122
            array('force_canonical' => true)
123
        ), $fb_args_param);
124
        $accessToken = $helper->getAccessToken();
125
126
        if (isset($accessToken) || $session->offsetExists('fb_token')) {
127
            if (isset($accessToken)) {
128
                $session->offsetSet('fb_token', $accessToken);
129
            }
130
131
            // checking if user access token is not valid then ask user to login again
132
            $debugToken = $fb->get('/debug_token?input_token='. $session->offsetGet('fb_token'), $platformFbAppId . '|' . $platformFbAppSecret)
133
            ->getGraphNode()
134
            ->asArray();
135
            if (isset($debugToken['error']['code'])) {
136
                $session->offsetUnset('fb_token');
137
            } else {
138
                // setting default user access token for future requests
139
                $fb->setDefaultAccessToken($session->offsetGet('fb_token'));
140
                $pages = $fb->get('/me/accounts')
141
                    ->getGraphEdge()
142
                    ->asArray();
143
144
                foreach ($pages as $key) {
145
                    $app_label = '';
146
                    if (isset($key['name'])) {
147
                        $app_label .= $key['name'];
148
                    }
149
                    if (isset($key['id'])) {
150
                        $app_label .= ' ('.$key['id'].')';
151
                    }
152
                    $appsArray[$key['id']] = $app_label;
153
                }
154
                $fb_login_url = '';
155
156
                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, Zend\Psr7Bridge\Zend\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...
157
                    $data = array_replace_recursive(
158
                        $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, Zend\Psr7Bridge\Zend\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...
159
                        $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, Zend\Psr7Bridge\Zend\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...
160
                    );
161
                    // Removing a previously page tab set on this game
162
                    if ($this->game &&
163
                        !empty($this->game->getFbPageId()) &&
164
                        !empty($this->game->getFbAppId()) &&
165
                        (
166
                            (
167
                                $this->game->getFbPageId() !== $data['fbPageId'] ||
168
                                $this->game->getFbAppId() !== $data['fbAppId']
169
                            ) ||
170
                            $data['broadcastFacebook'] == 0
171
                        )
172
                    ) {
173
                        $oldPage = $fb->get('/' . $this->game->getFbPageId() . '?fields=access_token,name,id')
174
                            ->getGraphNode()
175
                            ->asArray();
176
                        $removeTab = $fb->delete(
0 ignored issues
show
Unused Code introduced by
$removeTab is not used, you could remove the assignment.

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

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

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

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

Loading history...
177
                            '/' . $this->game->getFbPageId() . '/tabs',
178
                            [
179
                                    'tab' => 'app_'.$this->game->getFbAppId(),
180
                                ],
181
                            $oldPage['access_token']
182
                        )
183
                            ->getGraphNode()
184
                            ->asArray();
185
                    }
186
187
                    // Removing a previously post set on this game
188
                    if ($this->game &&
189
                        !empty($this->game->getFbPostId()) &&
190
                        $data['broadcastPostFacebook'] == 0
191
                    ) {
192
                        $oldPage = $fb->get('/' . $this->game->getFbPageId() . '?fields=access_token,name,id')
193
                            ->getGraphNode()
194
                            ->asArray();
195
                        $removePost = $fb->delete(
0 ignored issues
show
Unused Code introduced by
$removePost is not used, you could remove the assignment.

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

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

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

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

Loading history...
196
                            '/' . $this->game->getFbPostId(),
197
                            [],
198
                            $oldPage['access_token']
199
                        )
200
                            ->getGraphNode()
201
                            ->asArray();
202
                    }
203
                }
204
            }
205
        }
206
207
        $viewModel = new ViewModel();
208
        $viewModel->setTemplate($templatePath);
209
210
        $gameForm = new ViewModel();
211
        $gameForm->setTemplate('playground-game/game/game-form');
212
213
        $form   = $this->getServiceLocator()->get($formId);
214
        $form->setAttribute(
215
            'action',
216
            $this->adminUrl()->fromRoute(
0 ignored issues
show
Documentation Bug introduced by
The method adminUrl does not exist on object<PlaygroundGame\Co...r\Admin\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...
217
                'playgroundgame/edit-' . $this->game->getClassType(),
218
                array('gameId' => $this->game->getId())
219
            )
220
        );
221
        $form->setAttribute('method', 'post');
222
223
        $pageIds = $form->get('fbPageId')->getOption('value_options');
224
        foreach ($appsArray as $k => $v) {
225
            $pageIds[$k] = $v;
226
        }
227
        $form->get('fbPageId')->setAttribute('options', $pageIds);
228
229
        //if($form->get('fbAppId')->getValue() == '') {
230
            $form->get('fbAppId')->setValue($platformFbAppId);
231
        //}
232
233
        // if ($this->game->getFbAppId()) {
234
        //     $data['fbAppId'] = $form->get('fbAppId')->getOption('value_options');
235
        //     $appIds[$this->game->getFbAppId()] = $this->game->getFbAppId();
236
        //     $form->get('fbAppId')->setAttribute('options', $appIds);
237
        // }
238
239
        $gameOptions = $this->getAdminGameService()->getOptions();
240
        $gameStylesheet = $gameOptions->getMediaPath() . '/' . 'stylesheet_'. $this->game->getId(). '.css';
241 View Code Duplication
        if (is_file($gameStylesheet)) {
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...
242
            $values = $form->get('stylesheet')->getValueOptions();
243
            $values[$gameStylesheet] = 'Style personnalisé de ce jeu';
244
245
            $form->get('stylesheet')->setAttribute('options', $values);
246
        }
247
248
        $form->bind($this->game);
249
250
        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, Zend\Psr7Bridge\Zend\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...
251
            $data = array_replace_recursive(
252
                $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, Zend\Psr7Bridge\Zend\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...
253
                $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, Zend\Psr7Bridge\Zend\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...
254
            );
255
            if (empty($data['prizes'])) {
256
                $data['prizes'] = array();
257
            }
258
            if (isset($data['drawDate']) && $data['drawDate']) {
259
                $data['drawDate'] = \DateTime::createFromFormat('d/m/Y', $data['drawDate']);
260
            }
261
262
            $game = $this->getAdminGameService()->createOrUpdate($data, $this->game, $formId);
263
264
            if ($game) {
265
                if ($session->offsetExists('fb_token')) {
266
                    if (!empty($data['fbPageId']) && !empty($data['fbAppId'])) {
267
                        $page = $fb->get('/' . $data['fbPageId'] . '?fields=access_token,name,id')
268
                        ->getGraphNode()
269
                        ->asArray();
270
271
                        // let's create a post on FB
272
                        if ($data['broadcastPostFacebook'] && $game->getWelcomeBlock() != '' && $game->getMainImage() != '') {
273
                            $imgPath = $this->url()->fromRoute('frontend', [], ['force_canonical' => true], false).$game->getMainImage();
274
                            // emoticons : $emoji = html_entity_decode('&#128520;');
275
276
                            $message = str_replace('<p>', "", $game->getWelcomeBlock());
277
                            $message = str_replace('</p>', "\n", $message);
278
                            $message = strip_tags($message);
279
280
                            // Create the post
281
                            try {
282
                                // Associate the fbAppId to the page so that we can receive the webhooks
283
                                $linkAppToPage = $fb->post(
0 ignored issues
show
Unused Code introduced by
$linkAppToPage is not used, you could remove the assignment.

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

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

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

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

Loading history...
284
                                    '/' . $page['id'] . '/subscribed_apps',
285
                                    array(),
286
                                    $page['access_token']
287
                                );
288
289
                                /**
290
                                 *  post text and save the post_id to be able to get the likes and comments on the post
291
                                 */
292
                                // $post = $fb->post(
293
                                //     '/' . $page['id'] . '/feed',
294
                                //     array(
295
                                //         'message'           => 'message',
296
                                //     ),
297
                                //     $page['access_token']
298
                                // );
299
    
300
                                /**
301
                                 * Post a photo
302
                                 */
303
                                // $post = $fb->post(
304
                                //     '/' . $page['id'] . '/photos',
305
                                //     array(
306
                                //         'url'           => 'https://images.unsplash.com/photo-1538239010247-383da61e35db?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=22e9de10cd7e4d8e32d698099dc6d23c&auto=format&fit=crop&w=3289&q=80',
307
                                //         'published'     => true,
308
                                //     ),
309
                                //     $page['access_token']
310
                                // );
311
    
312
                                /**
313
                                 * Upload an unpublished photo and include it in a post
314
                                 */
315
                                $img = $fb->post(
316
                                    '/' . $page['id'] . '/photos',
317
                                    array(
318
                                        'url'           => $imgPath,
319
                                        'published'     => false,
320
                                    ),
321
                                    $page['access_token']
322
                                );
323
                                $img = $img->getGraphNode()->asArray();
324
                                
325
                                if ($game->getFbPostId() != '') {
326
                                    $post = $fb->post(
327
                                        '/' . $game->getFbPostId(),
328
                                        array(
329
                                            'message'           => $message,
330
                                            'attached_media[0]' => '{"media_fbid":"'.$img['id'].'"}',
331
                                        ),
332
                                        $page['access_token']
333
                                    );
334
                                } else {
335
                                    $post = $fb->post(
336
                                        '/' . $page['id'] . '/feed',
337
                                        array(
338
                                            'message'           => $message,
339
                                            'attached_media[0]' => '{"media_fbid":"'.$img['id'].'"}',
340
                                        ),
341
                                        $page['access_token']
342
                                    );
343
                                }
344
    
345
                                /**
346
                                 * Upload an unpublished photo and include it in a scheduled post
347
                                 */
348
                                // $img = $fb->post(
349
                                //     '/' . $page['id'] . '/photos',
350
                                //     array(
351
                                //         'url'           => 'https://images.unsplash.com/photo-1538239010247-383da61e35db?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=22e9de10cd7e4d8e32d698099dc6d23c&auto=format&fit=crop&w=3289&q=80',
352
                                //         'published'     => false,
353
                                //         'temporary'     => true
354
                                //     ),
355
                                //     $page['access_token']
356
                                // );
357
                                // $img = $img->getGraphNode()->asArray();
358
                                //
359
                                // $post = $fb->post(
360
                                //     '/' . $page['id'] . '/feed',
361
                                //     array(
362
                                //         'message'           => 'message avec image',
363
                                //         'attached_media[0]' => '{"media_fbid":"'.$img['id'].'"}',
364
                                //         'published'     => false,
365
                                //         'scheduled_publish_time' => '1512068400',
366
                                //         'unpublished_content_type' => 'SCHEDULED',
367
                                //     ),
368
                                //     $page['access_token']
369
                                // );
370
    
371
                                /**
372
                                 * publish multiple photos then associate these photos to a post
373
                                 */
374
                                // $endpoint = "/".$page['id']."/photos";
375
                                // $multiple_photos = [
376
                                //     'https://images.unsplash.com/photo-1538239010247-383da61e35db?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=22e9de10cd7e4d8e32d698099dc6d23c&auto=format&fit=crop&w=3289&q=80',
377
                                //     'https://images.unsplash.com/photo-1538218952949-2f5dda4a9156?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=b79a9c7314dd5ca8eac2f187902ceca2&auto=format&fit=crop&w=2704&q=80',
378
                                //     'https://images.unsplash.com/photo-1538157245064-badfdabb7142?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=dfa50d5dd51b85f25ca03f2b2667752a&auto=format&fit=crop&w=2700&q=80',
379
                                // ];
380
                                // $photos = [];
381
                                // $data_post = ['attached_media' => [], 'message' => 'message', 'published' => true];
382
                                // foreach ($multiple_photos as $file_url):
383
                                //     array_push($photos, $fb->request('POST',$endpoint,['url' =>$file_url,'published' => false,'temporary' => true], $page['access_token']));
384
                                // endforeach;
385
                                // $uploaded_photos = $fb->sendBatchRequest($photos, $page['access_token']);
386
                                // $uploaded_photos = $uploaded_photos->getGraphNode()->asArray();
387
                                
388
                                // foreach ($uploaded_photos as $photo):
389
                                //     $photo = json_decode($photo['body']);
390
                                //     array_push($data_post['attached_media'], '{"media_fbid":"'.$photo->id.'"}');
391
                                // endforeach;
392
                                // $post = $fb->sendRequest('POST', "/".$page['id']."/feed", $data_post, $page['access_token']);
393
    
394
                                /**
395
                                 * publish a carrousel to a post
396
                                 */
397
                                // $data_post = [
398
                                //     'child_attachments' => [],
399
                                //     'message' => 'message',
400
                                //     'link' => 'https://www.playground.gg',
401
                                //     'multi_share_end_card' => false,
402
                                //     'published' => true,
403
                                // ];
404
                                
405
                                // $multiple_photos = [
406
                                //     'https://images.unsplash.com/photo-1538239010247-383da61e35db?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=22e9de10cd7e4d8e32d698099dc6d23c&auto=format&fit=crop&w=3289&q=80',
407
                                //     'https://images.unsplash.com/photo-1538218952949-2f5dda4a9156?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=b79a9c7314dd5ca8eac2f187902ceca2&auto=format&fit=crop&w=2704&q=80',
408
                                //     'https://images.unsplash.com/photo-1538157245064-badfdabb7142?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=dfa50d5dd51b85f25ca03f2b2667752a&auto=format&fit=crop&w=2700&q=80',
409
                                // ];
410
                                // foreach ($multiple_photos as $k => $photo):
411
                                //     array_push($data_post['child_attachments'], '{"link":"'.$photo.'", "name": "message_'.$k.'"}');
412
                                // endforeach;
413
                                // $post = $fb->sendRequest('POST', "/".$page['id']."/feed", $data_post, $page['access_token']);
414
    
415
                                /** Texte avec lien vers une page
416
                                 *
417
                                 */
418
                                // $post = $fb->post(
419
                                //     '/' . $page['id'] . '/feed',
420
                                //     array(
421
                                //         'message'           => 'message',
422
                                //         'link'              => 'https://images.unsplash.com/photo-1538239010247-383da61e35db?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=22e9de10cd7e4d8e32d698099dc6d23c&auto=format&fit=crop&w=3289&q=80',
423
                                //         //'picture'           => 'https://images.unsplash.com/photo-1538239010247-383da61e35db?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=22e9de10cd7e4d8e32d698099dc6d23c&auto=format&fit=crop&w=3289&q=80',
424
                                //         'call_to_action'    => '{"type":"BOOK_TRAVEL","value":{"link":"https://images.unsplash.com/photo-1538239010247-383da61e35db?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=22e9de10cd7e4d8e32d698099dc6d23c&auto=format&fit=crop&w=3289&q=80"}}',
425
                                //     ),
426
                                //     $page['access_token']
427
                                // );
428
                            } catch (\Exception $e) {
429
                                if ($e->getMessage() == 'Missing or invalid image file') {
430
                                    if ($game->getFbPostId() != '') {
431
                                        $post = $fb->post(
432
                                            '/' . $game->getFbPostId(),
433
                                            array(
434
                                                'message' => $message,
435
                                            ),
436
                                            $page['access_token']
437
                                        );
438
                                    } else {
439
                                        $post = $fb->post(
440
                                            '/' . $page['id'] . '/feed',
441
                                            array(
442
                                                'message' => $message,
443
                                            ),
444
                                            $page['access_token']
445
                                        );
446
                                    }
447
                                } else {
448
                                    throw $e;
449
                                }
450
                            }
451
                            $post = $post->getGraphNode()->asArray();
452
                            if (isset($post['id'])) {
453
                                $game->setFbPostId($post['id']);
454
                                $game = $this->getAdminGameService()->getGameMapper()->update($game);
455
                            }
456
                        }
457
458
                        // Let's record the FB page tab if it is configured
459
                        // adding page tab to selected page using page access token
460
                        if ($data['broadcastFacebook']) {
461
                            try {
462
                                $addTab = $fb->post(
0 ignored issues
show
Unused Code introduced by
$addTab is not used, you could remove the assignment.

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

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

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

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

Loading history...
463
                                    '/' . $page['id'] . '/tabs',
464
                                    [
465
                                        'app_id' => $data['fbAppId'],
466
                                        'custom_name' => (!empty($data['fbPageTabTitle'])) ? $data['fbPageTabTitle'] : $data['title'],
467
                                        'custom_image_url' => ($game->getFbPageTabImage() !== '') ?
468
                                            $this->getAdminGameService()->getServiceManager()->get('ViewRenderer')->url(
469
                                                'frontend',
470
                                                array(),
471
                                                array('force_canonical' => true)
472
                                            ).$game->getFbPageTabImage() :
473
                                            null,
474
                                        'position' => (!empty($data['fbPageTabPosition'])) ? $data['fbPageTabPosition'] : 99
475
                                    ],
476
                                    $page['access_token']
477
                                )
478
                                    ->getGraphNode()
479
                                    ->asArray();
480
                            } catch (\Exception $e) {
481
                                // (#324) Missing or invalid image file
482
                                if ($e->getCode() == '324') {
483
                                    try {
484
                                        $addTab = $fb->post(
0 ignored issues
show
Unused Code introduced by
$addTab is not used, you could remove the assignment.

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

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

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

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

Loading history...
485
                                            '/' . $page['id'] . '/tabs',
486
                                            [
487
                                                'app_id' => $data['fbAppId'],
488
                                                'custom_name' => (!empty($data['fbPageTabTitle'])) ? $data['fbPageTabTitle'] : $data['title'],
489
                                                'position' => (!empty($data['fbPageTabPosition'])) ? $data['fbPageTabPosition'] : 99
490
                                            ],
491
                                            $page['access_token']
492
                                        )
493
                                            ->getGraphNode()
494
                                            ->asArray();
495
                                    } catch (\Exception $e) {
496
                                        throw $e;
497
                                    }
498
                                }
499
                            }
500
                        }
501
                    }
502
                }
503
                return $this->redirect()->toUrl($this->adminUrl()->fromRoute('playgroundgame/list'));
0 ignored issues
show
Documentation Bug introduced by
The method adminUrl does not exist on object<PlaygroundGame\Co...r\Admin\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...
504
            }
505
        }
506
507
        $gameForm->setVariables(
508
            array(
509
                'platform_fb_app_id' => $platformFbAppId,
510
                'fb_login_url' => $fb_login_url,
511
                'form' => $form,
512
                'game' => $this->game
513
            )
514
        );
515
        $viewModel->addChild($gameForm, 'game_form');
516
517
        return $viewModel->setVariables(
518
            array(
519
                'form' => $form,
520
                'title' => 'Edit this game',
521
            )
522
        );
523
    }
524
525
    public function listAction()
526
    {
527
        // We try to get FB pages from the logged in user
528
        $session = new Container('facebook');
529
        $config = $this->getServiceLocator()->get('config');
530
        
531
        if (isset($config['facebook'])) {
532
            $platformFbAppId     = $config['facebook']['fb_appid'];
533
            $platformFbAppSecret = $config['facebook']['fb_secret'];
534
            $fb = new \Facebook\Facebook([
535
                'app_id' => $platformFbAppId,
536
                'app_secret' => $platformFbAppSecret,
537
                'default_graph_version' => 'v3.1',
538
            ]);
539
540
            $helper = $fb->getRedirectLoginHelper();
541
            $accessToken = $helper->getAccessToken();
542
        }
543
544
        if (isset($accessToken) || $session->offsetExists('fb_token')) {
545
            if (isset($accessToken)) {
546
                $session->offsetSet('fb_token', $accessToken);
547
            }
548
549
            // checking if user access token is not valid then ask user to login again
550
            $debugToken = $fb->get('/debug_token?input_token='. $session->offsetGet('fb_token'), $platformFbAppId . '|' . $platformFbAppSecret)
0 ignored issues
show
Bug introduced by
The variable $fb 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...
Bug introduced by
The variable $platformFbAppId 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...
Bug introduced by
The variable $platformFbAppSecret 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...
551
            ->getGraphNode()
552
            ->asArray();
553
            if (isset($debugToken['error']['code'])) {
554
                $session->offsetUnset('fb_token');
555
            } else {
556
                // setting default user access token for future requests
557
                $fb->setDefaultAccessToken($session->offsetGet('fb_token'));
558
            }
559
        }
560
        $filter    = $this->getEvent()->getRouteMatch()->getParam('filter');
561
        $type    = $this->getEvent()->getRouteMatch()->getParam('type');
562
563
        $service    = $this->getAdminGameService();
564
        $adapter = new DoctrineAdapter(new ORMPaginator($service->getQueryGamesOrderBy($type, $filter)));
565
        $paginator = new Paginator($adapter);
566
        $paginator->setItemCountPerPage(25);
567
        $paginator->setCurrentPageNumber($this->getEvent()->getRouteMatch()->getParam('p'));
568
569
        foreach ($paginator as $game) {
570
            $game->entry = $service->getEntryMapper()->countByGame($game);
571
        }
572
573
        return array(
574
            'games'    => $paginator,
575
            'type'        => $type,
576
            'filter'    => $filter,
577
        );
578
    }
579
580
    public function entryAction()
581
    {
582
        $this->checkGame();
583
584
        $qb = $this->getAdminGameService()->getEntriesQuery($this->game);
585
        // $query = $qb->getQuery();
586
        // $adapter = new DoctrineAdapter(new LargeTablePaginator($query));
587
        // $paginator = new Paginator($adapter);
588
        // $paginator->setItemCountPerPage(50);
589
        // $paginator->setCurrentPageNumber($this->getEvent()->getRouteMatch()->getParam('p'));
590
591
        // $header = $this->getAdminGameService()->getEntriesHeader($this->game);
592
        // $entries = $this->getAdminGameService()->getGameEntries($header, $paginator, $this->game);
593
594
        // return array(
595
        //     'paginator' => $paginator,
596
        //     'entries' => $entries,
597
        //     'header' => $header,
598
        //     'game' => $this->game,
599
        //     'gameId' => $this->game->getId()
600
        // );
601
602
        /* @var $grid \ZfcDatagrid\Datagrid */
603
        $grid = $this->getServiceLocator()->get('ZfcDatagrid\Datagrid');
604
        $grid->setTitle('Entries');
605
        $grid->setDataSource($qb);
606
607
        $col = new Column\Select('id', 'u');
608
        $col->setLabel('Id');
609
        $col->setIdentity(true);
610
        $grid->addColumn($col);
611
        
612
        $colType = new Type\DateTime(
613
            'Y-m-d H:i:s',
614
            \IntlDateFormatter::MEDIUM,
615
            \IntlDateFormatter::MEDIUM
616
        );
617
        $colType->setSourceTimezone('UTC');
618
619
        $col = new Column\Select('created_at', 'u');
620
        $col->setLabel('Created');
621
        $col->setType($colType);
622
        $grid->addColumn($col);
623
624
        $col = new Column\Select('username', 'u');
625
        $col->setLabel('Username');
626
        $grid->addColumn($col);
627
628
        $col = new Column\Select('email', 'u');
629
        $col->setLabel('Email');
630
        $grid->addColumn($col);
631
632
        $col = new Column\Select('firstname', 'u');
633
        $col->setLabel('Firstname');
634
        $grid->addColumn($col);
635
636
        $col = new Column\Select('lastname', 'u');
637
        $col->setLabel('Lastname');
638
        $grid->addColumn($col);
639
640
        $col = new Column\Select('winner', 'e');
641
        $col->setLabel('Status');
642
        $col->setReplaceValues(
643
            [
644
                0 => 'looser',
645
                1 => 'winner',
646
            ]
647
        );
648
        $grid->addColumn($col);
649
650
        // $actions = new Column\Action();
651
        // $actions->setLabel('');
652
653
        // $viewAction = new Column\Action\Button();
654
        // $viewAction->setLabel('Reset Password');
655
        // $rowId = $viewAction->getRowIdPlaceholder();
656
        // $viewAction->setLink('/admin/user/reset/'.$rowId);
657
        // $actions->addAction($viewAction);
658
659
        // $grid->addColumn($actions);
660
661
        // $action = new Action\Mass();
662
        // $action->setTitle('This is incredible');
663
        // $action->setLink('/test');
664
        // $action->setConfirm(true);
665
        // $grid->addMassAction($action);
666
667
        $grid->render();
668
        
669
        return $grid->getResponse();
670
    }
671
672 View Code Duplication
    public function invitationAction()
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...
673
    {
674
        $this->checkGame();
675
676
        $adapter = new DoctrineAdapter(
677
            new LargeTablePaginator(
678
                $this->getAdminGameService()->getInvitationMapper()->queryByGame($this->game)
679
            )
680
        );
681
        $paginator = new Paginator($adapter);
682
        $paginator->setItemCountPerPage(25);
683
        $paginator->setCurrentPageNumber($this->getEvent()->getRouteMatch()->getParam('p'));
684
685
        return new ViewModel(
686
            array(
687
                'invitations' => $paginator,
688
                'gameId'      => $this->game->getId(),
689
                'game'        => $this->game,
690
            )
691
        );
692
    }
693
694
    public function removeInvitationAction()
695
    {
696
        $this->checkGame();
697
698
        $service = $this->getAdminGameService();
699
        $invitationId = $this->getEvent()->getRouteMatch()->getParam('invitationId');
700
        if ($invitationId) {
701
            $invitation   = $service->getInvitationMapper()->findById($invitationId);
702
            $service->getInvitationMapper()->remove($invitation);
703
        }
704
705
        return $this->redirect()->toUrl($this->adminUrl()->fromRoute($this->game->getClassType() .'/invitation', array('gameId'=>$this->game->getId())));
0 ignored issues
show
Documentation Bug introduced by
The method adminUrl does not exist on object<PlaygroundGame\Co...r\Admin\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...
706
    }
707
    
708
    public function downloadAction()
709
    {
710
        $this->checkGame();
711
        $header = $this->getAdminGameService()->getEntriesHeader($this->game);
712
        $qb = $this->getAdminGameService()->getEntriesQuery($this->game);
713
        $query = $qb->getQuery();
714
715
        $content = "\xEF\xBB\xBF"; // UTF-8 BOM
716
        $content .= $this->getAdminGameService()->getCSV(
717
            $this->getAdminGameService()->getGameEntries(
718
                $header,
719
                $query->getResult(),
720
                $this->game
721
            )
722
        );
723
724
        $response = $this->getResponse();
725
        $headers = $response->getHeaders();
726
        $headers->addHeaderLine('Content-Encoding: UTF-8');
727
        $headers->addHeaderLine('Content-Type', 'text/csv; charset=UTF-8');
728
        $headers->addHeaderLine('Content-Disposition', "attachment; filename=\"entry.csv\"");
729
        $headers->addHeaderLine('Accept-Ranges', 'bytes');
730
        $headers->addHeaderLine('Content-Length', strlen($content));
731
732
        $response->setContent($content);
733
734
        return $response;
735
    }
736
737
    // Only used for Quiz and Lottery
738
    public function drawAction()
739
    {
740
        $this->checkGame();
741
742
        $winningEntries = $this->getAdminGameService()->draw($this->game);
743
744
        $content = "\xEF\xBB\xBF"; // UTF-8 BOM
745
        $content .= "ID;Pseudo;Nom;Prenom;E-mail;Etat\n";
746
747
        foreach ($winningEntries as $e) {
748
            $etat = 'gagnant';
749
750
            $content   .= $e->getUser()->getId()
751
            . ";" . $e->getUser()->getUsername()
752
            . ";" . $e->getUser()->getLastname()
753
            . ";" . $e->getUser()->getFirstname()
754
            . ";" . $e->getUser()->getEmail()
755
            . ";" . $etat
756
            ."\n";
757
        }
758
759
        $response = $this->getResponse();
760
        $headers = $response->getHeaders();
761
        $headers->addHeaderLine('Content-Encoding: UTF-8');
762
        $headers->addHeaderLine('Content-Type', 'text/csv; charset=UTF-8');
763
        $headers->addHeaderLine('Content-Disposition', "attachment; filename=\"gagnants.csv\"");
764
        $headers->addHeaderLine('Accept-Ranges', 'bytes');
765
        $headers->addHeaderLine('Content-Length', strlen($content));
766
767
        $response->setContent($content);
768
769
        return $response;
770
    }
771
    
772
    /**
773
     * This method serialize a game an export it as a txt file
774
     * @return \Zend\Stdlib\ResponseInterface
775
     */
776
    public function exportAction()
777
    {
778
        $this->checkGame();
779
        $content = serialize($this->game);
780
781
        $response = $this->getResponse();
782
        $headers = $response->getHeaders();
783
        $headers->addHeaderLine('Content-Encoding: UTF-8');
784
        $headers->addHeaderLine('Content-Type', 'text/plain; charset=UTF-8');
785
        $headers->addHeaderLine(
786
            'Content-Disposition',
787
            "attachment; filename=\"". $this->game->getIdentifier() .".txt\""
788
        );
789
        $headers->addHeaderLine('Accept-Ranges', 'bytes');
790
        $headers->addHeaderLine('Content-Length', strlen($content));
791
    
792
        $response->setContent($content);
793
    
794
        return $response;
795
    }
796
    
797
    /**
798
     * This method take an uploaded txt file containing a serialized game
799
     * and persist it in the database
800
     * @return unknown
801
     */
802
    public function importAction()
803
    {
804
        $form = $this->getServiceLocator()->get('playgroundgame_import_form');
805
        $form->setAttribute('action', $this->adminUrl()->fromRoute('playgroundgame/import'));
0 ignored issues
show
Documentation Bug introduced by
The method adminUrl does not exist on object<PlaygroundGame\Co...r\Admin\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

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

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

class ParentClass {
    private $data = array();

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

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

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
806
        $form->setAttribute('method', 'post');
807
        
808
        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, Zend\Psr7Bridge\Zend\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...
809
            $data = array_replace_recursive(
810
                $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, Zend\Psr7Bridge\Zend\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...
811
                $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, Zend\Psr7Bridge\Zend\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...
812
            );
813
            
814
            if (! empty($data['import_file']['tmp_name'])) {
815
                ErrorHandler::start();
816
                $game = unserialize(file_get_contents($data['import_file']['tmp_name']));
817
                $game->setId(null);
818
                if ($data['slug']) {
819
                    $game->setIdentifier($data['slug']);
820
                }
821
                $duplicate = $this->getAdminGameService()->getGameMapper()->findByIdentifier($game->getIdentifier());
822
                if (!$duplicate) {
823
                    $this->getAdminGameService()->getGameMapper()->insert($game);
824
                }
825
826
                ErrorHandler::stop(true);
827
            }
828
            
829
            return $this->redirect()->toUrl($this->adminUrl()->fromRoute('playgroundgame/list'));
0 ignored issues
show
Documentation Bug introduced by
The method adminUrl does not exist on object<PlaygroundGame\Co...r\Admin\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...
830
        }
831
        
832
        return array(
833
            'form' => $form,
834
        );
835
    }
836
837
    public function removeAction()
838
    {
839
        $this->checkGame();
840
841
        try {
842
            $this->getAdminGameService()->getGameMapper()->remove($this->game);
843
            $this->flashMessenger()->setNamespace('playgroundgame')->addMessage('The game has been edited');
0 ignored issues
show
Documentation Bug introduced by
The method flashMessenger does not exist on object<PlaygroundGame\Co...r\Admin\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

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

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

class ParentClass {
    private $data = array();

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

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

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
844
        } catch (\Doctrine\DBAL\DBALException $e) {
845
            $this->flashMessenger()->setNamespace('playgroundgame')->addMessage(
0 ignored issues
show
Documentation Bug introduced by
The method flashMessenger does not exist on object<PlaygroundGame\Co...r\Admin\GameController>? Since you implemented __call, maybe consider adding a @method annotation.

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

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

class ParentClass {
    private $data = array();

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

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

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
846
                'Il y a déjà eu des participants à ce jeu. Vous ne pouvez plus le supprimer'
847
            );
848
        }
849
850
        return $this->redirect()->toUrl($this->adminUrl()->fromRoute('playgroundgame/list'));
0 ignored issues
show
Documentation Bug introduced by
The method adminUrl does not exist on object<PlaygroundGame\Co...r\Admin\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...
851
    }
852
853
    public function setActiveAction()
854
    {
855
        $this->checkGame();
856
857
        $this->game->setActive(!$this->game->getActive());
858
        $this->getAdminGameService()->getGameMapper()->update($this->game);
859
860
        return $this->redirect()->toUrl($this->adminUrl()->fromRoute('playgroundgame/list'));
0 ignored issues
show
Documentation Bug introduced by
The method adminUrl does not exist on object<PlaygroundGame\Co...r\Admin\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
    }
862
863
    public function formAction()
864
    {
865
        $this->checkGame();
866
        
867
        $form = $this->game->getPlayerForm();
868
869
        return $this->createForm($form);
870
    }
871
872
    public function setOptions(ModuleOptions $options)
873
    {
874
        $this->options = $options;
875
876
        return $this;
877
    }
878
879
    public function getOptions()
880
    {
881
        if (!$this->options instanceof ModuleOptions) {
882
            $this->setOptions($this->getServiceLocator()->get('playgroundgame_module_options'));
883
        }
884
885
        return $this->options;
886
    }
887
888
    public function getAdminGameService()
889
    {
890
        if (!$this->adminGameService) {
891
            $this->adminGameService = $this->getServiceLocator()->get('playgroundgame_game_service');
892
        }
893
894
        return $this->adminGameService;
895
    }
896
897
    public function setAdminGameService(AdminGameService $adminGameService)
898
    {
899
        $this->adminGameService = $adminGameService;
900
901
        return $this;
902
    }
903
}
904