Skip to content

Commit

Permalink
Merge pull request #67 from geerteltink/feat/slevomat7
Browse files Browse the repository at this point in the history
feat: upgrade to slevomat/coding-standard 7 with enhanced PHP 8 support
  • Loading branch information
geerteltink committed May 29, 2021
2 parents 1897419 + 9825280 commit bcf6e07
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 69 deletions.
39 changes: 22 additions & 17 deletions README.md
Expand Up @@ -4,8 +4,8 @@

The coding standard ruleset for Laminas components.

This specification extends and expands [PSR-12](https://github.com/php-fig/fig-standards/blob/master/proposed/extended-coding-style-guide.md),
the extended coding style guide and requires adherence to [PSR-1](https://www.php-fig.org/psr/psr-1),
This specification extends and expands [PSR-12](https://github.com/php-fig/fig-standards/blob/master/proposed/extended-coding-style-guide.md),
the extended coding style guide and requires adherence to [PSR-1](https://www.php-fig.org/psr/psr-1),
the basic coding standard. These are minimal specifications and don't address all factors, including things like:

- whitespace around operators
Expand All @@ -15,16 +15,16 @@ the basic coding standard. These are minimal specifications and don't address al
- what and what not to import, and how
- etc.

Contributors have different coding styles and so do the maintainers. During code reviews there are regularly
discussions about spaces and alignments, where and when was said that a function needs to be imported. And
Contributors have different coding styles and so do the maintainers. During code reviews there are regularly
discussions about spaces and alignments, where and when was said that a function needs to be imported. And
that's where this coding standard comes in: To have internal consistency in a component and between components.

## Installation

1. Install the module via composer by running:

```bash
$ composer require --dev laminas/laminas-coding-standard
composer require --dev laminas/laminas-coding-standard
```

2. Add composer scripts into your `composer.json`:
Expand All @@ -42,21 +42,21 @@ that's where this coding standard comes in: To have internal consistency in a co
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">

<arg name="basepath" value="."/>
<arg name="cache" value=".phpcs-cache"/>
<arg name="colors"/>
<arg name="extensions" value="php"/>
<arg name="parallel" value="80"/>

<!-- Show progress -->
<arg value="p"/>

<!-- Paths to check -->
<file>config</file>
<file>src</file>
<file>test</file>

<!-- Include all rules from the Laminas Coding Standard -->
<rule ref="LaminasCodingStandard"/>
</ruleset>
Expand All @@ -67,16 +67,16 @@ For a reference please see: https://github.com/squizlabs/PHP_CodeSniffer/wiki/An

## Usage

* To run checks only:
- To run checks only:

```bash
$ composer cs-check
composer cs-check
```

* To automatically fix many CS issues:
- To automatically fix many CS issues:

```bash
$ composer cs-fix
composer cs-fix
```

## Ignoring parts of a File
Expand All @@ -85,6 +85,7 @@ For a reference please see: https://github.com/squizlabs/PHP_CodeSniffer/wiki/An
> used. These are deprecated and will be removed in PHP_CodeSniffer version 4.0.
Disable parts of a file:

```php
$xmlPackage = new XMLPackage;
// phpcs:disable
Expand All @@ -94,6 +95,7 @@ $xmlPackage->send();
```

Disable a specific rule:

```php
// phpcs:disable Generic.Commenting.Todo.Found
$xmlPackage = new XMLPackage;
Expand All @@ -104,6 +106,7 @@ $xmlPackage->send();
```

Ignore a specific violation:

```php
$xmlPackage = new XMLPackage;
$xmlPackage['error_code'] = get_default_error_code_value();
Expand All @@ -114,11 +117,12 @@ $xmlPackage->send();

## Development

> **New rules or Sniffs may not be introduced in minor or bugfix releases and should always be based on the develop
> **New rules or Sniffs may not be introduced in minor or bugfix releases and should always be based on the develop
branch and queued for the next major release, unless considered a bugfix for existing rules.**

If you want to test changes against Laminas components or your own projects, install your forked
laminas-coding-standard globally with composer:
If you want to test changes against Laminas components or your own projects, install your forked
laminas-coding-standard globally with composer:

```bash
$ composer global config repositories.laminas-coding-standard vcs git@github.com:<FORK_NAMESPACE>/laminas-coding-standard.git
$ composer global require --dev laminas/laminas-coding-standard:dev-<FORKED_BRANCH>
Expand All @@ -127,9 +131,10 @@ $ composer global require --dev laminas/laminas-coding-standard:dev-<FORKED_BRAN
# Using `-s` prints the rules that triggered the errors so they can be reviewed easily. `-p` is for progress display.
$ phpcs -sp --standard=LaminasCodingStandard src test
```

Make sure you remove the global installation after testing from your global composer.json file!!!

Documentation can be previewed locally by installing [MkDocs](https://www.mkdocs.org/#installation) and run
Documentation can be previewed locally by installing [MkDocs](https://www.mkdocs.org/#installation) and run
`mkdocs serve`. This will start a server where you can read the docs.

## Reference
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Expand Up @@ -9,11 +9,11 @@
"homepage": "https://laminas.dev",
"license": "BSD-3-Clause",
"require": {
"php": "^7.3 || ~8.0.0",
"dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7",
"slevomat/coding-standard": "^6.4.1",
"squizlabs/php_codesniffer": "^3.5.8",
"webimpress/coding-standard": "^1.1.6"
"php": "^7.3 || ^8.0",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7",
"slevomat/coding-standard": "^7.0",
"squizlabs/php_codesniffer": "^3.6",
"webimpress/coding-standard": "^1.2"
},
"config": {
"sort-packages": true
Expand Down
63 changes: 30 additions & 33 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions src/LaminasCodingStandard/ruleset.xml
Expand Up @@ -104,8 +104,13 @@

<!-- The declare(strict_types=1) directive MUST be declared and be the
first statement in a file. -->
<rule ref="WebimpressCodingStandard.Files.DeclareStrictTypes">
<exclude name="WebimpressCodingStandard.Files.DeclareStrictTypes.BelowComment"/>
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
<properties>
<property name="declareOnFirstLine" value="false"/>
<property name="linesCountBeforeDeclare" value="1"/>
<property name="spacesCountAroundEqualsSign" value="0"/>
<property name="linesCountAfterDeclare" value="1"/>
</properties>
</rule>

<!-- 2.3 Lines -->
Expand Down Expand Up @@ -334,8 +339,6 @@
<rule ref="WebimpressCodingStandard.Formatting.StringClassReference"/>
<!-- There MAY NOT be any whitespace around the double colon operator. -->
<rule ref="WebimpressCodingStandard.Formatting.DoubleColon"/>
<!-- All private methods, constants and properties MUST be used. -->
<rule ref="SlevomatCodingStandard.Classes.UnusedPrivateElements"/>

<!-- 4.1 Extends and Implements -->

Expand Down
5 changes: 0 additions & 5 deletions test/fixable/4.ClassesPropertiesAndMethods.php
Expand Up @@ -110,9 +110,4 @@ public function testThereMayNotBeAnyWhitespaceAroundTheDoubleColon(): void
::
createFromFormat('Y-m-d', '2016-01-01');
}

public function testUnusedPrivateMethods(): void
{
// All private methods, constants and properties MUST be used.
}
}
6 changes: 6 additions & 0 deletions test/fixable/9.CommentingAndDocBlocks.php
@@ -1,5 +1,11 @@
<?php

/**
* This is a file level summary.
*
* This is a file level Description.
*/

declare(strict_types=1);

namespace LaminasCodingStandardTest\fixed;
Expand Down
5 changes: 0 additions & 5 deletions test/fixed/4.ClassesPropertiesAndMethods.php
Expand Up @@ -107,9 +107,4 @@ public function testThereMayNotBeAnyWhitespaceAroundTheDoubleColon(): void

DateTime::createFromFormat('Y-m-d', '2016-01-01');
}

public function testUnusedPrivateMethods(): void
{
// All private methods, constants and properties MUST be used.
}
}
6 changes: 6 additions & 0 deletions test/fixed/9.CommentingAndDocBlocks.php
@@ -1,5 +1,11 @@
<?php

/**
* This is a file level summary.
*
* This is a file level Description.
*/

declare(strict_types=1);

namespace LaminasCodingStandardTest\fixed;
Expand Down

0 comments on commit bcf6e07

Please sign in to comment.