Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d30a06a

Browse files
committed
Add a method to check if any results were found
1 parent 9b8d96b commit d30a06a

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

src/Symfony/Component/Finder/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
-----
66

77
* deprecated `Symfony\Component\Finder\Iterator\FilterIterator`
8+
* added Finder::found() method to check if any results were found
89

910
3.3.0
1011
-----

src/Symfony/Component/Finder/Finder.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,20 @@ public function append($iterator)
613613
return $this;
614614
}
615615

616+
/**
617+
* Check if the any results were found.
618+
*
619+
* @return bool
620+
*/
621+
public function found()
622+
{
623+
foreach ($this->getIterator() as $null) {
624+
return true;
625+
}
626+
627+
return false;
628+
}
629+
616630
/**
617631
* Counts all the results collected by the iterators.
618632
*

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,20 @@ public function testCountWithoutIn()
424424
count($finder);
425425
}
426426

427+
public function testFound()
428+
{
429+
$finder = $this->buildFinder();
430+
$finder->in(__DIR__);
431+
$this->assertTrue($finder->found());
432+
}
433+
434+
public function testNotFound()
435+
{
436+
$finder = $this->buildFinder();
437+
$finder->in(__DIR__)->name('DoesNotExist');
438+
$this->assertFalse($finder->found());
439+
}
440+
427441
/**
428442
* @dataProvider getContainsTestData
429443
*/

0 commit comments

Comments
 (0)