Skip to content

Commit e967980

Browse files
Update to laravel 12 and PHP 8.5 (#10)
* first version of updating to laravel 12 and php 8.5 * fixing last comments
1 parent 9f9a182 commit e967980

File tree

12 files changed

+175
-104
lines changed

12 files changed

+175
-104
lines changed

.github/workflows/tests.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [ master, main ]
6+
pull_request:
7+
branches: [ master, main ]
8+
9+
jobs:
10+
test:
11+
name: PHP 8.5 - Laravel 12
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Setup PHP
19+
uses: shivammathur/setup-php@v2
20+
with:
21+
php-version: '8.5'
22+
extensions: dom, curl, libxml, mbstring, zip, pcov
23+
coverage: pcov
24+
25+
- name: Get composer cache directory
26+
id: composer-cache
27+
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
28+
29+
- name: Cache dependencies
30+
uses: actions/cache@v4
31+
with:
32+
path: ${{ steps.composer-cache.outputs.dir }}
33+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
34+
restore-keys: ${{ runner.os }}-composer-
35+
36+
- name: Install dependencies
37+
run: composer update --prefer-dist --no-interaction --no-progress
38+
39+
- name: Execute tests
40+
run: composer run phpunit
41+
42+
- name: Check code style
43+
run: composer run phpcs
44+
45+
- name: Run static analysis
46+
run: composer run phpstan

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/vendor/
22
composer.lock
33
.php_cs.cache
4+
.php-cs-fixer.cache
5+
.phpunit.cache
46
.phpunit.result.cache
Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,36 @@
11
<?php
2+
23
$finder = PhpCsFixer\Finder::create()
3-
->in(__DIR__.'/src')
4-
->in(__DIR__.'/tests')
5-
;
6-
return PhpCsFixer\Config::create()
4+
->in(__DIR__ . '/src')
5+
->in(__DIR__ . '/tests');
6+
7+
return (new PhpCsFixer\Config())
8+
->setRiskyAllowed(true)
79
->setRules([
8-
'@PSR2' => true,
10+
'@PSR12' => true,
911
'array_syntax' => ['syntax' => 'short'],
1012
'concat_space' => ['spacing' => 'one'],
11-
'new_with_braces' => true,
13+
'new_with_parentheses' => true,
1214
'no_blank_lines_after_phpdoc' => true,
1315
'no_empty_phpdoc' => true,
1416
'no_empty_comment' => true,
1517
'no_leading_import_slash' => true,
16-
'no_trailing_comma_in_singleline_array' => true,
18+
'no_trailing_comma_in_singleline' => true,
1719
'no_unused_imports' => true,
18-
'ordered_imports' => ['importsOrder' => null, 'sortAlgorithm' => 'alpha'],
20+
'ordered_imports' => ['sort_algorithm' => 'alpha'],
1921
'phpdoc_add_missing_param_annotation' => ['only_untyped' => true],
20-
'phpdoc_align' => true,
22+
'phpdoc_align' => ['align' => 'left'],
2123
'phpdoc_no_empty_return' => true,
2224
'phpdoc_order' => true,
2325
'phpdoc_scalar' => true,
2426
'phpdoc_to_comment' => true,
25-
'psr0' => false,
26-
'psr4' => true,
27+
'psr_autoloading' => true,
2728
'return_type_declaration' => ['space_before' => 'none'],
28-
'single_blank_line_before_namespace' => true,
2929
'single_quote' => true,
3030
'space_after_semicolon' => true,
3131
'ternary_operator_spaces' => true,
32-
'trailing_comma_in_multiline_array' => true,
32+
'trailing_comma_in_multiline' => ['elements' => ['arrays']],
3333
'trim_array_spaces' => true,
3434
'whitespace_after_comma_in_array' => true,
3535
])
36-
->setFinder($finder)
37-
;
36+
->setFinder($finder);

.travis.yml

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

Dockerfile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
FROM composer:2
2+
3+
# Install build dependencies
4+
RUN apk add --no-cache $PHPIZE_DEPS linux-headers
5+
6+
# Install PCOV (for fast code coverage)
7+
RUN pecl install pcov && docker-php-ext-enable pcov
8+
9+
# Install Xdebug (for debugging when needed)
10+
RUN pecl install xdebug && docker-php-ext-enable xdebug
11+
12+
# Clean up
13+
RUN apk del $PHPIZE_DEPS linux-headers
14+
15+
# Configure PCOV (enabled by default for tests)
16+
RUN echo "pcov.enabled=1" >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini
17+
18+
# Configure Xdebug (disabled by default, enable when debugging)
19+
RUN echo "xdebug.mode=off" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
20+
&& echo "xdebug.start_with_request=yes" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
21+
&& echo "xdebug.client_host=host.docker.internal" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
22+
&& echo "xdebug.client_port=9003" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
23+
24+
# Disable Xdebug by default to use PCOV for coverage
25+
RUN mv /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini.disabled
26+
27+
WORKDIR /app

README.md

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Laravel request accept json middleware
33

44
[![Latest Version](https://img.shields.io/github/release/softonic/laravel-request-accept-json-middleware.svg?style=flat-square)](https://github.com/softonic/laravel-request-accept-json-middleware/releases)
55
[![Software License](https://img.shields.io/badge/license-Apache%202.0-blue.svg?style=flat-square)](LICENSE.md)
6-
[![Build Status](https://img.shields.io/travis/softonic/laravel-request-accept-json-middleware/master.svg?style=flat-square)](https://travis-ci.org/softonic/laravel-request-accept-json-middleware)
6+
[![Build Status](https://img.shields.io/github/actions/workflow/status/softonic/laravel-request-accept-json-middleware/tests.yml?branch=master&style=flat-square)](https://github.com/softonic/laravel-request-accept-json-middleware/actions)
77
[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/softonic/laravel-request-accept-json-middleware.svg?style=flat-square)](https://scrutinizer-ci.com/g/softonic/laravel-request-accept-json-middleware/code-structure)
88
[![Quality Score](https://img.shields.io/scrutinizer/g/softonic/laravel-request-accept-json-middleware.svg?style=flat-square)](https://scrutinizer-ci.com/g/softonic/laravel-request-accept-json-middleware)
99
[![Total Downloads](https://img.shields.io/packagist/dt/softonic/laravel-request-accept-json-middleware.svg?style=flat-square)](https://packagist.org/packages/softonic/laravel-request-accept-json-middleware)
@@ -12,6 +12,11 @@ Laravel request accept json middleware
1212

1313
This middleware adds the ability to automatically add the Accept application/json header to every request if it was not provided.
1414

15+
## Requirements
16+
17+
- PHP >= 8.5
18+
- Laravel 12.x
19+
1520
Installation
1621
-------
1722

@@ -39,18 +44,42 @@ From now on the header `Accept: application/json` will be automatically added to
3944
Testing
4045
-------
4146

42-
`softonic/laravel-request-accept-json-middleware` has a [PHPUnit](https://phpunit.de) test suite and a coding style compliance test suite using [PHP CS Fixer](http://cs.sensiolabs.org/).
47+
`softonic/laravel-request-accept-json-middleware` has a [PHPUnit](https://phpunit.de) test suite, code style compliance check using [PHP CS Fixer](https://cs.symfony.com/), and static analysis using [PHPStan](https://phpstan.org/).
48+
49+
To run the tests, run the following command from the project folder:
50+
51+
``` bash
52+
$ docker compose run --rm test
53+
```
54+
55+
To run PHPUnit only:
56+
57+
``` bash
58+
$ docker compose run --rm phpunit
59+
```
60+
61+
To check code style:
62+
63+
``` bash
64+
$ docker compose run --rm php composer run phpcs
65+
```
66+
67+
To fix code style issues:
68+
69+
``` bash
70+
$ docker compose run --rm fixcs
71+
```
4372

44-
To run the tests, run the following command from the project folder.
73+
To run static analysis:
4574

4675
``` bash
47-
$ docker-compose run test
76+
$ docker compose run --rm php composer run phpstan
4877
```
4978

5079
License
5180
-------
5281

5382
The Apache 2.0 license. Please see [LICENSE](LICENSE) for more information.
5483

55-
[PSR-2]: http://www.php-fig.org/psr/psr-2/
56-
[PSR-4]: http://www.php-fig.org/psr/psr-4/
84+
[PSR-12]: https://www.php-fig.org/psr/psr-12/
85+
[PSR-4]: https://www.php-fig.org/psr/psr-4/

composer.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99
"issues": "https://github.com/softonic/laravel-request-accept-json-middleware/issues"
1010
},
1111
"require": {
12-
"php": ">=8.2",
13-
"illuminate/http": "^11.0",
14-
"illuminate/contracts": "^11.0"
12+
"php": ">=8.5",
13+
"illuminate/http": "^12.0",
14+
"illuminate/contracts": "^12.0"
1515
},
1616
"require-dev": {
1717
"friendsofphp/php-cs-fixer": "^3.68",
1818
"mockery/mockery": "^1.2",
19-
"phpunit/phpunit": "^9.0"
19+
"phpunit/phpunit": "^12.0",
20+
"phpstan/phpstan": "^1.8"
2021
},
2122
"autoload": {
2223
"psr-4": {
@@ -29,10 +30,11 @@
2930
}
3031
},
3132
"scripts": {
32-
"tests": "phpunit --coverage-text; php-cs-fixer fix -v --diff --dry-run --allow-risky=yes;",
33+
"tests": "phpunit --coverage-text; php-cs-fixer fix -v --diff --dry-run --allow-risky=yes; phpstan analyse",
3334
"phpunit": "phpunit --coverage-text",
3435
"phpcs": "php-cs-fixer fix -v --diff --dry-run --allow-risky=yes;",
35-
"fix-cs": "php-cs-fixer fix -v --diff --allow-risky=yes;"
36+
"fix-cs": "php-cs-fixer fix -v --diff --allow-risky=yes;",
37+
"phpstan": "phpstan analyse"
3638
}
3739
}
3840

docker-compose.yml

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
11
services:
22
php:
3+
build: .
34
volumes:
45
- ./:/app
5-
image: composer:2.2
66

77
install:
8+
build: .
89
volumes:
910
- ./:/app
10-
image: composer:2.2
11-
command: composer install
11+
command: sh -c "git config --global --add safe.directory /app && composer install"
1212

1313
phpunit:
14+
build: .
1415
volumes:
1516
- ./:/app
16-
image: composer:2.2
17-
command: composer phpunit
17+
command: sh -c "git config --global --add safe.directory /app && composer run phpunit"
1818

1919
test:
20+
build: .
2021
volumes:
2122
- ./:/app
22-
image: composer:2.2
23-
command: composer run tests
23+
command: sh -c "git config --global --add safe.directory /app && composer run tests"
2424

2525
fixcs:
26+
build: .
2627
volumes:
2728
- ./:/app
28-
image: composer:2.2
29-
command: composer run fix-cs
29+
command: sh -c "git config --global --add safe.directory /app && composer run fix-cs"
30+
31+
debug:
32+
build: .
33+
volumes:
34+
- ./:/app
35+
command: sh -c "mv /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini.disabled /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini 2>/dev/null || true; php -dxdebug.mode=debug -dpcov.enabled=0 $@"

phpstan.neon

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
parameters:
2+
level: 7
3+
paths:
4+
- src

phpunit.xml

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,26 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
3-
<phpunit bootstrap="vendor/autoload.php"
4-
backupGlobals="false"
5-
backupStaticAttributes="false"
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/12.0/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
65
colors="true"
7-
verbose="true"
8-
convertErrorsToExceptions="true"
9-
convertNoticesToExceptions="true"
10-
convertWarningsToExceptions="true"
11-
processIsolation="false"
12-
stopOnFailure="false">
13-
6+
failOnRisky="true"
7+
failOnWarning="true"
8+
cacheDirectory=".phpunit.cache">
149
<testsuites>
1510
<testsuite name="All">
1611
<directory>tests</directory>
1712
</testsuite>
1813
</testsuites>
19-
20-
<filter>
21-
<whitelist>
14+
<source>
15+
<include>
2216
<directory suffix=".php">src</directory>
23-
</whitelist>
24-
</filter>
25-
26-
<logging>
27-
<log type="junit" target="build/report.junit.xml" />
28-
<log type="coverage-html" target="build/coverage" />
29-
<log type="coverage-text" target="build/coverage.txt" />
30-
<log type="coverage-clover" target="build/clover.xml" />
31-
</logging>
32-
17+
</include>
18+
</source>
19+
<coverage>
20+
<report>
21+
<clover outputFile="build/clover.xml"/>
22+
<html outputDirectory="build/coverage"/>
23+
<text outputFile="build/coverage.txt"/>
24+
</report>
25+
</coverage>
3326
</phpunit>

0 commit comments

Comments
 (0)