Skip to content

Commit 6e083d3

Browse files
author
Jakub Gawron
authored
Merge pull request #7 from netsells/feature/php8.2
Upgrades to Laravel 10 and PHP 8.2, plus fixes from static analysis and code styles
2 parents a8eff3c + 2e63488 commit 6e083d3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+203
-119
lines changed

.github/workflows/phpcsfixer.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Format with PHP CS Fixer
2+
3+
on: [pull_request, workflow_dispatch]
4+
5+
jobs:
6+
php-cs-fixer:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/checkout@v2
11+
12+
- name: Setup PHP
13+
uses: shivammathur/setup-php@v2
14+
with:
15+
php-version: '8.2'
16+
extensions: zip
17+
coverage: none
18+
19+
- name: Install Dependencies
20+
run: composer install --no-ansi --no-interaction --no-scripts --prefer-dist
21+
22+
- run: composer run format
23+
24+
- uses: stefanzweifel/git-auto-commit-action@v4
25+
with:
26+
commit_message: Apply php-cs-fixer changes

.github/workflows/phpstan.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Perform static analysis with PHPStan
2+
3+
on: [pull_request, workflow_dispatch]
4+
5+
jobs:
6+
phpstan:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/checkout@v2
11+
12+
- name: Setup PHP
13+
uses: shivammathur/setup-php@v2
14+
with:
15+
php-version: '8.2'
16+
extensions: zip
17+
coverage: none
18+
19+
- name: Install Dependencies
20+
run: composer install --no-ansi --no-interaction --no-scripts --prefer-dist
21+
22+
- run: composer run phpstan

.github/workflows/tests.yml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,14 @@ on: [pull_request, workflow_dispatch]
44

55
jobs:
66
test:
7-
# not self-hosted, because it's a public repo
87
runs-on: ubuntu-latest
98

10-
# we want to run it on combination of Laravel 8.12+ and PHP 8+
9+
# we want to run it on supported combination of Laravel and PHP versions
1110
strategy:
1211
fail-fast: false
1312
matrix:
14-
php: ['8.0', '8.1']
15-
laravel: ['^8.12', '^9.0', '^10.0']
16-
exclude:
17-
# minimum php version for Laravel 10 is PHP 8.1 so we need to exclude (php 8.0 and laravel 10) combination
18-
- php: '8.0'
19-
laravel: '^10.0'
13+
php: ['8.1', '8.2']
14+
laravel: ['^9.0', '^10.0']
2015

2116
steps:
2217
- name: Checkout the repo
@@ -35,4 +30,4 @@ jobs:
3530
run: composer require laravel/framework $LARAVEL_VERSION --no-interaction --no-scripts --prefer-dist
3631

3732
- name: Execute tests
38-
run: vendor/bin/phpunit
33+
run: composer run test

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
composer.lock
33
.idea
44
.phpunit.result.cache
5-
.phpunit.cache
5+
.phpunit.cache
6+
.php-cs-fixer.cache

.php-cs-fixer.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
use PhpCsFixer\Config;
4+
use PhpCsFixer\Finder;
5+
6+
/** @var Config $config */
7+
$config = require_once join(DIRECTORY_SEPARATOR, [__DIR__, 'vendor', 'netsells', 'code-standards-laravel', 'phpcsfixer', 'config.php']);
8+
9+
$rules = array_merge_recursive($config->getRules(), [
10+
// set project specific rules here
11+
]);
12+
13+
$finder = Finder::create()
14+
->in([
15+
__DIR__ . '/src',
16+
__DIR__ . '/tests',
17+
])
18+
->name('*.php')
19+
->notName('*.blade.php')
20+
->ignoreDotFiles(true)
21+
->ignoreVCS(true);
22+
23+
return $config
24+
->setFinder($finder)
25+
->setRules($rules);

