Skip to content

Commit

Permalink
support php 7.4 and added tests for multiple laravel versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Sairahcaz committed Apr 2, 2023
1 parent 82a8c39 commit 5df6a78
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 90 deletions.
15 changes: 7 additions & 8 deletions .github/workflows/fix-php-code-style-issues.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
name: Fix PHP code style issues
name: Check & fix styling

on:
push:
paths:
- '**.php'
on: [push]

jobs:
php-code-styling:
php-cs-fixer:
runs-on: ubuntu-latest

steps:
Expand All @@ -15,8 +12,10 @@ jobs:
with:
ref: ${{ github.head_ref }}

- name: Fix PHP code style issues
uses: aglipanci/laravel-pint-action@2.1.0
- name: Run PHP CS Fixer
uses: docker://oskarstark/php-cs-fixer-ga
with:
args: --config=.php-cs-fixer.dist.php --allow-risky=yes

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
Expand Down
26 changes: 0 additions & 26 deletions .github/workflows/phpstan.yml

This file was deleted.

17 changes: 15 additions & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,26 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest]
php: [8.2, 8.1]
laravel: [9.*]
php: [8.2, 8.1, 8.0, 7.4]
laravel: [10.*, 9.*, 8.*]
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 10.*
testbench: 8.*
carbon: ^2.63
- laravel: 9.*
testbench: 7.*
carbon: ^2.63
- laravel: 8.*
testbench: 6.27
carbon: ^2.63
exclude:
- laravel: 10.*
php: 8.0
- laravel: 10.*
php: 7.4
- laravel: 9.*
php: 7.4

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

Expand Down
39 changes: 39 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

$finder = Symfony\Component\Finder\Finder::create()
->in([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->name('*.php')
->ignoreDotFiles(true)
->ignoreVCS(true);

return (new PhpCsFixer\Config())
->setRules([
'@PSR12' => true,
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'no_unused_imports' => true,
'not_operator_with_successor_space' => true,
'trailing_comma_in_multiline' => true,
'phpdoc_scalar' => true,
'unary_operator_spaces' => true,
'binary_operator_spaces' => true,
'blank_line_before_statement' => [
'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'],
],
'phpdoc_single_line_var_spacing' => true,
'phpdoc_var_without_name' => true,
'class_attributes_separation' => [
'elements' => [
'method' => 'one',
],
],
'method_argument_space' => [
'on_multiline' => 'ensure_fully_multiline',
'keep_multiple_spaces_after_comma' => true,
],
'single_trait_insert_per_statement' => true,
])
->setFinder($finder);
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ php artisan vendor:publish --tag="useful-additions-config"

### UsefulEnums

This trait is only available with **PHP 8.1** or higher installed.

---

#### `names`, `values`, `array`
Expand Down
32 changes: 14 additions & 18 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,20 @@
}
],
"require": {
"php": "^8.1",
"spatie/laravel-package-tools": "^1.13.0",
"laravel/framework": "^10.0"
"php": "^7.4 || ^8.0",
"illuminate/database": "^8.0 || ^9.0 || ^10.0",
"illuminate/support": "^8.0 || ^9.0 || ^10.0",
"illuminate/testing": "^8.0 || ^9.0 || ^10.0",
"illuminate/contracts": "^8.0 || ^9.0 || ^10.0",
"spatie/laravel-package-tools": "^1.12 || ^1.14"
},
"require-dev": {
"laravel/pint": "^1.0",
"nunomaduro/collision": "^6.1",
"nunomaduro/larastan": "^2.0.1",
"orchestra/testbench": "^8.0",
"pestphp/pest": "^1.22",
"pestphp/pest-plugin-laravel": "^1.1",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^9.6",
"spatie/laravel-ray": "^1.26"
"friendsofphp/php-cs-fixer": "^3.13",
"nunomaduro/larastan": "^1.0 || ^2.5",
"orchestra/testbench": "^6.27 || ^7.0 || ^8.0 ",
"pestphp/pest": "^1.22 || ^2.0",
"pestphp/pest-plugin-laravel": "^1.22 || ^2.0",
"spatie/laravel-ray": "^1.32"
},
"autoload": {
"psr-4": {
Expand All @@ -46,16 +44,14 @@
},
"scripts": {
"post-autoload-dump": "@php ./vendor/bin/testbench package:discover --ansi",
"analyse": "vendor/bin/phpstan analyse",
"test": "vendor/bin/pest",
"test-coverage": "vendor/bin/pest --coverage",
"format": "vendor/bin/pint"
"format": "vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php --allow-risky=yes"
},
"config": {
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true,
"phpstan/extension-installer": true
"pestphp/pest-plugin": true
}
},
"extra": {
Expand Down
Empty file removed phpstan-baseline.neon
Empty file.
13 changes: 0 additions & 13 deletions phpstan.neon.dist

This file was deleted.

26 changes: 14 additions & 12 deletions src/Traits/UsefulEnums.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@

namespace LaracraftTech\LaravelUsefulAdditions\Traits;

trait UsefulEnums
{
public static function names(): array
if (PHP_VERSION_ID >= 80100) {
trait UsefulEnums
{
return array_column(self::cases(), 'name');
}
public static function names(): array
{
return array_column(self::cases(), 'name');
}

public static function values(): array
{
return array_column(self::cases(), 'value');
}
public static function values(): array
{
return array_column(self::cases(), 'value');
}

public static function array(): array
{
return array_combine(self::names(), self::values());
public static function array(): array
{
return array_combine(self::names(), self::values());
}
}
}
13 changes: 2 additions & 11 deletions tests/EnumTest.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
<?php

use LaracraftTech\LaravelUsefulAdditions\Traits\UsefulEnums;
use LaracraftTech\LaravelUsefulAdditions\Tests\PaymentType;

it('can give array of enum', function () {
enum PaymentType: int
{
use UsefulEnums;

case Pending = 1;
case Failed = 2;
case Success = 3;
}

expect(PaymentType::names())->toBe(['Pending', 'Failed', 'Success'])
->and(PaymentType::values())->toBe([1, 2, 3])
->and(PaymentType::array())->toBe([
'Pending' => 1,
'Failed' => 2,
'Success' => 3,
]);
});
})->skip(PHP_VERSION_ID < 80100, 'Only since PHP 8.1');
16 changes: 16 additions & 0 deletions tests/PaymentType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace LaracraftTech\LaravelUsefulAdditions\Tests;

use LaracraftTech\LaravelUsefulAdditions\Traits\UsefulEnums;

if (PHP_VERSION_ID >= 80100) {
enum PaymentType: int
{
use UsefulEnums;

case Pending = 1;
case Failed = 2;
case Success = 3;
}
}

0 comments on commit 5df6a78

Please sign in to comment.