Skip to content

Commit 6ac080a

Browse files
Nicolas D'Amourssebastianbergmann
authored andcommitted
[FEATURE] #82
Ignore coverage for the last line of the globstar function, since it's only used if the glob function returns an error. Added a test to validate the behaviour of the globstar function when passing non existant glob pattern. Fixed code using php-cs-fixer. Fixed error reported by phpstan.
1 parent 320aff7 commit 6ac080a

File tree

6 files changed

+63
-15
lines changed

6 files changed

+63
-15
lines changed

src/Factory.php

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@
1313
use function array_filter;
1414
use function array_map;
1515
use function array_merge;
16+
use function array_unique;
1617
use function array_values;
1718
use function glob;
1819
use function is_dir;
1920
use function is_string;
2021
use function realpath;
22+
use function sort;
23+
use function stripos;
24+
use function substr;
2125
use AppendIterator;
2226
use FilesystemIterator;
2327
use RecursiveDirectoryIterator;
@@ -106,39 +110,45 @@ private function resolveWildcards(array $paths): array
106110

107111
/**
108112
* @see https://gist.github.com/funkjedi/3feee27d873ae2297b8e2370a7082aad
109-
* @param string $pattern
110-
* @return list<non-empty-string>
113+
*
114+
* @return list<string>
111115
*/
112-
private function globstar(string $pattern) {
116+
private function globstar(string $pattern)
117+
{
113118
if (stripos($pattern, '**') === false) {
114119
$files = glob($pattern, GLOB_ONLYDIR);
115120
} else {
116-
$position = stripos($pattern, '**');
121+
$position = stripos($pattern, '**');
117122
$rootPattern = substr($pattern, 0, $position - 1);
118123
$restPattern = substr($pattern, $position + 2);
119124

120-
$patterns = [$rootPattern.$restPattern];
125+
$patterns = [$rootPattern . $restPattern];
121126
$rootPattern .= '/*';
122127

123-
while($dirs = glob($rootPattern, GLOB_ONLYDIR)) {
128+
while ($dirs = glob($rootPattern, GLOB_ONLYDIR)) {
124129
$rootPattern .= '/*';
125-
foreach($dirs as $dir) {
130+
131+
foreach ($dirs as $dir) {
126132
$patterns[] = $dir . $restPattern;
127133
}
128134
}
129135

130136
$files = [];
131-
foreach($patterns as $pat) {
137+
138+
foreach ($patterns as $pat) {
132139
$files = array_merge($files, $this->globstar($pat));
133140
}
134141
}
135142

136-
if($files !== false) {
143+
if ($files !== false) {
137144
$files = array_unique($files);
138145
sort($files);
146+
139147
return $files;
140148
}
141149

150+
// @codeCoverageIgnoreStart
142151
return [];
152+
// @codeCoverageIgnoreEnd
143153
}
144154
}
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1-
<?php
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of phpunit/php-file-iterator.
4+
*
5+
* (c) Sebastian Bergmann <sebastian@phpunit.de>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1-
<?php
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of phpunit/php-file-iterator.
4+
*
5+
* (c) Sebastian Bergmann <sebastian@phpunit.de>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/

tests/fixture/b/e/i/PrefixSuffix.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1-
<?php
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of phpunit/php-file-iterator.
4+
*
5+
* (c) Sebastian Bergmann <sebastian@phpunit.de>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1-
<?php
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of phpunit/php-file-iterator.
4+
*
5+
* (c) Sebastian Bergmann <sebastian@phpunit.de>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/

tests/unit/FacadeTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
* For the full copyright and license information, please view the LICENSE
88
* file that was distributed with this source code.
99
*/
10-
1110
namespace SebastianBergmann\FileIterator;
1211

1312
use function realpath;
@@ -148,7 +147,14 @@ public static function provider(): array
148147
__DIR__ . '/../fixture/**/i',
149148
'',
150149
'',
151-
[]
150+
[],
151+
],
152+
'invalid path, filter prefix: no, filter suffix: no, excludes: none' => [
153+
[],
154+
__DIR__ . '/../fixture/**/this/path/does/not/exists',
155+
'',
156+
'',
157+
[],
152158
],
153159
];
154160
}

0 commit comments

Comments
 (0)