TimezoneHelper   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 29
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getAll() 0 19 3
1
<?php
2
3
/*
4
 * This file is part of the 2amigos/yii2-usuario project.
5
 *
6
 * (c) 2amigOS! <http://2amigos.us/>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace Da\User\Helper;
13
14
use DateTime;
15
use DateTimeZone;
16
use yii\base\InvalidParamException;
17
use yii\helpers\ArrayHelper;
18
19
class TimezoneHelper
20
{
21
    /**
22
     * Get all of the time zones with the offsets sorted by their offset.
23
     *
24
     * @throws InvalidParamException
25
     * @return array
26
     *
27
     */
28 1
    public static function getAll()
29
    {
30 1
        $timeZones = [];
31 1
        $timeZoneIdentifiers = DateTimeZone::listIdentifiers();
32
33 1
        foreach ($timeZoneIdentifiers as $timeZone) {
34 1
            $date = new DateTime('now', new DateTimeZone($timeZone));
35 1
            $offset = $date->getOffset() / 60 / 60;
36 1
            $timeZones[] = [
37 1
                'timezone' => $timeZone,
38 1
                'name' => "{$timeZone} (UTC " . ($offset > 0 ? '+' : '') . "{$offset})",
39 1
                'offset' => $offset,
40
            ];
41
        }
42
43 1
        ArrayHelper::multisort($timeZones, 'offset', SORT_DESC, SORT_NUMERIC);
44
45 1
        return $timeZones;
46
    }
47
}
48