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

Alley Coding Standards 2.0 #199

Merged
merged 2 commits into from
Nov 17, 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
3 changes: 2 additions & 1 deletion app/jobs/class-example-job.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
* Example Job that can be queued.
*/
class Example_Job implements Job, Can_Queue {
use Queueable, Dispatchable;
use Queueable;
use Dispatchable;

/**
* Handle the job.
Expand Down
2 changes: 1 addition & 1 deletion app/models/class-category.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Category extends Term {
*
* @return Has_Many
*/
public function posts() : Has_Many {
public function posts(): Has_Many {
return $this->has_many( Post::class );
}
}
2 changes: 1 addition & 1 deletion app/models/class-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function category() {
*
* @return Has_Many
*/
public function tags() : Has_Many {
public function tags(): Has_Many {
return $this->has_many( Tag::class );
}
}
2 changes: 1 addition & 1 deletion app/models/class-tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Tag extends Term {
*
* @return Has_Many
*/
public function posts() : Has_Many {
public function posts(): Has_Many {
return $this->has_many( Post::class );
}
}
6 changes: 3 additions & 3 deletions app/providers/class-asset-service-provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ public function boot() {
|
| Enqueue a raw asset using the asset() helper:
|
| asset()->script( 'example-entry' )->async()->src( asset_loader( '/app.js' ) );
| asset()->style( 'example-entry' )->condition( 'single' )->src( asset_loader( '/app.css' ) );
| asset()->script( 'example-entry' )->async()->src( asset_loader( '/app.js' ) );
| asset()->style( 'example-entry' )->condition( 'single' )->src( asset_loader( '/app.css' ) );
|
| Enqueue an asset with dependencies from @wordpress/dependency-extraction-webpack-plugin:
|
| asset()->script( 'example-block' )->src( asset_loader( '/example-block.js' ) )->dependencies( asset_loader()->dependencies( '/example-block.js' ) );
| asset()->script( 'example-block' )->src( asset_loader( '/example-block.js' ) )->dependencies( asset_loader()->dependencies( '/example-block.js' ) );
|
| Get cookin'!
|
Expand Down
11 changes: 2 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@
"fakerphp/faker": "^1.23"
},
"require-dev": {
"alleyinteractive/alley-coding-standards": "^1.0",
"alleyinteractive/alley-coding-standards": "^2.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"
"szepeviktor/phpstan-wordpress": "^1.3"
},
"config": {
"allow-plugins": {
Expand All @@ -44,12 +43,6 @@
},
"minimum-stability": "dev",
"prefer-stable": true,
"repositories": [
{
"type": "vcs",
"url": "https://github.com/alleyinteractive/WordPress-Coding-Standards"
}
],
"scripts": {
"post-autoload-dump": [
"bin/mantle package:discover",
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 @@ -15,13 +15,13 @@
/**
* Category Factory
*
* @extends \Mantle\Database\Factory\Term_Factory<\App\Models\Category>
* @extends \Mantle\Database\Factory\Term_Factory<\App\Models\Category, \WP_Term, \App\Models\Category>
*/
class Category_Factory extends \Mantle\Database\Factory\Term_Factory {
/**
* Model to use when creating objects.
*
* @var class-string<\Mantle\Database\Model\Model>
* @var class-string<\App\Models\Category>
*/
protected string $model = Category::class;

Expand Down
6 changes: 3 additions & 3 deletions database/factory/class-post-factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
/**
* Post Factory
*
* @extends \Mantle\Database\Factory\Post_Factory<\App\Models\Post>
* @extends \Mantle\Database\Factory\Post_Factory<\App\Models\Post, \WP_Post, \App\Models\Post>
*/
class Post_Factory extends \Mantle\Database\Factory\Post_Factory {
/**
* Model to use when creating objects.
*
* @var class-string<\Mantle\Database\Model\Model>
* @var class-string<\App\Models\Post>
*/
protected string $model = Post::class;

Expand All @@ -33,7 +33,7 @@ class Post_Factory extends \Mantle\Database\Factory\Post_Factory {
public function definition(): array {
return [
'post_title' => $this->faker->sentence(),
'post_content' => trim( $this->faker->paragraph_blocks( 3 ) ),
'post_content' => trim( $this->faker->paragraph_blocks( 3 ) ), // @phpstan-ignore-line undefined method
'post_status' => 'publish',
'post_type' => 'post',
];
Comment on lines 33 to 39
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of @phpstan-ignore-line is generally discouraged as it suppresses static analysis for that line. If the method paragraph_blocks is indeed undefined, it would be better to define it or to use an alternative method that exists. If the method is defined in a class not analyzed by PHPStan (e.g., a magic method or in a trait), adding that class to PHPStan's configuration might be a better solution. If the method is part of a third-party package that is not correctly analyzed, consider contributing a stub file to the package or to PHPStan's repository.

// If the paragraph_blocks method is undefined, consider replacing it with a defined method.
'post_content' => trim( $this->faker->text(200) ), // Assuming text is a defined method

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 @@ -15,13 +15,13 @@
/**
* Tag Factory
*
* @extends \Mantle\Database\Factory\Term_Factory<\App\Models\Tag>
* @extends \Mantle\Database\Factory\Term_Factory<\App\Models\Tag, \WP_Term, \App\Models\Tag>
*/
class Tag_Factory extends \Mantle\Database\Factory\Term_Factory {
/**
* Model to use when creating objects.
*
* @var class-string<\Mantle\Database\Model\Model>
* @var class-string<\App\Models\Tag>
*/
protected string $model = Tag::class;

Expand Down
2 changes: 1 addition & 1 deletion mantle.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
if ( ! file_exists( __DIR__ . '/vendor/wordpress-autoload.php' ) ) {
add_action(
'admin_notices',
function() {
function () {
printf(
'<div class="notice notice-error"><p>%s</p></div>',
esc_html__( 'Mantle requires a `composer install` to run properly.', 'mantle' )
Expand Down
8 changes: 4 additions & 4 deletions routes/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
|
| Register a closure-based route:
|
| Route::get( '/closure-route', function( \WP_REST_Request $request ) {
| dd( $request );
| } );
| Route::get( '/closure-route', function( \WP_REST_Request $request ) {
| dd( $request );
| } );
|
*/

Route::rest_api( '/example-namespace', function() {
Route::rest_api( '/example-namespace', function () {
//
} );
14 changes: 7 additions & 7 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@
|
| Register a controller route:
|
| Route::get( '/controller-route', Example_Controller::class . '@method_to_call' );
| Route::get( '/controller-route', Example_Controller::class . '@method_to_call' );
|
| Register a closure-based route:
|
| Route::get( '/closure-route', function( \Mantle\Http\Request $request ) {
| dd( $request->all() );
| } );
| Route::get( '/closure-route', function( \Mantle\Http\Request $request ) {
| dd( $request->all() );
| } );
|
| Register a route with variables:
|
| Route::get( '/hello/{who}', function( $name ) {
| return "Why hello {$name}!";
| } );
| Route::get( '/hello/{who}', function( $name ) {
| return "Why hello {$name}!";
| } );
|
*/