Skip to content

Commit

Permalink
Merge pull request #1 from good-php/customization-for-class-properties
Browse files Browse the repository at this point in the history
feat: Customization for class properties
  • Loading branch information
autaut03 authored Nov 3, 2023
2 parents a813023 + 9c8834e commit 8a00d36
Show file tree
Hide file tree
Showing 99 changed files with 2,104 additions and 1,465 deletions.
14 changes: 14 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/.github export-ignore
/art export-ignore
/docs export-ignore
/tests export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.php-cs-fixer.dist.php export-ignore
/.releaserc.yml export-ignore
/CONTRIBUTING.md export-ignore
/phpstan.neon export-ignore
/phpunit.xml export-ignore
/README.md export-ignore
/UPGRADING.md export-ignore
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ jobs:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Create a release
uses: cycjimmy/semantic-release-action@v2
uses: cycjimmy/semantic-release-action@v3
with:
extra_plugins: |
@semantic-release/changelog
Expand Down
31 changes: 17 additions & 14 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
name: Tests

on:
push:
pull_request:
on: [push, pull_request]

jobs:
phpunit:
name: PHPUnit on PHP v${{ matrix.php }}

runs-on: ubuntu-latest

strategy:
fail-fast: true
matrix:
php: [8.1]
php: [ 8.1, 8.2 ]

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -31,12 +27,13 @@ jobs:

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

Expand All @@ -48,7 +45,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -60,29 +57,34 @@ jobs:

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

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

phpstan:
name: PHPStan
name: PHPStan on PHP v${{ matrix.php }}
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
php: [ 8.1, 8.2 ]
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
php-version: ${{ matrix.php }}
tools: composer:v2
coverage: none

Expand All @@ -91,12 +93,13 @@ jobs:

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

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@

# Build/coverage
/build
/coverage

# Cache
.php-cs-fixer.cache
.phpunit.cache
**/.phpunit.result.cache

# Temporary
Expand Down
130 changes: 12 additions & 118 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,124 +1,18 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in('src')
->in('tests')
require __DIR__ . '/vendor/kubawerlos/php-cs-fixer-custom-fixers/bootstrap.php';
require __DIR__ . '/vendor/tenantcloud/php-cs-fixer-rule-sets/bootstrap.php';

use PhpCsFixer\Finder;
use TenantCloud\PhpCsFixer\Config;

$finder = Finder::create()
->in(__DIR__)
->exclude('build')
->exclude('tmp')
->exclude('vendor')
->name('*.php')
->notName('_*.php')
->ignoreVCS(true);

return (new PhpCsFixer\Config())
->setFinder($finder)
->setRiskyAllowed(true)
->setIndent("\t")
->setRules([
'@PhpCsFixer' => true,
'@Symfony' => true,
'@Symfony:risky' => true,
'@PSR12' => true,
'@PSR12:risky' => true,
'assign_null_coalescing_to_coalesce_equal' => true,
'modernize_strpos' => true,
'empty_loop_condition' => true,
'declare_parentheses' => true,
'array_syntax' => ['syntax' => 'short'],
'binary_operator_spaces' => [
'default' => 'single_space',
'operators' => [
'=>' => 'align_single_space_minimal',
],
],
'blank_line_before_statement' => [
'statements' => [
'break', 'continue', 'declare', 'default', 'do', 'while', 'for',
'foreach', 'goto', 'if', 'return', 'switch', 'throw', 'try', 'yield',
],
],
'braces' => [
'position_after_control_structures' => 'same',
'allow_single_line_anonymous_class_with_empty_body' => true,
],
'class_attributes_separation' => [
'elements' => ['method' => 'one', 'property' => 'one'],
],
'concat_space' => [
'spacing' => 'one',
],
'increment_style' => [
'style' => 'post',
],
'linebreak_after_opening_tag' => true,
'native_function_invocation' => false,
'ordered_class_elements' => [
'order' => [
'use_trait',
'constant_public', 'constant_protected', 'constant_private',
'property_static', 'property_public_static', 'property_protected_static', 'property_private_static',
'property_public', 'property_protected', 'property_private',
'construct', 'destruct', 'magic', 'phpunit',
'method_static', 'method_public_static', 'method_protected_static', 'method_private_static',
'method_public', 'method_protected', 'method_private',
],
],
'ordered_imports' => true,
'phpdoc_no_empty_return' => false,
'phpdoc_summary' => false,
'ternary_to_null_coalescing' => true,
'visibility_required' => [
'elements' => [
'const', 'property', 'method',
],
],
'yoda_style' => ['always_move_variable' => true, 'equal' => false, 'identical' => false],
'php_unit_test_class_requires_covers' => false,
'php_unit_internal_class' => false,
'protected_to_private' => false,
// Adds stupid semicolons on newlines
'multiline_whitespace_before_semicolons' => false,
// Doesn't work with "nested" chaining
'method_chaining_indentation' => true,
'mb_str_functions' => true,
'global_namespace_import' => true,
'list_syntax' => [
'syntax' => 'short',
],
'phpdoc_line_span' => [
'const' => 'single',
'property' => 'single',
],
'general_phpdoc_annotation_remove' => [
// We don't believe so called "checked exceptions" are a good design. We're following the logic of Kotlin:
// https://kotlinlang.org/docs/reference/exceptions.html#checked-exceptions
'annotations' => ['throws'],
],
'error_suppression' => [
// Mutes trigger_error() with E_USER_DEPRECATED, but we handle deprecations manually so this is needed.
'mute_deprecation_error' => false,
],
'operator_linebreak' => [
'only_booleans' => true,
'position' => 'end',
],
'native_constant_invocation' => false,
'simplified_if_return' => true,
'heredoc_indentation' => true,
'use_arrow_functions' => true,
'no_trailing_whitespace_in_string' => false,
'phpdoc_no_alias_tag' => [
// Default except property-read and property-write replacement
'replacements' => ['type' => 'var', 'link' => 'see'],
],
// Force {@inheritDoc} to @inheritDoc whenever possible.
'phpdoc_tag_type' => [
'tags' => [
'inheritDoc' => 'annotation',
],
],
// Rename lower case & plural form @inheritDoc
'general_phpdoc_tag_rename' => [
'replacements' => [
'inheritDocs' => 'inheritDoc',
'inheritdoc' => 'inheritDoc',
],
],
]);
return Config::make()->setFinder($finder);
7 changes: 7 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Commands

Here are some of the commands that you'll need:
- install dependencies: `docker run -it --rm -v $PWD:/app -w /app chialab/php-dev:8.2 composer install`
- run tests with phpunit: `docker run -it --rm -v $PWD:/app -w /app chialab/php-dev:8.2 composer test`
- reformat using php-cs-fixer: `docker run -it --rm -v $PWD:/app -w /app chialab/php-dev:8.2 composer cs-fix`
- analyse with phpstan: `docker run -it --rm -v $PWD:/app -w /app chialab/php-dev:8.2 composer phpstan`
Loading

0 comments on commit 8a00d36

Please sign in to comment.