Skip to content

Commit

Permalink
refactor: Allow usage of php-cs-fixer/shim
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Change of structure. TenantCloudSet is no longer a php-cs-fixer rule set.
  • Loading branch information
oprypkhantc committed Aug 8, 2022
1 parent f8c58fc commit b7d3528
Show file tree
Hide file tree
Showing 19 changed files with 135 additions and 2,336 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Release

on:
workflow_run:
workflows: ["Tests"]
types:
- completed
branches:
- master
- next
- next-major
- beta
- alpha

jobs:
release:
name: Release
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Create a release
uses: cycjimmy/semantic-release-action@v2
with:
extra_plugins: |
@semantic-release/changelog
@semantic-release/git
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
17 changes: 0 additions & 17 deletions .github/workflows/tagger.yml

This file was deleted.

68 changes: 41 additions & 27 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,15 @@ on:
pull_request:

jobs:
test:
name: Tests & PHPStan on PHP ${{ matrix.php }} with php-cs-fixer ${{ matrix.cs-fixer }}
phpunit:
name: PHPUnit on PHP v${{ matrix.php }}

runs-on: ubuntu-latest

strategy:
fail-fast: true
matrix:
php: [7.4.9, 8.0, 8.1]
# Make sure we're testing with the lowest supported cs-fixer too because we're currently using @internal marked classes and those can break any time.
cs-fixer: [^2.16.8, 3.4.0]
exclude:
- php: 8.0
cs-fixer: 2.16.8
php: [8.1]

steps:
- name: Checkout code
Expand All @@ -28,7 +23,6 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip
tools: composer:v2
coverage: none

Expand All @@ -45,38 +39,58 @@ jobs:
${{ runner.os }}-php-
- name: Install dependencies
run: |
composer require "friendsofphp/php-cs-fixer=${{ matrix.cs-fixer }}" --no-update
composer install --prefer-dist --no-progress
run: composer install --prefer-dist --no-progress

- name: Execute tests
- name: Execute phpunit
run: composer test -- --colors=always

# Those should usually be a separate job, but as GitHub Actions currently does not support any form of sharing
# steps or an image between them, extracting those to a separate job would mean a full blown copy-paste of this one.
- name: Install dependencies
run: composer install --prefer-dist --no-progress --working-dir=tools/phpstan
php-cs-fixer:
name: php-cs-fixer
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Run phpstan
run: composer phpstan
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
extensions: dom, curl, libxml, mbstring, zip
tools: composer:v2
coverage: none

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
code-style:
name: Code style
- name: Install dependencies
run: composer install --prefer-dist --no-progress

runs-on: ubuntu-latest
- name: Execute php-cs-fixer
run: composer cs-fix -- --dry-run --diff --using-cache=no

phpstan:
name: PHPStan
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
extensions: dom, curl, libxml, mbstring, zip
php-version: 8.1
tools: composer:v2
coverage: none

- name: Validate composer.json and composer.lock
run: composer validate

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
Expand All @@ -87,7 +101,7 @@ jobs:
${{ runner.os }}-php-
- name: Install dependencies
run: composer install --prefer-dist --no-progress --working-dir=tools/php-cs-fixer
run: composer install --prefer-dist --no-progress

- name: Run php-cs-fixer
run: composer cs-fix -- --dry-run --diff --using-cache=no
- name: Execute phpstan
run: composer phpstan
13 changes: 10 additions & 3 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
<?php

$finder = PhpCsFixer\Finder::create()
//require __DIR__ . '/vendor/tenantcloud/php-cs-fixer-rule-sets/PhpdocSingleLineVarFixer.php';
require __DIR__ . '/src/TenantCloud/PhpCsFixer/RuleSet/TenantCloudSet.php';

use PhpCsFixer\Config;
use PhpCsFixer\Finder;
use TenantCloud\PhpCsFixer\RuleSet\TenantCloudSet;

$finder = Finder::create()
->in('src')
->in('tests')
->name('*.php')
->notName('_*.php')
->ignoreVCS(true);

return (new PhpCsFixer\Config())
return (new Config())
->setFinder($finder)
->setRiskyAllowed(true)
->setIndent("\t")
->setRules([
'@TenantCloud' => true,
...(new TenantCloudSet())->rules(),
]);
6 changes: 6 additions & 0 deletions .releaserc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
plugins:
- '@semantic-release/commit-analyzer'
- '@semantic-release/release-notes-generator'
- '@semantic-release/changelog'
- '@semantic-release/git'
- '@semantic-release/github'
13 changes: 13 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Commands

Install dependencies:
`docker run -it --rm -v $PWD:/app -w /app composer install`

Run tests:
`docker run -it --rm -v $PWD:/app -w /app php:8.1-cli vendor/bin/pest`

Run php-cs-fixer on self:
`docker run -it --rm -v $PWD:/app -w /app composer cs-fix`

