• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ICanBoogie / DateTime / 15263502053

26 May 2025 11:34PM UTC coverage: 96.624%. First build
15263502053

push

github

olvlvl
Add static analysis

14 of 17 new or added lines in 2 files covered. (82.35%)

229 of 237 relevant lines covered (96.62%)

41.27 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.89
/lib/TimeZoneLocation.php
1
<?php
2

3
namespace ICanBoogie;
4

5
/**
6
 * Representation of a time zone location.
7
 *
8
 * <pre>
9
 * <?php
10
 *
11
 * use ICanBoogie\TimeZoneLocation;
12
 *
13
 * $zone = new \DateTimeZone('Europe/Paris');
14
 * $location = new TimeZoneLocation($zone->getLocation());
15
 *
16
 * echo $location;               // FR,48.86667,2.33333
17
 * echo $location->country_code; // FR
18
 * echo $location->latitude;     // 48.86667
19
 * echo $location->longitude;    // 2.33333
20
 * </pre>
21
 */
22
final class TimeZoneLocation
23
{
24
        /**
25
         * @var array<string, self>
26
         */
27
        private static array $cache;
28

29
        /**
30
         * Creates an instance from a {@see \DateTimeZone} instance.
31
         */
32
        static public function from(\DateTimeZone $zone): self
33
        {
34
                $hash = spl_object_hash($zone);
3✔
35
                $location = $zone->getLocation()
3✔
NEW
36
                        ?: throw new \RunTimeException("Unable to get location for zone $hash");
×
37

38
                return self::$cache[$hash] ??= new self($location);
3✔
39
        }
40

41
        /**
42
         * The country code of the location.
43
         */
44
        public readonly string $country_code;
45

46
        /**
47
         * The latitude of the location.
48
         */
49
        public readonly float $latitude;
50

51
        /**
52
         * The longitude of the location.
53
         */
54
        public readonly float $longitude;
55

56
        /**
57
         * Comments on the location.
58
         */
59
        public readonly string $comments;
60

61
        /**
62
         * @param array{
63
         *     country_code: string,
64
         *     latitude: float,
65
         *     longitude: float,
66
         *     comments: string } $location Location information provided by {@see \DateTimeZone::getLocation()}.
67
         */
68
        public function __construct(
69
                public readonly array $location
70
        ) {
71
                $this->country_code = $location['country_code'];
4✔
72
                $this->latitude = $location['latitude'];
4✔
73
                $this->longitude = $location['longitude'];
4✔
74
                $this->comments = $location['comments'];
4✔
75
        }
76

77
        /**
78
         * Returns the instance formatted as "{$country_code},{$latitude},{$longitude}".
79
         */
80
        public function __toString(): string
81
        {
82
                return "$this->country_code,$this->latitude,$this->longitude";
1✔
83
        }
84
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc