From 78df8705f6c95e1f125eba717369fcf9119827fc Mon Sep 17 00:00:00 2001 From: Daryll Doyle Date: Thu, 11 Sep 2025 17:32:10 +0100 Subject: [PATCH 1/2] Add Rector for upgrades --- composer.json | 8 +- composer.lock | 207 +++++++++++++++++++++++++++++++++++++++++++++++++- phpstan.neon | 6 ++ rector.php | 27 +++++++ 4 files changed, 246 insertions(+), 2 deletions(-) create mode 100644 rector.php diff --git a/composer.json b/composer.json index a97cfc4..813c5bb 100644 --- a/composer.json +++ b/composer.json @@ -43,7 +43,9 @@ "10up/phpcs-composer": "^3.0", "phpcompatibility/php-compatibility": "dev-develop as 9.99.99", "phpunit/php-code-coverage": "^9.2", - "slevomat/coding-standard": "^8.15" + "slevomat/coding-standard": "^8.15", + "rector/rector": "^2.0", + "tomasvotruba/type-coverage": "^2.0" }, "scripts": { "test": "XDEBUG_MODE=coverage ./vendor/bin/phpunit", @@ -52,6 +54,10 @@ "static": [ "Composer\\Config::disableProcessTimeout", "phpstan --memory-limit=1G" + ], + "rector": [ + "./vendor/bin/rector", + "composer run lint-fix" ] }, "config": { diff --git a/composer.lock b/composer.lock index 7f69bb0..f386d5f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "5c674b2bd34e9e2105a937d69259c184", + "content-hash": "88da233f8a52d5119878cc443defdcdd", "packages": [ { "name": "amphp/amp", @@ -2329,6 +2329,95 @@ ], "time": "2025-02-12T12:17:51+00:00" }, + { + "name": "nette/utils", + "version": "v4.0.8", + "source": { + "type": "git", + "url": "https://github.com/nette/utils.git", + "reference": "c930ca4e3cf4f17dcfb03037703679d2396d2ede" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nette/utils/zipball/c930ca4e3cf4f17dcfb03037703679d2396d2ede", + "reference": "c930ca4e3cf4f17dcfb03037703679d2396d2ede", + "shasum": "" + }, + "require": { + "php": "8.0 - 8.5" + }, + "conflict": { + "nette/finder": "<3", + "nette/schema": "<1.2.2" + }, + "require-dev": { + "jetbrains/phpstorm-attributes": "^1.2", + "nette/tester": "^2.5", + "phpstan/phpstan-nette": "^2.0@stable", + "tracy/tracy": "^2.9" + }, + "suggest": { + "ext-gd": "to use Image", + "ext-iconv": "to use Strings::webalize(), toAscii(), chr() and reverse()", + "ext-intl": "to use Strings::webalize(), toAscii(), normalize() and compare()", + "ext-json": "to use Nette\\Utils\\Json", + "ext-mbstring": "to use Strings::lower() etc...", + "ext-tokenizer": "to use Nette\\Utils\\Reflection::getUseStatements()" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + }, + "autoload": { + "psr-4": { + "Nette\\": "src" + }, + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause", + "GPL-2.0-only", + "GPL-3.0-only" + ], + "authors": [ + { + "name": "David Grudl", + "homepage": "https://davidgrudl.com" + }, + { + "name": "Nette Community", + "homepage": "https://nette.org/contributors" + } + ], + "description": "🛠 Nette Utils: lightweight utilities for string & array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.", + "homepage": "https://nette.org", + "keywords": [ + "array", + "core", + "datetime", + "images", + "json", + "nette", + "paginator", + "password", + "slugify", + "string", + "unicode", + "utf-8", + "utility", + "validation" + ], + "support": { + "issues": "https://github.com/nette/utils/issues", + "source": "https://github.com/nette/utils/tree/v4.0.8" + }, + "time": "2025-08-06T21:43:34+00:00" + }, { "name": "nikic/php-parser", "version": "v5.4.0", @@ -3573,6 +3662,65 @@ ], "time": "2024-12-05T13:48:26+00:00" }, + { + "name": "rector/rector", + "version": "2.0.10", + "source": { + "type": "git", + "url": "https://github.com/rectorphp/rector.git", + "reference": "5844a718acb40f40afcd110394270afa55509fd0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/rectorphp/rector/zipball/5844a718acb40f40afcd110394270afa55509fd0", + "reference": "5844a718acb40f40afcd110394270afa55509fd0", + "shasum": "" + }, + "require": { + "php": "^7.4|^8.0", + "phpstan/phpstan": "^2.1.6" + }, + "conflict": { + "rector/rector-doctrine": "*", + "rector/rector-downgrade-php": "*", + "rector/rector-phpunit": "*", + "rector/rector-symfony": "*" + }, + "suggest": { + "ext-dom": "To manipulate phpunit.xml via the custom-rule command" + }, + "bin": [ + "bin/rector" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Instant Upgrade and Automated Refactoring of any PHP code", + "keywords": [ + "automation", + "dev", + "migration", + "refactoring" + ], + "support": { + "issues": "https://github.com/rectorphp/rector/issues", + "source": "https://github.com/rectorphp/rector/tree/2.0.10" + }, + "funding": [ + { + "url": "https://github.com/tomasvotruba", + "type": "github" + } + ], + "time": "2025-03-03T17:35:18+00:00" + }, { "name": "sebastian/cli-parser", "version": "1.0.2", @@ -4854,6 +5002,63 @@ ], "time": "2024-03-03T12:36:25+00:00" }, + { + "name": "tomasvotruba/type-coverage", + "version": "2.0.2", + "source": { + "type": "git", + "url": "https://github.com/TomasVotruba/type-coverage.git", + "reference": "d033429580f2c18bda538fa44f2939236a990e0c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/TomasVotruba/type-coverage/zipball/d033429580f2c18bda538fa44f2939236a990e0c", + "reference": "d033429580f2c18bda538fa44f2939236a990e0c", + "shasum": "" + }, + "require": { + "nette/utils": "^3.2 || ^4.0", + "php": "^7.4 || ^8.0", + "phpstan/phpstan": "^2.0" + }, + "type": "phpstan-extension", + "extra": { + "phpstan": { + "includes": [ + "config/extension.neon" + ] + } + }, + "autoload": { + "psr-4": { + "TomasVotruba\\TypeCoverage\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Measure type coverage of your project", + "keywords": [ + "phpstan-extension", + "static analysis" + ], + "support": { + "issues": "https://github.com/TomasVotruba/type-coverage/issues", + "source": "https://github.com/TomasVotruba/type-coverage/tree/2.0.2" + }, + "funding": [ + { + "url": "https://www.paypal.me/rectorphp", + "type": "custom" + }, + { + "url": "https://github.com/tomasvotruba", + "type": "github" + } + ], + "time": "2025-01-07T00:10:26+00:00" + }, { "name": "wp-coding-standards/wpcs", "version": "3.1.0", diff --git a/phpstan.neon b/phpstan.neon index 4d9795d..b6c7924 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,6 +1,7 @@ includes: - vendor/szepeviktor/phpstan-wordpress/extension.neon - vendor/phpstan/phpstan-deprecation-rules/rules.neon + - vendor/tomasvotruba/type-coverage/config/extension.neon parameters: paths: @@ -16,3 +17,8 @@ parameters: - '#^Function remove_filter invoked with [34567] parameters, 2-3 required\.$#' # Remove issues that come from using array as a type rather than string[] or array etc. - '#no value type specified in iterable type array#' + type_coverage: + return: 99 + param: 99 + property: 99 + constant: 99 diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..fac46ff --- /dev/null +++ b/rector.php @@ -0,0 +1,27 @@ +withPaths([ + __DIR__ . '/src', + __DIR__ . '/fixtures', + ]) + ->withSkip([ + __DIR__ . '/**/node_modules/**', + __DIR__ . '/**/vendor/**', + __DIR__ . '/**/dist/**', + + ]) + ->withPhpSets(php83: true) + ->withTypeCoverageLevel(49) + ->withSkip([ + Rector\Php81\Rector\Array_\FirstClassCallableRector::class, + Rector\Php83\Rector\ClassMethod\AddOverrideAttributeToOverriddenMethodsRector::class, + Rector\Php70\Rector\StmtsAwareInterface\IfIssetToCoalescingRector::class, + Rector\Php53\Rector\Ternary\TernaryToElvisRector::class, + Rector\Php81\Rector\Property\ReadOnlyPropertyRector::class, + ]); From c70f6cdc8ddd829cdcd473813fa1813f28aac740 Mon Sep 17 00:00:00 2001 From: Daryll Doyle Date: Thu, 11 Sep 2025 17:39:43 +0100 Subject: [PATCH 2/2] Add types --- fixtures/classes/PostTypes/Demo.php | 14 +++--- fixtures/classes/PostTypes/Page.php | 6 +-- fixtures/classes/PostTypes/Post.php | 6 +-- fixtures/classes/Standalone/Standalone.php | 2 +- fixtures/classes/Taxonomies/Demo.php | 8 ++-- src/Assets/GetAssetInfo.php | 10 ++--- src/Module.php | 12 ++--- src/ModuleInitialization.php | 44 +++++++------------ src/ModuleInterface.php | 12 ++--- src/PostTypes/AbstractCorePostType.php | 23 +++------- src/PostTypes/AbstractPostType.php | 51 ++++++---------------- src/Taxonomies/AbstractTaxonomy.php | 35 +++++---------- 12 files changed, 73 insertions(+), 150 deletions(-) diff --git a/fixtures/classes/PostTypes/Demo.php b/fixtures/classes/PostTypes/Demo.php index 410cf46..8e5c515 100644 --- a/fixtures/classes/PostTypes/Demo.php +++ b/fixtures/classes/PostTypes/Demo.php @@ -21,7 +21,7 @@ class Demo extends AbstractPostType { * * @return string */ - public function get_name() { + public function get_name(): string { return 'tenup-demo'; } @@ -30,7 +30,7 @@ public function get_name() { * * @return string */ - public function get_singular_label() { + public function get_singular_label(): string { return esc_html__( 'Demo', 'tenup-plugin' ); } @@ -39,7 +39,7 @@ public function get_singular_label() { * * @return string */ - public function get_plural_label() { + public function get_plural_label(): string { return esc_html__( 'Demos', 'tenup-plugin' ); } @@ -52,7 +52,7 @@ public function get_plural_label() { * * @return string */ - public function get_menu_icon() { + public function get_menu_icon(): string { return 'dashicons-chart-pie'; } @@ -61,7 +61,7 @@ public function get_menu_icon() { * * @return bool */ - public function can_register() { + public function can_register(): bool { return true; } @@ -71,7 +71,7 @@ public function can_register() { * * @return array */ - public function get_supported_taxonomies() { + public function get_supported_taxonomies(): array { return [ 'tenup-tax-demo', ]; @@ -82,7 +82,7 @@ public function get_supported_taxonomies() { * * @return void */ - public function after_register() { + public function after_register(): void { // Register any hooks/filters you need. } } diff --git a/fixtures/classes/PostTypes/Page.php b/fixtures/classes/PostTypes/Page.php index fa360d4..7815534 100644 --- a/fixtures/classes/PostTypes/Page.php +++ b/fixtures/classes/PostTypes/Page.php @@ -24,7 +24,7 @@ class Page extends AbstractCorePostType { * * @return string */ - public function get_name() { + public function get_name(): string { return 'page'; } @@ -34,7 +34,7 @@ public function get_name() { * * @return array */ - public function get_supported_taxonomies() { + public function get_supported_taxonomies(): array { return []; } @@ -43,7 +43,7 @@ public function get_supported_taxonomies() { * * @return void */ - public function after_register() { + public function after_register(): void { // Do nothing. } } diff --git a/fixtures/classes/PostTypes/Post.php b/fixtures/classes/PostTypes/Post.php index ce4a28c..21c93ab 100644 --- a/fixtures/classes/PostTypes/Post.php +++ b/fixtures/classes/PostTypes/Post.php @@ -24,7 +24,7 @@ class Post extends AbstractCorePostType { * * @return string */ - public function get_name() { + public function get_name(): string { return 'post'; } @@ -36,7 +36,7 @@ public function get_name() { * * @return array */ - public function get_supported_taxonomies() { + public function get_supported_taxonomies(): array { return []; } @@ -45,7 +45,7 @@ public function get_supported_taxonomies() { * * @return void */ - public function after_register() { + public function after_register(): void { // Do nothing. } } diff --git a/fixtures/classes/Standalone/Standalone.php b/fixtures/classes/Standalone/Standalone.php index d52c2b8..94bfdb7 100644 --- a/fixtures/classes/Standalone/Standalone.php +++ b/fixtures/classes/Standalone/Standalone.php @@ -27,7 +27,7 @@ public function __construct() { * * @return void */ - public function init() { + public function init(): void { echo 'Hello from the Standalone class!'; } } diff --git a/fixtures/classes/Taxonomies/Demo.php b/fixtures/classes/Taxonomies/Demo.php index de86cc6..281dc6b 100644 --- a/fixtures/classes/Taxonomies/Demo.php +++ b/fixtures/classes/Taxonomies/Demo.php @@ -21,7 +21,7 @@ class Demo extends AbstractTaxonomy { * * @return string */ - public function get_name() { + public function get_name(): string { return 'tenup-tax-demo'; } @@ -30,7 +30,7 @@ public function get_name() { * * @return string */ - public function get_singular_label() { + public function get_singular_label(): string { return esc_html__( 'Demo Term', 'tenup-plugin' ); } @@ -39,7 +39,7 @@ public function get_singular_label() { * * @return string */ - public function get_plural_label() { + public function get_plural_label(): string { return esc_html__( 'Demo Terms', 'tenup-plugin' ); } @@ -48,7 +48,7 @@ public function get_plural_label() { * * @return bool */ - public function can_register() { + public function can_register(): bool { return true; } } diff --git a/src/Assets/GetAssetInfo.php b/src/Assets/GetAssetInfo.php index 5241f31..f2d13a3 100644 --- a/src/Assets/GetAssetInfo.php +++ b/src/Assets/GetAssetInfo.php @@ -23,24 +23,22 @@ trait GetAssetInfo { * * @var ?string */ - public $dist_path = null; + public ?string $dist_path = null; /** * Fallback version to use if asset file is not found * * @var ?string */ - public $fallback_version = null; + public ?string $fallback_version = null; /** * Setup asset variables * * @param string $dist_path Path to the dist directory * @param string $fallback_version Fallback version to use if asset file is not found - * - * @return void */ - public function setup_asset_vars( string $dist_path, string $fallback_version ) { + public function setup_asset_vars( string $dist_path, string $fallback_version ): void { $this->dist_path = trailingslashit( $dist_path ); $this->fallback_version = $fallback_version; } @@ -55,7 +53,7 @@ public function setup_asset_vars( string $dist_path, string $fallback_version ) * * @return string|($attribute is null ? array{version: string, dependencies: array} : $attribute is'dependencies' ? array : string) */ - public function get_asset_info( string $slug, ?string $attribute = null ) { + public function get_asset_info( string $slug, ?string $attribute = null ): string|array { if ( is_null( $this->dist_path ) || is_null( $this->fallback_version ) ) { throw new RuntimeException( 'Asset variables not set. Please run setup_asset_vars() before calling get_asset_info().' ); diff --git a/src/Module.php b/src/Module.php index fc67ebf..a4fc4c7 100644 --- a/src/Module.php +++ b/src/Module.php @@ -20,24 +20,18 @@ trait Module { * Lower number will be initialized first. * * @note This has no correlation to the `init` priority. It's just a way to allow certain classes to be initialized before others. - * - * @return int The priority of the module. */ - public function load_order() { + public function load_order(): int { return 10; } /** * Checks whether the Module should run within the current context. - * - * @return bool */ - abstract public function can_register(); + abstract public function can_register(): bool; /** * Connects the Module with WordPress using Hooks and/or Filters. - * - * @return void */ - abstract public function register(); + abstract public function register(): void; } diff --git a/src/ModuleInitialization.php b/src/ModuleInitialization.php index 5c53d4b..01271cd 100644 --- a/src/ModuleInitialization.php +++ b/src/ModuleInitialization.php @@ -24,16 +24,14 @@ class ModuleInitialization { /** * The class instance. * - * @var null|ModuleInitialization + * @var ?\TenupFramework\ModuleInitialization */ - private static $instance = null; + private static ?\TenupFramework\ModuleInitialization $instance = null; /** * Get the instance of the class. - * - * @return ModuleInitialization */ - public static function instance() { + public static function instance(): \TenupFramework\ModuleInitialization { if ( null === self::$instance ) { self::$instance = new self(); } @@ -52,7 +50,7 @@ private function __construct() { * * @var array */ - protected $classes = []; + protected array $classes = []; /** * Get all the TenupFramework plugin classes. @@ -61,7 +59,7 @@ private function __construct() { * * @return array */ - public function get_classes( $dir ) { + public function get_classes( string $dir ): array { $this->directory_check( $dir ); // Get all classes from this directory and its subdirectories. @@ -77,7 +75,8 @@ public function get_classes( $dir ) { ); } - $classes = array_filter( $class_finder->get(), fn( $cl ) => is_string( $cl ) ); + // @phpstan-ignore-next-line typeCoverage.paramTypeCoverage + $classes = array_filter( $class_finder->get(), fn( $cl ): bool => is_string( $cl ) ); // Return the classes return $classes; @@ -89,10 +88,8 @@ public function get_classes( $dir ) { * @param string $dir The directory to check. * * @throws \RuntimeException If the directory does not exist. - * - * @return bool */ - protected function directory_check( $dir ): bool { + protected function directory_check( ?string $dir ): bool { if ( empty( $dir ) ) { throw new \RuntimeException( 'Directory is required to initialize classes.' ); } @@ -109,13 +106,12 @@ protected function directory_check( $dir ): bool { * Initialize all the TenupFramework plugin classes. * * @param string $dir The directory to search for classes. - * - * @return void */ - public function init_classes( $dir = '' ) { + public function init_classes( ?string $dir = '' ): void { $this->directory_check( $dir ); $load_class_order = []; + // @phpstan-ignore-next-line argument.type foreach ( $this->get_classes( $dir ) as $class ) { // Create a slug for the class name. $slug = $this->slugify_class_name( $class ); @@ -138,7 +134,7 @@ public function init_classes( $dir = '' ) { } // Check if the class implements ModuleInterface before instantiating it - if ( ! $reflection_class->implementsInterface( 'TenupFramework\ModuleInterface' ) ) { + if ( ! $reflection_class->implementsInterface( \TenupFramework\ModuleInterface::class ) ) { continue; } @@ -181,8 +177,6 @@ public function init_classes( $dir = '' ) { * * @param string $class_name The name of the class to load. * - * @return false|ReflectionClass Returns a ReflectionClass instance if the class is loadable, or false if it is not. - * * @phpstan-ignore missingType.generics */ public function get_fully_loadable_class( string $class_name ): false|ReflectionClass { @@ -190,7 +184,7 @@ public function get_fully_loadable_class( string $class_name ): false|Reflection // Create a new reflection of the class. // @phpstan-ignore argument.type return new ReflectionClass( $class_name ); - } catch ( \Throwable $e ) { + } catch ( \Throwable ) { // This includes ReflectionException, Error due to missing parent, etc. return false; } @@ -200,10 +194,8 @@ public function get_fully_loadable_class( string $class_name ): false|Reflection * Slugify a class name. * * @param string $class_name The class name. - * - * @return string */ - protected function slugify_class_name( $class_name ) { + protected function slugify_class_name( string $class_name ): string { return sanitize_title( str_replace( '\\', '-', $class_name ) ); } @@ -211,10 +203,8 @@ protected function slugify_class_name( $class_name ) { * Get a class by its full class name, including namespace. * * @param string $class_name The class name & namespace. - * - * @return false|ModuleInterface */ - public function get_class( $class_name ) { + public function get_class( string $class_name ): false|ModuleInterface { $class_name = $this->slugify_class_name( $class_name ); if ( isset( $this->classes[ $class_name ] ) ) { @@ -229,7 +219,7 @@ public function get_class( $class_name ) { * * @return array */ - public function get_all_classes() { + public function get_all_classes(): array { return $this->classes; } @@ -237,10 +227,8 @@ public function get_all_classes() { * Get an initialized class by its full class name, including namespace. * * @param string $class_name The class name including the namespace. - * - * @return false|ModuleInterface */ - public static function get_module( $class_name ) { + public static function get_module( string $class_name ): false|ModuleInterface { return self::instance()->get_class( $class_name ); } } diff --git a/src/ModuleInterface.php b/src/ModuleInterface.php index 960ec7b..b03b7e1 100644 --- a/src/ModuleInterface.php +++ b/src/ModuleInterface.php @@ -20,22 +20,16 @@ interface ModuleInterface { * Lower number will be initialized first. * * @note This has no correlation to the `init` priority. It's just a way to allow certain classes to be initialized before others. - * - * @return int The priority of the module. */ - public function load_order(); + public function load_order(): int; /** * Checks whether the Module should run within the current context. - * - * @return bool */ - public function can_register(); + public function can_register(): bool; /** * Connects the Module with WordPress using Hooks and/or Filters. - * - * @return void */ - public function register(); + public function register(): void; } diff --git a/src/PostTypes/AbstractCorePostType.php b/src/PostTypes/AbstractCorePostType.php index 1823423..4a92884 100644 --- a/src/PostTypes/AbstractCorePostType.php +++ b/src/PostTypes/AbstractCorePostType.php @@ -22,10 +22,8 @@ abstract class AbstractCorePostType extends AbstractPostType { * Get the singular post type label. * * No-op for core post types since they are already registered by WordPress. - * - * @return string */ - public function get_singular_label() { + public function get_singular_label(): string { return ''; } @@ -33,10 +31,8 @@ public function get_singular_label() { * Get the plural post type label. * * No-op for core post types since they are already registered by WordPress. - * - * @return string */ - public function get_plural_label() { + public function get_plural_label(): string { return ''; } @@ -44,10 +40,8 @@ public function get_plural_label() { * Get the menu icon for the post type. * * No-op for core post types since they are already registered by WordPress. - * - * @return string */ - public function get_menu_icon() { + public function get_menu_icon(): string { return ''; } @@ -55,23 +49,16 @@ public function get_menu_icon() { * Checks whether the Module should run within the current context. * * True for core post types since they are already registered by WordPress. - * - * @return bool */ - public function can_register() { + public function can_register(): bool { return true; } /** * Registers a post type and associates its taxonomies. - * - * @uses $this->get_name() to get the post's type name. - * @return Bool Whether this theme has supports for this post type. */ - public function register() { + public function register(): void { $this->register_taxonomies(); $this->after_register(); - - return true; } } diff --git a/src/PostTypes/AbstractPostType.php b/src/PostTypes/AbstractPostType.php index d945df3..855ae95 100644 --- a/src/PostTypes/AbstractPostType.php +++ b/src/PostTypes/AbstractPostType.php @@ -46,24 +46,18 @@ abstract class AbstractPostType implements ModuleInterface { /** * Get the post type name. - * - * @return string */ - abstract public function get_name(); + abstract public function get_name(): string; /** * Get the singular post type label. - * - * @return string */ - abstract public function get_singular_label(); + abstract public function get_singular_label(): string; /** * Get the plural post type label. - * - * @return string */ - abstract public function get_plural_label(); + abstract public function get_plural_label(): string; /** * Get the menu icon for the post type. @@ -71,26 +65,20 @@ abstract public function get_plural_label(); * This can be a base64 encoded SVG, a dashicons class or 'none' to leave it empty so it can be filled with CSS. * * @see https://developer.wordpress.org/resource/dashicons/ - * - * @return string */ - abstract public function get_menu_icon(); + abstract public function get_menu_icon(): string; /** * Get the menu position for the post type. - * - * @return int|null */ - public function get_menu_position() { + public function get_menu_position(): int|null { return null; } /** * Is the post type hierarchical? - * - * @return bool */ - public function is_hierarchical() { + public function is_hierarchical(): bool { return false; } @@ -99,7 +87,7 @@ public function is_hierarchical() { * * @return array */ - public function get_editor_supports() { + public function get_editor_supports(): array { $supports = [ 'title', 'editor', @@ -154,7 +142,7 @@ public function get_editor_supports() { * template_lock?: string|false, * } */ - public function get_options() { + public function get_options(): array { $options = [ 'labels' => $this->get_labels(), 'public' => true, @@ -182,7 +170,7 @@ public function get_options() { * * @return array */ - public function get_labels() { + public function get_labels(): array { $plural_label = $this->get_plural_label(); $singular_label = $this->get_singular_label(); @@ -225,25 +213,18 @@ public function get_labels() { /** * Registers a post type and associates its taxonomies. - * - * @uses $this->get_name() to get the post's type name. - * @return Bool Whether this theme has supports for this post type. */ - public function register() { + public function register(): void { $this->register_post_type(); $this->register_taxonomies(); $this->after_register(); - - return true; } /** * Registers the current post type with WordPress. - * - * @return void */ - public function register_post_type() { + public function register_post_type(): void { register_post_type( $this->get_name(), $this->get_options() @@ -252,10 +233,8 @@ public function register_post_type() { /** * Registers the taxonomies declared with the current post type. - * - * @return void */ - public function register_taxonomies() { + public function register_taxonomies(): void { $taxonomies = $this->get_supported_taxonomies(); $object_type = $this->get_name(); @@ -276,16 +255,14 @@ public function register_taxonomies() { * * @return array */ - public function get_supported_taxonomies() { + public function get_supported_taxonomies(): array { return []; } /** * Run any code after the post type has been registered. - * - * @return void */ - public function after_register() { + public function after_register(): void { // Do nothing. } } diff --git a/src/Taxonomies/AbstractTaxonomy.php b/src/Taxonomies/AbstractTaxonomy.php index c3dfdf3..328b0a2 100644 --- a/src/Taxonomies/AbstractTaxonomy.php +++ b/src/Taxonomies/AbstractTaxonomy.php @@ -44,40 +44,30 @@ abstract class AbstractTaxonomy implements ModuleInterface { * Used to alter the order in which classes are initialized. * * Lower number will be initialized first. - * - * @return int */ - public function load_order() { + public function load_order(): int { return 9; } /** * Get the taxonomy name. - * - * @return string */ - abstract public function get_name(); + abstract public function get_name(): string; /** * Get the singular taxonomy label. - * - * @return string */ - abstract public function get_singular_label(); + abstract public function get_singular_label(): string; /** * Get the plural taxonomy label. - * - * @return string */ - abstract public function get_plural_label(); + abstract public function get_plural_label(): string; /** * Is the taxonomy hierarchical? - * - * @return bool */ - public function is_hierarchical() { + public function is_hierarchical(): bool { return false; } @@ -85,9 +75,8 @@ public function is_hierarchical() { * Register hooks and actions. * * @uses $this->get_name() to get the taxonomy's slug. - * @return bool */ - public function register() { + public function register(): void { \register_taxonomy( $this->get_name(), $this->get_post_types(), @@ -95,8 +84,6 @@ public function register() { ); $this->after_register(); - - return true; } /** @@ -137,7 +124,7 @@ public function register() { * _builtin?: bool, * } */ - public function get_options() { + public function get_options(): array { return [ 'labels' => $this->get_labels(), 'hierarchical' => $this->is_hierarchical(), @@ -154,7 +141,7 @@ public function get_options() { * * @return array */ - public function get_labels() { + public function get_labels(): array { $plural_label = $this->get_plural_label(); $singular_label = $this->get_singular_label(); @@ -187,16 +174,14 @@ public function get_labels() { * * @return array */ - public function get_post_types() { + public function get_post_types(): array { return []; } /** * Run any code after the taxonomy has been registered. - * - * @return void */ - public function after_register() { + public function after_register(): void { // Do nothing. } }