Skip to content

Instantly share code, notes, and snippets.

@dwaard
Last active April 11, 2024 12:25
Show Gist options
  • Save dwaard/d598c0306393c69523673f4298a379d6 to your computer and use it in GitHub Desktop.
Save dwaard/d598c0306393c69523673f4298a379d6 to your computer and use it in GitHub Desktop.
PHP_CodeSniffer ruleset for HZ-HBOICT Laravel projects
<?xml version="1.0"?>
<!--
VERSION: 2.0
PHP_CodeSniffer ruleset tailored for HZ-HBOICT Laravel projects. This file defines
which files to check and what to check in each file. This will provide feedback to
students about their code quality.
This configuration is used in a GitHub action.
==================================
DO NOT CHANGE OR DELETE THIS FILE!
==================================
-->
<ruleset name="PHP_CodeSniffer">
<description>The coding standard for HZ-HBOICT Laravel projects.</description>
<!-- Show progress, show the error codes for each message (source). -->
<arg value="ps" />
<!-- Strip the filepaths in reports down to the relevant bit. -->
<arg name="basepath" value="./" />
<!-- PSR2 is the base style guide. -->
<rule ref="PSR2"/>
<!-- Namespaces and classes MUST follow PSR-0. This means each class is in
a file by itself, and is in a namespace of at least one level: a
top-level vendor name. Migrations are excluded in a Laravel app -->
<rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace">
<exclude-pattern>*/migrations/*</exclude-pattern>
</rule>
<!-- Method names MUST be declared in camelCaps(). Tests are excluded in
Laravel apps. Their names are declared in snake_case(). -->
<rule ref="PSR1.Methods.CamelCapsMethodName">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<!-- This sniff verifies that functions are documented using a docblock.
Laravel allows function docblocks without any annotations, so
this tests only if there is no blank line between a function and its
docblock -->
<rule ref="Squiz.Commenting.FunctionComment.SpacingAfter"/>
<!-- This rule checks for unimplemented, Laravel generated methods in i.e. controllers -->
<!-- <rule ref="Squiz.Commenting.InlineComment.Empty">-->
<!-- <exclude-pattern>app/Providers/*</exclude-pattern>-->
<!-- <exclude-pattern>app/Exceptions/*</exclude-pattern>-->
<!-- <exclude-pattern>app/Http/Middleware/*</exclude-pattern>-->
<!-- </rule>-->
<!-- Checks if the file name and the name of the class contained within the
file match. Migrations are excluded in Laravel apps -->
<rule ref="Squiz.Classes.ClassFileName">
<exclude-pattern>*/migrations/*</exclude-pattern>
</rule>
<!-- Enforce that every class method and other function has a doc block, except for tests -->
<rule ref="Squiz.Commenting.FunctionComment.Missing">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<!-- Checks the separation between functions and methods. In Laravel apps
the separation MUST be a single blank line. For first and last functions
and methods there MUST be no blank line -->
<rule ref="Squiz.WhiteSpace.FunctionSpacing" >
<properties>
<property name="spacing" value="1" />
<property name="spacingBeforeFirst" value="0" />
<property name="spacingAfterLast" value="0" />
</properties>
</rule>
<!-- Ensure there is no whitespace before/after an object operator. Newline
characters before or after an object operator are allowed -->
<rule ref="Squiz.WhiteSpace.ObjectOperatorSpacing">
<properties>
<property name="ignoreNewlines" value="true" />
</properties>
</rule>
<!-- Include the following (Laravel default) folders -->
<file>app</file>
<file>bootstrap</file>
<file>config</file>
<file>database</file>
<file>resources</file>
<file>routes</file>
<file>tests</file>
<!-- The following file patterns should be excluded -->
<exclude-pattern>bootstrap/cache/*</exclude-pattern>
<exclude-pattern>bootstrap/autoload.php</exclude-pattern>
<exclude-pattern>*.blade.php</exclude-pattern>
<exclude-pattern>*.js</exclude-pattern>
<exclude-pattern>*/public/index.php</exclude-pattern>
</ruleset>
@dwaard
Copy link
Author

dwaard commented Apr 11, 2024

Added more frequently made mistakes and improved readability

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment