Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: 2
updates:

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
labels:
- "dependencies"
27 changes: 27 additions & 0 deletions .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: PHP-CS-Fixer

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
php-cs-fixer:
name: PHP-CS-Fixer
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
coverage: none
tools: composer:v2

- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Run PHP-CS-Fixer
run: composer cs-check
27 changes: 27 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: PHPStan

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
phpstan:
name: PHPStan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
coverage: none
tools: composer:v2

- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Run PHPStan
run: composer phpstan
27 changes: 27 additions & 0 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: PHPUnit

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
phpunit:
name: PHPUnit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
coverage: none
tools: composer:v2

- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Run PHPUnit
run: composer test
27 changes: 27 additions & 0 deletions .github/workflows/rector.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Rector

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
rector:
name: Rector
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
coverage: none
tools: composer:v2

- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Run Rector
run: composer rector-dry-run
20 changes: 0 additions & 20 deletions .github/workflows/test.yaml

This file was deleted.

5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ vendor/

.php-cs-fixer.cache
composer.lock
.idea
.phpstan-cache

/vendor/
/.phpunit.cache/
16 changes: 9 additions & 7 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in('src')
;
require_once __DIR__ . '/vendor/autoload.php';

$config = new Valantic\PhpCsFixerConfig\Config();
use Valantic\PhpCsFixerConfig\ConfigFactory;

return $config
->setFinder($finder)
;
return ConfigFactory::createValanticConfig()
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__ . '/src')
->in(__DIR__ . '/tests')
)
->setRiskyAllowed(true);
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 valantic CEC Schweiz AG

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
66 changes: 65 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,65 @@
# php-cs-fixer-config
# PHP-CS-Fixer Config for Valantic Projects

This package provides standard PHP-CS-Fixer configurations used in projects built by Valantic.

## Installation

```bash
composer require --dev valantic/php-cs-fixer-config
```

> **Note:** This package requires PHP 8.1 or higher.

## Usage

Create a `.php-cs-fixer.php` or `.php-cs-fixer.dist.php` file in your project root with one of the following configurations:

### Basic Configuration

```php
<?php

require_once __DIR__ . '/vendor/autoload.php';

use Valantic\PhpCsFixerConfig\ConfigFactory;

return ConfigFactory::createValanticConfig([
'declare_strict_types' => false,
// Add your custom rules here
])
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__ . '/src')
->in(__DIR__ . '/tests')
)
// Enable risky rules (recommended as the ruleset includes risky rules)
->setRiskyAllowed(true)
;
```

## Development

This package provides several Composer scripts to help with development:

```bash
# Run PHP-CS-Fixer in dry-run mode with diff output
composer cs-check

# Run PHP-CS-Fixer to fix code style issues
composer cs-fix

# Run PHPStan for static analysis
composer phpstan

# Run Rector in dry-run mode
composer rector-dry-run

# Run Rector and apply changes
composer rector

# Run PHPUnit tests
composer test

# Run all checks (cs-check, phpstan, rector-dry-run, test)
composer check
```
38 changes: 36 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,46 @@
"description": "Provides a standard php-cs-fixer configuration used in projects built by Valantic.",
"license": "MIT",
"require": {
"php": "^8.0",
"friendsofphp/php-cs-fixer": "^3.16"
"php": "^8.1",
"friendsofphp/php-cs-fixer": "^3.76"
},
"require-dev": {
"phpunit/phpunit": "^12.2.6",
"phpstan/phpstan": "^2.1.17",
"phpstan/phpstan-deprecation-rules": "^2.0.3",
"phpstan/phpstan-strict-rules": "^2.0.4",
"rector/rector": "^2.1",
"roave/security-advisories": "dev-latest",
"phpstan/extension-installer": "^1.4.3"
},
"autoload": {
"psr-4": {
"Valantic\\PhpCsFixerConfig\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Valantic\\PhpCsFixerConfig\\Tests\\": "tests"
}
},
"scripts": {
"cs-check": "php-cs-fixer fix --dry-run --diff",
"cs-fix": "php-cs-fixer fix",
"phpstan": "phpstan analyse",
"test": "phpunit",
"rector": "rector process",
"rector-dry-run": "rector process --dry-run",
"check": [
"@cs-check",
"@phpstan",
"@rector-dry-run",
"@test"
],
"post-update-cmd": "composer bump -D"
},
"config": {
"allow-plugins": {
"phpstan/extension-installer": true
}
}
}
10 changes: 10 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
parameters:
level: 8
paths:
- src
- tests
excludePaths:
- vendor
tmpDir: .phpstan-cache
strictRules:
dynamicCallOnStaticMethod: false
17 changes: 17 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/12.0/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
cacheDirectory=".phpunit.cache">
<testsuites>
<testsuite name="Unit">
<directory>tests/Unit</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>src</directory>
</include>
</source>
</phpunit>
24 changes: 24 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;

return RectorConfig::configure()
->withPaths([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->withPreparedSets(
deadCode: true,
codeQuality: true,
codingStyle: true,
typeDeclarations: true,
privatization: true,
naming: false,
instanceOf: true,
earlyReturn: true,
strictBooleans: true
)
->withPhpSets()
->withAttributesSets(symfony: true, phpunit: true);
Loading