Skip to content

Commit 42da0ad

Browse files
authored
PHP 8.4 (#10)
* Install PHPStan, perform check * Add PHP8.4-tests
1 parent bfd56fa commit 42da0ad

File tree

9 files changed

+37
-16
lines changed

9 files changed

+37
-16
lines changed

.github/workflows/test.yml

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ jobs:
99
strategy:
1010
matrix:
1111
include:
12+
- php: 8.4
13+
laravel: ^11.0
1214
- php: 8.3
1315
laravel: ^11.0
1416
- php: 8.2

composer.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
},
1616
"require-dev": {
1717
"orchestra/testbench": ">=6.15",
18-
"squizlabs/php_codesniffer": "^3.5",
19-
"phpunit/phpunit": "<11"
18+
"phpstan/phpstan": "^2.0",
19+
"phpunit/phpunit": "<11",
20+
"squizlabs/php_codesniffer": "^3.5"
2021
},
2122
"autoload": {
2223
"psr-4": {
@@ -32,6 +33,7 @@
3233
"test": "./vendor/bin/phpunit --no-coverage",
3334
"phpsniff": "vendor/bin/phpcs --standard=\"PSR12\" ./src --ignore=./src/resources/*",
3435
"phpfix": "vendor/bin/phpcbf --standard=\"PSR12\" ./src --ignore=./src/resources/*",
36+
"phpstan": "./vendor/bin/phpstan",
3537
"post-autoload-dump": [
3638
"@php ./vendor/bin/testbench package:discover --ansi"
3739
]

phpstan.neon

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
parameters:
2+
level: 8
3+
paths:
4+
- src
5+
ignoreErrors:
6+
- identifier: missingType.generics

src/AmpersandServiceProvider.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
class AmpersandServiceProvider extends ServiceProvider
1414
{
15-
public function boot()
15+
public function boot(): void
1616
{
1717
if ($this->app->runningInConsole()) {
1818
$this->publishes([
@@ -24,7 +24,7 @@ public function boot()
2424
}
2525
}
2626

27-
public function register()
27+
public function register(): void
2828
{
2929
$this->setup();
3030
$this->registerRepositories();
@@ -33,20 +33,20 @@ public function register()
3333
$this->app->register(RouteServiceProvider::class);
3434
}
3535

36-
private function setup()
36+
private function setup(): void
3737
{
3838
$this->loadViewsFrom(__DIR__ . '/resources/views', 'ampersand');
3939

4040
$this->mergeConfigFrom(__DIR__ . '/config/ampersand.php', 'ampersand');
4141

4242
// Add a disk to the filesystem
43-
$this->app['config']->set('filesystems.disks.ampersand::posts', [
43+
config()->set('filesystems.disks.ampersand::posts', [
4444
'driver' => 'local',
4545
'root' => config('ampersand.posts_path')
4646
]);
4747

4848
// Overload sheets config to avoid local conflicts
49-
$this->app['config']->set('sheets.collections', [
49+
config()->set('sheets.collections', [
5050
'posts' => [
5151
'disk' => 'ampersand::posts',
5252
'sheet_class' => Post::class,
@@ -57,12 +57,12 @@ private function setup()
5757
]);
5858
}
5959

60-
private function registerRepositories()
60+
private function registerRepositories(): void
6161
{
6262
$this->app->singleton(PostRepository::class);
6363
}
6464

65-
private function registerCommands()
65+
private function registerCommands(): void
6666
{
6767
$this->commands([
6868
NewPost::class

src/Commands/NewPost.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function handle(): void
2020
$file = sprintf('%s.%s.md', $date->format('Y-m-d'), Str::slug($title));
2121

2222
$content = file_get_contents(__DIR__ . '/../resources/stubs/post.md');
23-
$content = Str::of($content)->replace('%title%', $title)
23+
$content = Str::of((string) $content)->replace('%title%', $title)
2424
->replace('%date%', $date);
2525

2626
$directory = config('ampersand.posts_path');

src/Http/Controllers/PostController.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Olssonm\Ampersand\Http\Controllers;
44

5+
use Illuminate\Http\Response;
56
use Olssonm\Ampersand\Models\Post;
67
use Olssonm\Ampersand\Repositories\PostRepository;
78

@@ -14,19 +15,19 @@ public function __construct(PostRepository $postRepository)
1415
$this->postRepository = $postRepository;
1516
}
1617

17-
public function index()
18+
public function index(): Response
1819
{
19-
return view('ampersand::index', [
20+
return response()->view('ampersand::index', [
2021
'posts' => $this->postRepository->paginate(
2122
config('ampersand.per_page'),
2223
config('ampersand.page_indicator'),
2324
)
2425
]);
2526
}
2627

27-
public function show(Post $post)
28+
public function show(Post $post): Response
2829
{
29-
return view('ampersand::show', [
30+
return response()->view('ampersand::show', [
3031
'post' => $post
3132
]);
3233
}

src/Models/Post.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22

33
namespace Olssonm\Ampersand\Models;
44

5+
use AllowDynamicProperties;
56
use Carbon\Carbon;
67
use Olssonm\Ampersand\Repositories\PostRepository;
78
use Olssonm\Ampersand\Services\Model;
89

10+
/**
11+
* @property string $slug
12+
*/
13+
#[AllowDynamicProperties]
914
class Post extends Model
1015
{
1116
public function getRouteKey(): string
@@ -28,8 +33,10 @@ public function getDateAttribute(): Carbon
2833
return Carbon::parse($this->attributes['date']);
2934
}
3035

31-
public static function __callStatic($name, $arguments)
36+
/** @phpstan-ignore-next-line */
37+
public static function __callStatic(string $name, array $arguments): mixed
3238
{
39+
/** @phpstan-ignore-next-line */
3340
return call_user_func_array([app(PostRepository::class), $name], $arguments);
3441
}
3542
}

src/Repositories/PostRepository.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ public function find(string $slug): Post
2020
{
2121
$post = $this->all()->where('slug', $slug)->first();
2222

23+
/** @phpstan-ignore argument.type */
2324
throw_if(!$post, (new ModelNotFoundException())->setModel(Post::class, $slug));
2425

2526
return $post;
2627
}
2728

28-
public function paginate($perPage = 10, $pageName = 'page'): LengthAwarePaginator
29+
public function paginate(int $perPage = 10, string $pageName = 'page'): LengthAwarePaginator
2930
{
3031
$page = LengthAwarePaginator::resolveCurrentPage($pageName, 1);
3132

src/Services/Model.php

+2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99

1010
abstract class Model extends Sheet implements UrlRoutable
1111
{
12+
/** @phpstan-ignore return.missing */
1213
public function resolveRouteBinding($value, $field = null)
1314
{
1415
}
1516

17+
/** @phpstan-ignore return.missing */
1618
public function resolveChildRouteBinding($childType, $value, $field)
1719
{
1820
}

0 commit comments

Comments
 (0)