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

Use is_file() instead of Filesystem::exists() #614

Merged
merged 1 commit into from
Jul 1, 2015
Merged

Use is_file() instead of Filesystem::exists() #614

merged 1 commit into from
Jul 1, 2015

Conversation

lstrojny
Copy link
Contributor

Filesystem::exists() will return true no matter what, even if the file is actually a directory. This happens e.g. if you pass an empty path to the Twig filter. I know this breaks the Filesystem encapsulation but there is no is_file() equivalent in Filesystem.

@lsmith77 lsmith77 added the State: Reviewing This item is being reviewed to determine if it should be accepted. label Jul 1, 2015
@@ -63,7 +63,7 @@ public function resolve($path, $filter)
*/
public function isStored($path, $filter)
{
return $this->filesystem->exists($this->getFilePath($path, $filter));
return is_file($this->getFilePath($path, $filter));
Copy link

Choose a reason for hiding this comment

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

(Hopping in here from Twitter! Hi Lukas!)

Wouldn't you want to call it as \is_file() instead (same for the sys_get_temp_dir() call in WebPathResolverTest.php) so that the call shaves off the resolve time instead of looking for:

\Liip\ImagineBundle\Imagine\Cache\Resolver\is_file()
\Liip\ImagineBundle\Imagine\Cache\is_file()
\Liip\ImagineBundle\Imagine\is_file()
\Liip\ImagineBundle\is_file()
\Liip\is_file()
\is_file()

Although I can't remember if the lookup attempts between \Liip\ImagineBundle\Imagine\Cache\Resolver\is_file() and \is_file() are still the case.

Copy link
Contributor

Choose a reason for hiding this comment

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

I do not have a link handy but afaik this isn't relevant in terms of performance.

Copy link

Choose a reason for hiding this comment

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

Indeed, although I would consider it good practice all-in-all (:

lsmith77 added a commit that referenced this pull request Jul 1, 2015
Use is_file() instead of Filesystem::exists()
@lsmith77 lsmith77 merged commit 0da0240 into liip:master Jul 1, 2015
@lsmith77 lsmith77 removed the State: Reviewing This item is being reviewed to determine if it should be accepted. label Jul 1, 2015
@makasim
Copy link
Collaborator

makasim commented Jul 2, 2015

👍

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.

4 participants