Skip to content

Commit 5df6a78

Browse files
committed
support php 7.4 and added tests for multiple laravel versions
1 parent 82a8c39 commit 5df6a78

File tree

11 files changed

+109
-90
lines changed

11 files changed

+109
-90
lines changed

.github/workflows/fix-php-code-style-issues.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
name: Fix PHP code style issues
1+
name: Check & fix styling
22

3-
on:
4-
push:
5-
paths:
6-
- '**.php'
3+
on: [push]
74

85
jobs:
9-
php-code-styling:
6+
php-cs-fixer:
107
runs-on: ubuntu-latest
118

129
steps:
@@ -15,8 +12,10 @@ jobs:
1512
with:
1613
ref: ${{ github.head_ref }}
1714

18-
- name: Fix PHP code style issues
19-
uses: aglipanci/[email protected]
15+
- name: Run PHP CS Fixer
16+
uses: docker://oskarstark/php-cs-fixer-ga
17+
with:
18+
args: --config=.php-cs-fixer.dist.php --allow-risky=yes
2019

2120
- name: Commit changes
2221
uses: stefanzweifel/git-auto-commit-action@v4

.github/workflows/phpstan.yml

Lines changed: 0 additions & 26 deletions
This file was deleted.

.github/workflows/run-tests.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,26 @@ jobs:
1313
fail-fast: true
1414
matrix:
1515
os: [ubuntu-latest, windows-latest]
16-
php: [8.2, 8.1]
17-
laravel: [9.*]
16+
php: [8.2, 8.1, 8.0, 7.4]
17+
laravel: [10.*, 9.*, 8.*]
1818
stability: [prefer-lowest, prefer-stable]
1919
include:
20+
- laravel: 10.*
21+
testbench: 8.*
22+
carbon: ^2.63
2023
- laravel: 9.*
2124
testbench: 7.*
2225
carbon: ^2.63
26+
- laravel: 8.*
27+
testbench: 6.27
28+
carbon: ^2.63
29+
exclude:
30+
- laravel: 10.*
31+
php: 8.0
32+
- laravel: 10.*
33+
php: 7.4
34+
- laravel: 9.*
35+
php: 7.4
2336

2437
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
2538

.php-cs-fixer.dist.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
$finder = Symfony\Component\Finder\Finder::create()
4+
->in([
5+
__DIR__ . '/src',
6+
__DIR__ . '/tests',
7+
])
8+
->name('*.php')
9+
->ignoreDotFiles(true)
10+
->ignoreVCS(true);
11+
12+
return (new PhpCsFixer\Config())
13+
->setRules([
14+
'@PSR12' => true,
15+
'array_syntax' => ['syntax' => 'short'],
16+
'ordered_imports' => ['sort_algorithm' => 'alpha'],
17+
'no_unused_imports' => true,
18+
'not_operator_with_successor_space' => true,
19+
'trailing_comma_in_multiline' => true,
20+
'phpdoc_scalar' => true,
21+
'unary_operator_spaces' => true,
22+
'binary_operator_spaces' => true,
23+
'blank_line_before_statement' => [
24+
'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'],
25+
],
26+
'phpdoc_single_line_var_spacing' => true,
27+
'phpdoc_var_without_name' => true,
28+
'class_attributes_separation' => [
29+
'elements' => [
30+
'method' => 'one',
31+
],
32+
],
33+
'method_argument_space' => [
34+
'on_multiline' => 'ensure_fully_multiline',
35+
'keep_multiple_spaces_after_comma' => true,
36+
],
37+
'single_trait_insert_per_statement' => true,
38+
])
39+
->setFinder($finder);

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ php artisan vendor:publish --tag="useful-additions-config"
3939

4040
### UsefulEnums
4141

42+
This trait is only available with **PHP 8.1** or higher installed.
43+
4244
---
4345

4446
#### `names`, `values`, `array`

