Skip to content
This repository

Replace file_exists() calls with is_file() where it is needed #225

Merged
merged 1 commit into from over 1 year ago

3 participants

Ilya Sabelnikov doctrinebot Johannes
Ilya Sabelnikov

The function file_exists() checks whether file or directory exists. And is_file() checks only files for the existence. All places, where file_exists() is replaced with is_file() needs only to check for file existence.

doctrinebot
Collaborator

Hello,

thank you for positing this Pull Request. I have automatically opened an issue on our Jira Bug Tracker for you with the details of this Pull-Request. See the Link:

http://doctrine-project.org/jira/browse/DCOM-145

Johannes schmittjoh merged commit c577cc7 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Nov 20, 2012
Ilya Sabelnikov fruit Replace file_exists() calls with is_file() where it is needed c17b9da
This page is out of date. Refresh to see the latest.
2  lib/Doctrine/Common/Annotations/AnnotationRegistry.php
@@ -120,7 +120,7 @@ static public function loadAnnotationClass($class)
120 120 }
121 121 } else {
122 122 foreach((array)$dirs AS $dir) {
123   - if (file_exists($dir . DIRECTORY_SEPARATOR . $file)) {
  123 + if (is_file($dir . DIRECTORY_SEPARATOR . $file)) {
124 124 require $dir . DIRECTORY_SEPARATOR . $file;
125 125 return true;
126 126 }
6 lib/Doctrine/Common/Annotations/FileCacheReader.php
@@ -91,7 +91,7 @@ public function getClassAnnotations(\ReflectionClass $class)
91 91 }
92 92
93 93 $path = $this->dir.'/'.strtr($key, '\\', '-').'.cache.php';
94   - if (!file_exists($path)) {
  94 + if (!is_file($path)) {
95 95 $annot = $this->reader->getClassAnnotations($class);
96 96 $this->saveCacheFile($path, $annot);
97 97 return $this->loadedAnnotations[$key] = $annot;
@@ -129,7 +129,7 @@ public function getPropertyAnnotations(\ReflectionProperty $property)
129 129 }
130 130
131 131 $path = $this->dir.'/'.strtr($key, '\\', '-').'.cache.php';
132   - if (!file_exists($path)) {
  132 + if (!is_file($path)) {
133 133 $annot = $this->reader->getPropertyAnnotations($property);
134 134 $this->saveCacheFile($path, $annot);
135 135 return $this->loadedAnnotations[$key] = $annot;
@@ -167,7 +167,7 @@ public function getMethodAnnotations(\ReflectionMethod $method)
167 167 }
168 168
169 169 $path = $this->dir.'/'.strtr($key, '\\', '-').'.cache.php';
170   - if (!file_exists($path)) {
  170 + if (!is_file($path)) {
171 171 $annot = $this->reader->getMethodAnnotations($method);
172 172 $this->saveCacheFile($path, $annot);
173 173 return $this->loadedAnnotations[$key] = $annot;
4 lib/Doctrine/Common/Annotations/PhpParser.php
@@ -46,7 +46,7 @@ public function parseClass(\ReflectionClass $class)
46 46 }
47 47
48 48 $content = $this->getFileContent($filename, $class->getStartLine());
49   -
  49 +
50 50 if (null === $content) {
51 51 return array();
52 52 }
@@ -69,7 +69,7 @@ public function parseClass(\ReflectionClass $class)
69 69 */
70 70 private function getFileContent($filename, $lineNumber)
71 71 {
72   - if ( ! file_exists($filename)) {
  72 + if ( ! is_file($filename)) {
73 73 return null;
74 74 }
75 75
4 lib/Doctrine/Common/Cache/FilesystemCache.php
@@ -44,7 +44,7 @@ protected function doFetch($id)
44 44 $lifetime = -1;
45 45 $filename = $this->getFilename($id);
46 46
47   - if ( ! file_exists($filename)) {
  47 + if ( ! is_file($filename)) {
48 48 return false;
49 49 }
50 50
@@ -77,7 +77,7 @@ protected function doContains($id)
77 77 $lifetime = -1;
78 78 $filename = $this->getFilename($id);
79 79
80   - if ( ! file_exists($filename)) {
  80 + if ( ! is_file($filename)) {
81 81 return false;
82 82 }
83 83
4 lib/Doctrine/Common/Cache/PhpFileCache.php
@@ -42,7 +42,7 @@ protected function doFetch($id)
42 42 {
43 43 $filename = $this->getFilename($id);
44 44
45   - if ( ! file_exists($filename)) {
  45 + if ( ! is_file($filename)) {
46 46 return false;
47 47 }
48 48
@@ -62,7 +62,7 @@ protected function doContains($id)
62 62 {
63 63 $filename = $this->getFilename($id);
64 64
65   - if ( ! file_exists($filename)) {
  65 + if ( ! is_file($filename)) {
66 66 return false;
67 67 }
68 68
2  lib/Doctrine/Common/ClassLoader.php
@@ -181,7 +181,7 @@ public function canLoadClass($className)
181 181 $file = str_replace($this->namespaceSeparator, DIRECTORY_SEPARATOR, $className) . $this->fileExtension;
182 182
183 183 if ($this->includePath !== null) {
184   - return file_exists($this->includePath . DIRECTORY_SEPARATOR . $file);
  184 + return is_file($this->includePath . DIRECTORY_SEPARATOR . $file);
185 185 }
186 186
187 187 return (false !== stream_resolve_include_path($file));
4 lib/Doctrine/Common/Persistence/Mapping/Driver/DefaultFileLocator.php
@@ -109,7 +109,7 @@ public function findMappingFile($className)
109 109
110 110 // Check whether file exists
111 111 foreach ($this->paths as $path) {
112   - if (file_exists($path . DIRECTORY_SEPARATOR . $fileName)) {
  112 + if (is_file($path . DIRECTORY_SEPARATOR . $fileName)) {
113 113 return $path . DIRECTORY_SEPARATOR . $fileName;
114 114 }
115 115 }
@@ -160,7 +160,7 @@ public function fileExists($className)
160 160
161 161 // Check whether file exists
162 162 foreach ((array) $this->paths as $path) {
163   - if (file_exists($path . DIRECTORY_SEPARATOR . $fileName)) {
  163 + if (is_file($path . DIRECTORY_SEPARATOR . $fileName)) {
164 164 return true;
165 165 }
166 166 }
2  lib/Doctrine/Common/Reflection/Psr0FindFile.php
@@ -73,7 +73,7 @@ public function findFile($class)
73 73 foreach ($this->prefixes as $prefix => $dirs) {
74 74 if (0 === strpos($class, $prefix)) {
75 75 foreach ($dirs as $dir) {
76   - if (file_exists($dir . DIRECTORY_SEPARATOR . $classPath)) {
  76 + if (is_file($dir . DIRECTORY_SEPARATOR . $classPath)) {
77 77 return $dir . DIRECTORY_SEPARATOR . $classPath;
78 78 }
79 79 }
4 tests/Doctrine/Tests/TestInit.php
@@ -11,14 +11,14 @@
11 11 {
12 12 if (0 === strpos($class, 'Doctrine\Tests\\')) {
13 13 $path = __DIR__.'/../../'.strtr($class, '\\', '/').'.php';
14   - if (file_exists($path) && is_readable($path)) {
  14 + if (is_file($path) && is_readable($path)) {
15 15 require_once $path;
16 16
17 17 return true;
18 18 }
19 19 } else if (0 === strpos($class, 'Doctrine\Common\\')) {
20 20 $path = __DIR__.'/../../../lib/'.($class = strtr($class, '\\', '/')).'.php';
21   - if (file_exists($path) && is_readable($path)) {
  21 + if (is_file($path) && is_readable($path)) {
22 22 require_once $path;
23 23
24 24 return true;
2  tests/NativePhpunitTask.php
@@ -124,7 +124,7 @@ public function main()
124 124 "failures (".$result->skippedCount()." skipped, ".$result->notImplementedCount()." not implemented)");
125 125
126 126 // Hudson for example doesn't like the backslash in class names
127   - if (file_exists($this->coverageClover)) {
  127 + if (is_file($this->coverageClover)) {
128 128 $this->log("Generated Clover Coverage XML to: ".$this->coverageClover);
129 129 $content = file_get_contents($this->coverageClover);
130 130 $content = str_replace("\\", ".", $content);

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.