System::getTimeZone()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Soluble Japha
7
 *
8
 * @link      https://github.com/belgattitude/soluble-japha
9
 * @copyright Copyright (c) 2013-2020 Vanvelthem Sébastien
10
 * @license   MIT License https://github.com/belgattitude/soluble-japha/blob/master/LICENSE.md
11
 */
12
13
namespace Soluble\Japha\Bridge\Adapter;
14
15
use Soluble\Japha\Bridge;
16
use Soluble\Japha\Interfaces;
17
use Soluble\Japha\Util\TimeZone;
18
use Soluble\Japha\Util\Exception\UnsupportedTzException;
19
20
class System
21
{
22
    /**
23
     * @var Bridge\Adapter
24
     */
25
    protected $ba;
26
27
    /**
28
     * @var TimeZone
29
     */
30
    protected $timeZone;
31
32
    /**
33
     * @param Bridge\Adapter $ba
34
     */
35 8
    public function __construct(Bridge\Adapter $ba)
36
    {
37 8
        $this->ba = $ba;
38 8
        $this->timeZone = new TimeZone($ba);
39 8
    }
40
41
    /**
42
     * Get php DateTime helper object.
43
     *
44
     * @return TimeZone
45
     */
46 1
    public function getTimeZone(): TimeZone
47
    {
48 1
        return $this->timeZone;
49
    }
50
51
    /**
52
     * Return system default timezone id.
53
     *
54
     * @return string
55
     */
56 3
    public function getTimeZoneId(): string
57
    {
58 3
        return (string) $this->timeZone->getDefault()->getID();
0 ignored issues
show
Bug introduced by
The method getID() does not exist on Soluble\Japha\Interfaces\JavaObject. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

58
        return (string) $this->timeZone->getDefault()->/** @scrutinizer ignore-call */ getID();
Loading history...
59
    }
60
61
    /**
62
     * Set system default timezone.
63
     *
64
     * @throws UnsupportedTzException
65
     * @throws Bridge\Exception\JavaException
66
     *
67
     * @param string|Interfaces\JavaObject|\DateTimeZone $timezone timezone id, Java(java.util.Timezone) or php DateTimeZone
68
     */
69 5
    public function setTimeZoneId($timezone): void
70
    {
71 5
        $this->timeZone->setDefault($timezone);
72 2
    }
73
}
74