composer.json

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,20 @@
1616
}
1717
],
1818
"require": {
19-
"php": "^8.1",
20-
"spatie/laravel-package-tools": "^1.13.0",
21-
"laravel/framework": "^10.0"
19+
"php": "^7.4 || ^8.0",
20+
"illuminate/database": "^8.0 || ^9.0 || ^10.0",
21+
"illuminate/support": "^8.0 || ^9.0 || ^10.0",
22+
"illuminate/testing": "^8.0 || ^9.0 || ^10.0",
23+
"illuminate/contracts": "^8.0 || ^9.0 || ^10.0",
24+
"spatie/laravel-package-tools": "^1.12 || ^1.14"
2225
},
2326
"require-dev": {
24-
"laravel/pint": "^1.0",
25-
"nunomaduro/collision": "^6.1",
26-
"nunomaduro/larastan": "^2.0.1",
27-
"orchestra/testbench": "^8.0",
28-
"pestphp/pest": "^1.22",
29-
"pestphp/pest-plugin-laravel": "^1.1",
30-
"phpstan/extension-installer": "^1.1",
31-
"phpstan/phpstan-deprecation-rules": "^1.0",
32-
"phpstan/phpstan-phpunit": "^1.0",
33-
"phpunit/phpunit": "^9.6",
34-
"spatie/laravel-ray": "^1.26"
27+
"friendsofphp/php-cs-fixer": "^3.13",
28+
"nunomaduro/larastan": "^1.0 || ^2.5",
29+
"orchestra/testbench": "^6.27 || ^7.0 || ^8.0 ",
30+
"pestphp/pest": "^1.22 || ^2.0",
31+
"pestphp/pest-plugin-laravel": "^1.22 || ^2.0",
32+
"spatie/laravel-ray": "^1.32"
3533
},
3634
"autoload": {
3735
"psr-4": {
@@ -46,16 +44,14 @@
4644
},
4745
"scripts": {
4846
"post-autoload-dump": "@php ./vendor/bin/testbench package:discover --ansi",
49-
"analyse": "vendor/bin/phpstan analyse",
5047
"test": "vendor/bin/pest",
5148
"test-coverage": "vendor/bin/pest --coverage",
52-
"format": "vendor/bin/pint"
49+
"format": "vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php --allow-risky=yes"
5350
},
5451
"config": {
5552
"sort-packages": true,
5653
"allow-plugins": {
57-
"pestphp/pest-plugin": true,
58-
"phpstan/extension-installer": true
54+
"pestphp/pest-plugin": true
5955
}
6056
},
6157
"extra": {

phpstan-baseline.neon

Whitespace-only changes.

phpstan.neon.dist

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/Traits/UsefulEnums.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,22 @@
22

33
namespace LaracraftTech\LaravelUsefulAdditions\Traits;
44

5-
trait UsefulEnums
6-
{
7-
public static function names(): array
5+
if (PHP_VERSION_ID >= 80100) {
6+
trait UsefulEnums
87
{
9-
return array_column(self::cases(), 'name');
10-
}
8+
public static function names(): array
9+
{
10+
return array_column(self::cases(), 'name');
11+
}
1112

12-
public static function values(): array
13-
{
14-
return array_column(self::cases(), 'value');
15-
}
13+
public static function values(): array
14+
{
15+
return array_column(self::cases(), 'value');
16+
}
1617

17-
public static function array(): array
18-
{
19-
return array_combine(self::names(), self::values());
18+
public static function array(): array
19+
{
20+
return array_combine(self::names(), self::values());
21+
}
2022
}
2123
}

tests/EnumTest.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
<?php
22

3-
use LaracraftTech\LaravelUsefulAdditions\Traits\UsefulEnums;
3+
use LaracraftTech\LaravelUsefulAdditions\Tests\PaymentType;
44

55
it('can give array of enum', function () {
6-
enum PaymentType: int
7-
{
8-
use UsefulEnums;
9-
10-
case Pending = 1;
11-
case Failed = 2;
12-
case Success = 3;
13-
}
14-
156
expect(PaymentType::names())->toBe(['Pending', 'Failed', 'Success'])
167
->and(PaymentType::values())->toBe([1, 2, 3])
178
->and(PaymentType::array())->toBe([
189
'Pending' => 1,
1910
'Failed' => 2,
2011
'Success' => 3,
2112
]);
22-
});
13+
})->skip(PHP_VERSION_ID < 80100, 'Only since PHP 8.1');

0 commit comments

Comments
 (0)