TimeZone::getAll()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 12
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 19
ccs 13
cts 13
cp 1
crap 3
rs 9.8666
1
<?php
2
3
namespace terabytesoft\helpers;
4
5
/**
6
 * Class Timezone
7
 *
8
 * Helper showing all time zones
9
 **/
10
class TimeZone
11
{
12
    /**
13
     * Get all of the time zones with the offsets sorted by their offset
14
     **/
15 1
    public function getAll(): array
16
    {
17 1
        $timeZones = [];
18 1
        $timeZoneIdentifiers = \DateTimeZone::listIdentifiers();
19
20 1
        foreach ($timeZoneIdentifiers as $timeZone) {
21 1
            $date = new \DateTime('now', new \DateTimeZone($timeZone));
22 1
            $offset = $date->getOffset();
23 1
            $tz = ($offset > 0 ? '+' : '-') . gmdate('H:i', (int) abs($offset));
24 1
            $timeZones[] = [
25 1
                'timezone' => $timeZone,
26 1
                'name' => "{$timeZone} (UTC {$tz})",
27 1
                'offset' => $offset
28
            ];
29
        }
30
31 1
        \yii\helpers\ArrayHelper::multisort($timeZones, 'offset', SORT_DESC, SORT_NUMERIC);
32
33 1
        return $timeZones;
34
    }
35
}
36