Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
9 / 9 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
SchemataUtils | |
100.00% |
9 / 9 |
|
100.00% |
5 / 5 |
6 | |
100.00% |
1 / 1 |
joinPath | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
dataDirectory | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
testDataDirectory | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
readYaml | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
readYamlAsSecretJson | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | /** |
3 | * @file |
4 | * @copyright 2020– Abstract Wikipedia team; see AUTHORS.txt |
5 | * @license MIT |
6 | */ |
7 | |
8 | namespace MediaWiki\Extension\WikiLambda\Validation; |
9 | |
10 | use Symfony\Component\Yaml\Yaml; |
11 | |
12 | class SchemataUtils { |
13 | |
14 | /** |
15 | * Joins an arbitrary number of path components via DIRECTORY_SEPARATOR. |
16 | * @return string |
17 | */ |
18 | public static function joinPath(): string { |
19 | $components = []; |
20 | foreach ( func_get_args() as $component ) { |
21 | $component = rtrim( $component, DIRECTORY_SEPARATOR ); |
22 | array_push( $components, $component ); |
23 | } |
24 | return implode( DIRECTORY_SEPARATOR, $components ); |
25 | } |
26 | |
27 | /** |
28 | * @return string |
29 | */ |
30 | public static function dataDirectory(): string { |
31 | return self::joinPath( __DIR__, "..", "..", "function-schemata", "data" ); |
32 | } |
33 | |
34 | /** |
35 | * @return string |
36 | */ |
37 | public static function testDataDirectory(): string { |
38 | return self::joinPath( __DIR__, "..", "..", "function-schemata", "test_data" ); |
39 | } |
40 | |
41 | /** |
42 | * @param string $yamlFile File to read |
43 | * @return string |
44 | */ |
45 | public static function readYaml( string $yamlFile ) { |
46 | return Yaml::parseFile( $yamlFile ); |
47 | } |
48 | |
49 | /** |
50 | * @param string $yamlFile File to read |
51 | * @return string |
52 | */ |
53 | public static function readYamlAsSecretJson( string $yamlFile ) { |
54 | return json_encode( self::readYaml( $yamlFile ) ); |
55 | } |
56 | |
57 | } |