Skip to content
Draft
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ This project adheres to [Semantic Versioning](https://semver.org/).
The format of this change log follows the advice given at [Keep a CHANGELOG](https://keepachangelog.com).

## [Unreleased]
### Changed
- The `moodle600` standard now requires opening braces of functions, methods and classes on a new line (PSR-12):
- Enabled `PSR2.Classes.ClassDeclaration.OpenBraceNewLine`.
- Enabled `Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine`.
- Disabled `Generic.Functions.OpeningFunctionBraceKernighanRitchie`.

## [v3.9.0] - 2026-11-05
### Added
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
<?php

/**
* This fixture tests the use of PSR-12 Opening Function Braces.
*
* We test that the opening braces for functions and methods meet the PSR-12 standard.
* Explicitly include the now-disabled sniff, Generic.Functions.OpeningFunctionBraceKernighanRitchie,
* to ensure that it is no longer applied.
*/
// @sniff Generic.Functions.OpeningFunctionBraceKernighanRitchie
// @sniff PSR2.Classes.ClassDeclaration
// @sniff Squiz.Functions.MultiLineFunctionDeclaration

defined('MOODLE_INTERNAL') || die(); // Make this always the 1st line in all CS fixtures.

// These were wrong in OpeningFunctionBraceKernighanRitchie, now it only fails because it lacks the new line.
// Functions.
// @warning Opening brace should be on a new line
function test01():int{
}

// @warning Opening brace should be on a new line
function test02():?int{
}

// @warning Opening brace should be on a new line
function test03():int {
}

// @warning Opening brace should be on a new line
function test04():?int {
}

// Methods.
// @warning Opening brace of a class must be on the line after the definition
class testbad {
// @warning Opening brace should be on a new line
public function test01():int{
}

// @warning Opening brace should be on a new line
public function test02():?int{
}

// @warning Opening brace should be on a new line
public function test03():int {
}

// @warning Opening brace should be on a new line
public function test04():?int {
}
}

// These were ok in in OpeningFunctionBraceKernighanRitchie, now they are wrong because of the lack of new line.
// All together with and without nullable question mark.
// Functions.
// @warning Opening brace should be on a new line
function test05():int {
}

// @warning Opening brace should be on a new line
function test06():?int {
}

// One space everywhere, with and without nullable question marks.
// @warning Opening brace should be on a new line
function test07() : int {
}

// @warning Opening brace should be on a new line
function test08() : ? int {
}

// Multiple spaces everywhere, with and without nullable question marks.
// @warning Opening brace should be on a new line
function test09() : int {
}

// @warning Opening brace should be on a new line
function test10() : ? int {
}

// @warning Opening brace should be on a new line
function test11() :? int {
}

// @warning Opening brace should be on a new line
function test12() : ?int {
}

// @warning Opening brace should be on a new line
function test13(): ?int {
}

// Methods.
// @warning Opening brace of a class must be on the line after the definition
class test_still_bad {
// All together with and without nullable question mark.
// @warning Opening brace should be on a new line
public function test05():int {
}

// @warning Opening brace should be on a new line
public function test06():?int {
}

// One space everywhere, with and without nullable question marks.
// @warning Opening brace should be on a new line
public function test07() : int {
}

// @warning Opening brace should be on a new line
public function test08() : ? int {
}

// Multiple spaces everywhere, with and without nullable question marks.
// @warning Opening brace should be on a new line
public function test09() : int {
}

// @warning Opening brace should be on a new line
public function test10() : ? int {
}

// @warning Opening brace should be on a new line
public function test11() :? int {
}

// @warning Opening brace should be on a new line
public function test12() : ?int {
}

// @warning Opening brace should be on a new line
public function test13(): ?int {
}
}

function test_good_01()
{
}

function test_good_02(): void
{
}

function test_good_03(
string $param,
): void {
}

class good_class
{
public function test1(): void
{
}

private function test2(
string $string,
): void {
}
}

class good_class_implements implements something
{
}

class good_class_implements_newlines implements
something,
somethingelse
{
}
14 changes: 13 additions & 1 deletion Standards/moodle600/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
<description>Coding Style Standard for Moodle 6.0</description>

<!-- Extend the standard Moodle coding style -->
<rule ref="moodle"/>
<rule ref="moodle">
<exclude name="Generic.Functions.OpeningFunctionBraceKernighanRitchie" />
</rule>

<rule ref="moodle.Deprecations.DeprecatedCFGProperties">
<properties>
Expand All @@ -18,4 +20,14 @@
</property>
</properties>
</rule>

<!-- MDLSITE-8442 moves to Opening Braces on new lines -->
<rule ref="PSR2.Classes.ClassDeclaration.OpenBraceNewLine">
<severity>5</severity>
<type>warning</type>
</rule>
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine">
<severity>5</severity>
<type>warning</type>
</rule>
</ruleset>
Loading