Issues (16)

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.

tests/DataValues/TimeValueCalculatorTest.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
namespace DataValues\Tests;
4
5
use DataValues\TimeValue;
6
use DataValues\TimeValueCalculator;
7
use PHPUnit\Framework\TestCase;
8
9
/**
10
 * @covers DataValues\TimeValueCalculator
11
 *
12
 * @group DataValue
13
 * @group DataValueExtensions
14
 *
15
 * @license GPL-2.0-or-later
16
 * @author Thiemo Kreuz
17
 */
18
class TimeValueCalculatorTest extends TestCase {
19
20
	/**
21
	 * @var TimeValueCalculator
22
	 */
23
	private $calculator;
24
25
	protected function setUp() : void {
26
		$this->calculator = new TimeValueCalculator();
27
	}
28
29
	/**
30
	 * @param string $time an ISO 8601 date and time
31
	 * @param int $timezone offset from UTC in minutes
32
	 *
33
	 * @return TimeValue
34
	 */
35
	private function getTimeValueMock( $time, $timezone = 0 ) {
36
		$timeValue = $this->getMockBuilder( TimeValue::class )
37
			->disableOriginalConstructor()
38
			->getMock();
39
40
		$timeValue->expects( $this->any() )
41
			->method( 'getTime' )
42
			->will( $this->returnValue( $time ) );
43
		$timeValue->expects( $this->any() )
44
			->method( 'getTimezone' )
45
			->will( $this->returnValue( $timezone ) );
46
		$timeValue->expects( $this->any() )
47
			->method( 'getPrecision' )
48
			->will( $this->returnValue( TimeValue::PRECISION_DAY ) );
49
		$timeValue->expects( $this->any() )
50
			->method( 'getCalendarModel' )
51
			->will( $this->returnValue( 'Stardate' ) );
52
53
		return $timeValue;
54
	}
55
56
	public function timestampProvider() {
57
		return array(
58
			// Make sure it's identical to the PHP/Unix time stamps in current years
59
			array( '+2004-02-29T00:00:00Z', strtotime( '2004-02-29T00:00:00+00:00' ) ),
60
			array( '+2038-00-00T00:00:00Z', strtotime( '2038-01-01T00:00:00+00:00' ) ),
61
62
			// Time zones
63
			array( '+2000-01-01T12:59:59', strtotime( '2000-01-01T12:59:59-02:00' ), -120 ),
64
			array( '+2000-01-01T12:59:59', strtotime( '2000-01-01T12:59:59+04:45' ), 285 ),
65
66
			array( '+0401-00-00T00:00:00Z', -49512816000 ),
67
			array( '+1902-00-00T00:00:00Z', -2145916800 ),
68
			array( '+1939-00-00T00:00:00Z', -978307200 ),
69
			array( '+1969-12-31T23:59:00Z', -60 ),
70
			array( '+1969-12-31T23:59:59Z', -1 ),
71
			array( '+1970-01-01T00:00:00Z', 0 ),
72
			array( '+1970-01-01T00:00:01Z', 1 ),
73
			array( '+1970-01-01T00:01:00Z', 60 ),
74
			array( '+1972-02-29T00:00:00Z', 68169600 ),
75
			array( '+1996-02-29T00:00:00Z', 825552000 ),
76
			array( '+1999-12-31T23:59:59Z', 946684799 ),
77
			array( '+2000-01-01T00:00:00Z', 946684800 ),
78
			array( '+2000-02-01T00:00:00Z', 949363200 ),
79
			array( '+2000-02-29T00:00:00Z', 951782400 ),
80
			array( '+2001-00-00T00:00:00Z', 978307200 ),
81
			array( '+2001-01-01T00:00:00Z', 978307200 ),
82
			array( '+2014-04-30T12:35:55Z', 1398861355 ),
83
			array( '+2401-00-00T00:00:00Z', 13601088000 ),
84
85
			// Make sure there is only 1 second between these two
86
			array( '-0001-12-31T23:59:59Z', -62135596801 ),
87
			array( '+0001-00-00T00:00:00Z', -62135596800 ),
88
89
			// No special calculation for leap seconds, just make sure they pass
90
			array( '+1970-10-11T12:13:61Z', 24495241 ),
91
			array( '+1970-10-11T12:14:01Z', 24495241 ),
92
93
			// Year 0 does not exist, but we do not complain, assume -1
94
			array( '-0000-12-31T23:59:59Z', -62135596801 ),
95
			array( '+0000-00-00T00:00:00Z', floor( ( -1 - 1969 ) * 365.2425 ) * 86400 ),
96
97
			// Since there is no year 0, negative leap years are -1, -5 and so on
98
			array( '-8001-00-00T00:00:00Z', floor( ( -8001 - 1969 ) * 365.2425 ) * 86400 ),
99
			array( '-0005-00-00T00:00:00Z', floor( ( -5 - 1969 ) * 365.2425 ) * 86400 ),
100
			array( '+0004-00-00T00:00:00Z', floor( ( 4 - 1970 ) * 365.2425 ) * 86400 ),
101
			array( '+8000-00-00T00:00:00Z', floor( ( 8000 - 1970 ) * 365.2425 ) * 86400 ),
102
103
			// PHP_INT_MIN is -2147483648
104
			array( '-2147484001-00-00T00:00:00Z', floor( ( -2147484001 - 1969 ) * 365.2425 ) * 86400 ),
105
			// PHP_INT_MAX is +2147483647
106
			array( '+2147484000-00-00T00:00:00Z', floor( ( 2147484000 - 1970 ) * 365.2425 ) * 86400 ),
107
		);
108
	}
109
110
	/**
111
	 * @dataProvider timestampProvider
112
	 */
113
	public function testGetTimestamp( $time, $expectedTimestamp = 0.0, $timezone = 0 ) {
114
		$timeValue = $this->getTimeValueMock( $time, $timezone );
115
		$timestamp = $this->calculator->getTimestamp( $timeValue );
0 ignored issues
show
$timeValue is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<DataValues\TimeValue>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
116
117
		$this->assertEquals( $expectedTimestamp, $timestamp );
118
	}
119
120
	public function yearProvider() {
121
		return array(
122
			// Every 4 years
123
			array( 1895, 459 ),
124
			array( 1896, 460, true ),
125
			array( 1897, 460 ),
126
127
			// Not every 100 years but every 400 years
128
			array( 1900, 460 ),
129
			array( 2000, 485, true ),
130
			array( 2100, 509 ),
131
132
			// Extremes
133
			array( 1, 0 ),
134
			array( 9999, 2424 ),
135
			array( 2147483647, 520764784 ),
136
137
			// There is no year zero, assume -1
138
			array( -1, 0, true ),
139
			array( 0, 0, true ),
140
141
			// Off by 1 for negative years because zero is skipped
142
			array( -6, -2 ),
143
			array( -5, -1, true ),
144
			array( -4, -1 ),
145
			array( -3, -1 ),
146
			array( -2, -1 ),
147
			array( -1, 0, true ),
148
			array( 1, 0 ),
149
			array( 2, 0 ),
150
			array( 3, 0 ),
151
			array( 4, 1, true ),
152
			array( 5, 1 ),
153
154
			// Because we can
155
			array( -6.9, -2 ),
156
			array( -6.1, -2 ),
157
			array( -5.501, -1, true ),
158
			array( -5.499, -1, true ),
159
			array( -4.6, -1 ),
160
			array( -4.4, -1 ),
161
			array( 1995.01, 483 ),
162
			array( 1995.09, 483 ),
163
			array( 1996.001, 484, true ),
164
			array( 1996.009, 484, true ),
165
			array( 1997.1, 484 ),
166
			array( 1997.9, 484 ),
167
		);
168
	}
169
170
	/**
171
	 * @dataProvider yearProvider
172
	 */
173
	public function testIsLeapYear( $year, $numberOfLeapYears, $expected = false ) {
0 ignored issues
show
The parameter $numberOfLeapYears is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
174
		$isLeapYear = $this->calculator->isLeapYear( $year );
175
176
		$this->assertEquals( $expected, $isLeapYear );
177
	}
178
179
	/**
180
	 * @dataProvider yearProvider
181
	 */
182
	public function testGetNumberOfLeapYears( $year, $expected, $isLeapYear = false ) {
0 ignored issues
show
The parameter $isLeapYear is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
183
		$numberOfLeapYears = $this->calculator->getNumberOfLeapYears( $year );
184
185
		$this->assertEquals( $expected, $numberOfLeapYears );
186
	}
187
188
	public function precisionProvider() {
189
		$secondsPerDay = 60 * 60 * 24;
190
		$daysPerGregorianYear = 365 + 1 / 4 - 1 / 100 + 1 / 400;
191
192
		return array(
193
			array( TimeValue::PRECISION_SECOND, 1 ),
194
			array( TimeValue::PRECISION_MINUTE, 60 ),
195
			array( TimeValue::PRECISION_HOUR, 60 * 60 ),
196
			array( TimeValue::PRECISION_DAY, $secondsPerDay ),
197
			array( TimeValue::PRECISION_MONTH, $secondsPerDay * $daysPerGregorianYear / 12 ),
198
			array( TimeValue::PRECISION_YEAR, $secondsPerDay * $daysPerGregorianYear ),
199
			array( TimeValue::PRECISION_YEAR10, $secondsPerDay * $daysPerGregorianYear * 1e1 ),
200
			array( TimeValue::PRECISION_YEAR1G, $secondsPerDay * $daysPerGregorianYear * 1e9 ),
201
		);
202
	}
203
204
	/**
205
	 * @dataProvider precisionProvider
206
	 */
207
	public function testGetSecondsForPrecision( $precision, $expected ) {
208
		$seconds = $this->calculator->getSecondsForPrecision( $precision );
209
210
		$this->assertEquals( $expected, $seconds );
211
	}
212
213
}
214