Giter Site home page Giter Site logo

narrowspark / php-cs-fixer-config Goto Github PK

View Code? Open in Web Editor NEW
5.0 3.0 3.0 966 KB

:notebook: Provides a configuration for fabpot/php-cs-fixer, used within Narrowspark.

License: MIT License

PHP 95.70% Dockerfile 2.70% JavaScript 1.60%
php-cs-fixer narrowspark php configuration

php-cs-fixer-config's Introduction

Narrowspark php-cs-fixer Config

This repository provides a configuration for https://github.com/FriendsOfPHP/PHP-CS-Fixer, which we use to verify and enforce a single coding standard for PHP code within Narrowspark and Anolilab.

Installation

Via Composer

$ composer require narrowspark/php-cs-fixer-config

Usage

Create a configuration file .php_cs in the root of your project:

<?php
declare(strict_types=1);
use Narrowspark\CS\Config\Config;

$config = new Config();
$config->getFinder()
    ->files()
    ->in(__DIR__)
    ->exclude('.build')
    ->exclude('vendor')
    ->name('*.php')
    ->ignoreDotFiles(true)
    ->ignoreVCS(true);

$config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/php_cs.cache');

return $config;

Git

All configuration examples use the caching feature, and if you want to use it as well, you add the cache directory to .gitignore:

+ /.build/
 /vendor/

πŸ’‘ personally, I prefer to use a .build directory for storing build artifacts.

Configuration with header

πŸ’‘ optionally specify a header:

<?php
declare(strict_types=1);

use Narrowspark\CS\Config\Config;

+$header = <<<EOF
+Copyright (c) 2020 Narrowspark
+
+For the full copyright and license information, please view
+the LICENSE file that was distributed with this source code.
+EOF;

-$config = new Narrowspark\CS\Config\Config();
+$config = new Narrowspark\CS\Config\Config($header);

$config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/php_cs.cache');

return $config;

This will turn on and configure the HeaderCommentFixer, so that file headers will be added to PHP files, for example:

Configuration with override rules

πŸ’‘ optionally override rules from a rule set by passing in an array of rules to be merged in:

<?php
declare(strict_types=1);

use Narrowspark\CS\Config\Config;

- $config = new Config();
+ $config = new Config(null /* if you dont need a header */, [
    'mb_str_functions' => false,
    'strict_comparison' => false,
]);

$config->getFinder()
    ->files()
    ->in(__DIR__)
    ->exclude('.build')
    ->exclude('vendor')
    ->name('*.php')
    ->ignoreDotFiles(true)
    ->ignoreVCS(true);

$config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/php_cs.cache');

return $config;

Composer

If you like composer scripts, add a coding-standards script to composer.json:

 {
   "name": "foo/bar",
   "require": {
     "php": "^7.3",
   },
   "require-dev": {
     "narrowspark/php-cs-fixer-config": "~1.0.0"
+  },
+  "scripts": {
+    "cs:check": [
+      "mkdir -p .build/php-cs-fixer",
+      "php-cs-fixer fix --diff --diff-format=udiff --verbose"
+    ]
   }
 }

Run

$ composer cs:check

To automatically fix coding standard violations.

Travis

If you like Travis CI, add a coding-standards stage to your jobs:

 language: php

 cache:
   directories:
     - $HOME/.composer/cache
+    - .build/php-cs-fixer

 jobs:
   include:
+    - stage: "Coding Standards"
+
+      php: 7.3
+
+      install:
+        - composer install --no-interaction --no-progress --no-suggest
+
+      before_script:
+        - mkdir -p .build/php-cs-fixer
+
+      script:
+        - vendor/bin/php-cs-fixer fix --config=.php_cs --diff --dry-run --verbose

GitHub Actions

If you like GitHub Actions, add a coding-standards job to your workflow:

 on:
   pull_request:
   push:
     branches:
       - master
     tags:
       - "**"

 name: "Continuous Integration"

 jobs:
