Pljopi / Project-Laravel

Test PHP project, now in Laravel
0 stars 0 forks source link

Stick to a coding standard #6

Open Putr opened 2 years ago

Putr commented 2 years ago

You're all over the place with the coding standard.

Install and configure PHPCS in your project and IDE.

Use this phpcs.xml:

<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PSR2" xsi:noNamespaceSchemaLocation="../../../phpcs.xsd">
    <description>The PSR-2 coding standard.</description>
    <arg name="extensions" value="php,module,inc"/>
    <file>app</file>
    <arg name="tab-width" value="4"/>
    <rule ref="PSR1">
        <exclude name="PSR1.Classes.ClassDeclaration.MissingNamespace"/>
    </rule>
    <rule ref="PSR2">
        <exclude name="Generic.WhiteSpace.DisallowTabIndent"/>
        <exclude name="Generic.Files.LineLength"/>
    </rule>
    <rule ref="Generic.WhiteSpace.DisallowSpaceIndent"/>
    <rule ref="Generic.WhiteSpace.ScopeIndent">
        <properties>
            <property name="indent" value="4"/>
            <property name="tabIndent" value="true"/>
        </properties>
    </rule>

</ruleset>

All configure "editorconfig" in your IDE and add this config file:

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = tab
indent_size = 4
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false
indent_style = space
indent_size = 2

[*.{yml,yaml}]
indent_style = tab
indent_size = 2

Then stick to it.

Putr commented 2 years ago

Read this: https://www.mindtwo.de/guidelines/coding/laravel#follow-laravel-naming-conventions