Skip to content

Commit 243afc7

Browse files
committed
Fix code style
1 parent 0e5c1d5 commit 243afc7

10 files changed

Lines changed: 30 additions & 18 deletions

File tree

src/Specification/AndSpecification.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
namespace Flyfinder\Specification;
1515

1616
/**
17-
* Class AndSpecification
18-
*
1917
* @psalm-immutable
2018
*/
2119
final class AndSpecification extends CompositeSpecification

src/Specification/CompositeSpecification.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
namespace Flyfinder\Specification;
1515

1616
/**
17-
* Class CompositeSpecification
1817
* Base class for specifications, allows for combining specifications
1918
*
2019
* @psalm-immutable

src/Specification/Glob.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,7 @@ public function isSatisfiedBy(array $value) : bool
8484
return false;
8585
}
8686

87-
if (preg_match($this->regex, $path)) {
88-
return true;
89-
}
90-
91-
return false;
87+
return preg_match($this->regex, $path) === 1;
9288
}
9389

9490
/**
@@ -118,6 +114,7 @@ private static function getStaticPrefix(string $glob) : string
118114
if (self::isRecursiveWildcard($glob, $i)) {
119115
break 2;
120116
}
117+
121118
break;
122119
case '*':
123120
case '?':
@@ -134,6 +131,7 @@ private static function getStaticPrefix(string $glob) : string
134131
break;
135132
}
136133
}
134+
137135
return $prefix;
138136
}
139137

@@ -151,6 +149,7 @@ private static function getBoundedPrefix(string $glob) : string
151149
if (self::isRecursiveWildcard($glob, $i)) {
152150
break 2;
153151
}
152+
154153
break;
155154
case '\\':
156155
[$unescaped, $consumedChars] = self::scanBackslashSequence($glob, $i);
@@ -162,13 +161,15 @@ private static function getBoundedPrefix(string $glob) : string
162161
break;
163162
}
164163
}
164+
165165
return $prefix;
166166
}
167167

168168
private static function getTotalPrefix(string $glob) : ?string
169169
{
170170
self::assertValidGlob($glob);
171171
$matches = [];
172+
172173
return preg_match('~(?<!\\\\)/\\*\\*(?:/\\*\\*?)+$~', $glob, $matches)
173174
? substr($glob, 0, strlen($glob)-strlen($matches[0]))
174175
: null;
@@ -202,6 +203,7 @@ private static function scanBackslashSequence(string $glob, int $offset) : array
202203
default:
203204
$result .= '\\';
204205
}
206+
205207
return [$result, $offset - $startOffset];
206208
}
207209

@@ -268,6 +270,7 @@ private static function toRegEx(string $glob) : string
268270
} else {
269271
$regex .= '/';
270272
}
273+
271274
break;
272275
case '*':
273276
$regex .= '[^/]*';
@@ -286,6 +289,7 @@ private static function toRegEx(string $glob) : string
286289
} else {
287290
$regex .= '}';
288291
}
292+
289293
break;
290294
case ',':
291295
$regex .= $curlyLevels > 0 ? '|' : ',';
@@ -297,6 +301,7 @@ private static function toRegEx(string $glob) : string
297301
$regex .= '^';
298302
++$i;
299303
}
304+
300305
break;
301306
case ']':
302307
$regex .= $inSquare ? ']' : '\\]';
@@ -326,24 +331,28 @@ private static function toRegEx(string $glob) : string
326331
$regex .= '\\\\';
327332
}
328333
}
334+
329335
break;
330336
default:
331337
$regex .= $c;
332338
break;
333339
}
334340
}
341+
335342
if ($inSquare) {
336343
throw new InvalidArgumentException(sprintf(
337344
'Invalid glob: missing ] in %s',
338345
$glob
339346
));
340347
}
348+
341349
if ($curlyLevels > 0) {
342350
throw new InvalidArgumentException(sprintf(
343351
'Invalid glob: missing } in %s',
344352
$glob
345353
));
346354
}
355+
347356
return $delimiter . '^' . $regex . '$' . $delimiter;
348357
}
349358

@@ -358,6 +367,7 @@ public function canBeSatisfiedBySomethingBelow(array $value) : bool
358367
$prefixValue = $value;
359368
$prefixValue['path'] = $valuePathPrefix;
360369
$spec = new Glob($boundedPrefixGlob);
370+
361371
return $spec->isSatisfiedBy($prefixValue);
362372
}
363373

@@ -367,9 +377,11 @@ public function willBeSatisfiedByEverythingBelow(array $value) : bool
367377
if ($this->totalPrefix === null) {
368378
return false;
369379
}
380+
370381
$spec = new Glob(rtrim($this->totalPrefix, '/') . '/**/*');
371382
$terminatedValue = $value;
372383
$terminatedValue['path'] = rtrim($terminatedValue['path'], '/') . '/x/x';
384+
373385
return $spec->isSatisfiedBy($terminatedValue);
374386
}
375387
}

