Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce formatting #13

Merged
merged 4 commits into from
Dec 4, 2022
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
22 changes: 22 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = false
indent_style = tab
indent_size = 4
trim_trailing_whitespace = true

[composer.json]
indent_style = space
indent_size = 4
trim_trailing_whitespace = true


[*.md]
trim_trailing_whitespace = false

[*.js]
indent_style = tab
indent_size = 4
126 changes: 82 additions & 44 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,92 @@ on:
- '**/*.markdown'

jobs:
tests:
kill_previous:
name: 0️⃣ Kill previous runs
runs-on: ubuntu-latest
# We want to run on external PRs, but not on our own internal PRs as they'll be run by the push to the branch.
if: (github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository)
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.11.0
with:
access_token: ${{ github.token }}

php_syntax_errors:
name: 1️⃣ PHP - Syntax errors
runs-on: ubuntu-latest
needs:
- kill_previous
steps:
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.0

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

- name: Install dependencies
uses: ramsey/composer-install@v2

- name: Check source code for syntax errors
run: vendor/bin/parallel-lint --exclude .git --exclude vendor .

code_style_errors:
name: 2️⃣ PHP - Code Style errors
runs-on: ubuntu-latest
needs:
- php_syntax_errors
steps:
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: latest

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

- name: Install dependencies
uses: ramsey/composer-install@v2

- name: Check source code for code style errors
run: PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --verbose --diff --dry-run

phpstan:
name: 2️⃣ PHP 8.1 - PHPStan
runs-on: ubuntu-latest
needs:
- php_syntax_errors
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
coverage: none
tools: phpstan

- name: Install Composer dependencies
uses: ramsey/composer-install@v2

- name: Run PHPStan
run: vendor/bin/phpstan analyze

tests:
name: 2️⃣ PHP ${{ matrix.php-version }}
needs:
- php_syntax_errors
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-versions: ['8.0', '8.1', '8.2']
php-version:
- 8.0
- 8.1
- 8.2

name: PHP ${{ matrix.php-versions }}

env:
COMPOSER_NO_INTERACTION: 1
extensions: curl, json, libxml, dom
Expand All @@ -32,56 +107,19 @@ jobs:

# Checks out a copy of your repository on the ubuntu machine
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup cache environment
id: extcache
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ matrix.php-versions }}
extensions: ${{ env.extensions }}
key: ${{ env.key }}

- name: Cache PHP Extensions
uses: actions/cache@v2
with:
path: ${{ steps.extcache.outputs.dir }}
key: ${{ steps.extcache.outputs.key }}
restore-keys: ${{ steps.extcache.outputs.key }}

- name: Cache Composer Dependencies
uses: actions/cache@v1
with:
path: ~/.composer/cache/files
key: dependencies-composer-${{ hashFiles('composer.json') }}

- name: Setup PHP Action
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
php-version: ${{ matrix.php-version }}
extensions: ${{ env.extensions }}
coverage: xdebug
tools: pecl, composer

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install Composer dependencies
run: composer install --no-interaction
uses: ramsey/composer-install@v2

- name: Validate files
run: composer validate-files

- name: Run PHPStan
run: composer phpstan

- name: Run tests
run: composer run-tests
45 changes: 45 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

$finder = array_reduce(
[
__DIR__ . '/src/',
__DIR__ . '/tests/',
],
function (PhpCsFixer\Finder $finder, $dir) {
return $finder->in($dir);
},
PhpCsFixer\Finder::create()->ignoreUnreadableDirs()
)->notName('*.blade.php');
$rules = [
'@Symfony' => true,
'align_multiline_comment' => true,
'array_indentation' => true,
'backtick_to_shell_exec' => true,
'increment_style' => ['style' => 'post'],
'indentation_type' => true,
'multiline_comment_opening_closing' => true,
'no_php4_constructor' => true,
'phpdoc_no_empty_return' => false,
'single_blank_line_at_eof' => false,
'yoda_style' => false,
'concat_space' => ['spacing' => 'one'],
'no_superfluous_phpdoc_tags' => false,
'phpdoc_to_comment' => false, // required until https://github.com/phpstan/phpstan/issues/7486 got fixed
'blank_line_between_import_groups' => false, // not PSR-12 compatible, but preserves old behaviour
'ordered_imports' => [
'sort_algorithm' => 'alpha',
'imports_order' => null, // for PSR-12 compatability, this need to be `['class', 'function', 'const']`, but no grouping preserves old behaviour
],
'no_unneeded_control_parentheses' => [
'statements' => ['break', 'clone', 'continue', 'echo_print', 'switch_case', 'yield'],
],
];
$config = new PhpCsFixer\Config();

$config->setRiskyAllowed(true);
$config->setRules($rules);
$config->setIndent("\t");
$config->setLineEnding("\n");
$config->setFinder($finder);

return $config;
41 changes: 24 additions & 17 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,44 +1,50 @@
{
"name": "lychee-org/nestedset",
"description": "Nested Set Model for Laravel 5.7 and up (fork with patches for Lychee)",
"keywords": ["laravel", "nested sets", "nsm", "database", "hierarchy"],
"keywords": [
"laravel",
"nested sets",
"nsm",
"database",
"hierarchy"
],
"license": "MIT",

"authors": [
{
"name": "Alexander Kalnoy",
"email": "lazychaser@gmail.com"
}
],

"repositories": [
{
"type": "vcs",
"url": "https://github.com/LycheeOrg/phpstan-lychee"
}
],

"require": {
"php": "^8.0",
"illuminate/support": "^9.0",
"illuminate/database": "^9.0",
"illuminate/events": "^9.0"
},

"autoload": {
"psr-4": {
"Kalnoy\\Nestedset\\": "src/"
}
},

"require-dev": {
"friendsofphp/php-cs-fixer": "^3.3",
"php-parallel-lint/php-parallel-lint": "^1.2",
"phpunit/phpunit": "^9.5.20",
"lychee-org/phpstan-lychee": "dev-master",
"nunomaduro/larastan": "^2.0",
"orchestra/testbench": "^7.15"
},

"autoload": {
"psr-4": {
"Kalnoy\\Nestedset\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"scripts": {
"run-tests": [
"vendor/bin/phpunit -c phpunit.xml",
Expand All @@ -47,13 +53,16 @@
"validate-files": [
"vendor/bin/parallel-lint --exclude vendor ."
],
"format": [
"rm .php_cs.cache 2> /dev/null || true",
"vendor/bin/php-cs-fixer fix -v --config=.php-cs-fixer.php"
],
"phpstan": [
"vendor/bin/phpstan analyze"
"vendor/bin/phpstan analyze"
]
},
"minimum-stability": "dev",
"prefer-stable": true,

"config": {
"platform": {
"php": "8.0.2"
Expand All @@ -62,16 +71,14 @@
"sort-packages": true,
"optimize-autoloader": true
},

"extra": {
"branch-alias": {
"dev-master": "v5.0.x-dev"
},

"laravel": {
"providers": [
"Kalnoy\\Nestedset\\NestedSetServiceProvider"
]
}
}
}
}
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading