Skip to content

Commit ba53ae9

Browse files
committed
Returns false if the Qualified Name is not found
1 parent d477ac0 commit ba53ae9

2 files changed

Lines changed: 9 additions & 10 deletions

File tree

system/Autoloader/FileLocator.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,7 @@ public function search(string $path, string $ext = 'php'): array
220220

221221
foreach ($this->getNamespaces() as $namespace)
222222
{
223-
$namespace['path'] = rtrim($namespace['path'], '/') . '/';
224-
225-
if (is_file($namespace['path'] . $path) === true)
223+
if (is_file($namespace['path'] . $path))
226224
{
227225
$foundPaths[] = $namespace['path'] . $path;
228226
}
@@ -294,21 +292,20 @@ protected function getNamespaces(string $prefix = null)
294292
//--------------------------------------------------------------------
295293

296294
/**
297-
* Attempts to load a file and instantiate a new class by looking
298-
* at its full path and comparing that to our existing psr4 namespaces
299-
* in Autoloader config file.
295+
* Find the qualified name of a file according to
296+
* the namespace of the first matched namespace path.
300297
*
301298
* @param string $path
302299
*
303-
* @return string|void
300+
* @return string|false The qualified name or false if the path is not found
304301
*/
305302
public function findQualifiedNameFromPath(string $path)
306303
{
307304
$path = realpath($path);
308305

309306
if (! $path)
310307
{
311-
return;
308+
return false;
312309
}
313310

314311
foreach ($this->getNamespaces() as $namespace)
@@ -332,6 +329,8 @@ public function findQualifiedNameFromPath(string $path)
332329
return $className;
333330
}
334331
}
332+
333+
return false;
335334
}
336335

337336
//--------------------------------------------------------------------

tests/system/Autoloader/FileLocatorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,14 @@ public function testFindQNameFromPathWithFileNotExist()
245245
{
246246
$ClassName = $this->locator->findQualifiedNameFromPath('modules/blog/Views/index.php');
247247

248-
$this->assertNull($ClassName);
248+
$this->assertFalse($ClassName);
249249
}
250250

251251
public function testFindQNameFromPathWithoutCorrespondingNamespace()
252252
{
253253
$ClassName = $this->locator->findQualifiedNameFromPath('/etc/hosts');
254254

255-
$this->assertNull($ClassName);
255+
$this->assertFalse($ClassName);
256256
}
257257

258258
public function testGetClassNameFromClassFile()

0 commit comments

Comments
 (0)