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 24dcb52

Browse filesBrowse files
committed
Add a method to check if any results were found
1 parent 07f7973 commit 24dcb52
Copy full SHA for 24dcb52

File tree

3 files changed

+29
-0
lines changed
Filter options

3 files changed

+29
-0
lines changed

‎src/Symfony/Component/Finder/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Finder/CHANGELOG.md
+1Lines 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::hasResults() method to check if any results were found
89

910
3.3.0
1011
-----

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Finder/Finder.php
+14Lines 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 hasResults()
622+
{
623+
foreach ($this->getIterator() as $_) {
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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Finder/Tests/FinderTest.php
+14Lines 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 testHasResults()
428+
{
429+
$finder = $this->buildFinder();
430+
$finder->in(__DIR__);
431+
$this->assertTrue($finder->hasResults());
432+
}
433+
434+
public function testNoResults()
435+
{
436+
$finder = $this->buildFinder();
437+
$finder->in(__DIR__)->name('DoesNotExist');
438+
$this->assertFalse($finder->hasResults());
439+
}
440+
427441
/**
428442
* @dataProvider getContainsTestData
429443
*/

0 commit comments

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