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 SMW\Tests\Integration\ExtraneousLanguage; |
||
4 | |||
5 | use SMW\ExtraneousLanguage\ExtraneousLanguage; |
||
6 | use SMW\Tests\TestEnvironment; |
||
7 | |||
8 | /** |
||
9 | * @group semantic-mediawiki |
||
10 | * |
||
11 | * @license GNU GPL v2+ |
||
12 | * @since 2.5 |
||
13 | * |
||
14 | * @author mwjames |
||
15 | */ |
||
16 | class LanguageContent extends \PHPUnit_Framework_TestCase { |
||
17 | |||
18 | protected function tearDown() { |
||
19 | ExtraneousLanguage::clear(); |
||
20 | parent::tearDown(); |
||
21 | } |
||
22 | |||
23 | /** |
||
24 | * @dataProvider canonicalPropertyAliasesProvider |
||
25 | */ |
||
26 | public function testGetCanonicalPropertyAliases( $languageCode, $canonicalMatch, $aliasMatch, $expected ) { |
||
27 | |||
28 | $extraneousLanguage = ExtraneousLanguage::getInstance()->fetchByLanguageCode( |
||
29 | $languageCode |
||
30 | ); |
||
31 | |||
32 | $canonicalPropertyAliases = $extraneousLanguage->getCanonicalPropertyAliases(); |
||
33 | |||
34 | $this->assertEquals( |
||
35 | $expected, |
||
36 | $canonicalPropertyAliases[$canonicalMatch] |
||
37 | ); |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * @dataProvider canonicalPropertyAliasesProvider |
||
42 | */ |
||
43 | public function testGetPropertyAliases( $languageCode, $canonicalMatch, $aliasMatch, $expected ) { |
||
44 | |||
45 | $extraneousLanguage = ExtraneousLanguage::getInstance()->fetchByLanguageCode( |
||
46 | $languageCode |
||
47 | ); |
||
48 | |||
49 | $propertyAliases = $extraneousLanguage->getPropertyAliases(); |
||
50 | |||
51 | $this->assertEquals( |
||
52 | $expected, |
||
53 | $propertyAliases[$aliasMatch] |
||
54 | ); |
||
55 | } |
||
56 | |||
57 | public function canonicalPropertyAliasesProvider() { |
||
58 | |||
59 | $provider[] = array( |
||
0 ignored issues
–
show
|
|||
60 | 'fr', |
||
61 | 'Query size', |
||
62 | 'Taille de la requête', |
||
63 | '_ASKSI' |
||
64 | ); |
||
65 | |||
66 | return $provider; |
||
67 | } |
||
68 | |||
69 | } |
||
70 |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.