8000 feature #30744 [Finder] Throw a dedicated exception for non-existing … · symfony/symfony@30b9617 · GitHub
[go: up one dir, main page]

Skip to content

Commit 30b9617

Browse files
committed
feature #30744 [Finder] Throw a dedicated exception for non-existing directory (xelan)
This PR was merged into the 4.3-dev branch. Discussion ---------- [Finder] Throw a dedicated exception for non-existing directory | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes [1] | New feature? | yes | BC breaks? | no | Deprecations? | no [2] | Tests pass? | yes | Fixed tickets | #30723 | License | MIT | Doc PR | N/A [3] 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 backward compatibility, the new exception class inherits from `InvalidArgumentException`. [1] A valid, but non-existent directory name is IMHO not an invalid argument [2] However, it may be semantically better to extend from `RuntimeException`, This would require a deprecation. [3] Possible exceptions are currently not explained at https://symfony.com/doc/current/components/finder.html Commits ------- 48d5f94 Throw a dedicated exception for non-existing directory
2 parents 7cb14f3 + 48d5f94 commit 30b9617

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed
Lines 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

Lines 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

Lines 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