-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into forbid-unserialize
- Loading branch information
Showing
50 changed files
with
1,792 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ path: ./ | |
exclude: | ||
- vendor | ||
- moodle/Tests/fixtures | ||
- moodle/Tests/Sniffs/Namespaces/fixtures |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,12 +12,17 @@ | |
{ | ||
"name": "Andrew Lyons", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Eloy Lafuente", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"dealerdirect/phpcodesniffer-composer-installer": "^1.0.0", | ||
"squizlabs/php_codesniffer": "^3.7.2", | ||
"phpcompatibility/php-compatibility": "dev-develop#70e4ca24" | ||
"phpcsstandards/phpcsextra": "^1.1.0", | ||
"phpcompatibility/php-compatibility": "dev-develop#0a17f9ed" | ||
}, | ||
"config": { | ||
"allow-plugins": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?xml version="1.0"?> | ||
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd" | ||
name="moodle-strict" | ||
namespace="MoodleHQ\MoodleCS\MoodleExtra"> | ||
|
||
<description>Best Practices for Moodle development beyond the core Coding Standards</description> | ||
|
||
<!-- Extend the standard Moodle coding style --> | ||
<rule ref="moodle"/> | ||
|
||
<!-- This is an error in moodle-extra. TODO: Remove as part of #58 --> | ||
<rule ref="Generic.Arrays.DisallowLongArraySyntax"> | ||
<type>error</type> | ||
</rule> | ||
|
||
<!-- Include the PSR-12 ruleset with relevant Moodle exclusions --> | ||
<rule ref="PSR12"> | ||
|
||
<!-- Moodle has a header manager and places its copyright on the first line after the opening tag --> | ||
<exclude name="PSR12.Files.FileHeader.SpacingAfterBlock"/> | ||
|
||
<!-- Moodle already defines its own line length, so remove this from the PSR-12 standard --> | ||
<exclude name="Generic.Files.LineLength.TooLong"/> | ||
|
||
<!-- Moodle has its own custom sniff for side effects --> | ||
<exclude name="PSR1.Files.SideEffects.FoundWithSymbols"/> | ||
|
||
<!-- Moodle does not support camel case at all --> | ||
<exclude name="PSR1.Methods.CamelCapsMethodName.NotCamelCaps"/> | ||
|
||
<!-- Moodle contains a lot of code which pre-dates PHP 7.1 and did not support constant visibility --> | ||
<exclude name="PSR12.Properties.ConstantVisibility.NotFound"/> | ||
|
||
<!-- Moodle does not place the opening brace on a new line --> | ||
<exclude name="PSR2.Classes.ClassDeclaration.OpenBraceNewLine"/> | ||
|
||
<!-- Moodle allows use of else if--> | ||
<exclude name="PSR2.ControlStructures.ElseIfDeclaration.NotAllowed"/> | ||
|
||
<!-- Moodle casing rules do not allow camel case at all --> | ||
<exclude name="Squiz.Classes.ValidClassName.NotCamelCaps"/> | ||
|
||
<!-- Moodle casing currently places the brace in the same line --> | ||
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine"/> | ||
</rule> | ||
|
||
<!-- Detect duplicate array keys --> | ||
<rule ref="Universal.Arrays.DuplicateArrayKey"/> | ||
|
||
<!-- Disallow use of list() instead of [] --> | ||
<rule ref="Universal.Lists.DisallowLongListSyntax"/> | ||
|
||
<!-- Enusre that ::class is lower-cased --> | ||
<rule ref="Universal.Constants.LowercaseClassResolutionKeyword"/> | ||
|
||
<!-- Require a consistent modifier keyword order for OO constant declarations --> | ||
<rule ref="Universal.Constants.ModifierKeywordOrder"/> | ||
|
||
<!-- Enforce that the names used in a class/enum "implements" statement or an interface "extends" statement are listed in alphabetic order --> | ||
<rule ref="Universal.OOStructures.AlphabeticExtendsImplements"/> | ||
|
||
<!-- Enforce the use of a single space after the use, function, const keywords and both before and after the as keyword in import use statements --> | ||
<rule ref="Universal.UseStatements.KeywordSpacing"/> | ||
|
||
<!-- Enforce lowercase function/const --> | ||
<rule ref="Universal.UseStatements.LowercaseFunctionConst"/> | ||
|
||
<!-- Detect useless class imports (aliases) --> | ||
<rule ref="Universal.UseStatements.NoUselessAliases"/> | ||
|
||
<!-- Enfore comma, spacing, like, this --> | ||
<rule ref="Universal.WhiteSpace.CommaSpacing"/> | ||
|
||
<!-- | ||
TODO | ||
PER-2.0 support (https://github.com/squizlabs/PHP_CodeSniffer/issues/3793), including: | ||
- Trailing commas in function parameters https://github.com/squizlabs/PHP_CodeSniffer/issues/2030 | ||
- Multi-line implements/extends changes | ||
--> | ||
|
||
<!-- | ||
Detect issues with Unit Test dataProviders: | ||
- private providers | ||
- providers which do not exist | ||
- providers whose name is prefixed with _test | ||
- incorrect casing of dataProvider | ||
- dataProviders which do not return an array or Iterable | ||
- dataProviders which can be converted to a static method (PHPUnit 10 compatibility) | ||
--> | ||
<rule ref="moodle.PHPUnit.TestCaseProvider"> | ||
<properties> | ||
<property name="autofixStaticProviders" value="true"/> | ||
</properties> | ||
</rule> | ||
|
||
</ruleset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Checks that each file contains the standard GPL comment. | ||
* | ||
* @package moodle-cs | ||
* @copyright 2023 Andrew Lyons <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace MoodleHQ\MoodleCS\moodle\Sniffs\Namespaces; | ||
|
||
use PHP_CodeSniffer\Sniffs\Sniff; | ||
use PHP_CodeSniffer\Files\File; | ||
use PHP_CodeSniffer\Util\Tokens; | ||
|
||
// phpcs:disable moodle.NamingConventions | ||
|
||
class NamespaceStatementSniff implements Sniff { | ||
public function register() | ||
{ | ||
return [ | ||
T_NAMESPACE, | ||
]; | ||
} | ||
|
||
public function process(File $file, $stackPtr) | ||
{ | ||
$tokens = $file->getTokens(); | ||
// Format should be: | ||
// - T_NAMESPACE | ||
// - T_WHITESPACE | ||
// - T_STRING | ||
|
||
$checkPtr = $stackPtr + 2; | ||
$token = $tokens[$checkPtr]; | ||
if ($token['code'] === T_NS_SEPARATOR) { | ||
$fqdn = ''; | ||
$stop = $file->findNext(Tokens::$emptyTokens, ($stackPtr + 2)); | ||
for ($i = $stackPtr + 2; $i < $stop; $i++) { | ||
$fqdn .= $tokens[$i]['content']; | ||
} | ||
$fix = $file->addFixableError( | ||
'Namespace should not start with a slash: %s', | ||
$checkPtr, | ||
'LeadingSlash', | ||
[$fqdn] | ||
); | ||
|
||
if ($fix) { | ||
$file->fixer->beginChangeset(); | ||
$file->fixer->replaceToken($checkPtr, ''); | ||
$file->fixer->endChangeset(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.