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.
Completed
Push — develop ( 64c0c8...2d0c86 )
by Luis Ramón
05:14
created

frontpage.php ➔ getGroupings()   B

Complexity

Conditions 9
Paths 24

Size

Total Lines 54
Code Lines 39

Duplication

Lines 32
Ratio 59.26 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 9
eloc 39
c 1
b 0
f 0
nc 24
nop 5
dl 32
loc 54
rs 7.255

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
/*  ATICA - Web application for supporting Quality Management Systems
4
  Copyright (C) 2009-2015: Luis-Ramón López López
5
6
  This program is free software: you can redistribute it and/or modify
7
  it under the terms of the GNU Affero General Public License as published by
8
  the Free Software Foundation, either version 3 of the License, or
9
  (at your option) any later version.
10
11
  This program is distributed in the hope that it will be useful,
12
  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
  GNU Affero General Public License for more details.
15
16
  You should have received a copy of the GNU Affero General Public License
17
  along with this program.  If not, see [http://www.gnu.org/licenses/]. */
18
19
$app->get('/(portada)', function () use ($app, $user) {
20
    if (!isset($_SESSION['organization_id'])) {
21
        $app->redirect($app->urlFor('organization'));
22
    }
23
    $breadcrumb = array(
24
        array('display_name' => 'Portada', 'target' => '#')
25
    );
26
27
    $parentGrouping = array();
28
    $matchedGrouping = array();
29
30
    $sidebar = getGroupings($_SESSION['organization_id'], $app, null, $matchedGrouping, $parentGrouping);
31
32
    $app->render('frontpage.html.twig', array(
33
        'navigation' => $breadcrumb,
34
        'search' => false,
35
        'sidebar' => $sidebar,
36
        'user' => $user));
37
38
})->name('frontpage');
39
40
$app->get('/portada/:id', function ($id) use ($app, $user) {
41
    if (!isset($_SESSION['organization_id'])) {
42
        $app->redirect($app->urlFor('organization'));
43
    }
44
    $matchedGrouping = null;
45
    $parentGrouping = null;
46
47
    $sidebar = getGroupings($_SESSION['organization_id'], $app, $id, $matchedGrouping, $parentGrouping);
48
49
    if ($matchedGrouping == null) {
50
        $app->redirect($app->urlFor('frontpage'));
51
    }
52
53
    $breadcrumb = array(
54
            array('display_name' => 'Portada', 'target' => $app->urlFor('frontpage')),
55
            array('display_name' => $parentGrouping['display_name'], 'target' => $app->urlFor('grouping', array('id' => $id))),
56
            array('display_name' => $matchedGrouping['display_name'])
57
    );
58
59
    $folders = getGroupingFolders($id);
60
    $data = getParsedDeliveriesFromGroupingFolders($folders);
61
62
    $app->render('grouping.html.twig', array(
63
        'navigation' => $breadcrumb,
64
        'search' => !empty($data),
65
        'sidebar' => $sidebar,
66
        'data' => $data,
67
        'folders' => $folders,
68
        'grouping' => $matchedGrouping,
69
        'user' => $user));
70
})->name('grouping');
71
72
function getGroupings($orgId, $app, $id, &$matchedGrouping, &$parentGrouping) {
73
    $return = array();
74
    $currentData = array();
75
    $currentGrouping = null;
76
    $match = false;
77
78
    $data = ORM::for_table('grouping')->
79
            order_by_asc('grouping_left')->
80
            where('organization_id', $orgId)->
81
            where_gt('grouping_level', 0)->
82
            find_array();
83
84
    foreach ($data as $grouping) {
85
        if ($grouping['grouping_level'] == 1) {
86 View Code Duplication
            if ($currentGrouping != null) {
87
                array_unshift($currentData,
88
                        array(
89
                            'caption' => $currentGrouping['display_name']
90
                        ));
91
                $return[] = $currentData;
92
                if ($match) {
93
                    $parentGrouping = $currentGrouping;
94
                }
95
            }
96
            $currentData = array();
97
            $currentGrouping = $grouping;
98
            $match = false;
99
        }
100 View Code Duplication
        else {
101
            $localMatch = ($id == $grouping['id']);
102
            $currentData[] = array(
103
                'caption' => $grouping['display_name'],
104
                'active' => $localMatch,
105
                'target' => $app->urlFor('grouping', array('id' => $grouping['id']))
106
            );
107
            if ($localMatch) {
108
                $matchedGrouping = $grouping;
109
            }
110
            $match = $match || $localMatch;
111
        }
112
    }
113 View Code Duplication
    if ($currentGrouping != null) {
114
        array_unshift($currentData,
115
                array(
116
                    'caption' => $currentGrouping['display_name']
117
                ));
118
        $return[] = $currentData;
119
        if ($match) {
120
            $parentGrouping = $currentGrouping;
121
        }
122
    }
123
124
    return $return;
125
}
126
127
function getGroupingFolders($groupingId) {
128
    return parseArray(ORM::for_table('folder')->
129
        inner_join('grouping_folder', array('grouping_folder.folder_id', '=', 'folder.id'))->
130
        where('grouping_folder.grouping_id', $groupingId)->
131
        order_by_asc('grouping_folder.order_nr')->
132
        find_many());
133
}
134
135
136
function getParsedDeliveriesFromGroupingFolders($folders) {
137
138
    $return = array();
139
    foreach($folders as $folder) {
140
        $deliveries = ORM::for_table('delivery')->
141
                select('delivery.*')->
142
                select('folder_delivery.order_nr')->
143
                select('revision.upload_date')->
144
                inner_join('folder_delivery', array('folder_delivery.delivery_id', '=', 'delivery.id'))->
145
                inner_join('revision', array('delivery.current_revision_id', '=', 'revision.id'))->
146
                inner_join('person', array('person.id', '=', 'revision.uploader_person_id'))->
147
                where('folder_delivery.folder_id', $folder['id'])->
148
                where_null('folder_delivery.snapshot_id')->
149
                order_by_asc('delivery.profile_id')->
150
                order_by_asc('order_nr')->find_array();
151
152
        $return[] = array(
153
            'id' => $folder['id'],
154
            'data' => $deliveries
155
        );
156
    }
157
    return $return;
158
}
159