Skip to content
Snippets Groups Projects
Verified Commit c5892c9d authored by Bartek Jaskulski's avatar Bartek Jaskulski
Browse files

refactor: upgrade to php 7.4, property types, etc

parent 38eb5000
No related branches found
No related tags found
2 merge requests!5feat: remove compilation command,!4feat: remove compilation command
Showing
with 42 additions and 42 deletions
......@@ -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>
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
}
......
......@@ -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;
......
<?php
// phpcs:disable
declare(strict_types=1);
......
......@@ -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 );
......
......@@ -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;
......
......@@ -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() ),
......
......@@ -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 );
......
......@@ -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 );
......
......@@ -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;
......
......@@ -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;
......
......@@ -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',
......
......@@ -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;
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment