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/ValueParsers/YearTimeParserTest.php (1 issue)

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 ValueParsers\Test;
4
5
use DataValues\TimeValue;
6
use ValueParsers\EraParser;
7
use ValueParsers\ParseException;
8
use ValueParsers\ParserOptions;
9
use ValueParsers\YearTimeParser;
10
11
/**
12
 * @covers ValueParsers\YearTimeParser
13
 *
14
 * @group DataValue
15
 * @group DataValueExtensions
16
 * @group TimeParsers
17
 * @group ValueParsers
18
 *
19
 * @license GPL-2.0-or-later
20
 * @author Addshore
21
 * @author Thiemo Kreuz
22
 */
23
class YearTimeParserTest extends ValueParserTestCase {
24
25
	/**
26
	 * @see ValueParserTestBase::getInstance
27
	 *
28
	 * @return YearTimeParser
29
	 */
30
	protected function getInstance() {
31
		return new YearTimeParser( $this->getMockEraParser() );
0 ignored issues
show
$this->getMockEraParser() is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a null|object<ValueParsers\ValueParser>.

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...
32
	}
33
34
	/**
35
	 * @return EraParser
36
	 */
37
	private function getMockEraParser() {
38
		$mock = $this->getMockBuilder( EraParser::class )
39
			->disableOriginalConstructor()
40
			->getMock();
41
		$mock->expects( $this->any() )
42
			->method( 'parse' )
43
			->with( $this->isType( 'string' ) )
44
			->will( $this->returnCallback(
45
				function ( $value ) {
46
					$sign = '+';
47
					// Tiny parser that supports a single negative sign only
48
					if ( $value[0] === '-' ) {
49
						$sign = '-';
50
						$value = substr( $value, 1 );
51
					}
52
					return array( $sign, $value );
53
				}
54
			) );
55
		return $mock;
56
	}
57
58
	/**
59
	 * @see ValueParserTestBase::validInputProvider
60
	 */
61
	public function validInputProvider() {
62
		$gregorian = 'http://www.wikidata.org/entity/Q1985727';
63
		$julian = 'http://www.wikidata.org/entity/Q1985786';
64
65
		$argLists = array();
66
67
		$valid = array(
68
			// Whitespace
69
			"1999\n" =>
70
				array( '+1999-00-00T00:00:00Z' ),
71
			' 2000 ' =>
72
				array( '+2000-00-00T00:00:00Z' ),
73
74
			'2010' =>
75
				array( '+2010-00-00T00:00:00Z' ),
76
			'2000000' =>
77
				array( '+2000000-00-00T00:00:00Z', TimeValue::PRECISION_YEAR1M ),
78
			'2000000000' =>
79
				array( '+2000000000-00-00T00:00:00Z', TimeValue::PRECISION_YEAR1G ),
80
			'2000020000' =>
81
				array( '+2000020000-00-00T00:00:00Z', TimeValue::PRECISION_YEAR10K ),
82
			'2000001' =>
83
				array( '+2000001-00-00T00:00:00Z' ),
84
			'02000001' =>
85
				array( '+2000001-00-00T00:00:00Z' ),
86
			'1' =>
87
				array( '+0001-00-00T00:00:00Z', TimeValue::PRECISION_YEAR, $julian ),
88
			'000000001' =>
89
				array( '+0001-00-00T00:00:00Z', TimeValue::PRECISION_YEAR, $julian ),
90
			'-1000000' =>
91
				array( '-1000000-00-00T00:00:00Z', TimeValue::PRECISION_YEAR1M, $julian ),
92
			'-1 000 000' =>
93
				array( '-1000000-00-00T00:00:00Z', TimeValue::PRECISION_YEAR1M, $julian ),
94
			'-19_000' =>
95
				array( '-19000-00-00T00:00:00Z', TimeValue::PRECISION_YEAR1K, $julian ),
96
			// Digit grouping in the Indian numbering system
97
			'-1,99,999' =>
98
				array( '-199999-00-00T00:00:00Z', TimeValue::PRECISION_YEAR, $julian ),
99
		);
100
101
		foreach ( $valid as $value => $expected ) {
102
			$timestamp = $expected[0];
103
			$precision = isset( $expected[1] ) ? $expected[1] : TimeValue::PRECISION_YEAR;
104
			$calendarModel = isset( $expected[2] ) ? $expected[2] : $gregorian;
105
106
			$argLists[] = array(
107
				(string)$value,
108
				new TimeValue( $timestamp, 0, 0, 0, $precision, $calendarModel )
109
			);
110
		}
111
112
		return $argLists;
113
	}
114
115
	public function testDigitGroupSeparatorOption() {
116
		$options = new ParserOptions();
117
		$options->setOption( YearTimeParser::OPT_DIGIT_GROUP_SEPARATOR, '.' );
118
		$parser = new YearTimeParser( null, $options );
119
		$timeValue = $parser->parse( '-19.000' );
120
		$this->assertSame( '-19000-00-00T00:00:00Z', $timeValue->getTime() );
121
	}
122
123
	/**
124
	 * @see StringValueParserTest::invalidInputProvider
125
	 */
126
	public function invalidInputProvider() {
127
		$argLists = parent::NON_VALID_CASES;
128
129
		$invalid = array(
130
			// These are just wrong
131
			'June June June',
132
			'111 111 111',
133
			'Jann 2014',
134
135
			// Not within the scope of this parser
136
			'1 July 20000',
137
138
			// We should not try to parse these, this just gets confusing
139
			'-100BC',
140
			'+100BC',
141
			'-100 BC',
142
			'+100 BC',
143
			'+100 BCE',
144
			'+100BCE',
145
146
			// Non-default and invalid thousands separators
147
			'-,999',
148
			'-999,',
149
			'-19.000',
150
			'-1/000/000',
151
152
			// Positive years are unlikely to have thousands separators, it's more likely a date
153
			'1 000 000',
154
			'19_000',
155
			'1,99,999',
156
		);
157
158
		foreach ( $invalid as $value ) {
159
			$argLists[] = array( $value );
160
		}
161
162
		return $argLists;
163
	}
164
165
	public function testParseExceptionMessage() {
166
		$parser = $this->getInstance();
167
		$this->expectException( ParseException::class );
168
		$parser->parse( 'ju5t 1nval1d' );
169
	}
170
171
}
172