+  coding-standards:
+    name: "Coding Standards"
+
+    runs-on: ubuntu-latest
+
+    steps:
+      - name: "Checkout"
+        uses: actions/[email protected]
+
+      - name: "Disable Xdebug"
+        run: php7.3 --ini | grep xdebug | sed 's/,$//' | xargs sudo rm
+
+      - name: "Cache dependencies installed with composer"
+        uses: actions/[email protected]
+        with:
+          path: ~/.composer/cache
+          key: php7.3-composer-locked-${{ hashFiles('**/composer.lock') }}
+          restore-keys: |
+            php7.3-composer-locked-
+
+      - name: "Install locked dependencies with composer"
+        run: php7.3 $(which composer) install --no-interaction --no-progress --no-suggest
+
+      - name: "Create cache directory for friendsofphp/php-cs-fixer"
+        run: mkdir -p .build/php-cs-fixer
+
+      - name: "Cache cache directory for friendsofphp/php-cs-fixer"
+        uses: actions/[email protected]
+        with:
+          path: ~/.build/php-cs-fixer
+          key: php7.3-php-cs-fixer-${{ hashFiles('**/composer.lock') }}
+          restore-keys: |
+            php7.3-php-cs-fixer-
+
+      - name: "Run friendsofphp/php-cs-fixer"
+        run: php7.3 vendor/bin/php-cs-fixer fix --config=.php_cs --diff --diff-format=udiff --dry-run --verbose

Testing

$ vendor/bin/phpunit

Contributing

If you would like to help take a look at the list of issues and check our Contributing guild.

Note: please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

Credits

License

The Narrowspark http-emitter is open-sourced software licensed under the MIT license

php-cs-fixer-config's People

Contributors

dependabot-preview[bot] avatar prisis avatar renovate-bot avatar semantic-release-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

php-cs-fixer-config's Issues

Dependabot couldn't parse the config file at .dependabot/config.yml

Dependabot couldn't parse the config file at .dependabot/config.yml. The error raised was:

(<unknown>): did not find expected '-' indicator while parsing a block collection at line 20 column 7

Please ensure the config file is a valid YAML file. An online YAML linter is available here.

Your .dependabot/config.yml contained invalid details

Dependabot encountered the following error when parsing your .dependabot/config.yml:

