-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Tribe__Cache::has method #2061
base: master
Are you sure you want to change the base?
Conversation
For back-compatibility purposes, I've not modified existing methods like `offsetGet`. This add a `$found` flag, set by reference, to the `get` method similarly to the one set by the `wp_cache_get` function. To just check on a value, I've added the `has` method.
* | ||
* @return mixed | ||
*/ | ||
public function get( $id, $expiration_trigger = '', $default = false, $expiration = 0, $args = [] ) { | ||
public function get( $id, $expiration_trigger = '', $default = false, $expiration = 0, $args = [], ?bool &$found = false ) { |
There was a problem hiding this comment.
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
tests/wpunit/Tribe/CacheTest.php
Outdated
|
||
$cache->set( 'foo-bar', 'bar' ); | ||
$this->assertTrue( $cache->has( 'foo-bar' ) ); | ||
$this->assertEquals('bar', $cache->get( 'foo-bar','', false, 0, [], $found ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[phpcs] reported by reviewdog 🐶PEAR.Functions.FunctionCallSignature.SpaceAfterOpenBracket
Expected 1 spaces after opening parenthesis; 0 found
tests/wpunit/Tribe/CacheTest.php
Outdated
|
||
$cache->set( 'foo-bar', 'bar' ); | ||
$this->assertTrue( $cache->has( 'foo-bar' ) ); | ||
$this->assertEquals('bar', $cache->get( 'foo-bar','', false, 0, [], $found ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[phpcs] reported by reviewdog 🐶Generic.Functions.FunctionCallArgumentSpacing.NoSpaceAfterComma
No space found after comma in argument list
tests/wpunit/Tribe/CacheTest.php
Outdated
|
||
$cache->set( 'foo-bar-save-post', 'bar', 0, Triggers::TRIGGER_SAVE_POST ); | ||
$this->assertTrue( $cache->has( 'foo-bar-save-post', Triggers::TRIGGER_SAVE_POST ) ); | ||
$this->assertEquals('bar', $cache->get( 'foo-bar-save-post', Triggers::TRIGGER_SAVE_POST, false, 0, [], $found ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[phpcs] reported by reviewdog 🐶PEAR.Functions.FunctionCallSignature.SpaceAfterOpenBracket
Expected 1 spaces after opening parenthesis; 0 found
tests/wpunit/Tribe/CacheTest.php
Outdated
|
||
$cache->set( 'foo-bar-updated-option', 'bar', 0, Triggers::TRIGGER_UPDATED_OPTION ); | ||
$this->assertTrue( $cache->has( 'foo-bar-updated-option', Triggers::TRIGGER_UPDATED_OPTION ) ); | ||
$this->assertEquals('bar', $cache->get( 'foo-bar-updated-option', Triggers::TRIGGER_UPDATED_OPTION, false, 0, [], $found ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[phpcs] reported by reviewdog 🐶PEAR.Functions.FunctionCallSignature.SpaceAfterOpenBracket
Expected 1 spaces after opening parenthesis; 0 found
tests/wpunit/Tribe/CacheTest.php
Outdated
|
||
$cache->set( 'foo-bar-generate-rewrite-rules', 'bar', 0, Triggers::TRIGGER_GENERATE_REWRITE_RULES ); | ||
$this->assertTrue( $cache->has( 'foo-bar-generate-rewrite-rules', Triggers::TRIGGER_GENERATE_REWRITE_RULES ) ); | ||
$this->assertEquals('bar', $cache->get( 'foo-bar-generate-rewrite-rules', Triggers::TRIGGER_GENERATE_REWRITE_RULES, false, 0, [], $found ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[phpcs] reported by reviewdog 🐶PEAR.Functions.FunctionCallSignature.SpaceAfterOpenBracket
Expected 1 spaces after opening parenthesis; 0 found
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit
phpcs
tests/unit/Tribe/Utils/ArrayTest.php|404 col 100| WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
When a multi-item array uses associative keys, each value should start on a new line.
tests/unit/Tribe/Utils/ArrayTest.php|406 col 17| NormalizedArrays.Arrays.CommaAfterLast.MissingMultiLine
There should be a comma after the last array item in a multi-line array.
tests/unit/Tribe/Utils/ArrayTest.php|406 col 17| SlevomatCodingStandard.Arrays.TrailingArrayComma.MissingTrailingComma
Multi-line arrays must have a trailing comma after the last element.
tests/unit/Tribe/Utils/ArrayTest.php|408 col 80| WordPress.Arrays.MultipleStatementAlignment.LongIndexSpaceBeforeDoubleArrow
Expected 1 space between "'non-empty array, closure shape, all key pass, strict'" and double arrow; 13 found.
tests/unit/Tribe/Utils/ArrayTest.php|409 col 54| WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
When a multi-item array uses associative keys, each value should start on a new line.
tests/unit/Tribe/Utils/ArrayTest.php|410 col 100| WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
When a multi-item array uses associative keys, each value should start on a new line.
tests/unit/Tribe/Utils/ArrayTest.php|412 col 17| NormalizedArrays.Arrays.CommaAfterLast.MissingMultiLine
There should be a comma after the last array item in a multi-line array.
tests/unit/Tribe/Utils/ArrayTest.php|412 col 17| SlevomatCodingStandard.Arrays.TrailingArrayComma.MissingTrailingComma
Multi-line arrays must have a trailing comma after the last element.
tests/unit/Tribe/Utils/ArrayTest.php|414 col 80| WordPress.Arrays.MultipleStatementAlignment.LongIndexSpaceBeforeDoubleArrow
Expected 1 space between "'non-empty array, closure shape, all key pass, non-strict '" and double arrow; 8 found.
tests/unit/Tribe/Utils/ArrayTest.php|415 col 54| WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
When a multi-item array uses associative keys, each value should start on a new line.
tests/unit/Tribe/Utils/ArrayTest.php|416 col 100| WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
When a multi-item array uses associative keys, each value should start on a new line.
tests/unit/Tribe/Utils/ArrayTest.php|418 col 17| NormalizedArrays.Arrays.CommaAfterLast.MissingMultiLine
There should be a comma after the last array item in a multi-line array.
tests/unit/Tribe/Utils/ArrayTest.php|418 col 17| SlevomatCodingStandard.Arrays.TrailingArrayComma.MissingTrailingComma
Multi-line arrays must have a trailing comma after the last element.
tests/unit/Tribe/Utils/ArrayTest.php|420 col 80| WordPress.Arrays.MultipleStatementAlignment.LongIndexSpaceBeforeDoubleArrow
Expected 1 space between "'non-empty array, closure shape, some key pass, strict'" and double arrow; 12 found.
tests/unit/Tribe/Utils/ArrayTest.php|421 col 49| WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
When a multi-item array uses associative keys, each value should start on a new line.
tests/unit/Tribe/Utils/ArrayTest.php|422 col 100| WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
When a multi-item array uses associative keys, each value should start on a new line.
tests/unit/Tribe/Utils/ArrayTest.php|424 col 17| NormalizedArrays.Arrays.CommaAfterLast.MissingMultiLine
There should be a comma after the last array item in a multi-line array.
tests/unit/Tribe/Utils/ArrayTest.php|424 col 17| SlevomatCodingStandard.Arrays.TrailingArrayComma.MissingTrailingComma
Multi-line arrays must have a trailing comma after the last element.
tests/unit/Tribe/Utils/ArrayTest.php|426 col 80| WordPress.Arrays.MultipleStatementAlignment.LongIndexSpaceBeforeDoubleArrow
Expected 1 space between "'non-empty array, closure shape, some key pass, non-strict'" and double arrow; 8 found.
tests/unit/Tribe/Utils/ArrayTest.php|427 col 49| WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
When a multi-item array uses associative keys, each value should start on a new line.
tests/unit/Tribe/Utils/ArrayTest.php|428 col 100| WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
When a multi-item array uses associative keys, each value should start on a new line.
tests/unit/Tribe/Utils/ArrayTest.php|430 col 17| NormalizedArrays.Arrays.CommaAfterLast.MissingMultiLine
There should be a comma after the last array item in a multi-line array.
tests/unit/Tribe/Utils/ArrayTest.php|430 col 17| SlevomatCodingStandard.Arrays.TrailingArrayComma.MissingTrailingComma
Multi-line arrays must have a trailing comma after the last element.
* The callable must have the signature `fn( mixed $value ) :bool`. | ||
* | ||
* @return bool | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/Tribe/Utils/Array.php
Outdated
* | ||
* @return bool | ||
*/ | ||
public static function has_shape( $array, array $shape ): bool { |
There was a problem hiding this comment.
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
tests/unit/Tribe/Utils/ArrayTest.php
Outdated
|
||
public function has_shape_data_provider(): array { | ||
return [ | ||
'not an array' => [ 'foo', [], true, false ], |
There was a problem hiding this comment.
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.
tests/unit/Tribe/Utils/ArrayTest.php
Outdated
public function has_shape_data_provider(): array { | ||
return [ | ||
'not an array' => [ 'foo', [], true, false ], | ||
'empty array, empty shape' => [ [], [], true, true ], |
There was a problem hiding this comment.
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.
tests/unit/Tribe/Utils/ArrayTest.php
Outdated
return [ | ||
'not an array' => [ 'foo', [], true, false ], | ||
'empty array, empty shape' => [ [], [], true, true ], | ||
'empty array, non-empty shape, strict' => [ |
There was a problem hiding this comment.
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.
tests/unit/Tribe/Utils/ArrayTest.php
Outdated
true | ||
], | ||
'non-empty array, closure shape, all key fail failure, strict' => [ | ||
[ 'foo' => 23, 'bar' => 89 ], |
There was a problem hiding this comment.
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.
tests/unit/Tribe/Utils/ArrayTest.php
Outdated
], | ||
'non-empty array, closure shape, all key fail failure, strict' => [ | ||
[ 'foo' => 23, 'bar' => 89 ], | ||
[ 'foo' => fn( $foo ) => $foo === 'hello', 'bar' => fn( $bar ) => $bar === 'world' ], |
There was a problem hiding this comment.
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.
tests/unit/Tribe/Utils/ArrayTest.php
Outdated
[ 'foo' => 23, 'bar' => 89 ], | ||
[ 'foo' => fn( $foo ) => $foo === 'hello', 'bar' => fn( $bar ) => $bar === 'world' ], | ||
true, | ||
false |
There was a problem hiding this comment.
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.
tests/unit/Tribe/Utils/ArrayTest.php
Outdated
[ 'foo' => 23, 'bar' => 89 ], | ||
[ 'foo' => fn( $foo ) => $foo === 'hello', 'bar' => fn( $bar ) => $bar === 'world' ], | ||
true, | ||
false |
There was a problem hiding this comment.
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.
tests/unit/Tribe/Utils/ArrayTest.php
Outdated
false | ||
], | ||
'non-empty array, closure shape, all key fail failure, non-strict' => [ | ||
[ 'foo' => 23, 'bar' => 89 ], |
There was a problem hiding this comment.
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.
7032a98
to
a9bc11e
Compare
tests/unit/Tribe/Utils/ArrayTest.php
Outdated
], | ||
'non-empty array, closure shape, all key fail failure, non-strict' => [ | ||
[ 'foo' => 23, 'bar' => 89 ], | ||
[ 'foo' => fn( $foo ) => $foo === 'hello', 'bar' => fn( $bar ) => $bar === 'world' ], |
There was a problem hiding this comment.
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.
tests/unit/Tribe/Utils/ArrayTest.php
Outdated
[ 'foo' => 23, 'bar' => 89 ], | ||
[ 'foo' => fn( $foo ) => $foo === 'hello', 'bar' => fn( $bar ) => $bar === 'world' ], | ||
false, | ||
false |
There was a problem hiding this comment.
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.
tests/unit/Tribe/Utils/ArrayTest.php
Outdated
[ 'foo' => 23, 'bar' => 89 ], | ||
[ 'foo' => fn( $foo ) => $foo === 'hello', 'bar' => fn( $bar ) => $bar === 'world' ], | ||
false, | ||
false |
There was a problem hiding this comment.
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.
tests/unit/Tribe/Utils/ArrayTest.php
Outdated
false, | ||
false | ||
], | ||
'non-empty array, closure shape, all key pass, strict' => [ |
There was a problem hiding this comment.
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.
tests/unit/Tribe/Utils/ArrayTest.php
Outdated
false | ||
], | ||
'non-empty array, closure shape, all key pass, strict' => [ | ||
[ 'foo' => 'hello', 'bar' => 'world' ], |
There was a problem hiding this comment.
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.
tests/unit/Tribe/Utils/ArrayTest.php
Outdated
true, | ||
false | ||
], | ||
'non-empty array, closure shape, some key pass, non-strict' => [ |
There was a problem hiding this comment.
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.
tests/unit/Tribe/Utils/ArrayTest.php
Outdated
false | ||
], | ||
'non-empty array, closure shape, some key pass, non-strict' => [ | ||
[ 'foo' => 'hello', 'bar' => 89 ], |
There was a problem hiding this comment.
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.
tests/unit/Tribe/Utils/ArrayTest.php
Outdated
], | ||
'non-empty array, closure shape, some key pass, non-strict' => [ | ||
[ 'foo' => 'hello', 'bar' => 89 ], | ||
[ 'foo' => fn( $foo ) => $foo === 'hello', 'bar' => fn( $bar ) => $bar === 'world' ], |
There was a problem hiding this comment.
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.
tests/unit/Tribe/Utils/ArrayTest.php
Outdated
[ 'foo' => 'hello', 'bar' => 89 ], | ||
[ 'foo' => fn( $foo ) => $foo === 'hello', 'bar' => fn( $bar ) => $bar === 'world' ], | ||
false, | ||
true |
There was a problem hiding this comment.
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.
tests/unit/Tribe/Utils/ArrayTest.php
Outdated
[ 'foo' => 'hello', 'bar' => 89 ], | ||
[ 'foo' => fn( $foo ) => $foo === 'hello', 'bar' => fn( $bar ) => $bar === 'world' ], | ||
false, | ||
true |
There was a problem hiding this comment.
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.
a9bc11e
to
fa40956
Compare
* | ||
* @return bool Whether the array has the specified shape. | ||
*/ | ||
public static function has_shape( $array, array $shape, bool $strict = false ): bool { |
There was a problem hiding this comment.
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
tests/unit/Tribe/Utils/ArrayTest.php
Outdated
[], | ||
[ 'foo' => 'is_string' ], | ||
false, | ||
false |
There was a problem hiding this comment.
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.
tests/unit/Tribe/Utils/ArrayTest.php
Outdated
[], | ||
[ 'foo' => 'is_string' ], | ||
false, | ||
false |
There was a problem hiding this comment.
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.
tests/unit/Tribe/Utils/ArrayTest.php
Outdated
[ 'foo' => 'hello', 'bar' => 89 ], | ||
[ 'foo' => fn( $foo ) => $foo === 'hello', 'bar' => fn( $bar ) => $bar === 'world' ], | ||
false, | ||
false |
There was a problem hiding this comment.
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.
tests/unit/Tribe/Utils/ArrayTest.php
Outdated
[ 'foo' => 'hello', 'bar' => 89 ], | ||
[ 'foo' => fn( $foo ) => $foo === 'hello', 'bar' => fn( $bar ) => $bar === 'world' ], | ||
false, | ||
false |
There was a problem hiding this comment.
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.
🎫 Ticket
Innovation Day work, Cookbook
🗒️ Description
For back-compatibility purposes, I've not modified existing methods like
offsetGet
.This add a
$found
flag, set by reference, to theget
method similarly to the one set by thewp_cache_get
function.To just check on a value, I've added the
has
method.✔️ Checklist
readme.txt
file.wpunit
orintegration
tests.wpunit
orintegration
tests.