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

Add PHPStan to base mantle #197

Merged
merged 2 commits into from
Aug 29, 2023
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
7 changes: 6 additions & 1 deletion .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ jobs:
coding-standards:
uses: alleyinteractive/.github/.github/workflows/php-coding-standards.yml@main
with:
php: '8.2'
php: 8.2
phpstan:
uses: alleyinteractive/.github/.github/workflows/php-code-quality.yml@main
with:
command: "phpstan"
php: 8.2
2 changes: 1 addition & 1 deletion app/console/class-kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Kernel extends Console_Kernel {
/**
* The commands provided by the application.
*
* @var array
* @var array<int, class-string<\Mantle\Console\Command>>
*/
protected $commands = [
// ...
Expand Down
8 changes: 4 additions & 4 deletions app/exceptions/class-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Handler extends Base_Handler {
/**
* A list of the exception types that are not reported.
*
* @var string[]
* @var array<int, class-string<\Throwable>>
*/
protected $dont_report = [
// ...
Expand All @@ -29,7 +29,7 @@ class Handler extends Base_Handler {
*
* @param Throwable $exception Exception thrown.
*/
public function report( Throwable $exception ) {
public function report( Throwable $exception ): void {
parent::report( $exception );
}

Expand All @@ -38,9 +38,9 @@ public function report( Throwable $exception ) {
*
* @param \Mantle\Http\Request $request Request object.
* @param \Throwable $exception Exception thrown.
* @return \Symfony\Component\HttpFoundation\Response
* @return mixed
*/
public function render( $request, Throwable $exception ) {
public function render( $request, Throwable $exception ): mixed {
return parent::render( $request, $exception );
}
}
6 changes: 3 additions & 3 deletions app/http/class-kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ class Kernel extends Http_Kernel {
*
* These middleware are run during every request to your application.
*
* @var array
* @var array<int, callable|class-string>
*/
protected $middleware = [];

/**
* The application's route middleware groups.
*
* @var array
* @var array<string, array<int, callable|class-string>>
*/
protected $middleware_groups = [
'web' => [
Expand All @@ -43,7 +43,7 @@ class Kernel extends Http_Kernel {
*
* These middleware may be assigned to groups or used individually.
*
* @var array
* @var array<string, callable|class-string>
*/
protected $route_middleware = [
'can' => \Mantle\Auth\Middleware\Authorize::class,
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/class-example-job.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Example_Job implements Job, Can_Queue {
/**
* Handle the job.
*/
public function handle() {
public function handle(): void {
// Handle it here!
}
}
7 changes: 4 additions & 3 deletions app/providers/class-app-service-provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace App\Providers;

use Mantle\Application\App_Service_Provider as Service_Provider;
use Mantle\Scheduling\Schedule;

/**
* Application Service Provider
Expand All @@ -16,14 +17,14 @@ class App_Service_Provider extends Service_Provider {
/**
* Register any application services.
*/
public function register() {
public function register(): void {
// Add application registration here.
}

/**
* Bootstrap any application services.
*/
public function boot() {
public function boot(): void {
// Boot the application here.
}

Expand All @@ -32,7 +33,7 @@ public function boot() {
*
* @param \Mantle\Scheduling\Schedule $schedule Scheduler instance.
*/
protected function schedule( $schedule ) {
protected function schedule( $schedule ): void {
// Schedule any commands, jobs, callbacks, etc. here.
}
}
4 changes: 2 additions & 2 deletions app/providers/class-asset-service-provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public function boot() {
/**
* Filter the asset conditions for the site.
*
* @param array $conditions Conditions to filter.
* @return array
* @param array<string, boolean> $conditions Conditions to filter.
* @return array<string, boolean>
*/
public function on_am_asset_conditions( array $conditions ): array {
// Perform any modifications here.
Expand Down
6 changes: 2 additions & 4 deletions app/providers/class-event-service-provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Event_Service_Provider extends Service_Provider {
/**
* The event listener mappings for the application.
*
* @var array
* @var array<string, array<int, class-string>>
*/
protected $listen = [
/**
Expand All @@ -35,10 +35,8 @@ class Event_Service_Provider extends Service_Provider {

/**
* Register any other events for your application.
*
* @return void
*/
public function boot() {
public function boot(): void {
// ...
}

Expand Down
4 changes: 2 additions & 2 deletions app/providers/class-route-service-provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Route_Service_Provider extends Service_Provider {
/**
* Bootstrap any application services.
*/
public function boot() {
public function boot(): void {
parent::boot();

$this->allow_pass_through_requests();
Expand All @@ -26,7 +26,7 @@ public function boot() {
/**
* Define routes for the application.
*/
public function map() {
public function map(): void {
Route::middleware( 'web' )->group( base_path( 'routes/web.php' ) );
Route::middleware( 'rest-api' )->group( base_path( 'routes/rest-api.php' ) );
}
Expand Down
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
"require-dev": {
"alleyinteractive/alley-coding-standards": "^1.0",
"nunomaduro/collision": "^6.4",
"phpstan/phpstan": "1.10.15",
"phpunit/phpunit": "^9.6.10",
"szepeviktor/phpstan-wordpress": "^1.3",
"wp-coding-standards/wpcs": "dev-php-8-1 as 2.3.x-dev"
},
"config": {
Expand Down Expand Up @@ -53,10 +55,14 @@
"bin/mantle package:discover",
"bin/mantle model:discover"
],
"lint": "@phpcs",
"lint": [
"@phpcs",
"@phpstan"
],
"lint:fix": "@phpcbf",
"phpcbf": "phpcbf --standard=./phpcs.xml .",
"phpcs": "phpcs --standard=./phpcs.xml .",
"phpstan": "phpstan --memory-limit=512M",
"phpunit": "phpunit",
"test": [
"@lint",
Expand Down
4 changes: 2 additions & 2 deletions database/factory/class-category-factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ class Category_Factory extends \Mantle\Database\Factory\Term_Factory {
/**
* Model to use when creating objects.
*
* @var class-string
* @var class-string<\Mantle\Database\Model\Model>
*/
protected string $model = Category::class;

/**
* Define the model's default state.
*
* @return array
* @return array<string, mixed>
*/
public function definition(): array {
return [
Expand Down
4 changes: 2 additions & 2 deletions database/factory/class-post-factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ class Post_Factory extends \Mantle\Database\Factory\Post_Factory {
/**
* Model to use when creating objects.
*
* @var class-string
* @var class-string<\Mantle\Database\Model\Model>
*/
protected string $model = Post::class;

/**
* Define the model's default state.
*
* @return array
* @return array<string, mixed>
*/
public function definition(): array {
return [
Expand Down
4 changes: 2 additions & 2 deletions database/factory/class-tag-factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ class Tag_Factory extends \Mantle\Database\Factory\Term_Factory {
/**
* Model to use when creating objects.
*
* @var class-string
* @var class-string<\Mantle\Database\Model\Model>
*/
protected string $model = Tag::class;

/**
* Define the model's default state.
*
* @return array
* @return array<string, mixed>
*/
public function definition(): array {
return [
Expand Down
2 changes: 1 addition & 1 deletion database/seeds/class-database-seeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Database_Seeder extends Seeder {
/**
* Run the seeder.
*/
public function run() {
public function run(): void {
// Call additional seeders...
}
}
1 change: 1 addition & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<!-- Set severity to 1 to see everything that isn't effectively turned off. -->
<arg name="severity" value="1" />

<exclude-pattern>build/</exclude-pattern>
<exclude-pattern>tests/</exclude-pattern>
<exclude-pattern>bootstrap/cache</exclude-pattern>
<exclude-pattern>storage/framework/views</exclude-pattern>
Expand Down
16 changes: 16 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
includes:
- vendor/szepeviktor/phpstan-wordpress/extension.neon

parameters:
level: 8

paths:
- mantle.php
- app/
- config/
- database/
- routes/
- views/

# ignoreErrors:
# - "..."
2 changes: 1 addition & 1 deletion routes/console.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
*/

Console::command( 'hello {name}', function ( $name ) {
$this->info( "Hello, {$name}!" );
$this->info( "Hello, {$name}!" ); // @phpstan-ignore-line Undefined variable
} )->describe( 'Greet a user by name' );
2 changes: 1 addition & 1 deletion views/error/error.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<body>
<div class="flex-center position-ref full-height">
<div class="code">
<?php echo (int) mantle_get_var( 'code' ); ?>
<?php echo esc_html( mantle_get_var( 'code' ) ); ?>
</div>

<div class="message" style="padding: 10px;">
Expand Down