This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * File StarDate.php |
||
4 | * |
||
5 | * @author Edward Pfremmer <[email protected]> |
||
6 | */ |
||
7 | namespace PHPWeekly\Issue63; |
||
8 | |||
9 | use DateTime; |
||
10 | use DateTimeZone; |
||
11 | use LogicException; |
||
12 | |||
13 | /** |
||
14 | * Class Stardate |
||
15 | * |
||
16 | * @package PHPWeekly\Issue63 |
||
17 | */ |
||
18 | class Stardate extends DateTime |
||
19 | { |
||
20 | /** |
||
21 | * Stardate 00000.0 |
||
22 | * |
||
23 | * Started on Friday, July 5, 2318, around noon (Starfleet Command time) |
||
24 | * (a.k.a Fri Jul 05 2318 12:00:00 GMT-0500 (CDT)) |
||
25 | * |
||
26 | * @var float |
||
27 | */ |
||
28 | const STARDATE_EPOCH = 10997830800; |
||
29 | |||
30 | /**#@+ |
||
31 | * |
||
32 | * Stardate to standard time constants |
||
33 | * |
||
34 | * @var float |
||
35 | */ |
||
36 | const STARDATE_PER_YEAR = 918.23186; |
||
37 | const DAY_PER_STARDATE = 0.397766856; |
||
38 | const SECONDS_PER_STARDATE = 34367.0564; |
||
39 | /**#@-*/ |
||
40 | |||
41 | /** |
||
42 | * StarDate constructor |
||
43 | * |
||
44 | * {@inheritDoc} |
||
45 | * |
||
46 | * @param string $time |
||
47 | */ |
||
48 | public function __construct($time = 'now') |
||
49 | { |
||
50 | if ($time === 'now') { |
||
51 | return parent::__construct($time); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
52 | } |
||
53 | |||
54 | if (!is_numeric($time)) { |
||
55 | throw new LogicException( |
||
56 | sprintf('Stardates *MUST* be numeric. Got "%s".', is_scalar($time) ? $time : gettype($time)) |
||
57 | ); |
||
58 | } |
||
59 | |||
60 | $timestamp = $this->stardateToTimestamp($time); |
||
61 | |||
62 | return parent::__construct("@$timestamp"); |
||
0 ignored issues
–
show
|
|||
63 | } |
||
64 | |||
65 | /** |
||
66 | * Return scalar stardate |
||
67 | * |
||
68 | * @return float |
||
69 | */ |
||
70 | public function getStardate() |
||
71 | { |
||
72 | return $this->timestampToStardate($this->getTimestamp()); |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * Convert federation stardate to epoch timestamp |
||
77 | * |
||
78 | * @param float|int $stardate |
||
79 | * @return int |
||
80 | */ |
||
81 | public static function stardateToTimestamp($stardate) |
||
82 | { |
||
83 | return (int) round(self::STARDATE_EPOCH + ($stardate * self::SECONDS_PER_STARDATE)); |
||
84 | } |
||
85 | |||
86 | /** |
||
87 | * Convert epoch timestamp to federation stardate |
||
88 | * |
||
89 | * @param int $timestamp |
||
90 | * @return float |
||
91 | */ |
||
92 | public static function timestampToStardate($timestamp) |
||
93 | { |
||
94 | return (float) round(($timestamp - self::STARDATE_EPOCH) / self::SECONDS_PER_STARDATE, 4); |
||
95 | } |
||
96 | |||
97 | /** |
||
98 | * Create a new Stardate from a stardate scalar value |
||
99 | * |
||
100 | * @param float $stardate |
||
101 | * @return static |
||
102 | */ |
||
103 | public static function createFromStardate($stardate) |
||
104 | { |
||
105 | return new static($stardate); |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * Create a new Stardate from an epoch timestamp |
||
110 | * |
||
111 | * @param int $timestamp |
||
112 | * @return static |
||
113 | */ |
||
114 | public static function createFromTimestamp($timestamp) |
||
115 | { |
||
116 | return new static(self::timestampToStardate($timestamp)); |
||
117 | } |
||
118 | |||
119 | /** |
||
120 | * Create a new Stardate from a formatted date string |
||
121 | * |
||
122 | * @param string $time |
||
123 | * @param DateTimeZone|null $timezone |
||
124 | * @return Stardate |
||
125 | */ |
||
126 | public static function createFromDateString($time, DateTimeZone $timezone = null) |
||
127 | { |
||
128 | return self::createFromDateTime(new parent($time, $timezone)); |
||
129 | } |
||
130 | |||
131 | /** |
||
132 | * Create a new Stardate from an existing DateTime object |
||
133 | * |
||
134 | * @param DateTime $datetime |
||
135 | * @return static |
||
136 | */ |
||
137 | public static function createFromDateTime(DateTime $datetime) |
||
138 | { |
||
139 | return new static(self::timestampToStardate($datetime->getTimestamp())); |
||
140 | } |
||
141 | |||
142 | /** |
||
143 | * {@inheritDoc} |
||
144 | */ |
||
145 | public static function createFromFormat($format, $time, $timezone = null) |
||
146 | { |
||
147 | return self::createFromDateTime($timezone instanceof DateTimeZone |
||
0 ignored issues
–
show
|
|||
148 | ? parent::createFromFormat($format, $time, $timezone) |
||
149 | : parent::createFromFormat($format, $time) |
||
150 | ); |
||
151 | } |
||
152 | |||
153 | /** |
||
154 | * {@inheritDoc} |
||
155 | */ |
||
156 | public function __toString() |
||
157 | { |
||
158 | return (string) $this->getStardate(); |
||
159 | } |
||
160 | |||
161 | /** |
||
162 | * {@inheritDoc} |
||
163 | */ |
||
164 | public function __debugInfo() |
||
165 | { |
||
166 | return array_replace(['stardate' => $this->getStardate()], get_object_vars($this)); |
||
167 | } |
||
168 | } |
||
169 |