Skip to content

Commit dd45e10

Browse files
authored
Enforce formatting (#13)
1 parent 5324ba5 commit dd45e10

20 files changed

+3949
-3818
lines changed

.editorconfig

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = false
7+
indent_style = tab
8+
indent_size = 4
9+
trim_trailing_whitespace = true
10+
11+
[composer.json]
12+
indent_style = space
13+
indent_size = 4
14+
trim_trailing_whitespace = true
15+
16+
17+
[*.md]
18+
trim_trailing_whitespace = false
19+
20+
[*.js]
21+
indent_style = tab
22+
indent_size = 4

.github/workflows/CI.yaml

+82-44
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,92 @@ on:
1212
- '**/*.markdown'
1313

1414
jobs:
15-
tests:
15+
kill_previous:
16+
name: 0️⃣ Kill previous runs
1617
runs-on: ubuntu-latest
18+
# 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.
1719
if: (github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository)
20+
steps:
21+
- name: Cancel Previous Runs
22+
uses: styfle/[email protected]
23+
with:
24+
access_token: ${{ github.token }}
25+
26+
php_syntax_errors:
27+
name: 1️⃣ PHP - Syntax errors
28+
runs-on: ubuntu-latest
29+
needs:
30+
- kill_previous
31+
steps:
32+
- name: Set up PHP
33+
uses: shivammathur/setup-php@v2
34+
with:
35+
php-version: 8.0
36+
37+
- name: Checkout code
38+
uses: actions/checkout@v3
39+
40+
- name: Install dependencies
41+
uses: ramsey/composer-install@v2
42+
43+
- name: Check source code for syntax errors
44+
run: vendor/bin/parallel-lint --exclude .git --exclude vendor .
1845

46+
code_style_errors:
47+
name: 2️⃣ PHP - Code Style errors
48+
runs-on: ubuntu-latest
49+
needs:
50+
- php_syntax_errors
51+
steps:
52+
- name: Set up PHP
53+
uses: shivammathur/setup-php@v2
54+
with:
55+
php-version: latest
56+
57+
- name: Checkout code
58+
uses: actions/checkout@v3
59+
60+
- name: Install dependencies
61+
uses: ramsey/composer-install@v2
62+
63+
- name: Check source code for code style errors
64+
run: PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --verbose --diff --dry-run
65+
66+
phpstan:
67+
name: 2️⃣ PHP 8.1 - PHPStan
68+
runs-on: ubuntu-latest
69+
needs:
70+
- php_syntax_errors
71+
steps:
72+
- name: Checkout code
73+
uses: actions/checkout@v3
74+
75+
- name: Setup PHP
76+
uses: shivammathur/setup-php@v2
77+
with:
78+
php-version: 8.0
79+
coverage: none
80+
tools: phpstan
81+
82+
- name: Install Composer dependencies
83+
uses: ramsey/composer-install@v2
84+
85+
- name: Run PHPStan
86+
run: vendor/bin/phpstan analyze
87+
88+
tests:
89+
name: 2️⃣ PHP ${{ matrix.php-version }}
90+
needs:
91+
- php_syntax_errors
92+
runs-on: ubuntu-latest
1993
strategy:
2094
fail-fast: false
2195
matrix:
22-
php-versions: ['8.0', '8.1', '8.2']
96+
php-version:
97+
- 8.0
98+
- 8.1
99+
- 8.2
23100

24-
name: PHP ${{ matrix.php-versions }}
25-
26101
env:
27102
COMPOSER_NO_INTERACTION: 1
28103
extensions: curl, json, libxml, dom
@@ -32,56 +107,19 @@ jobs:
32107

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

37-
- name: Setup cache environment
38-
id: extcache
39-
uses: shivammathur/cache-extensions@v1
40-
with:
41-
php-version: ${{ matrix.php-versions }}
42-
extensions: ${{ env.extensions }}
43-
key: ${{ env.key }}
44-
45-
- name: Cache PHP Extensions
46-
uses: actions/cache@v2
47-
with:
48-
path: ${{ steps.extcache.outputs.dir }}
49-
key: ${{ steps.extcache.outputs.key }}
50-
restore-keys: ${{ steps.extcache.outputs.key }}
51-
52-
- name: Cache Composer Dependencies
53-
uses: actions/cache@v1
54-
with:
55-
path: ~/.composer/cache/files
56-
key: dependencies-composer-${{ hashFiles('composer.json') }}
57112

58113
- name: Setup PHP Action
59114
uses: shivammathur/setup-php@v2
60115
with:
61-
php-version: ${{ matrix.php-versions }}
116+
php-version: ${{ matrix.php-version }}
62117
extensions: ${{ env.extensions }}
63118
coverage: xdebug
64119
tools: pecl, composer
65120

66-
- name: Get composer cache directory
67-
id: composer-cache
68-
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
69-
70-
- name: Cache dependencies
71-
uses: actions/cache@v2
72-
with:
73-
path: ${{ steps.composer-cache.outputs.dir }}
74-
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
75-
restore-keys: ${{ runner.os }}-composer-
76-
77121
- name: Install Composer dependencies
78-
run: composer install --no-interaction
122+
uses: ramsey/composer-install@v2
79123

80-
- name: Validate files
81-
run: composer validate-files
82-
83-
- name: Run PHPStan
84-
run: composer phpstan
85-
86124
- name: Run tests
87125
run: composer run-tests

.php-cs-fixer.php

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
$finder = array_reduce(
4+
[
5+
__DIR__ . '/src/',
6+
__DIR__ . '/tests/',
7+
],
8+
function (PhpCsFixer\Finder $finder, $dir) {
9+
return $finder->in($dir);
10+
},
11+
PhpCsFixer\Finder::create()->ignoreUnreadableDirs()
12+
)->notName('*.blade.php');
13+
$rules = [
14+
'@Symfony' => true,
15+
'align_multiline_comment' => true,
16+
'array_indentation' => true,
17+
'backtick_to_shell_exec' => true,
18+
'increment_style' => ['style' => 'post'],
19+
'indentation_type' => true,
20+
'multiline_comment_opening_closing' => true,
21+
'no_php4_constructor' => true,
22+
'phpdoc_no_empty_return' => false,
23+
'single_blank_line_at_eof' => false,
24+
'yoda_style' => false,
25+
'concat_space' => ['spacing' => 'one'],
26+
'no_superfluous_phpdoc_tags' => false,
27+
'phpdoc_to_comment' => false, // required until https://github.com/phpstan/phpstan/issues/7486 got fixed
28+
'blank_line_between_import_groups' => false, // not PSR-12 compatible, but preserves old behaviour
29+
'ordered_imports' => [
30+
'sort_algorithm' => 'alpha',
31+
'imports_order' => null, // for PSR-12 compatability, this need to be `['class', 'function', 'const']`, but no grouping preserves old behaviour
32+
],
33+
'no_unneeded_control_parentheses' => [
34+
'statements' => ['break', 'clone', 'continue', 'echo_print', 'switch_case', 'yield'],
35+
],
36+
];
37+
$config = new PhpCsFixer\Config();
38+
39+
$config->setRiskyAllowed(true);
40+
$config->setRules($rules);
41+
$config->setIndent("\t");
42+
$config->setLineEnding("\n");
43+
$config->setFinder($finder);
44+
45+
return $config;

composer.json

+24-17
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,50 @@
11
{
22
"name": "lychee-org/nestedset",
33
"description": "Nested Set Model for Laravel 5.7 and up (fork with patches for Lychee)",
4-
"keywords": ["laravel", "nested sets", "nsm", "database", "hierarchy"],
4+
"keywords": [
5+
"laravel",
6+
"nested sets",
7+
"nsm",
8+
"database",
9+
"hierarchy"
10+
],
511
"license": "MIT",
6-
712
"authors": [
813
{
914
"name": "Alexander Kalnoy",
1015
"email": "[email protected]"
1116
}
1217
],
13-
1418
"repositories": [
1519
{
1620
"type": "vcs",
1721
"url": "https://github.com/LycheeOrg/phpstan-lychee"
1822
}
1923
],
20-
2124
"require": {
2225
"php": "^8.0",
2326
"illuminate/support": "^9.0",
2427
"illuminate/database": "^9.0",
2528
"illuminate/events": "^9.0"
2629
},
27-
28-
"autoload": {
29-
"psr-4": {
30-
"Kalnoy\\Nestedset\\": "src/"
31-
}
32-
},
33-
3430
"require-dev": {
31+
"friendsofphp/php-cs-fixer": "^3.3",
3532
"php-parallel-lint/php-parallel-lint": "^1.2",
3633
"phpunit/phpunit": "^9.5.20",
3734
"lychee-org/phpstan-lychee": "dev-master",
3835
"nunomaduro/larastan": "^2.0",
3936
"orchestra/testbench": "^7.15"
4037
},
41-
38+
"autoload": {
39+
"psr-4": {
40+
"Kalnoy\\Nestedset\\": "src/"
41+
}
42+
},
43+
"autoload-dev": {
44+
"psr-4": {
45+
"Tests\\": "tests/"
46+
}
47+
},
4248
"scripts": {
4349
"run-tests": [
4450
"vendor/bin/phpunit -c phpunit.xml",
@@ -47,13 +53,16 @@
4753
"validate-files": [
4854
"vendor/bin/parallel-lint --exclude vendor ."
4955
],
56+
"format": [
57+
"rm .php_cs.cache 2> /dev/null || true",
58+
"vendor/bin/php-cs-fixer fix -v --config=.php-cs-fixer.php"
59+
],
5060
"phpstan": [
51-
"vendor/bin/phpstan analyze"
61+
"vendor/bin/phpstan analyze"
5262
]
5363
},
5464
"minimum-stability": "dev",
5565
"prefer-stable": true,
56-
5766
"config": {
5867
"platform": {
5968
"php": "8.0.2"
@@ -62,16 +71,14 @@
6271
"sort-packages": true,
6372
"optimize-autoloader": true
6473
},
65-
6674
"extra": {
6775
"branch-alias": {
6876
"dev-master": "v5.0.x-dev"
6977
},
70-
7178
"laravel": {
7279
"providers": [
7380
"Kalnoy\\Nestedset\\NestedSetServiceProvider"
7481
]
7582
}
7683
}
77-
}
84+
}

composer.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)