composer.json

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,25 @@
2020
}
2121
],
2222
"require": {
23-
"php": ">=8.0",
23+
"php": "^8.1 || ^8.2",
2424
"ext-json": "*",
25-
"laravel/framework": "^8.12 || ^9.0 || ^10.0"
25+
"laravel/framework": "^9.0 || ^10.0"
2626
},
2727
"require-dev": {
28-
"orchestra/testbench": "^6.0 || ^7.0 || ^8.0",
29-
"tmarsteel/mockery-callable-mock": "~2.1"
28+
"orchestra/testbench": "^7.0 || ^8.0",
29+
"tmarsteel/mockery-callable-mock": "~2.1",
30+
"netsells/code-standards-laravel": "^1.1"
3031
},
3132
"autoload": {
3233
"psr-4": {
3334
"Netsells\\Http\\Resources\\": "src/",
3435
"Netsells\\Http\\Resources\\Tests\\": "tests/"
3536
}
37+
},
38+
"scripts": {
39+
"phpstan": "vendor/bin/phpstan",
40+
"lint": "vendor/bin/php-cs-fixer fix --dry-run --diff",
41+
"format": "vendor/bin/php-cs-fixer fix",
42+
"test": "vendor/bin/phpunit"
3643
}
3744
}

phpstan.neon

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
includes:
2+
- ./vendor/netsells/code-standards-laravel/phpstan/extension.neon
3+
4+
parameters:
5+
paths:
6+
- src
7+
- tests
8+
9+
# The level 9 is the highest level
10+
level: 5
11+
12+
ignoreErrors:
13+
excludePaths:
14+
15+
checkMissingIterableValueType: false

src/Eloquent/EloquentDeferredValue.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Netsells\Http\Resources\Eloquent;
44

5+
use Illuminate\Support\Collection;
56
use Netsells\Http\Resources\DeferredValue;
67
use Netsells\Http\Resources\Json\JsonResource;
78
use Netsells\Http\Resources\Json\ResourceCollection;
@@ -26,12 +27,12 @@ public static function resolve(array $deferredValues): void
2627
{
2728
static::loadEloquentRelations($deferredValues);
2829

29-
collect($deferredValues)
30+
Collection::make($deferredValues)
3031
->filter(function (EloquentDeferredValue $deferredValue) {
31-
return $deferredValue->resolver;
32+
return (bool) $deferredValue->resolver;
3233
})
3334
->each(function (EloquentDeferredValue $deferredValue) {
34-
$relations = collect($deferredValue->relations)->map(function ($relation) use ($deferredValue) {
35+
$relations = Collection::make($deferredValue->relations)->map(function ($relation) use ($deferredValue) {
3536
return data_get($deferredValue->resource, $relation);
3637
})->all();
3738

@@ -41,6 +42,7 @@ public static function resolve(array $deferredValues): void
4142

4243
/**
4344
* Begins eager loading eloquent model relations.
45+
*
4446
* @param static[] $deferredValues
4547
*/
4648
abstract protected static function loadEloquentRelations(array $deferredValues): void;

src/Eloquent/Load.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
class Load extends EloquentDeferredValue
99
{
1010
/**
11-
* @inheritDoc
11+
* {@inheritDoc}
1212
*/
1313
protected static function loadEloquentRelations(array $deferredValues): void
1414
{
15-
collect($deferredValues)->groupBy('relations')
15+
Collection::make($deferredValues)->groupBy('relations')
1616
->each(function (Collection $collection, $relation) {
1717
EloquentCollection::make($collection->pluck('resource.resource'))
1818
->load($relation);

src/Eloquent/LoadCount.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
class LoadCount extends EloquentDeferredValue
99
{
1010
/**
11-
* @inheritDoc
11+
* {@inheritDoc}
1212
*/
1313
protected static function loadEloquentRelations(array $deferredValues): void
1414
{
15-
collect($deferredValues)->groupBy('relations')
15+
Collection::make($deferredValues)->groupBy('relations')
1616
->each(function (Collection $collection, $relation) {
1717
EloquentCollection::make($collection->pluck('resource.resource'))
1818
->loadCount($relation);

0 commit comments

Comments
 (0)