pattisahusiwa/coding-standard

This package is abandoned and no longer maintained. The author suggests using the asispts/ptscs package instead.

Another PHP Coding Standard for PHP_CodeSniffer

Installs: 677

Dependents: 2

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 0

Open Issues: 2

Type:phpcodesniffer-standard

v0.4 2020-10-05 22:01 UTC

This package is auto-updated.

Last update: 2023-04-28 01:01:59 UTC


README

This repository has been archived. Please use asispts/ptscs instead.

PHP coding standard based on PSR-12

Packagist License Packagist PHP Version Support Packagist Version

Another PHP Coding Standard for PHP_CodeSniffer based on PSR-12 with some exceptions and additions.

Deprecated

Please use asispts/ptscs

Installation

Install with composer

composer require --dev pattisahusiwa/coding-standard

Usage

After installation, create phpcs.xml or phpcs.xml.dist file in the root of your project and add this code,

<?xml version="1.0" encoding="UTF-8"?>
<ruleset>
    <arg name="colors"/>
    <arg name="parallel" value="8"/>
    <arg value="psv"/>
    <arg name="extensions" value="php"/>

  <file>src</file>
  <file>tests</file>

  <exclude-pattern>vendor</exclude-pattern>

  <rule ref="ptscs"/>
</ruleset>

Run phpcs to validate your source code style and phpcbf to fix the violations.

Coding style

Examples of all coding style can be found at /tests/**/_data/*.php.fixed. Here is an example of a class declaration.

<?php declare(strict_types=1);

namespace Ptscs\Tests;

use ParentClass;
use SomeInterface;

final class Classes extends ParentClass implements SomeInterface
{
    use sometrait;

    /**
     * @var object
     */
    private $obj1;

    /**
     * @var object
     */
    private $obj2;

    /**
     * @var string[]
     */
    private $data = [];

    // Example of multiline function arguments
    public function __construct(
        object $obj1,
        object $obj2
    ) {
        $this->obj1 = $obj1;
        $this->obj2 = $obj2;
    }

    public function setData(string $key, string $value): void
    {
        $this->data[$key] = $value;
    }

    public function getData(string $key): string
    {
        if (array_key_exists($key, $this->data) === true) {
            return $this->data[$key];
        }

        return '';
    }
}

License

Released under MIT License. See LICENSE file.