Issues (362)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

AdminModule/presenters/PagesPresenter.php (23 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace AdminModule;
4
5
use Nette\Application\UI;
6
use Nette\Utils\Finder;
7
8
/**
9
 * Admin presenter.
10
 * @author Tomáš Voslař <tomas.voslar at webcook.cz>
11
 * @package WebCMS2
12
 */
13
class PagesPresenter extends \AdminModule\BasePresenter
14
{
15
    /* @var Page */
16
17
    private $page;
18
19
    private $repository;
20
21 1
    protected function beforeRender()
22
    {
23 1
        parent::beforeRender();
24 1
    }
25
26 1
    protected function startup()
27
    {
28 1
        parent::startup();
29
30 1
        $this->repository = $this->em->getRepository('WebCMS\Entity\Page');
31 1
    }
32
33 1
    protected function createComponentPageForm()
34
    {
35
        $repository = $this->em->getRepository('WebCMS\Entity\Page');
36
        $hierarchy = $repository->getTreeForSelect(array(
37
            array('by' => 'root', 'dir' => 'ASC'),
38
            array('by' => 'lft', 'dir' => 'ASC'),
39
            ), array(
40
            'language = '.$this->state->language->getId(),
41
        ));
42
43
        $hierarchy = array(0 => $this->translation['Pick parent']) + $hierarchy;
44
45
        // loads modules
46
        $modules = $this->em->getRepository('WebCMS\Entity\Module')->findAll();
47
        $modulesToSelect = array(NULL => 'No module');
48
        foreach ($modules as $module) {
49
            $objectModule = $this->createObject($module->getName());
50
51
            foreach ($objectModule->getPresenters() as $presenter) {
52
                if ($presenter['frontend']) {
53
                    $modulesToSelect[$module->getId().'-'.$presenter['name']] = $module->getName().' '.$presenter['name'];
54
                }
55
            }
56
        }
57
58
        $layouts = array();
59
        foreach (Finder::findFiles('@*.latte')->in(APP_DIR.'/templates') as $key => $file) {
60
            $layouts[str_replace(array('@', '.latte'), '', $file->getFileName())] = $file->getFileName();
61
        }
62
63
        $form = $this->createForm();
64
        $form->addText('title', 'Name')->setAttribute('class', 'form-control')->setRequired();
0 ignored issues
show
'form-control' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
65 1
        $form->addText('redirect', 'Redirect')->setAttribute('class', 'form-control');
0 ignored issues
show
'form-control' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
66
        $form->addText('class', 'Menu item class')->setAttribute('class', 'form-control');
0 ignored issues
show
'form-control' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
67
        $form->addSelect('module', 'Module')->setTranslator(null)->setItems($modulesToSelect)->setAttribute('class', 'form-control')->setRequired();
0 ignored issues
show
'form-control' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
68
        $form->addSelect('parent', 'Parent')->setTranslator(null)->setItems($hierarchy)->setAttribute('class', 'form-control');
0 ignored issues
show
'form-control' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
69
        $form->addSelect('layout', 'Page layout')->setTranslator(null)->setItems($layouts)->setAttribute('class', 'form-control');
0 ignored issues
show
'form-control' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
70
        $form->addCheckbox('default', 'Default');
71
        $form->addCheckbox('visible', 'Show');
72
        $form->addCheckbox('secured', 'Secured');
73
74
        $form->addSubmit('save', 'Save')->setAttribute('class', 'btn btn-success');
0 ignored issues
show
'btn btn-success' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
75
76
        $form->onSuccess[] = callback($this, 'pageFormSubmitted');
77
78 1
        if ($this->page) {
79 1
            $form->setDefaults($this->page->toArray());
80 1
            if (is_object($this->page->getModule())) {
81 1
                $form['module']->setDefaultValue($this->page->getModule()->getId().'-'.$this->page->getPresenter());
82 1
            }
83 1
        }
84
85 1
        return $form;
86 1
    }
87
88
    public function pageFormSubmitted(UI\Form $form)
89
    {
90
        $values = $form->getValues();
91
92
        $tmpBoxes = array();
93
        if ($values->parent) {
94
            $parent = $this->em->find("WebCMS\Entity\Page", $values->parent);
95
            // copy boxes
96
            $tmpBoxes = $parent->getBoxes();
97
        } else {
98
            $parent = null;
99
        }
100
101
        $this->setPageValues($values, $parent);
102
103
        if (!$this->page->getId()) {
104
            $this->em->persist($this->page);
105
106
            $this->createBoxesFromParent($tmpBoxes);
107
108
            $this->em->flush();
109
            $this->copyPermissions();
110
        } else {
111
            $children = $this->page->getChildren();
112
113
            foreach ($children as $child) {
114
                  $this->generatePath($child);
115
            }
116
	}
117
118
        // persist and generate path
119
        $this->em->flush();
120
        $this->generatePath($this->page);
121
        $this->em->flush();
122
        $this->generateSitemap();
123
124
        $this->flashMessage('Page has been added.', 'success');
125
        $this->forward('Pages:default');
126
    }
127
128
    /**
129
     *
130
     *
131
     * @param [type] $values [description]
0 ignored issues
show
The doc-type [type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
132
     */
133 1
    private function setPageValues($values, $parent)
134
    {
135
        if ($values->module) {
136
            $parse = explode('-', $values->module);
137
            $module = $this->em->find("WebCMS\Entity\Module", $parse[0]);
138
            $presenter = $parse[1];
139
        } else {
140
            $module = null;
141
            $presenter = '';
142 1
        }
143
144
        $this->page->setTitle($values->title);
145
146
        if (!empty($values->redirect)) {
147 1
            $this->page->setRedirect($values->redirect);
148
        } else {
149
            $this->page->setRedirect(null);
150
        }
151
152
        if ($module) {
153
            $this->page->setModuleName($module->getName());
154
        } else {
155
            $this->page->setModuleName('');
156
        }
157
158
        $this->page->setVisible($values->visible);
159
        $this->page->setDefault($values->default);
160
        $this->page->setSecured($values->secured);
161 1
        $this->page->setParent($parent);
162
        $this->page->setLanguage($this->state->language);
163 1
        $this->page->setModule($module);
164
        $this->page->setPresenter($presenter);
165
        $this->page->setPath('tmp value');
166
        $this->page->setClass($values->class);
167
        $this->page->setLayout($values->layout);
168
    }
169
170
    /**
171
     *
172
     *
173
     * @param  [type] $boxes [description]
0 ignored issues
show
The doc-type [type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
174
     * @return [type] [description]
0 ignored issues
show
The doc-type [type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
175
     */
176
    private function createBoxesFromParent($boxes)
177
    {
178
        foreach ($boxes as $box) {
179
            $tmp = new \WebCMS\Entity\Box();
180
            $tmp->setBox($box->getBox());
181
            $tmp->setFunction($box->getFunction());
182
            $tmp->setModuleName($box->getModuleName());
183
            $tmp->setPresenter($box->getPresenter());
184
            $tmp->setPageFrom($box->getPageFrom());
185
            $tmp->setPageTo($this->page);
186
187
            $this->em->persist($tmp);
188
        }
189
    }
190
191
    /**
192
     *
193
     *
194
     * @return [type] [description]
0 ignored issues
show
The doc-type [type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
195
     */
196 View Code Duplication
    private function generatePath($page)
0 ignored issues
show
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...
197
    {
198
        $path = $this->em->getRepository('WebCMS\Entity\Page')->getPath($page);
199
        $final = array();
200
        foreach ($path as $p) {
201
            if ($p->getParent() != NULL) {
202
                $final[] = $p->getSlug();
203
            }
204
        }
205
206
        $page->setPath(implode('/', $final));
207
    }
208
209
    /**
210
     *
211
     *
212
     * @return [type] [description]
0 ignored issues
show
The doc-type [type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
213
     */
214
    private function copyPermissions()
215
    {
216
        $roles = $this->em->getRepository('WebCMS\Entity\Role')->findBy(array(
217
            'automaticEnable' => true,
218
        ));
219
220
        foreach ($roles as $r) {
221
            $module = $this->createObject($this->page->getModuleName());
222
            foreach ($module->getPresenters() as $presenter) {
223
                $permission = new \WebCMS\Entity\Permission();
224
225
                $resource = 'admin:'.$this->page->getModuleName().$presenter['name'].$this->page->getId();
226
                $permission->setResource($resource);
227
                $permission->setPage($this->page);
228
                $permission->setRead(true);
229
230
                $r->addPermission($permission);
231
            }
232
        }
233
    }
234
235 1
    protected function createComponentPagesGrid($name)
236
    {
237 1
        $parents = $this->em->getRepository('WebCMS\Entity\Page')->findBy(array(
238 1
            'parent' => NULL,
239 1
            'language' => $this->state->language->getId(),
240 1
        ));
241
242 1
        $prnts = array('' => $this->translation['Pick structure']);
243
244 1
        foreach ($parents as $p) {
245
            $prnts[$p->getId()] = $p->getTitle();
246 1
        }
247
248 1
        $grid = $this->createGrid($this, $name, 'Page', array(
249 1
            array('by' => 'root', 'dir' => 'ASC'),
250 1
            array('by' => 'lft', 'dir' => 'ASC'),
251 1
            ), array(
252 1
            'language = '.$this->state->language->getId(),
253
            )
254 1
        );
255
256
        $grid->addColumnText('title', 'Name')->setCustomRender(function ($item) {
257
            return str_repeat("-", $item->getLevel()).$item->getTitle();
258 1
        });
259
260 1
        $grid->addColumnText('root', 'Structure')->setCustomRender(function ($item) {
261
            return $item->getParent() ? $item->getParent() : '-';
262 1
        });
263
264 1
        $grid->addFilterSelect('root', 'Structure')->getControl()->setTranslator(null)->setItems($prnts);
265
266 1
        $grid->addColumnText('moduleName', 'Module');
267
268 1
        $grid->addColumnText('visible', 'Visible')->setReplacement(array(
269 1
            '1' => 'Yes',
270 1
            NULL => 'No',
271 1
        ));
272
273 1
        $grid->addColumnText('default', 'Default')->setReplacement(array(
274 1
            '1' => 'Yes',
275 1
            NULL => 'No',
276 1
        ));
277
278 1
        $grid->addColumnText('secured', 'Secured')->setReplacement(array(
279 1
            '1' => 'Yes',
280 1
            NULL => 'No',
281 1
        ));
282
283
        //$grid->addActionHref("moveUp", "Move up");
284
        //$grid->addActionHref("moveDown", "Move down");
285 1
        $grid->addActionHref("updatePage", 'Edit')->getElementPrototype()->addAttributes(array('class' => array('btn', 'btn-primary', 'ajax')));
286 1
        $grid->addActionHref("deletePage", 'Delete')->getElementPrototype()->addAttributes(array('class' => array('btn', 'btn-danger'), 'data-confirm' => 'Are you sure you want to delete this item?'));
287
288 1
        return $grid;
289
    }
290
291 1
    public function actionUpdatePage($id)
292
    {
293
        if ($id) {
294
            $this->page = $this->em->find("WebCMS\Entity\Page", $id);
295
        } else {
296
            $this->page = new \WebCMS\Entity\Page();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \WebCMS\Entity\Page() of type object<WebCMS\Entity\Page> is incompatible with the declared type object<AdminModule\Page> of property $page.

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...
297 1
        }
298
    }
299
300 View Code Duplication
    public function actionDeletePage($id)
0 ignored issues
show
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...
301
    {
302
        $this->page = $this->em->find("WebCMS\Entity\Page", $id);
303
        $this->em->remove($this->page);
304
        $this->em->flush();
305
306
        $this->flashMessage('Page has been removed.', 'success');
307
308
        $this->forward('Pages:default');
309
    }
310
311
    public function renderUpdatePage($id)
0 ignored issues
show
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
312
    {
313
        $this->reloadContent();
314
315
        $this->template->page = $this->page;
0 ignored issues
show
The property $template is declared private in Nette\Application\UI\Control. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Accessing page on the interface Nette\Templating\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
316
    }
317
318 1
    public function renderDefault()
319
    {
320 1
        $this->reloadContent();
321 1
    }
322
323
    // Sorting
324
    public function renderSorting($id)
0 ignored issues
show
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
325
    {
326
        $this->reloadContent();
327
328
        $roots = $this->repository->findBy(array(
329
            'parent' => NULL,
330
            'language' => $this->state->language->getId(),
331
        ));
332
333
        $tree = array();
334
        foreach ($roots as $r) {
335
            $tmp = array();
336
            $tmp['title'] = $r->getTitle();
337
            $tmp['__children'] = $this->repository->childrenHierarchy($r);
338
339
            $tree[] = $tmp;
340
        }
341
342
        $this->template->tree = $tree;
0 ignored issues
show
The property $template is declared private in Nette\Application\UI\Control. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Accessing tree on the interface Nette\Templating\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
343
    }
344
345
    public function actionMove($id, $oldPosition, $newPosition)
346
    {
347
        $step = $newPosition - $oldPosition;
348
349
        if ($step > 0) {
350
            $this->actionMoveDown($id, $step);
351
        } else {
352
            $this->actionMoveUp($id, $step * -1);
353
        }
354
355
        $this->forward('Pages:sorting');
356
    }
357
358 View Code Duplication
    public function actionMoveUp($id, $step = 1)
0 ignored issues
show
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...
359
    {
360
        $this->page = $this->em->find("WebCMS\Entity\Page", $id);
361
362
        if ($this->page->getParent()) {
363
            $repository = $this->em->getRepository('WebCMS\Entity\Page');
364
            $repository->moveUp($this->page, $step);
365
366
            $this->flashMessage('Page has been moved up.', 'success');
367
        } else {
368
            $this->flashMessage('Page has not been moved up, because it is root page.', 'warning');
369
        }
370
371
        if (!$this->isAjax()) {
372
            $this->forward('Pages:default');
373
        }
374
    }
375
376 View Code Duplication
    public function actionMoveDown($id, $step = 1)
0 ignored issues
show
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...
377
    {
378
        $this->page = $this->em->find("WebCMS\Entity\Page", $id);
379
380
        if ($this->page->getParent()) {
381
            $repository = $this->em->getRepository('WebCMS\Entity\Page');
382
            $repository->moveDown($this->page, $step);
383
384
            $this->flashMessage('Page has been moved down.', 'success');
385
        } else {
386
            $this->flashMessage('Page has not been moved up, because it is root page.', 'warning');
387
        }
388
389
        if (!$this->isAjax()) {
390
            $this->forward('Pages:default');
391
        }
392
    }
393
}
394