Passed
Push — newinternal-releasecandidate ( cb0a64 )
by Simon
03:29
created

PageTeam::assocArrayShuffle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 11
ccs 0
cts 9
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
1
<?php
2
/******************************************************************************
3
 * Wikipedia Account Creation Assistance tool                                 *
4
 *                                                                            *
5
 * All code in this file is released into the public domain by the ACC        *
6
 * Development Team. Please see team.json for a list of contributors.         *
7
 ******************************************************************************/
8
9
namespace Waca\Pages;
10
11
use Waca\Tasks\InternalPageBase;
12
13
class PageTeam extends InternalPageBase
14
{
15
    /**
16
     * Main function for this page, when no specific actions are called.
17
     * @return void
18
     */
19
    protected function main()
20
    {
21
        $path = $this->getSiteConfiguration()->getFilePath() . '/team.json';
22
        $json = file_get_contents($path);
23
24
        $teamData = json_decode($json, true);
25
26
        $active = array();
27
        $inactive = array();
28
29
        foreach ($teamData as $name => $item) {
30
            if (count($item['Role']) == 0) {
31
                $inactive[$name] = $item;
32
            }
33
            else {
34
                $active[$name] = $item;
35
            }
36
        }
37
38
        $this->assign('developer', $this->assocArrayShuffle($active));
39
        $this->assign('inactiveDeveloper', $this->assocArrayShuffle($inactive));
40
        $this->setTemplate('team/team.tpl');
41
    }
42
43
    private function assocArrayShuffle($array)
44
    {
45
        $arrayKeys = array_keys($array);
46
        shuffle($arrayKeys);
47
48
        $sorted = [];
49
        foreach ($arrayKeys as $k) {
50
            $sorted[$k] = $array[$k];
51
        }
52
53
        return $sorted;
54
    }
55
}
56