Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Update PHPDoc for patch commands
- Remove extra spaces in `cache patch` PHPDoc annotation
- Specify default value for `expiration` argument in `transient patch` PHPDoc annotation
  • Loading branch information
petitphp committed May 14, 2025
commit e01820870753e8cabab8c3f48bb08769b4534c86
8 changes: 4 additions & 4 deletions src/Cache_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -499,10 +499,10 @@ function ( $key ) {
* ---
*
* [--expiration=<expiration>]
* : Define how long to keep the value, in seconds. `0` means as long as possible.
* ---
* default: 0
* ---
* : Define how long to keep the value, in seconds. `0` means as long as possible.
* ---
* default: 0
* ---
*
* [--format=<format>]
* : The serialization format for the value.
Expand Down
5 changes: 4 additions & 1 deletion src/Transient_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,9 @@ function ( $key ) {
*
* [--expiration=<expiration>]
* : Time until expiration, in seconds.
* ---
* default: 0
* ---
*
* [--network]
* : Get the value of a network|site transient. On single site, this is
Expand All @@ -505,7 +508,7 @@ function ( $key ) {
*/
public function patch( $args, $assoc_args ) {
list( $action, $key ) = $args;
$expiration = (int) Utils\get_flag_value( $assoc_args, 'expiration', 0 );
$expiration = (int) Utils\get_flag_value( $assoc_args, 'expiration' );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I assume you remove the 0 here for consistency with the other commands, but I think this is the only one that is actually correct. For all of the expiration flags, we should:

  1. be explicit with the default value (as it will otherwise default to null)
  2. cast to the expected type (int) to ensure we don't see unexpected changes later in the code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

1/
Yes it was for consistency, I removed the default value here and set it in the PHPDoc like what was done in the cache command.
During my testing, I saw that the default value from the PHPDoc was automatically used without having to set it in get_flag_value. I thought it was cleaner, and I apply the change here.

I can add the 0 back here and in the cache command if you think it's more explicit ?

2/
I've done that in 4bf6850


$read_func = Utils\get_flag_value( $assoc_args, 'network' ) ? 'get_site_transient' : 'get_transient';
$write_func = Utils\get_flag_value( $assoc_args, 'network' ) ? 'set_site_transient' : 'set_transient';
Expand Down