TimeZone   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 24
ccs 13
cts 13
cp 1
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A getAll() 0 19 3
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