Skip to content
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

#186 check if file exists before asking for mtime #436

Closed
wants to merge 1 commit into from
Closed

#186 check if file exists before asking for mtime #436

wants to merge 1 commit into from

Conversation

lstrojny
Copy link

doctrine/annotations handles reading annotations from eval’ed code (as in mock objects) just fine, except that it attempts to determine the modification time via ReflectionClass::getFile() which will return the file and line where the eval() happened. This change adds fix and test for the PsrCachedReader and also fixes CachedReader but without a tests since it’s deprecated.

Fixes #186


private static function getFileMtime(string $fileName): int
{
return file_exists($fileName) && is_file($fileName) ? filemtime($fileName) : 0;
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to call both file_exists and is_file?

Copy link
Member

Choose a reason for hiding this comment

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

return file_exists($fileName) ? filemtime($fileName) : 0;

should do the trick too, shouldn't it?

Copy link

Choose a reason for hiding this comment

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

The edge case that is_file checks for here is if $fileName is a directory. I guess it makes sense to return 0 in this case, but I don't know if :

  1. It's the focus of this PR
  2. getFileMtime() can get called with a directory name at all

Copy link
Member

Choose a reason for hiding this comment

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

Isn't file_exists redundant if we have is_file?

Copy link

Choose a reason for hiding this comment

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


private static function getFileMtime(string $fileName): int
{
return file_exists($fileName) && is_file($fileName) ? filemtime($fileName) : 0;
Copy link
Member

Choose a reason for hiding this comment

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

return file_exists($fileName) ? filemtime($fileName) : 0;

should do the trick too, shouldn't it?

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.

CachedReader fails if Reflection class is eval'd code
4 participants