Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 48d5f94

Browse filesBrowse files
committed
Throw a dedicated exception for non-existing directory
Makes Finder::in() throw a DirectoryNotFoundException instead of an InvalidArgumentException if one of the directories is not found. This behavior is more consistent with the AccessDeniedException for files which are unreadable due to insufficient permissions. To keep BC, the new exception class inherits from InvalidArgumentException.
1 parent 71c33c1 commit 48d5f94
Copy full SHA for 48d5f94

File tree

3 files changed

+32
-3
lines changed
Filter options

3 files changed

+32
-3
lines changed
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Finder\Exception;
13+
14+
/**
15+
* @author Andreas Erhard <andreas.erhard@i-med.ac.at>
16+
*/
17+
class DirectoryNotFoundException extends \InvalidArgumentException
18+
{
19+
}

‎src/Symfony/Component/Finder/Finder.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Finder/Finder.php
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Finder\Comparator\DateComparator;
1515
use Symfony\Component\Finder\Comparator\NumberComparator;
16+
use Symfony\Component\Finder\Exception\DirectoryNotFoundException;
1617
use Symfony\Component\Finder\Iterator\CustomFilterIterator;
1718
use Symfony\Component\Finder\Iterator\DateRangeFilterIterator;
1819
use Symfony\Component\Finder\Iterator\DepthRangeFilterIterator;
@@ -585,7 +586,7 @@ public function ignoreUnreadableDirs($ignore = true)
585586
*
586587
* @return $this
587588
*
588-
* @throws \InvalidArgumentException if one of the directories does not exist
589+
* @throws DirectoryNotFoundException if one of the directories does not exist
589590
*/
590591
public function in($dirs)
591592
{
@@ -597,7 +598,7 @@ public function in($dirs)
597598
} elseif ($glob = glob($dir, (\defined('GLOB_BRACE') ? GLOB_BRACE : 0) | GLOB_ONLYDIR)) {
598599
$resolvedDirs = array_merge($resolvedDirs, array_map([$this, 'normalizeDir'], $glob));
599600
} else {
600-
throw new \InvalidArgumentException(sprintf('The "%s" directory does not exist.', $dir));
601+
throw new DirectoryNotFoundException(sprintf('The "%s" directory does not exist.', $dir));
601602
}
602603
}
603604

‎src/Symfony/Component/Finder/Tests/FinderTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Finder/Tests/FinderTest.php
+10-1Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -888,14 +888,23 @@ public function testIn()
888888
}
889889

890890
/**
891-
* @expectedException \InvalidArgumentException
891+
* @expectedException \Symfony\Component\Finder\Exception\DirectoryNotFoundException
892892
*/
893893
public function testInWithNonExistentDirectory()
894894
{
895895
$finder = new Finder();
896896
$finder->in('foobar');
897897
}
898898

899+
/**
900+
* @expectedException \InvalidArgumentException
901+
*/
902+
public function testInWithNonExistentDirectoryLegacyException()
903+
{
904+
$finder = new Finder();
905+
$finder->in('foobar');
906+
}
907+
899908
public function testInWithGlob()
900909
{
901910
$finder = $this->buildFinder();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.