Skip to content

Remove unreachable code #1079

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

Merged
merged 3 commits into from
May 26, 2023
Merged

Remove unreachable code #1079

merged 3 commits into from
May 26, 2023

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented May 25, 2023

Remove private properties and method never accessed. Found thanks to ./vendor/bin/psalm --find-dead-code.

This code should be safe to remove, unless it's used for introspection, using reflection or by the C driver.

@@ -272,8 +271,6 @@ private function fileCollectionInsert()

throw $e;
}

return $this->file['_id'];
Copy link
Member Author

Choose a reason for hiding this comment

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

Returned value never used.

Copy link
Member

Choose a reason for hiding this comment

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

It looks like this dates back to some early GridFS code which was refactored long ago. This looks good to remove.

@GromNaN GromNaN requested review from jmikola and alcaeus May 25, 2023 15:27
@@ -181,7 +178,6 @@ public function __construct(Manager $manager, string $databaseName, array $optio
$this->databaseName = $databaseName;
$this->bucketName = $options['bucketName'];
$this->chunkSizeBytes = $options['chunkSizeBytes'];
$this->disableMD5 = $options['disableMD5'];
Copy link
Member

Choose a reason for hiding this comment

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

This looks like a bug.

The option was introduced in f169616 for PHPLIB-319. The GridFS spec notes that it's relevant so long as a driver still supports MD5 hashes, which PHPLIB does.

It looks like openUploadStream() never inherits the Bucket's default value like it does for chunkSizeBytes. I believe all of the existing spec tests only set the option when invoking the operation, so the Bucket inheritance is never tested.

Would you mind reporting a new issue for this and marking it linking it to PHPLIB-319 and this comment thread for context?

@@ -159,13 +159,4 @@ private function createOptions(): array

return $options;
}

private function isFindAndModify(Explainable $explainable): bool
Copy link
Member

Choose a reason for hiding this comment

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

This was originally introduced in c6a2df9 and I missed removing it in 103c1f2#diff-fc0bd4b2f7c5d5615660cecd2acc184702ebfbd7153723cc4d0954bc6696bc08L121 when cleaning up code for pre-3.6 servers.

@@ -127,7 +124,6 @@ public function stream_eof(): bool
public function stream_open(string $path, string $mode, int $options, ?string &$openedPath): bool
{
$this->initProtocol($path);
$this->mode = $mode;
Copy link
Member

Choose a reason for hiding this comment

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

Introduced in e2bf1d4#diff-87d70a08d4e98fae61febf5131732ba9564f41ce431a1ea8f4bd759df70c2365R95 and never removed in bc98d9c when stream_stat() was refactored.

Copy link
Member

@jmikola jmikola left a comment

Choose a reason for hiding this comment

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

LGTM with the disableMD5 change reverted (and a new issue created).

Thanks for digging into this.

@GromNaN
Copy link
Member Author

GromNaN commented May 25, 2023

Thanks for the review in deep. I reverted $disableMD5 and created PHPLIB-1142

@GromNaN GromNaN requested a review from jmikola May 26, 2023 07:36
@GromNaN GromNaN merged commit 8d985e6 into mongodb:master May 26, 2023
@GromNaN GromNaN deleted the dead-code branch May 26, 2023 07:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants