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

ValidatorHooks   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 44
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A onRegistration() 0 17 2
A onUnitTestsList() 0 15 3
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