Skip to content

Commit

Permalink
Merge pull request #139 from stronk7/methods_declaration
Browse files Browse the repository at this point in the history
Apply for standard abstract/final/static positioning
  • Loading branch information
andrewnicols authored Mar 17, 2021
2 parents 4505b2b + 0444e25 commit 86c7a01
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 1 deletion.
1 change: 1 addition & 0 deletions moodle/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<rule ref="Squiz.ControlStructures.LowercaseDeclaration"/>

<rule ref="Squiz.Functions.LowercaseFunctionKeywords"/>
<rule ref="PSR2.Methods.MethodDeclaration"/>

<rule ref="Squiz.PHP.LowercasePHPFunctions"/>
<rule ref="Squiz.PHP.CommentedOutCode">
Expand Down
50 changes: 50 additions & 0 deletions moodle/tests/fixtures/psr2_methods_methoddeclaration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
defined('MOODLE_INTERNAL') || die(); // Make this always the 1st line in all CS fixtures.

// phpcs:disable Squiz.WhiteSpace.ScopeClosingBrace.ContentBefore

// These are ok declarations. https://www.php-fig.org/psr/psr-12/#46-abstract-final-and-static .
abstract class goodclass {
private function private_function() { }
protected function protected_function() { }
public function public_function() { }

private static function private_static_function() { }
protected static function protected_static_function() { }
public static function public_static_function() { }

final private function final_private_function() { }
final protected function final_protected_function() { }
final public function final_public_function() { }

final private static function final_private_static_function() { }
final protected static function final_protected_static_function() { }
final public static function final_public_static_function() { }

abstract protected function abstract_protected_function();
abstract public function abstract_public_function();

abstract protected static function abstract_protected_static_function();
abstract public static function abstract_public_static_function();
}

// These are wrong declarations.
abstract class badclass {
static private function private_static_function() { }
static protected function protected_static_function() { }
static public function public_static_function() { }

private final function final_private_function() { }
protected final function final_protected_function() { }
public final function final_public_function() { }

static private final function final_private_static_function() { }
static protected final function final_protected_static_function() { }
static public final function final_public_static_function() { }

protected abstract function abstract_protected_function();
public abstract function abstract_public_function();

static protected abstract function abstract_protected_static_function();
static public abstract function abstract_public_static_function();
}
31 changes: 31 additions & 0 deletions moodle/tests/moodlestandard_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,37 @@
*/
class moodlestandard_testcase extends local_codechecker_testcase {

public function test_psr2_methods_methoddeclaration() {

// Define the standard, sniff and fixture to use.
$this->set_standard('moodle');
$this->set_sniff('PSR2.Methods.MethodDeclaration');
$this->set_fixture(__DIR__ . '/fixtures/psr2_methods_methoddeclaration.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(
33 => 'The static declaration must come after the visibility',
34 => 1,
35 => 1,
37 => 'The final declaration must precede the visibility',
38 => 1,
39 => 1,
41 => array('FinalAfterVisibility', 'StaticBeforeVisibility'),
42 => 2,
43 => 2,
45 => 'The abstract declaration must precede the visibility',
46 => 1,
48 => array('AbstractAfterVisibility', 'StaticBeforeVisibility'),
49 => 2));
$this->set_warnings(array());

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

public function test_moodle_commenting_inlinecomment() {

// Define the standard, sniff and fixture to use.
Expand Down
2 changes: 1 addition & 1 deletion tests/behat/ui.feature
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Feature: Codechecker UI works as expected
| path | exclude | seen | notseen |
| local/codechecker/moodle/tests | */tests/fixtures/* | Files found: 1 | Invalid path |
| local/codechecker/moodle/tests | */tests/fixtures/* | moodlestandard_test.php | Invalid path |
| local/codechecker/moodle/tests/ | *PHPC*, *moodle_* | Files found: 8 | Invalid path |
| local/codechecker/moodle/tests/ | *PHPC*, *moodle_* | Files found: 9 | Invalid path |
| local/codechecker/moodle/tests/ | *PHPC*, *moodle_* | Line 1 of the opening comment | moodle_php |
| local/codechecker/moodle/tests/ | *PHPC*, *moodle_* | Inline comments must end | /phpcompat |
| local/codechecker/moodle/tests/ | *PHPC*, *moodle_* | Inline comments must end | /phpcompat |
Expand Down

0 comments on commit 86c7a01

Please sign in to comment.