src/Specification/HasExtension.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use function in_array;
1717

1818
/**
19-
* Class HasExtension
2019
* Files and directories meet the specification if they have the given extension
2120
*
2221
* @psalm-immutable
@@ -41,6 +40,6 @@ public function __construct(array $extensions)
4140
*/
4241
public function isSatisfiedBy(array $value) : bool
4342
{
44-
return isset($value['extension']) && in_array($value['extension'], $this->extensions, false) ? true : false;
43+
return isset($value['extension']) && in_array($value['extension'], $this->extensions, false);
4544
}
4645
}

src/Specification/InPath.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
use function str_replace;
2525

2626
/**
27-
* Class InPath
28-
*
2927
* Files *and directories* meet the specification if they are in the given path.
3028
* Note this behavior is different than in Finder, in that directories *can* meet the spec,
3129
* whereas Finder would never return a directory as "found".
@@ -98,6 +96,7 @@ public function canBeSatisfiedBySomethingBelow(array $value) : bool
9896
$valueSegments = explode('/', $value['path']);
9997
$pathPrefixSegments = array_slice($pathSegments, 0, min(count($pathSegments), count($valueSegments)));
10098
$spec = new InPath(new Path(implode('/', $pathPrefixSegments)));
99+
101100
return $spec->isSatisfiedBy($value);
102101
}
103102

src/Specification/IsHidden.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use function substr;
1717

1818
/**
19-
* Class IsHidden
2019
* Files or directories meet the specification if they are hidden
2120
*
2221
* @psalm-immutable

src/Specification/NotSpecification.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
namespace Flyfinder\Specification;
1515

1616
/**
17-
* Class NotSpecification
18-
*
1917
* @psalm-immutable
2018
*/
2119
final class NotSpecification extends CompositeSpecification

src/Specification/OrSpecification.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
namespace Flyfinder\Specification;
1515

1616
/**
17-
* Class OrSpecification
18-
*
1917
* @psalm-immutable
2018
*/
2119
final class OrSpecification extends CompositeSpecification

tests/unit/FinderTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ public function testIfNegatedAndCullsExactMatches() : void
165165
);
166166
}
167167

168-
169168
/**
170169
* @covers ::handle
171170
* @covers ::setFilesystem
@@ -349,6 +348,7 @@ protected function generatorToFileList(Generator $generator) : array
349348
return $v['path'];
350349
}, iterator_to_array($generator)));
351350
sort($actual);
351+
352352
return $actual;
353353
}
354354

@@ -396,17 +396,21 @@ protected function mockFileTree(array $pathList) : array
396396
'contents' => [],
397397
];
398398
}
399+
399400
if ($child!==null) {
400401
$result[$path]['contents'][] = $child;
401402
}
403+
402404
if ($existed) {
403405
break;
404406
}
405407
}
408+
406409
$child = $info['basename'];
407410
$path = $info['dirname'];
408411
}
409412
}
413+
410414
return $result;
411415
}
412416

@@ -421,13 +425,15 @@ protected function mockListContents(array $fileTreeMock, string $path) : array
421425
if (substr($path . ' ', 0, 2)==='./') {
422426
$path = substr($path, 2);
423427
}
428+
424429
if ($path==='') {
425430
$path = '.';
426431
}
427432

428433
if (!isset($fileTreeMock[$path]) || $fileTreeMock[$path]['type'] === 'file') {
429434
return [];
430435
}
436+
431437
$result = [];
432438
foreach ($fileTreeMock[$path]['contents'] as $basename) {
433439
$childPath = ($path==='.' ? '' : $path . '/') . $basename;
@@ -437,6 +443,7 @@ protected function mockListContents(array $fileTreeMock, string $path) : array
437443

438444
$result[$basename] = $fileTreeMock[$childPath];
439445
}
446+
440447
return $result;
441448
}
442449

@@ -452,8 +459,10 @@ protected function mockFileSystem(array $paths, array $pathsThatShouldNotBeListe
452459
->zeroOrMoreTimes()
453460
->andReturnUsing(function (string $path) use ($fsData, $pathsThatShouldNotBeListed) : array {
454461
$this->assertNotContains($path, $pathsThatShouldNotBeListed);
462+
455463
return array_values($this->mockListContents($fsData, $path));
456464
});
465+
457466
return $filesystem;
458467
}
459468
}

tests/unit/Specification/GlobTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ public function matchingPatternFileWithEscapeCharProvider() : Generator
123123

124124
foreach ($escapeChars as $char) {
125125
$file = sprintf('/src/test\\%s.php', $char);
126+
126127
yield $file => [
127128
$file,
128129
['path' => sprintf('src/test%s.php', $char)],

0 commit comments

Comments
 (0)