Issues (3)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Stardate.php (3 issues)

Upgrade to new PHP Analysis Engine

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
Constructors do not have meaningful return values, anything that is returned from here is discarded. Are you sure this is correct?
Loading history...
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
Constructors do not have meaningful return values, anything that is returned from here is discarded. Are you sure this is correct?
Loading history...
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
It seems like $timezone instanceof \Da...mFormat($format, $time) can also be of type false; however, PHPWeekly\Issue63\Stardate::createFromDateTime() does only seem to accept object<DateTime>, did you maybe forget to handle an error condition?
Loading history...
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