Run phpstan on self:
`docker run -it --rm -v $PWD:/app -w /app composer phpstan`
26 changes: 15 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,25 @@ Install the package:

Then use the rule sets in php-cs-fixer's config:
```php
return (new PhpCsFixer\Config())
require __DIR__ . '/vendor/tenantcloud/php-cs-fixer-rule-sets/src/TenantCloud/PhpCsFixer/RuleSet/TenantCloudSet.php';

use PhpCsFixer\Config;
use PhpCsFixer\Finder;
use TenantCloud\PhpCsFixer\RuleSet\TenantCloudSet;

$finder = Finder::create()
->in('src')
->in('tests')
->name('*.php')
->notName('_*.php')
->ignoreVCS(true);

return (new Config())
->setFinder($finder)
->setRiskyAllowed(true)
->setIndent("\t")
->setRules([
'@TenantCloud' => true,
...(new TenantCloudSet())->rules(),
]);
```

## Commands
Install dependencies:
`docker run -it --rm -v $PWD:/app -w /app composer install`

Run tests:
`docker run -it --rm -v $PWD:/app -w /app php:7.4-cli vendor/bin/pest`

Run php-cs-fixer on self:
`docker run -it --rm -v $PWD:/app -w /app composer cs-fix`
17 changes: 8 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "tenantcloud/php-cs-fixer-rule-sets",
"description": "TenantCloud's php-cs-fixer rule set",
"minimum-stability": "stable",
"license": "MIT",
"authors": [
{
Expand All @@ -11,18 +10,16 @@
],
"require": {
"php": ">=7.4.9",
"friendsofphp/php-cs-fixer": "^3.4"
"php-cs-fixer/shim": "~3.8.0"
},
"require-dev": {
"pestphp/pest": "^1.0"
"pestphp/pest": "^1.0",
"phpstan/phpstan": "~1.7.0"
},
"autoload": {
"psr-0": {
"": "src/"
},
"files": [
"src/TenantCloud/PhpCsFixer/RuleSet/add.php"
]
}
},
"autoload-dev": {
"psr-4": {
Expand All @@ -31,9 +28,11 @@
},
"scripts": {
"test": "./vendor/bin/pest",
"cs-fix": "./tools/php-cs-fixer/vendor/bin/php-cs-fixer fix -v --show-progress=dots",
"phpstan": "./tools/phpstan/vendor/bin/phpstan analyse"
"cs-fix": "./vendor/bin/php-cs-fixer fix -v --show-progress=dots",
"phpstan": "./vendor/bin/phpstan analyse"
},
"minimum-stability": "stable",
"prefer-stable": true,
"config": {
"allow-plugins": {
"pestphp/pest-plugin": true
Expand Down
6 changes: 2 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
includes:
- tools/phpstan/vendor/phpstan/phpstan/conf/bleedingEdge.neon
- vendor/phpstan/phpstan/conf/bleedingEdge.neon

parameters:
level: 8
level: max
tmpDir: ./tmp/phpstan

paths:
Expand All @@ -12,5 +12,3 @@ parameters:
ignoreErrors:
# There's no extension for that :(
- '#Call to an undefined method Pest\\Expectation|Pest\\Support\\Extendable::#i'
# php-cs-fixer must specify a return type (or, rather, remake the way rule configuration is implemented)
- '#Method TenantCloud\\PhpCsFixer\\RuleSet\\TenantCloudSet::getRules\(\) return type has no value type specified in iterable type array\.#i'
40 changes: 3 additions & 37 deletions src/TenantCloud/PhpCsFixer/RuleSet/TenantCloudSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace TenantCloud\PhpCsFixer\RuleSet;

use PhpCsFixer\RuleSet\RuleSetDescriptionInterface;

/**
* Rule set of all TenantCloud's projects.
*
Expand All @@ -12,44 +10,12 @@
* - the least amount of merges (ordered imports etc)
* - PSR practices
*/
class TenantCloudSet implements RuleSetDescriptionInterface
class TenantCloudSet
{
/**
* Why the hell does PHP allow you to put this into an interface? ....
*/
public function __construct()
{
}

/**
* @inheritDoc
*/
public function getName(): string
{
return '@TenantCloud';
}

/**
* @inheritDoc
*/
public function getDescription(): string
{
return 'TenantCloud\'s default rule set';
}

/**
* @inheritDoc
*/
public function isRisky(): bool
{
// Includes risky sets, hence is risky.
return true;
}

/**
* @inheritDoc
* @return array<string, boolean|array<string, mixed>>
*/
public function getRules(): array
public function rules(): array
{
return [
'@PhpCsFixer' => true,
Expand Down
19 changes: 0 additions & 19 deletions src/TenantCloud/PhpCsFixer/RuleSet/add.php

This file was deleted.

Loading

0 comments on commit b7d3528

Please sign in to comment.