Automerging is not enabled for this account. You can enable it from the [account settings](https://app.dependabot.com/accounts/narrowspark/settings) screen in your Dependabot dashboard.

Please update the config file to conform with Dependabot's specification using our docs and online validator.

Dependabot can't resolve your PHP dependency files

Dependabot can't resolve your PHP dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Your requirements could not be resolved to an installable set of packages.
  Problem 1
    - Root composer.json requires wikimedia/composer-merge-plugin ^1.4.1 -> satisfiable by wikimedia/composer-merge-plugin[v1.4.1].
    - wikimedia/composer-merge-plugin v1.4.1 requires composer-plugin-api ^1.0 -> found composer-plugin-api[2.0.0] but it does not match the constraint.

You are using Composer 2, which some of your plugins seem to be incompatible with. Make sure you update your plugins or report a plugin-issue to ask them to support Composer 2.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • chore(deps): update actions/stale action to v5
  • chore(deps): update actions/stale action to v6
  • chore(deps): update actions/upload-artifact action to v3
  • chore(deps): update codecov/codecov-action action to v2
  • chore(deps): update codecov/codecov-action action to v3
  • chore(deps): update dependency slam/phpstan-extensions to v6
  • chore(deps): update dependency symplify/phpstan-rules to v10
  • chore(deps): update dependency symplify/phpstan-rules to v11
  • chore(deps): update devdependencies (major) to v1 (major) (phpstan/phpstan, phpstan/phpstan-deprecation-rules, phpstan/phpstan-mockery, phpstan/phpstan-phpunit, phpstan/phpstan-strict-rules, thecodingmachine/phpstan-strict-rules)
  • chore(deps): update node.js to v16
  • chore(deps): update node.js to v18
  • deps(deps): update dependency ergebnis/license to v2
  • fix(deps): update dependency @anolilab/textlint-config to v3
  • fix(deps): update dependency @anolilab/textlint-config to v4
  • πŸ” Create all rate-limited PRs at once πŸ”

Edited/Blocked

These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

composer
composer.json
  • php ^8.0
  • ergebnis/license ~1.1.0
  • friendsofphp/php-cs-fixer ~2.18.2
  • kubawerlos/php-cs-fixer-custom-fixers ~2.4.1
  • pedrotroller/php-cs-custom-fixer ~2.24.0
  • infection/infection ^0.21.3
  • phpstan/phpstan ^0.12.80
  • phpstan/phpstan-deprecation-rules ^0.12.6
  • phpstan/phpstan-mockery ^0.12.12
  • phpstan/phpstan-phpunit ^0.12.17
  • phpstan/phpstan-strict-rules ^0.12.9
  • phpunit/phpunit ^9.5.2
  • psalm/plugin-phpunit ^0.15.1
  • rector/rector ^0.10.6
  • rector/rector-phpunit ^0.10.6
  • slam/phpstan-extensions ^5.1.0
  • symplify/phpstan-rules ^9.2
  • thecodingmachine/phpstan-strict-rules ^0.12.1
  • vimeo/psalm ^4.6.2
docker-compose
.github/workflows/composer-normalize.yml
docker-compose.yml
dockerfile
.docker/php/Dockerfile
github-actions
.github/workflows/coding-standard.yml
  • actions/checkout v2
  • shivammathur/cache-extensions v1
  • actions/cache v2
  • shivammathur/setup-php v2
  • ramsey/composer-install v1
.github/workflows/composer-normalize.yml
  • actions/checkout v2
  • stefanzweifel/git-auto-commit-action v4.0.0
.github/workflows/continuous-integration.yml
  • actions/checkout v2
  • shivammathur/cache-extensions v1
  • actions/cache v2
  • shivammathur/setup-php v2
  • ramsey/composer-install v1
  • actions/upload-artifact v2
  • actions/checkout v2
  • shivammathur/cache-extensions v1
  • actions/cache v2
  • shivammathur/setup-php v2
  • ramsey/composer-install v1
  • actions/upload-artifact v2
  • actions/checkout v2
  • actions/download-artifact v2
  • codecov/codecov-action v1
.github/workflows/greetings.yml
  • actions/first-interaction v1
.github/workflows/license-update.yml
  • actions/checkout v2
  • shivammathur/cache-extensions v1
  • actions/cache v2
  • shivammathur/setup-php v2
  • ramsey/composer-install v1
  • stefanzweifel/git-auto-commit-action v4.9.1
.github/workflows/markdown-lint.yml
  • actions/checkout v2
  • actions/setup-node v2
  • actions/cache v2
.github/workflows/mutation.yml
  • actions/checkout v2
  • shivammathur/cache-extensions v1
  • actions/cache v2
  • shivammathur/setup-php v2
  • ramsey/composer-install v1
.github/workflows/rector-ci.yml
  • actions/checkout v2
  • shivammathur/cache-extensions v1
  • actions/cache v2
  • shivammathur/setup-php v2
  • ramsey/composer-install v1
.github/workflows/semantic-release.yml
  • actions/checkout v2
  • shivammathur/cache-extensions v1
  • actions/cache v2
  • shivammathur/setup-php v2
  • ramsey/composer-install v1
  • actions/checkout v2
  • cycjimmy/semantic-release-action v2
.github/workflows/stale-issues.yml
  • actions/stale v3
  • actions/stale v3
  • actions/stale v3
  • actions/stale v3
.github/workflows/static-analyze.yml
  • actions/checkout v2
  • shivammathur/cache-extensions v1
  • actions/cache v2
  • shivammathur/setup-php v2
  • ramsey/composer-install v1
  • actions/checkout v2
  • shivammathur/cache-extensions v1
  • actions/cache v2
  • shivammathur/setup-php v2
  • ramsey/composer-install v1
.github/workflows/template-sync.yml
  • actions/checkout v2
  • narrowspark/template-sync-action v1.0.0-alpha.9
.github/workflows/yaml-lint.yml
  • actions/checkout v2
  • ibiqlik/action-yamllint v3
npm
package.json
  • @anolilab/textlint-config ^2.0.0
nvm
.nvmrc
  • node 14.16.1

  • Check this box to trigger a request for Renovate to run again on this repository

Dependabot can't resolve your PHP dependency files

Dependabot can't resolve your PHP dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Your requirements could not be resolved to an installable set of packages.
  Problem 1
    - wikimedia/composer-merge-plugin dev-master requires composer-plugin-api ^1.1 -> found composer-plugin-api[2.0.0] but it does not match the constraint.
    - wikimedia/composer-merge-plugin v1.4.1 requires composer-plugin-api ^1.0 -> found composer-plugin-api[2.0.0] but it does not match the constraint.
    - wikimedia/composer-merge-plugin 1.5.x-dev is an alias of wikimedia/composer-merge-plugin dev-master and thus requires it to be installed too.
    - Root composer.json requires wikimedia/composer-merge-plugin ^1.4.1 -> satisfiable by wikimedia/composer-merge-plugin[v1.4.1, 1.5.x-dev (alias of dev-master)].

You are using Composer 2, which some of your plugins seem to be incompatible with. Make sure you update your plugins or report a plugin-issue to ask them to support Composer 2.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.