Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions moodle/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<rule ref="Squiz.Scope.MethodScope"/>
<rule ref="Squiz.Scope.StaticThisUsage"/>

<rule ref="Squiz.WhiteSpace.OperatorSpacing"/>
<rule ref="Squiz.WhiteSpace.ObjectOperatorSpacing"/>
<rule ref="Squiz.WhiteSpace.ScopeClosingBrace"/>
<rule ref="Squiz.WhiteSpace.ScopeKeywordSpacing"/>
Expand Down
45 changes: 45 additions & 0 deletions moodle/tests/fixtures/squiz_whitespace_operatorspacing.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
// Array representations.
$array = array('test' => 'Test');
$array = array('test'=> 'Test');
$array = array('test' =>'Test');
$array = array('test'=>'Test');
$array = array('test' => 'Test');
$array = array('test' => 'Test');

// Various assignments representations.
$a= 10;
$a =10;
$a=10;
$a = 10;
$a = 10;
$a = 10;

// Mathematical operations.
$c = $a+ 10;
$c = $a +10;
$c = $a+10;
$c = $a + 10;
$c = $a + 10;
$c = $a + 10;

$c = $a- 10;
$c = $a -10;
$c = $a-10;
$c = $a - 10;
$c = $a - 10;
$c = $a - 10;

$c = $a* 10;
$c = $a *10;
$c = $a*10;
$c = $a * 10;
$c = $a * 10;
$c = $a * 10;

$c = $a/ 10;
$c = $a /10;
$c = $a/10;
$c = $a / 10;
$c = $a / 10;
$c = $a / 10;
66 changes: 66 additions & 0 deletions moodle/tests/moodlestandard_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,70 @@ public function test_moodle_namingconventions_variablename() {
// Let's do all the hard work!
$this->verify_cs_results();
}

/**
* Test operator spacing standards
*/
public function test_moodle_operator_spacing() {

// Define the standard, sniff and fixture to use.
$this->set_standard('moodle');
$this->set_sniff('Squiz_Sniffs_WhiteSpace_OperatorSpacingSniff');
$this->set_fixture(__DIR__ . '/fixtures/squiz_whitespace_operatorspacing.php');

// Define expected results (errors and warnings). Format, array of:
// - line => number of problems, or
// - line => array of contents for message / source problem matching.
// - line => string of contents for message / source problem matching (only 1).
$this->set_errors(array(
3 => 0,
4 => 'Expected 1 space before',
5 => 'Expected 1 space after',
6 => array('Expected 1 space before', 'Expected 1 space after'),
7 => 0,
8 => 'Expected 1 space after "=>"; 3 found',
9 => 0,
10 => 0,
11 => 'Expected 1 space before',
12 => 'Expected 1 space after',
13 => array('Expected 1 space before', 'Expected 1 space after'),
14 => 0,
15 => 'Expected 1 space after "="; 2 found',
16 => 0,
17 => 0,
18 => 0,
19 => 'Expected 1 space before',
20 => 'Expected 1 space after',
21 => array('Expected 1 space before', 'Expected 1 space after'),
22 => 0,
23 => 'Expected 1 space after "+"; 2 found',
24 => 'Expected 1 space before "+"; 2 found',
25 => 0,
26 => 'Expected 1 space before',
27 => 'Expected 1 space after',
28 => array('Expected 1 space before', 'Expected 1 space after'),
29 => 0,
30 => 'Expected 1 space after "-"; 2 found',
31 => 'Expected 1 space before "-"; 2 found',
32 => 0,
33 => 'Expected 1 space before',
34 => 'Expected 1 space after',
35 => array('Expected 1 space before', 'Expected 1 space after'),
36 => 0,
37 => 'Expected 1 space after "*"; 2 found',
38 => 'Expected 1 space before "*"; 2 found',
39 => 0,
40 => 'Expected 1 space before',
41 => 'Expected 1 space after',
42 => array('Expected 1 space before', 'Expected 1 space after'),
43 => 0,
44 => 'Expected 1 space after "/"; 2 found',
45 => 'Expected 1 space before "/"; 2 found',

));
$this->set_warnings(array());

// Let's do all the hard work!
$this->verify_cs_results();
}
}