GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

contentAjaxReorder::view()   C
last analyzed

Complexity

Conditions 16
Paths 37

Size

Total Lines 44
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 16
eloc 31
c 0
b 0
f 0
nc 37
nop 0
dl 0
loc 44
rs 5.5666

How to fix   Complexity   

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
 * @package content
4
 */
5
/**
6
 * The AjaxReorder page is used for reordering objects in the Symphony
7
 * backend through Javascript. At the moment this is only supported for
8
 * Pages and Sections.
9
 */
10
11
class contentAjaxReorder extends XMLPage
0 ignored issues
show
Coding Style introduced by
This class is not in CamelCase format.

Classes in PHP are usually named in CamelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.

Thus the name database provider becomes DatabaseProvider.

Loading history...
12
{
13
    const kREORDER_PAGES = 0;
0 ignored issues
show
Coding Style introduced by
This class constant is not uppercase (expected KREORDER_PAGES).
Loading history...
14
    const kREORDER_SECTIONS = 1;
0 ignored issues
show
Coding Style introduced by
This class constant is not uppercase (expected KREORDER_SECTIONS).
Loading history...
15
    const kREORDER_EXTENSION = 2;
0 ignored issues
show
Coding Style introduced by
This class constant is not uppercase (expected KREORDER_EXTENSION).
Loading history...
16
    const kREORDER_UNKNOWN = 3;
0 ignored issues
show
Coding Style introduced by
This class constant is not uppercase (expected KREORDER_UNKNOWN).
Loading history...
17
18
    public function view()
19
    {
20
        $items = $_REQUEST['items'];
21
22
        if (!is_array($items) || empty($items)) {
23
            return;
24
        }
25
26
        $destination = self::kREORDER_UNKNOWN;
27
28
        if ($this->_context[0] == 'blueprints' && $this->_context[1] == 'pages') {
29
            $destination = self::kREORDER_PAGES;
30
        } elseif ($this->_context[0] == 'blueprints' && $this->_context[1] == 'sections') {
31
            $destination = self::kREORDER_SECTIONS;
32
        } elseif ($this->_context[0] == 'extensions') {
33
            $destination = self::kREORDER_EXTENSION;
34
        }
35
36
        switch ($destination) {
37
            case self::kREORDER_PAGES:
38
                foreach ($items as $id => $position) {
39
                    if (!PageManager::edit($id, array('sortorder' => $position))) {
40
                        $this->setHttpStatus(self::HTTP_STATUS_ERROR);
41
                        $this->_Result->setValue(__('A database error occurred while attempting to reorder.'));
42
                        break;
43
                    }
44
                }
45
                break;
46
            case self::kREORDER_SECTIONS:
47
                foreach ($items as $id => $position) {
48
                    if (!SectionManager::edit($id, array('sortorder' => $position))) {
49
                        $this->setHttpStatus(self::HTTP_STATUS_ERROR);
50
                        $this->_Result->setValue(__('A database error occurred while attempting to reorder.'));
51
                        break;
52
                    }
53
                }
54
                break;
55
            case self::kREORDER_EXTENSION:
56
                // TODO
57
                break;
58
            case self::kREORDER_UNKNOWN:
59
            default:
60
                $this->setHttpStatus(self::HTTP_STATUS_BAD_REQUEST);
61
                break;
62
        }
63
    }
64
}
65