Completed
Pull Request — master (#37)
by
unknown
01:03
created

ValidatorHooks::onRegistration()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.7
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
class ValidatorHooks {
3
	public static function onRegistration() {
4
		if ( !class_exists( ParamProcessor\Processor::class ) ) {
5
			throw new Exception( 'Validator depends on the ParamProcessor library.' );
6
		}
7
8
		define( 'Validator_VERSION', '2.2.5' );
9
		define( 'ParamProcessor_VERSION', Validator_VERSION ); // @deprecated since 1.0
10
11
		global $wgDataValues, $wgParamDefinitions;
12
13
		$wgDataValues['mediawikititle'] = ParamProcessor\MediaWikiTitleValue::class;
14
15
		$wgParamDefinitions['title'] = [
16
			'string-parser' => ParamProcessor\TitleParser::class,
17
			'validator' => ValueValidators\TitleValidator::class,
18
		];
19
	}
20
21
	/**
22
	 * Hook to add PHPUnit test cases.
23
	 * @see https://www.mediawiki.org/wiki/Manual:Hooks/UnitTestsList
24
	 *
25
	 * @since 1.0
26
	 *
27
	 * @param array $files
28
	 * @return bool
29
	 */
30
	public static function onUnitTestsList( array &$files ) {
31
		// @codeCoverageIgnoreStart
32
		$directoryIterator = new RecursiveDirectoryIterator( __DIR__ . '/tests/phpunit/' );
33
34
		/**
35
		 * @var SplFileInfo $fileInfo
36
		 */
37
		foreach ( new RecursiveIteratorIterator( $directoryIterator ) as $fileInfo ) {
38
			if ( substr( $fileInfo->getFilename(), -8 ) === 'Test.php' ) {
39
				$files[] = $fileInfo->getPathname();
40
			}
41
		}
42
43
		return true;
44
	}
45
}
46