PHPackages                             narrowspark/coding-standard - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. narrowspark/coding-standard

AbandonedArchivedLibrary[Testing &amp; Quality](/categories/testing)

narrowspark/coding-standard
===========================

The Narrowspark Coding Standard is a set of phpstan, psalm, infection, rector and php-cs-fixer rules applied to all Narrowspark projects.

v5.3.2(5y ago)241.4k2[10 PRs](https://github.com/narrowspark/coding-standard/pulls)8MITDockerfilePHP ^8.0

Since Jul 25Pushed 3y ago1 watchersCompare

[ Source](https://github.com/narrowspark/coding-standard)[ Packagist](https://packagist.org/packages/narrowspark/coding-standard)[ Docs](https://github.com/narrowspark/coding-standard)[ GitHub Sponsors](https://github.com/prisis)[ Fund](https://opencollective.com/_prisis_)[ RSS](/packages/narrowspark-coding-standard/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (17)Versions (38)Used By (8)

Narrowspark Coding Standard
---------------------------

[](#narrowspark-coding-standard)

### The Narrowspark Coding Standard for all Narrowspark projects.

[](#the-narrowspark-coding-standard-for-all--narrowspark-projects)

Installation
------------

[](#installation)

```
composer require narrowspark/coding-standard
```

Use
---

[](#use)

### Settings.yml

[](#settingsyml)

Create a configuration file `settings.yml` in `.github`

```
# https://github.com/probot/settings

branches:
  - name: main
    protection:
      enforce_admins: false
      required_pull_request_reviews:
        dismiss_stale_reviews: true
        require_code_owner_reviews: true
        required_approving_review_count: 1
      restrictions:

        # https://developer.github.com/v3/repos/branches/#parameters-1

        # Note: User, app, and team restrictions are only available for organization-owned repositories.
        # Set to null to disable when using this configuration for a repository on a personal account.

        apps: []
        teams: []

labels:
  - name: Added
    description: "Changelog Added"
    color: 90db3f

  - name: Changed
    description: "Changelog Changed"
    color: fbca04

  - name: dependency
    description: "Pull requests that update a dependency file"
    color: e1f788

  - name: Deprecated
    description: "Changelog Deprecated"
    color: 1d76db

  - name: Duplicate
    color: 000000

  - name: Enhancement
    color: d7e102

  - name: Fixed
    description: "Changelog Fixed"
    color: 9ef42e

  - name: Removed
    description: "Changelog Removed"
    color: e99695

  - name: Security
    description: "Changelog Security"
    color: ed3e3b

  - name: "Status: Good first issue"
    color: d7e102

  - name: "Status: Help wanted"
    color: 85d84e

  - name: "Status: Needs Work"
    color: fad8c7

  - name: "Status: Waiting for feedback"
    color: fef2c0

  - name: "Type: BC Break"
    color: b60205

  - name: "Type: Bug"
    color: b60205

  - name: "Type: Critical"
    color: ff8c00

  - name: "Type: RFC"
    color: fbca04

  - name: "Type: Unconfirmed"
    color: 444444

  - name: "Type: Wontfix"
    color: 000000

repository:
  allow_merge_commit: true
  allow_rebase_merge: false
  allow_squash_merge: false
  archived: false
  default_branch: main
  delete_branch_on_merge: true
  # Needs to be added
  description: ""
  has_downloads: true
  has_issues: true
  has_pages: false
  has_projects: false
  has_wiki: false
  # Needs to be added
  name: ""
  private: false

  # https://developer.github.com/v3/repos/branches/#remove-branch-protection
  # Needs to be added
  topics: ""
```

#### PHPstan

[](#phpstan)

Create a configuration file `phpstan.neon` and `phpstan-baseline.neon`.

```
includes:
    - vendor/narrowspark/coding-standard/base_rules.neon
    - vendor/phpstan/phpstan/conf/bleedingEdge.neon
    - %currentWorkingDirectory%/phpstan-baseline.neon

parameters:
    level: max
    inferPrivatePropertyTypeFromConstructor: true

    paths:
        -  %currentWorkingDirectory%/src
        -  %currentWorkingDirectory%/tests

    tmpDir: %currentWorkingDirectory%/.build/phpstan

    excludes_analyse:
        - vendor
```

Follow the links to check, how to configure the rules:

-
-

The Narrowspark PHPstan rules providing configurations for `symplify/phpstan-rules`.

Default configurations:

```
parameters:
    symplify:
        no_chain_method_call:
            allowed_chain_types:
                - Mockery
                - Mockery\MockInterface
                - Mockery\ExpectationInterface
                - Mockery\Expectation
                - Mockery\HigherOrderMessage
        prevent_duplicate_class_method:
            minimum_line_count: 4
        no_short_name:
            min_name_length: 2
        forbidden_complex_func_call:
            forbidden_complex_functions:
                - 'array_filter'
            maximum_stmt_count: 2
        forbidden_node:
            forbidden_nodes:
                - PhpParser\Node\Expr\Empty_
                - PhpParser\Node\Stmt\Switch_
                - PhpParser\Node\Expr\ErrorSuppress
        forbidden_func_call:
            forbidden_functions:
                - 'd'
                - 'dd'
                - 'dump'
                - 'var_dump'
                - 'extract'
                - 'curl_*'
                - 'compact'
                - 'method_exists'
                - 'property_exists'
                - 'spl_autoload_register'
                - 'spl_autoload_unregister'
                - array_walk
        see_annotation_to_test:
            required_see_types:
                - PHPStan\Rules\Rule
        class_name_respects_parent_suffix:
            parent_classes:
                - Symfony\Component\Console\Command\Command
        too_long_variable:
            max_variable_length: 10
```

#### PHP-CS-Fixer

[](#php-cs-fixer)

Create a configuration file `.php_cs` in the root of your project with this content:

```
