Skip to content
Draft
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
== Changelog ==

= [TBD] TBD =

* Feature - Add the `has( string $key, string $expiration_trigger = '' ): bool`; add the `&$found` parameter to the `Tribe__Cache::get` method.
* Feature - Add the `has_shape( mixed $array, array $shape ): bool ` method to the `Tribe__Utils__Array` class.

= [5.2.3] 2024-02-19 =

* Tweak - Refactor JS logic to prevent ticketing of recurring events. [ET-1936]
Expand Down
40 changes: 33 additions & 7 deletions src/Tribe/Cache.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
<?php
/**
* Manage setting and expiring cached data
*
* Select actions can be used to force cached
*/

/**
* Manage setting and expiring cached data
*
* Select actions can be used to force cached
* data to expire. Implemented so far:
* - save_post
* - update main option
* - regenerate rewrite rules
*
* When used in its ArrayAccess API the cache will provide non persistent storage.
*/
Expand Down Expand Up @@ -99,17 +106,21 @@ public function set_transient( $id, $value, $expiration = 0, $expiration_trigger
*
* Note: When a default value or callback is specified, this value gets set in the cache.
*
* @since 4.11.0
* @since TBD Added the `$found` parameter.
*
* @param string $id The key for the cached value.
* @param string|array $expiration_trigger Optional. Hook to trigger cache invalidation.
* @param mixed $default Optional. A default value or callback that returns a default value.
* @param int $expiration Optional. When the default value expires, if it gets set.
* @param mixed $args Optional. Args passed to callback.
* @param bool $found Optional. Whether the value was found in the cache. Set by reference.
*
* @return mixed
*/
public function get( $id, $expiration_trigger = '', $default = false, $expiration = 0, $args = [] ) {
$group = isset( $this->non_persistent_keys[ $id ] ) ? 'tribe-events-non-persistent' : 'tribe-events';
$value = wp_cache_get( $this->get_id( $id, $expiration_trigger ), $group );
public function get( $id, $expiration_trigger = '', $default = false, $expiration = 0, $args = [], ?bool &$found = false ) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
Universal.NamingConventions.NoReservedKeywordParameterNames.defaultFound
It is recommended not to use reserved keyword "default" as function parameter name. Found: $default

$group = isset( $this->non_persistent_keys[ $id ] ) ? 'tribe-events-non-persistent' : 'tribe-events';
$value = wp_cache_get( $this->get_id( $id, $expiration_trigger ), $group, false, $found );

// Value found.
if ( false !== $value ) {
Expand Down Expand Up @@ -149,7 +160,7 @@ public function get_transient( $id, $expiration_trigger = '' ) {
* @return bool
*/
public function delete( $id, $expiration_trigger = '' ) {
$group = isset( $this->non_persistent_keys[ $id ] ) ? 'tribe-events-non-persistent' : 'tribe-events';
$group = isset( $this->non_persistent_keys[ $id ] ) ? 'tribe-events-non-persistent' : 'tribe-events';

// Delete from non-persistent keys list.
if ( 'tribe-events-non-persistent' === $group ) {
Expand Down Expand Up @@ -369,7 +380,6 @@ public function make_key( $components, $prefix = '', $sort = true ) {
*
* @return boolean Whether the offset exists in the cache.
*@link http://php.net/manual/en/arrayaccess.offsetexists.php
*
*/
#[\ReturnTypeWillChange]
public function offsetExists( $offset ): bool {
Expand Down Expand Up @@ -499,7 +509,7 @@ public function warmup_post_caches( $post_ids, $update_post_meta_cache = false )

do {
$limit_clause = $limit < 0 ? sprintf( 'LIMIT %d,%d', $limit * $page, $limit ) : '';
$page++;
++$page;
$these_ids = array_splice( $buffer, 0, $limit );
$interval = implode( ',', array_map( 'absint', $these_ids ) );
$posts_query = "SELECT * FROM {$wpdb->posts} WHERE ID IN ({$interval}) {$limit_clause}";
Expand Down Expand Up @@ -604,7 +614,6 @@ public function get_chunkable_transient( $id, $expiration_trigger = '' ) {
*
* The method will redirect to the `set_transient` function if the site is using object caching.
*
*
* @since 4.13.3
*
* @param string $id The transient ID.
Expand Down Expand Up @@ -643,4 +652,21 @@ public function set_chunkable_transient( $id, $value, $expiration = 0, $expirati

return true;
}

/**
* Checks whether a value is set in the cache or not.
*
* @since TBD
*
* @param string $id The key for the cached value.
* @param string $expiration_trigger Optional. Hook to trigger cache invalidation.
*
* @return bool Whether the value is set in the cache or not.
*/
public function has( $id, $expiration_trigger = '' ): bool {
$group = isset( $this->non_persistent_keys[ $id ] ) ? 'tribe-events-non-persistent' : 'tribe-events';
wp_cache_get( $this->get_id( $id, $expiration_trigger ), $group, false, $found );

return $found;
}
}
50 changes: 50 additions & 0 deletions src/Tribe/Utils/Array.php
Original file line number Diff line number Diff line change
Expand Up @@ -732,5 +732,55 @@ public static function usearch( $needle, array $haystack, callable $callback ) {

return false;
}

/**
* Checks if an array has a specific shape.
*
* @since TBD
*
* @param array $array The array to check.
* @param array<string|int,callable> $shape The shape to check for. Each key, either a string or an integer,
* maps to a callable that will be used to validate the value at that key.
* The callable must have the signature `fn( mixed $value ) :bool`.
* @param bool $strict Whether the array should only contain the keys specified in the shape.
*
* @return bool Whether the array has the specified shape.
*/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
Squiz.Commenting.FunctionCommentThrowTag.Missing
Missing @throws tag in function comment

public static function has_shape( $array, array $shape, bool $strict = false ): bool {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
Universal.NamingConventions.NoReservedKeywordParameterNames.arrayFound
It is recommended not to use reserved keyword "array" as function parameter name. Found: $array

if ( ! is_array( $array ) ) {
return false;
}

if (
$strict
&& (
array_intersect_key( $array, $shape ) !== $array
||
array_diff_key( $array, $shape ) !== []
)
) {
return false;
}

if ( count( array_intersect_key( $shape, $array ) ) < count( $shape ) ) {
return false;
}

foreach ( $shape as $key => $check ) {
if ( ! is_callable( $check ) ) {
throw new \BadMethodCallException( 'The shape array must contain only callables as values.' );
}

try {
if ( ! $check( $array[ $key ] ) ) {
return false;
}
} catch ( \Throwable $th ) {
return false;
}
}

return true;
}
}
}
92 changes: 89 additions & 3 deletions tests/unit/Tribe/Utils/ArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class Tribe__Utils__Array_Test extends \Codeception\Test\Unit {
public function shape_filter_data_provider() {
$test_shape = [
$test_shape = [
'a' =>
[
'deeply' =>
Expand Down Expand Up @@ -306,10 +306,10 @@ public function test_shape_filter( array $input, array $shape, array $expected )
}

public function usearch_data_provider() {
$value_gt_needle = static function ( $needle, $value ): bool {
$value_gt_needle = static function ( $needle, $value ): bool {
return $value > $needle;
};
$matches_needle = static function ( $needle, $value ): bool {
$matches_needle = static function ( $needle, $value ): bool {
return $value === $needle;
};
$callback_using_value_and_key = static function ( $needle, $value, $key ): bool {
Expand Down Expand Up @@ -352,4 +352,90 @@ public function usearch_data_provider() {
public function test_usearch( $needle, array $haystack, $expected, callable $callback ) {
$this->assertEquals( $expected, Arr::usearch( $needle, $haystack, $callback ) );
}

public function has_shape_data_provider(): array {
return [
'not an array' => [ 'foo', [], true, false ],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
WordPress.Arrays.MultipleStatementAlignment.DoubleArrowNotAligned
Array double arrow not aligned correctly; expected 29 space(s) between "'not an array'" and double arrow, but found 53.

'empty array, empty shape' => [ [], [], true, true ],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
WordPress.Arrays.MultipleStatementAlignment.DoubleArrowNotAligned
Array double arrow not aligned correctly; expected 17 space(s) between "'empty array, empty shape'" and double arrow, but found 41.

'empty array, non-empty shape, strict' => [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
WordPress.Arrays.MultipleStatementAlignment.DoubleArrowNotAligned
Array double arrow not aligned correctly; expected 5 space(s) between "'empty array, non-empty shape, strict'" and double arrow, but found 29.

[],
[ 'foo' => 'is_string' ],
true,
false

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
NormalizedArrays.Arrays.CommaAfterLast.MissingMultiLine
There should be a comma after the last array item in a multi-line array.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
SlevomatCodingStandard.Arrays.TrailingArrayComma.MissingTrailingComma
Multi-line arrays must have a trailing comma after the last element.

],
'empty array, non-empty shape, non-strict' => [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
WordPress.Arrays.MultipleStatementAlignment.DoubleArrowNotAligned
Array double arrow not aligned correctly; expected 1 space(s) between "'empty array, non-empty shape, non-strict'" and double arrow, but found 25.

[],
[ 'foo' => 'is_string' ],
false,
false

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
NormalizedArrays.Arrays.CommaAfterLast.MissingMultiLine
There should be a comma after the last array item in a multi-line array.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
SlevomatCodingStandard.Arrays.TrailingArrayComma.MissingTrailingComma
Multi-line arrays must have a trailing comma after the last element.

],
'non-empty array, function shape, missing key, strict' => [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
WordPress.Arrays.MultipleStatementAlignment.LongIndexSpaceBeforeDoubleArrow
Expected 1 space between "'non-empty array, function shape, missing key, strict'" and double arrow; 13 found.

[ 'foo' => 23 ],
[ 'bar' => 'is_string' ],
true,
false

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
NormalizedArrays.Arrays.CommaAfterLast.MissingMultiLine
There should be a comma after the last array item in a multi-line array.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
SlevomatCodingStandard.Arrays.TrailingArrayComma.MissingTrailingComma
Multi-line arrays must have a trailing comma after the last element.

],
'non-empty array, function shape, missing key, non-strict' => [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
WordPress.Arrays.MultipleStatementAlignment.LongIndexSpaceBeforeDoubleArrow
Expected 1 space between "'non-empty array, function shape, missing key, non-strict'" and double arrow; 9 found.

[ 'foo' => 23 ],
[ 'bar' => 'is_string' ],
false,
false

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
NormalizedArrays.Arrays.CommaAfterLast.MissingMultiLine
There should be a comma after the last array item in a multi-line array.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
SlevomatCodingStandard.Arrays.TrailingArrayComma.MissingTrailingComma
Multi-line arrays must have a trailing comma after the last element.

],
'non-empty array, function shape, extra key, strict' => [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
WordPress.Arrays.MultipleStatementAlignment.LongIndexSpaceBeforeDoubleArrow
Expected 1 space between "'non-empty array, function shape, extra key, strict'" and double arrow; 15 found.

[ 'foo' => 23, 'bar' => 'baz' ],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
When a multi-item array uses associative keys, each value should start on a new line.

[ 'foo' => 'is_int' ],
true,
false

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
NormalizedArrays.Arrays.CommaAfterLast.MissingMultiLine
There should be a comma after the last array item in a multi-line array.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
SlevomatCodingStandard.Arrays.TrailingArrayComma.MissingTrailingComma
Multi-line arrays must have a trailing comma after the last element.

],
'non-empty array, function shape, extra key, non-strict' => [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
WordPress.Arrays.MultipleStatementAlignment.LongIndexSpaceBeforeDoubleArrow
Expected 1 space between "'non-empty array, function shape, extra key, non-strict'" and double arrow; 11 found.

[ 'foo' => 23, 'bar' => 'baz' ],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
When a multi-item array uses associative keys, each value should start on a new line.

[ 'foo' => 'is_int' ],
false,
true

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
NormalizedArrays.Arrays.CommaAfterLast.MissingMultiLine
There should be a comma after the last array item in a multi-line array.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
SlevomatCodingStandard.Arrays.TrailingArrayComma.MissingTrailingComma
Multi-line arrays must have a trailing comma after the last element.

],
'non-empty array, closure shape, all key fail failure, strict' => [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
WordPress.Arrays.MultipleStatementAlignment.LongIndexSpaceBeforeDoubleArrow
Expected 1 space between "'non-empty array, closure shape, all key fail failure, strict'" and double arrow; 5 found.

[ 'foo' => 23, 'bar' => 89 ],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
When a multi-item array uses associative keys, each value should start on a new line.

[ 'foo' => fn( $foo ) => $foo === 'hello', 'bar' => fn( $bar ) => $bar === 'world' ],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
When a multi-item array uses associative keys, each value should start on a new line.

true,
false

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
NormalizedArrays.Arrays.CommaAfterLast.MissingMultiLine
There should be a comma after the last array item in a multi-line array.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
SlevomatCodingStandard.Arrays.TrailingArrayComma.MissingTrailingComma
Multi-line arrays must have a trailing comma after the last element.

],
'non-empty array, closure shape, all key fail failure, non-strict' => [
[ 'foo' => 23, 'bar' => 89 ],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
When a multi-item array uses associative keys, each value should start on a new line.

[ 'foo' => fn( $foo ) => $foo === 'hello', 'bar' => fn( $bar ) => $bar === 'world' ],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
When a multi-item array uses associative keys, each value should start on a new line.

false,
false

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
NormalizedArrays.Arrays.CommaAfterLast.MissingMultiLine
There should be a comma after the last array item in a multi-line array.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
SlevomatCodingStandard.Arrays.TrailingArrayComma.MissingTrailingComma
Multi-line arrays must have a trailing comma after the last element.

],
'non-empty array, closure shape, all key pass, strict' => [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
WordPress.Arrays.MultipleStatementAlignment.LongIndexSpaceBeforeDoubleArrow
Expected 1 space between "'non-empty array, closure shape, all key pass, strict'" and double arrow; 13 found.

[ 'foo' => 'hello', 'bar' => 'world' ],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
When a multi-item array uses associative keys, each value should start on a new line.

[ 'foo' => fn( $foo ) => $foo === 'hello', 'bar' => fn( $bar ) => $bar === 'world' ],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
When a multi-item array uses associative keys, each value should start on a new line.

true,
true

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
NormalizedArrays.Arrays.CommaAfterLast.MissingMultiLine
There should be a comma after the last array item in a multi-line array.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
SlevomatCodingStandard.Arrays.TrailingArrayComma.MissingTrailingComma
Multi-line arrays must have a trailing comma after the last element.

],
'non-empty array, closure shape, all key pass, non-strict ' => [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
WordPress.Arrays.MultipleStatementAlignment.LongIndexSpaceBeforeDoubleArrow
Expected 1 space between "'non-empty array, closure shape, all key pass, non-strict '" and double arrow; 8 found.

[ 'foo' => 'hello', 'bar' => 'world' ],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
When a multi-item array uses associative keys, each value should start on a new line.

[ 'foo' => fn( $foo ) => $foo === 'hello', 'bar' => fn( $bar ) => $bar === 'world' ],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
When a multi-item array uses associative keys, each value should start on a new line.

false,
true

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
NormalizedArrays.Arrays.CommaAfterLast.MissingMultiLine
There should be a comma after the last array item in a multi-line array.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
SlevomatCodingStandard.Arrays.TrailingArrayComma.MissingTrailingComma
Multi-line arrays must have a trailing comma after the last element.

],
'non-empty array, closure shape, some key pass, strict' => [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
WordPress.Arrays.MultipleStatementAlignment.LongIndexSpaceBeforeDoubleArrow
Expected 1 space between "'non-empty array, closure shape, some key pass, strict'" and double arrow; 12 found.

[ 'foo' => 'hello', 'bar' => 89 ],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
When a multi-item array uses associative keys, each value should start on a new line.

[ 'foo' => fn( $foo ) => $foo === 'hello', 'bar' => fn( $bar ) => $bar === 'world' ],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
When a multi-item array uses associative keys, each value should start on a new line.

true,
false

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
NormalizedArrays.Arrays.CommaAfterLast.MissingMultiLine
There should be a comma after the last array item in a multi-line array.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
SlevomatCodingStandard.Arrays.TrailingArrayComma.MissingTrailingComma
Multi-line arrays must have a trailing comma after the last element.

],
'non-empty array, closure shape, some key pass, non-strict' => [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
WordPress.Arrays.MultipleStatementAlignment.LongIndexSpaceBeforeDoubleArrow
Expected 1 space between "'non-empty array, closure shape, some key pass, non-strict'" and double arrow; 8 found.

[ 'foo' => 'hello', 'bar' => 89 ],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
When a multi-item array uses associative keys, each value should start on a new line.

[ 'foo' => fn( $foo ) => $foo === 'hello', 'bar' => fn( $bar ) => $bar === 'world' ],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
When a multi-item array uses associative keys, each value should start on a new line.

false,
false

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
NormalizedArrays.Arrays.CommaAfterLast.MissingMultiLine
There should be a comma after the last array item in a multi-line array.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
SlevomatCodingStandard.Arrays.TrailingArrayComma.MissingTrailingComma
Multi-line arrays must have a trailing comma after the last element.

],
];
}

/**
* @dataProvider has_shape_data_provider
*/
public function test_has_shape( $input, $shape, $strict, $expected ): void {
$this->assertEquals( $expected, Arr::has_shape( $input, $shape, $strict ) );
}
}
Loading