Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 8.4 #10

Merged
merged 2 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ jobs:
strategy:
matrix:
include:
- php: 8.4
laravel: ^11.0
- php: 8.3
laravel: ^11.0
- php: 8.2
Expand Down
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
},
"require-dev": {
"orchestra/testbench": ">=6.15",
"squizlabs/php_codesniffer": "^3.5",
"phpunit/phpunit": "<11"
"phpstan/phpstan": "^2.0",
"phpunit/phpunit": "<11",
"squizlabs/php_codesniffer": "^3.5"
},
"autoload": {
"psr-4": {
Expand All @@ -32,6 +33,7 @@
"test": "./vendor/bin/phpunit --no-coverage",
"phpsniff": "vendor/bin/phpcs --standard=\"PSR12\" ./src --ignore=./src/resources/*",
"phpfix": "vendor/bin/phpcbf --standard=\"PSR12\" ./src --ignore=./src/resources/*",
"phpstan": "./vendor/bin/phpstan",
"post-autoload-dump": [
"@php ./vendor/bin/testbench package:discover --ansi"
]
Expand Down
6 changes: 6 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
level: 8
paths:
- src
ignoreErrors:
- identifier: missingType.generics
14 changes: 7 additions & 7 deletions src/AmpersandServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class AmpersandServiceProvider extends ServiceProvider
{
public function boot()
public function boot(): void
{
if ($this->app->runningInConsole()) {
$this->publishes([
Expand All @@ -24,7 +24,7 @@ public function boot()
}
}

public function register()
public function register(): void
{
$this->setup();
$this->registerRepositories();
Expand All @@ -33,20 +33,20 @@ public function register()
$this->app->register(RouteServiceProvider::class);
}

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

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

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

// Overload sheets config to avoid local conflicts
$this->app['config']->set('sheets.collections', [
config()->set('sheets.collections', [
'posts' => [
'disk' => 'ampersand::posts',
'sheet_class' => Post::class,
Expand All @@ -57,12 +57,12 @@ private function setup()
]);
}

private function registerRepositories()
private function registerRepositories(): void
{
$this->app->singleton(PostRepository::class);
}

private function registerCommands()
private function registerCommands(): void
{
$this->commands([
NewPost::class
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/NewPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function handle(): void
$file = sprintf('%s.%s.md', $date->format('Y-m-d'), Str::slug($title));

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

$directory = config('ampersand.posts_path');
Expand Down
9 changes: 5 additions & 4 deletions src/Http/Controllers/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Olssonm\Ampersand\Http\Controllers;

use Illuminate\Http\Response;
use Olssonm\Ampersand\Models\Post;
use Olssonm\Ampersand\Repositories\PostRepository;

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

public function index()
public function index(): Response
{
return view('ampersand::index', [
return response()->view('ampersand::index', [
'posts' => $this->postRepository->paginate(
config('ampersand.per_page'),
config('ampersand.page_indicator'),
)
]);
}

public function show(Post $post)
public function show(Post $post): Response
{
return view('ampersand::show', [
return response()->view('ampersand::show', [
'post' => $post
]);
}
Expand Down
9 changes: 8 additions & 1 deletion src/Models/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

namespace Olssonm\Ampersand\Models;

use AllowDynamicProperties;
use Carbon\Carbon;
use Olssonm\Ampersand\Repositories\PostRepository;
use Olssonm\Ampersand\Services\Model;

/**
* @property string $slug
*/
#[AllowDynamicProperties]
class Post extends Model
{
public function getRouteKey(): string
Expand All @@ -28,8 +33,10 @@ public function getDateAttribute(): Carbon
return Carbon::parse($this->attributes['date']);
}

public static function __callStatic($name, $arguments)
/** @phpstan-ignore-next-line */
public static function __callStatic(string $name, array $arguments): mixed
{
/** @phpstan-ignore-next-line */
return call_user_func_array([app(PostRepository::class), $name], $arguments);
}
}
3 changes: 2 additions & 1 deletion src/Repositories/PostRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ public function find(string $slug): Post
{
$post = $this->all()->where('slug', $slug)->first();

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

return $post;
}

public function paginate($perPage = 10, $pageName = 'page'): LengthAwarePaginator
public function paginate(int $perPage = 10, string $pageName = 'page'): LengthAwarePaginator
{
$page = LengthAwarePaginator::resolveCurrentPage($pageName, 1);

Expand Down
2 changes: 2 additions & 0 deletions src/Services/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@

abstract class Model extends Sheet implements UrlRoutable
{
/** @phpstan-ignore return.missing */
public function resolveRouteBinding($value, $field = null)
{
}

/** @phpstan-ignore return.missing */
public function resolveChildRouteBinding($childType, $value, $field)
{
}
Expand Down
Loading