Skip to content

Commit

Permalink
Fix Psalm passing
Browse files Browse the repository at this point in the history
  • Loading branch information
joehoyle committed Jul 8, 2020
1 parent 0f42215 commit 923a5ec
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion inc/class-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ public function set_attachment_files_acl( int $attachment_id, string $acl ) : ?W
* Get all the files stored for a given attachment.
*
* @param integer $attachment_id
* @return array Array of all full paths to the attachment's files.
* @return list<string> Array of all full paths to the attachment's files.
*/
public static function get_attachment_files( int $attachment_id ) : array {
$uploadpath = wp_get_upload_dir();
Expand Down
10 changes: 8 additions & 2 deletions inc/class-stream-wrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ public function dir_opendir( $path, $options ) {
// Set the opened bucket prefix to be the directory. This is because $this->openedBucketPrefix
// will be removed from the resulting keys, and we want to return all files in the directory
// of the wildcard.
$this->openedBucketPrefix = substr( $params['Key'], 0, strrpos( $params['Key'], '/' ) + 1 );
$this->openedBucketPrefix = substr( $params['Key'], 0, ( strrpos( $params['Key'], '/' ) ?: 0 ) + 1 );
} else {
$params['Key'] = rtrim( $params['Key'], $delimiter ) . $delimiter;
$this->openedBucketPrefix = $params['Key'];
Expand Down Expand Up @@ -617,7 +617,13 @@ public function dir_opendir( $path, $options ) {
//
// Anyone reading this far, brace yourselves for a mighty horrible hack.
$backtrace = debug_backtrace( 0, 3 ); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection
if ( isset( $backtrace[1]['function'] ) && $backtrace[1]['function'] === 'scandir' && isset( $backtrace[2]['function'] ) && $backtrace[2]['function'] === 'wp_unique_filename' ) {
if ( isset( $backtrace[1]['function'] )
&& $backtrace[1]['function'] === 'scandir'
&& isset( $backtrace[2]['function'] )
&& $backtrace[2]['function'] === 'wp_unique_filename' && isset( $backtrace[2]['args'][1] )
&& isset( $op['Prefix'] )
) {
/** @var string $filename */
$filename = $backtrace[2]['args'][1];
$name = pathinfo( $filename, PATHINFO_FILENAME );
$op['Prefix'] .= $name;
Expand Down
2 changes: 1 addition & 1 deletion tests/test-s3-uploads-stream-wrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public function test_list_directory_with_wildcard() {
$files = scandir( $upload_dir['path'] . '/my-file*' );
$this->assertEquals(
[
'my-file-scaled.jpg'
'my-file-scaled.jpg',
],
$files
);
Expand Down

0 comments on commit 923a5ec

Please sign in to comment.