diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 05dfc78138a32ed739f2e9ad714552ed440d1438..0f86d5806d0372295019a4d4650c204360313b7c 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -36,7 +36,7 @@ <config name="minimum_supported_wp_version" value="6.2"/> <!-- Set value aligned with supported PHP Version for PHPCompatibilityWP check. --> - <config name="testVersion" value="7.2-"/> + <config name="testVersion" value="7.4-"/> <rule ref="WPDeskPlugin"/> @@ -48,4 +48,16 @@ <rule ref="Squiz.ControlStructures.InlineIfDeclaration"> <exclude name="Squiz.ControlStructures.InlineIfDeclaration.NoBrackets"/> </rule> + + <rule ref="Squiz.Commenting.ClassComment.Missing"> + <exclude-pattern>*src/**/*.php$</exclude-pattern> + <exclude-pattern>*src/*.php$</exclude-pattern> + </rule> + <rule ref="Squiz.Commenting.VariableComment.MissingVar"> + <exclude-pattern>*src/**/*.php$</exclude-pattern> + </rule> + <rule ref="Squiz.Commenting.VariableComment.Missing"> + <exclude-pattern>*src/**/*.php$</exclude-pattern> + <exclude-pattern>*src/*.php$</exclude-pattern> + </rule> </ruleset> diff --git a/src/Binding/Binder/CallableBinder.php b/src/Binding/Binder/CallableBinder.php index f4f2ade5e0250b49581dff6696c4c8d42e8f45f7..291b9e5b0dae8e84498d1d5f8cca23351f56bb16 100644 --- a/src/Binding/Binder/CallableBinder.php +++ b/src/Binding/Binder/CallableBinder.php @@ -9,10 +9,9 @@ use WPDesk\Init\Binding\ComposableBinder; use WPDesk\Init\Binding\Definition; use WPDesk\Init\Binding\Definition\CallableDefinition; -class CallableBinder implements ComposableBinder { +final class CallableBinder implements ComposableBinder { - /** @var ContainerInterface */ - private $container; + private ContainerInterface $container; public function __construct( ContainerInterface $c ) { $this->container = $c; diff --git a/src/Binding/Binder/CompositeBinder.php b/src/Binding/Binder/CompositeBinder.php index 9ee8eeceda6576ab53592126321ff466ab4826e0..febe91584e467c34a357db5bb0df900042df8481 100644 --- a/src/Binding/Binder/CompositeBinder.php +++ b/src/Binding/Binder/CompositeBinder.php @@ -12,7 +12,7 @@ use WPDesk\Init\Binding\Definition\HookableDefinition; final class CompositeBinder implements Binder { /** @var ComposableBinder[] */ - private $binders; + private array $binders; public function __construct( ComposableBinder ...$binders ) { $this->binders = $binders; diff --git a/src/Binding/Binder/HookableBinder.php b/src/Binding/Binder/HookableBinder.php index f8426dacddff213d58bdd0be5e9f0d68fb9ffaee..88b9da41cd80a556fd8d4dfd0f53f974644f46f0 100644 --- a/src/Binding/Binder/HookableBinder.php +++ b/src/Binding/Binder/HookableBinder.php @@ -11,8 +11,7 @@ use WPDesk\Init\Binding\Definition\HookableDefinition; class HookableBinder implements ComposableBinder { - /** @var ContainerInterface */ - private $container; + private ContainerInterface $container; public function __construct( ContainerInterface $c ) { $this->container = $c; diff --git a/src/Binding/Binder/ObservableBinder.php b/src/Binding/Binder/ObservableBinder.php index 0f05c03d6c82a121538fda25e9e0a44ae2ffadcd..9aebce11584858898cb73f7645661f129ba4e1fa 100644 --- a/src/Binding/Binder/ObservableBinder.php +++ b/src/Binding/Binder/ObservableBinder.php @@ -13,10 +13,9 @@ use WPDesk\Init\Binding\Definition; */ final class ObservableBinder implements ComposableBinder { - /** @var Binder */ - private $binder; + private Binder $binder; - private $binds_count = 0; + private int $binds_count = 0; public function __construct( Binder $b ) { $this->binder = $b; diff --git a/src/Binding/Binder/StoppableBinder.php b/src/Binding/Binder/StoppableBinder.php index 8917f7867e90c75ac1f20f2809cef78fb07149f9..d1b15003608d84979ec32f47ff8a311c1782622c 100644 --- a/src/Binding/Binder/StoppableBinder.php +++ b/src/Binding/Binder/StoppableBinder.php @@ -13,13 +13,12 @@ use WPDesk\Init\Binding\Definition\HookableDefinition; class StoppableBinder implements ComposableBinder { - /** @var ContainerInterface */ - private $container; + private ContainerInterface $container; /** @var Binder */ private $binder; - private $should_stop = false; + private bool $should_stop = false; public function __construct( BinderInstance $b, ContainerInterface $c ) { $this->binder = $b; diff --git a/src/Binding/Definition/CallableDefinition.php b/src/Binding/Definition/CallableDefinition.php index 5ceb6d08c3e9a59b3fe11b1d3f17b485bdba743d..737536d1ff0add7eea21707ccd61f98e5c08849a 100644 --- a/src/Binding/Definition/CallableDefinition.php +++ b/src/Binding/Definition/CallableDefinition.php @@ -9,8 +9,7 @@ use WPDesk\Init\Binding\Definition; /** @implements Definition<callable> */ class CallableDefinition implements Definition { - /** @var ?string */ - private $hook; + private ?string $hook; /** @var callable */ private $callable; diff --git a/src/Binding/Definition/DefinitionCollection.php b/src/Binding/Definition/DefinitionCollection.php index 99b82ba501b9e7e51a3098319a8ff65cae819297..b6adf54b93493e7a28de88ae870c89f67e0ef2ef 100644 --- a/src/Binding/Definition/DefinitionCollection.php +++ b/src/Binding/Definition/DefinitionCollection.php @@ -38,7 +38,7 @@ class DefinitionCollection implements Definition, \IteratorAggregate { yield from $this->defs; } - public function add( Definition $def ) { + public function add( Definition $def ): void { $this->defs[] = $def; } diff --git a/src/Binding/Definition/UnknownDefinition.php b/src/Binding/Definition/UnknownDefinition.php index e238d9b5a6e701876d14d7e74f77204049e777a3..dd61d8a6dd26159e24a1e1fa71b2e5b814a6aa2a 100644 --- a/src/Binding/Definition/UnknownDefinition.php +++ b/src/Binding/Definition/UnknownDefinition.php @@ -9,8 +9,7 @@ use WPDesk\Init\Binding\Definition; /** @implements Definition<mixed> */ class UnknownDefinition implements Definition { - /** @var ?string */ - private $hook; + private ?string $hook; /** @var mixed */ private $value; diff --git a/src/Binding/Hookable.php b/src/Binding/Hookable.php index 0ed2900b0e9a17c940866129f2ccbf55f7818e7f..e8ec97760d16f6c9df99f962807dc1d32b945403 100644 --- a/src/Binding/Hookable.php +++ b/src/Binding/Hookable.php @@ -1,4 +1,5 @@ <?php +// phpcs:disable declare(strict_types=1); diff --git a/src/Binding/Loader/ArrayDefinitions.php b/src/Binding/Loader/ArrayDefinitions.php index aa30bbe03d5bd950b3f566c21871b6d2e8b73bd6..fd765ebfd4cdc1928db37b3886ca9d1777d8c8fb 100644 --- a/src/Binding/Loader/ArrayDefinitions.php +++ b/src/Binding/Loader/ArrayDefinitions.php @@ -10,11 +10,9 @@ use WPDesk\Init\Plugin\Plugin; class ArrayDefinitions implements BindingDefinitions { - /** @var array */ - private $bindings; + private array $bindings; - /** @var DefinitionFactory */ - private $factory; + private DefinitionFactory $factory; public function __construct( array $bindings, ?DefinitionFactory $factory = null ) { $this->bindings = $bindings; @@ -29,10 +27,10 @@ class ArrayDefinitions implements BindingDefinitions { foreach ( $bindings as $key => $value ) { if ( is_array( $value ) ) { if ( isset( $value['handler'] ) ) { - // Single item with handler + // Single item with handler. yield $this->create( $value['handler'], $key, $value ); } else { - // Multiple items + // Multiple items. foreach ( $value as $unit ) { if ( is_array( $unit ) && isset( $unit['handler'] ) ) { yield $this->create( $unit['handler'], $key, $unit ); diff --git a/src/Binding/Loader/CompositeBindingLoader.php b/src/Binding/Loader/CompositeBindingLoader.php index 81f501bdafd2c64bee62e123bdaa2db6369da37b..e5755b28fbd83b29f0d1bcbc747982cb7c9bb5da 100644 --- a/src/Binding/Loader/CompositeBindingLoader.php +++ b/src/Binding/Loader/CompositeBindingLoader.php @@ -8,7 +8,7 @@ use WPDesk\Init\Plugin\Plugin; class CompositeBindingLoader implements BindingDefinitions { /** @var BindingDefinitionLoader[] */ - private $loaders; + private array $loaders; public function __construct( BindingDefinitions ...$loaders ) { $this->loaders = $loaders; diff --git a/src/Binding/Loader/DebugBindingLoader.php b/src/Binding/Loader/DebugBindingLoader.php index 286237d806f3586b7df9d222bdbc212b74b3712e..67aab6c641a77de30be6d10a9900601769a753fe 100644 --- a/src/Binding/Loader/DebugBindingLoader.php +++ b/src/Binding/Loader/DebugBindingLoader.php @@ -22,7 +22,7 @@ final class DebugBindingLoader implements BindingDefinitions { public function load(): iterable { foreach ( $this->loader->load() as $definition ) { if ( $definition instanceof UnknownDefinition ) { - @trigger_error( + @trigger_error( // phpcs:ignore sprintf( 'Trying to bind unknown value "%1$s". Currently wp-init can handle only simple callables and classes implementing "%2$s" interface', is_string( $definition->value() ) ? $definition->value() : json_encode( $definition->value() ), diff --git a/src/Binding/Loader/FilesystemDefinitions.php b/src/Binding/Loader/FilesystemDefinitions.php index f86c22e5848685a0e272faa9d207a10fc09b59f5..10f0742e70fbf9c8d13539b223510828765bc572 100644 --- a/src/Binding/Loader/FilesystemDefinitions.php +++ b/src/Binding/Loader/FilesystemDefinitions.php @@ -9,14 +9,11 @@ use WPDesk\Init\Util\PhpFileLoader; class FilesystemDefinitions implements BindingDefinitions { - /** @var Path */ - private $path; + private Path $path; - /** @var PhpFileLoader */ - private $loader; + private PhpFileLoader $loader; - /** @var DefinitionFactory */ - private $def_factory; + private DefinitionFactory $def_factory; public function __construct( $path, ?PhpFileLoader $loader = null, ?DefinitionFactory $def_factory = null ) { $this->path = new Path( (string) $path ); diff --git a/src/Binding/Loader/OrderedBindingLoader.php b/src/Binding/Loader/OrderedBindingLoader.php index 6ec899af63ae090ca8cd58d1df0c9a8214c04b18..4aa1c438c05c42b796ec7422ff477417c4899b8b 100644 --- a/src/Binding/Loader/OrderedBindingLoader.php +++ b/src/Binding/Loader/OrderedBindingLoader.php @@ -19,7 +19,7 @@ final class OrderedBindingLoader implements BindingDefinitions { usort( $definitions, - fn ( $a, $b ) => $a->option( 'priority' ) <=> $b->option( 'priority' ) + fn ( $a, $b ): int => $a->option( 'priority' ) <=> $b->option( 'priority' ) ); yield from array_reverse( $definitions, false ); diff --git a/src/Configuration/Configuration.php b/src/Configuration/Configuration.php index 69c5b8cdc637cf6cf58540b3055bbdfb9d056117..1451a089456ef5bb190ac63c0b224486b93f9d30 100644 --- a/src/Configuration/Configuration.php +++ b/src/Configuration/Configuration.php @@ -9,7 +9,7 @@ namespace WPDesk\Init\Configuration; class Configuration implements ReadableConfig, \ArrayAccess { /** @var array<string, mixed> */ - private $config; + private array $config; public function __construct( array $config ) { $this->config = $config; diff --git a/src/DependencyInjection/ContainerBuilder.php b/src/DependencyInjection/ContainerBuilder.php index c147090d3c406564dd0730a2c3f0d16c74bd5197..3ebbaa607602a5677d96d228259a7baf82b382c0 100644 --- a/src/DependencyInjection/ContainerBuilder.php +++ b/src/DependencyInjection/ContainerBuilder.php @@ -9,8 +9,7 @@ use DI\Definition\Source\DefinitionSource; final class ContainerBuilder { - /** @var DiBuilder */ - private $original_builder; + private DiBuilder $original_builder; public function __construct( DiBuilder $original_builder ) { $this->original_builder = $original_builder; diff --git a/src/Extension/CommonBinding/CustomOrdersTableCompatibility.php b/src/Extension/CommonBinding/CustomOrdersTableCompatibility.php index c5571ded55971bb6aaa14c5b0d595d2159681966..c800f4964bed44771f2b4c1f309f8c774f69eea4 100644 --- a/src/Extension/CommonBinding/CustomOrdersTableCompatibility.php +++ b/src/Extension/CommonBinding/CustomOrdersTableCompatibility.php @@ -7,8 +7,7 @@ use WPDesk\Init\Plugin\Plugin; class CustomOrdersTableCompatibility implements Hookable { - /** @var Plugin */ - private $plugin; + private Plugin $plugin; public function __construct( Plugin $plugin ) { $this->plugin = $plugin; @@ -19,7 +18,8 @@ class CustomOrdersTableCompatibility implements Hookable { } public function __invoke(): void { - $features_util_class = '\\' . 'Automattic' . '\\' . 'WooCommerce' . '\\' . 'Utilities' . '\\' . 'FeaturesUtil'; + // Concatenate string to make sure, prefixer will not parse it. + $features_util_class = '\\' . 'Automattic' . '\\' . 'WooCommerce' . '\\' . 'Utilities' . '\\' . 'FeaturesUtil'; //phpcs:ignore Generic.Strings.UnnecessaryStringConcat.Found if ( class_exists( $features_util_class ) ) { $features_util_class::declare_compatibility( 'custom_order_tables', diff --git a/src/Extension/CommonBinding/I18n.php b/src/Extension/CommonBinding/I18n.php index a5221732e4a9c3f5f4fae4e7b76a5259898f6662..0f5cd6ed64f8cf6440ebc04a80de0753a81ab8e6 100644 --- a/src/Extension/CommonBinding/I18n.php +++ b/src/Extension/CommonBinding/I18n.php @@ -7,8 +7,7 @@ use WPDesk\Init\Plugin\Plugin; class I18n implements Hookable { - /** @var Plugin */ - private $plugin; + private Plugin $plugin; public function __construct( Plugin $plugin ) { $this->plugin = $plugin; diff --git a/src/Extension/CommonBinding/WPDeskLicenseBridge.php b/src/Extension/CommonBinding/WPDeskLicenseBridge.php index 51d45347e872f44d0eab335d84bcef61b356714d..5fbc06716003467ca751299f21b3941be69c186f 100644 --- a/src/Extension/CommonBinding/WPDeskLicenseBridge.php +++ b/src/Extension/CommonBinding/WPDeskLicenseBridge.php @@ -36,7 +36,7 @@ class WPDeskLicenseBridge implements Hookable { add_action( 'plugins_loaded', $this, -50 ); } - public function __invoke() { + public function __invoke(): void { // Backward compatibility with wp-builder hook. if ( apply_filters( 'wpdesk_can_register_plugin', true, $this->plugin ) === false ) { return; diff --git a/src/Extension/CommonBinding/WPDeskTrackerBridge.php b/src/Extension/CommonBinding/WPDeskTrackerBridge.php index 20660f99a7eb0e236805e60ea2c29963763c52a6..131a9e9c222cee4961d4445f578d8e128d59ab59 100644 --- a/src/Extension/CommonBinding/WPDeskTrackerBridge.php +++ b/src/Extension/CommonBinding/WPDeskTrackerBridge.php @@ -7,8 +7,7 @@ use WPDesk\Init\Plugin\Plugin; class WPDeskTrackerBridge implements Hookable { - /** @var Plugin */ - private $plugin; + private Plugin $plugin; public function __construct( Plugin $plugin ) { $this->plugin = $plugin; diff --git a/src/Extension/ConfigExtension.php b/src/Extension/ConfigExtension.php index 303c514b2b45b664140fd11ae754d79a2e74931d..0924093b4374092d92f9ac9daca74946b99c02e5 100644 --- a/src/Extension/ConfigExtension.php +++ b/src/Extension/ConfigExtension.php @@ -29,9 +29,7 @@ class ConfigExtension implements Extension { public function build( ContainerBuilder $builder, Plugin $plugin, ReadableConfig $config ): void { $services = array_map( - function ( $service ) use ( $plugin ) { - return (string) ( new Path( $service ) )->absolute( $plugin->get_path() ); - }, + fn( $service ): string => (string) ( new Path( $service ) )->absolute( $plugin->get_path() ), (array) $config->get( 'services', [] ) ); diff --git a/src/Extension/ExtensionsSet.php b/src/Extension/ExtensionsSet.php index 650560e9e1418d636b274c24f68f02e2683e1519..c5e7fb546ec80136e568c70976245a0af8a11c7a 100644 --- a/src/Extension/ExtensionsSet.php +++ b/src/Extension/ExtensionsSet.php @@ -5,12 +5,12 @@ declare( strict_types=1 ); namespace WPDesk\Init\Extension; /** - * @implements \IteratorAggregate<class-string, Extension> + * @implements \IteratorAggregate<class-string<Extension>, Extension> */ class ExtensionsSet implements \IteratorAggregate { /** @var array<class-string<Extension>, Extension> */ - private $extensions = []; + private array $extensions = []; public function __construct( Extension ...$extensions ) { foreach ( $extensions as $extension ) { diff --git a/src/HookDriver/CompositeDriver.php b/src/HookDriver/CompositeDriver.php index ea17e1fc452da40e0af7aec9757b62dfbef2f724..c79522a42461da5454ec63e5dc959b8f201c4afb 100644 --- a/src/HookDriver/CompositeDriver.php +++ b/src/HookDriver/CompositeDriver.php @@ -6,7 +6,7 @@ namespace WPDesk\Init\HookDriver; final class CompositeDriver implements HookDriver { /** @var HookDriver[] */ - private $drivers; + private array $drivers; public function __construct( HookDriver ...$drivers ) { $this->drivers = $drivers; diff --git a/src/HookDriver/GenericDriver.php b/src/HookDriver/GenericDriver.php index 51167426aee7c08d9eb253301ec11cb7c3e585e0..cfc2d29b9f2a50179e5c6ccb656420b8802b0dda 100644 --- a/src/HookDriver/GenericDriver.php +++ b/src/HookDriver/GenericDriver.php @@ -8,11 +8,9 @@ use WPDesk\Init\Binding\Loader\BindingDefinitions; class GenericDriver implements HookDriver { - /** @var BindingDefinitions */ - private $definitions; + private BindingDefinitions $definitions; - /** @var Binder */ - private $binder; + private Binder $binder; public function __construct( BindingDefinitions $definitions, Binder $binder ) { $this->definitions = $definitions; @@ -23,7 +21,7 @@ class GenericDriver implements HookDriver { // Load has to be deffered until plugins_loaded because classes may implement or extend interfaces/classes which doesn't exist yet. add_action( 'plugins_loaded', - function () { + function (): void { foreach ( $this->definitions->load() as $definition ) { if ( $definition->hook() === null ) { $this->binder->bind( $definition ); diff --git a/src/HookDriver/Legacy/HooksRegistry.php b/src/HookDriver/Legacy/HooksRegistry.php index 1ef8730d9370d3d82d5fd34cbf74f435b7c8db47..d34499beab1108fe7dedd514800a7de341cf99c3 100644 --- a/src/HookDriver/Legacy/HooksRegistry.php +++ b/src/HookDriver/Legacy/HooksRegistry.php @@ -11,16 +11,16 @@ use WPDesk\PluginBuilder\Plugin\Hookable; */ final class HooksRegistry implements \IteratorAggregate { - private static $instance; + private static ?HooksRegistry $instance = null; /** @var array<class-string<Hookable>|Hookable> */ - private $callbacks = []; + private array $callbacks = []; - private $container; + private ?ContainerInterface $container = null; private function __construct() {} - public function inject_container( ContainerInterface $c ) { + public function inject_container( ContainerInterface $c ): void { $this->container = $c; } @@ -35,19 +35,13 @@ final class HooksRegistry implements \IteratorAggregate { public function getIterator(): Traversable { return new \ArrayIterator( array_map( - function ( $hookable ) { - if ( is_string( $hookable ) ) { - return $this->container->get( $hookable ); - } - - return $hookable; - }, + fn ( $hookable ) => is_string( $hookable ) ? $this->container->get( $hookable ) : $hookable, $this->callbacks ) ); } - public function add( $hookable ) { + public function add( $hookable ): void { $this->callbacks[] = $hookable; } } diff --git a/src/HookDriver/LegacyDriver.php b/src/HookDriver/LegacyDriver.php index ff0e7e36657bcfe16da8d6fc3329d6897d8e4570..33ce6dd8f5ea283f08aaafd91ecd3cfb37d9268c 100644 --- a/src/HookDriver/LegacyDriver.php +++ b/src/HookDriver/LegacyDriver.php @@ -8,8 +8,7 @@ use WPDesk\Init\HookDriver\Legacy\HooksRegistry; final class LegacyDriver implements HookDriver { - /** @var ContainerInterface */ - private $container; + private ContainerInterface $container; public function __construct( ContainerInterface $container ) { if ( ! class_exists( \WPDesk_Plugin_Info::class ) ) { diff --git a/src/Init.php b/src/Init.php index 9b8414a3d6ad7b55ba3a4a5a21a4e63a9a061314..fb8845840e77966320fb77983bf67a96bccb0810 100644 --- a/src/Init.php +++ b/src/Init.php @@ -15,6 +15,7 @@ use WPDesk\Init\Extension\ConditionalExtension; final class Init { + /** @var bool */ private static $bootable = true; /** @var Configuration */ @@ -58,7 +59,7 @@ final class Init { } if ( $filename === null ) { - $backtrace = \debug_backtrace( \DEBUG_BACKTRACE_IGNORE_ARGS, 1 ); + $backtrace = \debug_backtrace( \DEBUG_BACKTRACE_IGNORE_ARGS, 1 ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace $filename = $backtrace[0]['file']; } diff --git a/src/Kernel.php b/src/Kernel.php index 6a75c8bafee6ac3a9c18677cb0f57f736aed834a..c1b45597c327545a89253746e4f68395f1731a1b 100644 --- a/src/Kernel.php +++ b/src/Kernel.php @@ -33,19 +33,15 @@ use WPDesk\Init\Plugin\Plugin; final class Kernel { /** @var string|null Plugin filename. */ - private $filename; + private ?string $filename; - /** @var Configuration */ - private $config; + private Configuration $config; - /** @var PhpFileLoader */ - private $loader; + private PhpFileLoader $loader; - /** @var HeaderParser */ - private $parser; + private HeaderParser $parser; - /** @var ExtensionsSet */ - private $extensions; + private ExtensionsSet $extensions; private PhpFileDumper $dumper; diff --git a/src/Plugin/Header.php b/src/Plugin/Header.php index 97beba37909f75e3e31baafcb886fe1bf8945a9c..91634ec86c074a7c08a7b4ab5e5a20a4d5a7adb4 100644 --- a/src/Plugin/Header.php +++ b/src/Plugin/Header.php @@ -6,8 +6,7 @@ namespace WPDesk\Init\Plugin; final class Header implements \ArrayAccess { - /** @var array */ - private $header_data; + private array $header_data; public function __construct( array $header_data ) { $this->header_data = $header_data; diff --git a/src/Plugin/Plugin.php b/src/Plugin/Plugin.php index 5fd3c2a450b8d242c7ec154e45878427f05ba8e3..19e3e7d0c1898683a22fc3ee0043f6c3fb4d9c1d 100644 --- a/src/Plugin/Plugin.php +++ b/src/Plugin/Plugin.php @@ -9,57 +9,40 @@ final class Plugin { * Plugin basename. * * Ex: plugin-name/plugin-name.php - * - * @var string */ - private $basename; + private string $basename; /** * Absolute path to the main plugin directory. - * - * @var string */ - private $directory; + private string $directory; /** * Plugin name to display. - * - * @var string */ - private $name; + private string $name; /** * Absolute path to the main plugin file. - * - * @var string */ - private $file; + private string $file; /** * Plugin identifier. - * - * @var string */ - private $slug; + private string $slug; /** * URL to the main plugin directory. - * - * @var string */ - private $url; + private string $url; /** * Plugin version string. - * - * @var string */ - private $version; + private string $version; - /** - * @var Header - */ - private $header; + private Header $header; public function __construct( string $file, Header $header ) { $this->file = $file; diff --git a/src/Util/Path.php b/src/Util/Path.php index a7cf66fde392accc8bc0ec0cdd45eaf12e6b1859..ce4fdef683a473198b5437272ad76447b0f2200f 100644 --- a/src/Util/Path.php +++ b/src/Util/Path.php @@ -6,8 +6,7 @@ namespace WPDesk\Init\Util; final class Path { - /** @var string */ - private $path; + private string $path; public function __construct( string $path ) { $this->path = $path; @@ -19,7 +18,7 @@ final class Path { } public function absolute( ?string $base_path = null ): self { - $base_path = $base_path ?? getcwd(); + $base_path ??= getcwd(); return ( new self( rtrim( $base_path, '/\\' ) . '/' . $this->path ) )->canonical(); } @@ -29,21 +28,21 @@ final class Path { $canonical_parts = []; - // Collapse "." and "..", if possible + // Collapse "." and "..", if possible. foreach ( $parts as $part ) { if ( '.' === $part || '' === $part ) { continue; } // Collapse ".." with the previous part, if one exists - // Don't collapse ".." if the previous part is also ".." + // Don't collapse ".." if the previous part is also "..". if ( '..' === $part && \count( $canonical_parts ) > 0 && '..' !== $canonical_parts[ \count( $canonical_parts ) - 1 ] ) { array_pop( $canonical_parts ); continue; } - // Only add ".." prefixes for relative paths + // Only add ".." prefixes for relative paths. if ( '..' !== $part || '' === $root ) { $canonical_parts[] = $part; } @@ -79,9 +78,7 @@ final class Path { } return array_map( - function ( $file ) { - return ( new self( $file ) )->absolute( $this->path ); - }, + fn( $file ): Path => ( new self( $file ) )->absolute( $this->path ), array_values( array_diff( scandir( $this->path ), diff --git a/src/Util/PhpFileDumper.php b/src/Util/PhpFileDumper.php index 8bc45f9644b4a3bebca72143d0dae353395972b7..7f777de07dc1ff128b47145fe62e813f54f8e5b2 100644 --- a/src/Util/PhpFileDumper.php +++ b/src/Util/PhpFileDumper.php @@ -1,4 +1,5 @@ <?php +// phpcs:disable WordPress.PHP.NoSilencedErrors.Discouraged declare( strict_types=1 ); namespace WPDesk\Init\Util; @@ -11,7 +12,7 @@ class PhpFileDumper { $content = '<?php' . PHP_EOL . PHP_EOL; $content .= 'declare(strict_types=1);' . PHP_EOL . PHP_EOL; - $content .= 'return ' . var_export( $config, true ) . ';' . PHP_EOL; + $content .= 'return ' . var_export( $config, true ) . ';' . PHP_EOL; // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export $this->writeFileAtomic( $filename, $content ); } diff --git a/src/di-functions.php b/src/di-functions.php index 993a5b3f980ef8fc22a3140f7a0382ed71f99fe6..60472ce72ae1a17f946cdcc3cfe058d2bd617b34 100644 --- a/src/di-functions.php +++ b/src/di-functions.php @@ -1,4 +1,5 @@ <?php +// phpcs:disable WordPress.NamingConventions.ValidVariableName /** * This is a vendored set of php-di/php-di helper functions. We place it directly in our library to improve experience when using DI along with code scoping, which defy composer's file autoloading. * diff --git a/src/platform_check.php b/src/platform_check.php index 5219843ba889ef17d4f364f36246845c72fd2a87..365bf219008979567d25abfbb1e1d033c4ab1496 100644 --- a/src/platform_check.php +++ b/src/platform_check.php @@ -5,7 +5,7 @@ if ( ! ( PHP_VERSION_ID >= 70400 ) ) { function () { printf( '<div class="notice notice-error"><p>%s</p></div>', - __( 'The plugin cannot run on PHP versions older than 7.4. Please, contact your host and ask them to upgrade.', 'wp-init' ) + esc_html__( 'The plugin cannot run on PHP versions older than 7.4. Please, contact your host and ask them to upgrade.', 'wp-init' ) ); } ); diff --git a/tests/DefaultHeaderParserTest.php b/tests/DefaultHeaderParserTest.php index f3f2a40ff7c2679cb88788a8664858d1c5eebe80..372b66d6d3f8d24ecc2cb2c74bf2d5a54fdef3f2 100644 --- a/tests/DefaultHeaderParserTest.php +++ b/tests/DefaultHeaderParserTest.php @@ -8,7 +8,7 @@ use WPDesk\Init\Plugin\DefaultHeaderParser; class DefaultHeaderParserTest extends TestCase { /** @dataProvider provider */ - public function test_should_parse_plugin_data_from_file( $name, string $content, array $expected ): void { + public function test_should_parse_plugin_data_from_file( string $name, string $content, array $expected ): void { $file = $this->createTempFile($name, $content); $data = new DefaultHeaderParser(); @@ -18,18 +18,18 @@ class DefaultHeaderParserTest extends TestCase { public function provider(): iterable { yield [ 'first.php', -<<<PHP +<<<PHP_WRAP <?php /** * Plugin Name: Example plugin */ -PHP, +PHP_WRAP, [ 'Name' => 'Example plugin' ], ]; yield [ 'second.php', -<<<PHP +<<<PHP_WRAP <?php /** * Plugin Name: ShopMagic for WooCommerce @@ -46,7 +46,8 @@ PHP, * WC tested up to: 7.2 * Requires PHP: 7.2 */ -PHP, +PHP_WRAP +, [ 'Name' => 'ShopMagic for WooCommerce', 'PluginURI' => 'https://shopmagic.app/', diff --git a/tests/Dumper/PhpFileDumperTest.php b/tests/Dumper/PhpFileDumperTest.php index 84460038121f0a2b3a734cdb440529b2e54f7454..56cfe58f348ae91eb78cf9b26afa83b8a68f14ee 100644 --- a/tests/Dumper/PhpFileDumperTest.php +++ b/tests/Dumper/PhpFileDumperTest.php @@ -7,7 +7,7 @@ use WPDesk\Init\Util\PhpFileDumper; class PhpFileDumperTest extends \WPDesk\Init\Tests\TestCase { - public function test_dump_php_file() { + public function test_dump_php_file(): void { $dir = $this->initTempPlugin(); $dumper = new PhpFileDumper(); $dumper->dump( [ 'foo' => 'bar' ], $dir . '/dump.php' ); diff --git a/tests/HookDriver/GenericDriverTest.php b/tests/HookDriver/GenericDriverTest.php index ce92478304e5937f25ca752d80a7191be955d31d..c1e1f1ab60b3c138db4ff12d0a29c21b70be31be 100644 --- a/tests/HookDriver/GenericDriverTest.php +++ b/tests/HookDriver/GenericDriverTest.php @@ -22,7 +22,7 @@ class GenericDriverTest extends TestCase { public function bind( Definition $def ): void { } }), - function ( $binder ) { + function ( $binder ): void { $this->assertTrue( $binder->is_bound() ); } ]; diff --git a/tests/Loader/PhpFileLoaderTest.php b/tests/Loader/PhpFileLoaderTest.php index b996b7e9d634d4e460b582ed44d3b72d17d2a2fc..3a5ac971b83fb3a78337a7108c963056c30a3f49 100644 --- a/tests/Loader/PhpFileLoaderTest.php +++ b/tests/Loader/PhpFileLoaderTest.php @@ -7,7 +7,7 @@ use WPDesk\Init\Util\PhpFileLoader; class PhpFileLoaderTest extends \WPDesk\Init\Tests\TestCase { - public function test_load_php_file() { + public function test_load_php_file(): void { $loader = new PhpFileLoader(); $resource = __DIR__ . '/../Fixtures/load.php'; $data = $loader->load( $resource ); diff --git a/tests/generated/plugin.php b/tests/generated/plugin.php index a0057af93b0e7bd2ded056e4f3a88bf3ae5703f0..0dae23dee5e19103a18ad465098da0018bd4991b 100644 --- a/tests/generated/plugin.php +++ b/tests/generated/plugin.php @@ -2,5 +2,4 @@ declare(strict_types=1); -return array ( -); +return [];