Skip to content

Fix codestyle #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<ruleset name="phpDocumentor">
<description>The coding standard for phpDocumentor.</description>

<config name="php_version" value="70200"/>
<file>src</file>
<file>tests/unit</file>
<file>tests/integration</file>
Expand Down
18 changes: 10 additions & 8 deletions src/Finder.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ class Finder implements PluginInterface
/**
* Get the method name.
*/
public function getMethod() : string
public function getMethod(): string
{
return 'find';
}

/**
* Set the Filesystem object.
*/
public function setFilesystem(FilesystemInterface $filesystem) : void
public function setFilesystem(FilesystemInterface $filesystem): void
{
$this->filesystem = $filesystem;
}
Expand All @@ -59,12 +59,14 @@ public function setFilesystem(FilesystemInterface $filesystem) : void
*
* @return Generator<mixed>
*/
public function handle(SpecificationInterface $specification) : Generator
public function handle(SpecificationInterface $specification): Generator
{
foreach ($this->yieldFilesInPath($specification, '') as $path) {
if (isset($path['type']) && $path['type'] === 'file') {
yield $path;
if (!isset($path['type']) || $path['type'] !== 'file') {
continue;
}

yield $path;
}
}

Expand All @@ -77,10 +79,9 @@ public function handle(SpecificationInterface $specification) : Generator
* by {@link handle()}.
*
* @return Generator<mixed>
*
* @psalm-return Generator<array{basename: string, path: string, stream: resource, dirname: string, type: string, extension: string}>
*/
private function yieldFilesInPath(SpecificationInterface $specification, string $path) : Generator
private function yieldFilesInPath(SpecificationInterface $specification, string $path): Generator
{
$listContents = $this->filesystem->listContents($path);
/** @psalm-var array{basename: string, path: string, stream: resource, dirname: string, type: string, extension: string} $location */
Expand All @@ -89,7 +90,8 @@ private function yieldFilesInPath(SpecificationInterface $specification, string
yield $location;
}

if ($location['type'] !== 'dir'
if (
$location['type'] !== 'dir'
|| !CompositeSpecification::thatCanBeSatisfiedBySomethingBelow($specification, $location)
) {
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/Path.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct(string $path)
/**
* returns a string representation of the path.
*/
public function __toString() : string
public function __toString(): string
{
return $this->path;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Specification/AndSpecification.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,20 @@ public function __construct(SpecificationInterface $one, SpecificationInterface
/**
* {@inheritDoc}
*/
public function isSatisfiedBy(array $value) : bool
public function isSatisfiedBy(array $value): bool
{
return $this->one->isSatisfiedBy($value) && $this->other->isSatisfiedBy($value);
}

/** {@inheritDoc} */
public function canBeSatisfiedBySomethingBelow(array $value) : bool
public function canBeSatisfiedBySomethingBelow(array $value): bool
{
return self::thatCanBeSatisfiedBySomethingBelow($this->one, $value)
&& self::thatCanBeSatisfiedBySomethingBelow($this->other, $value);
}

/** {@inheritDoc} */
public function willBeSatisfiedByEverythingBelow(array $value) : bool
public function willBeSatisfiedByEverythingBelow(array $value): bool
{
return self::thatWillBeSatisfiedByEverythingBelow($this->one, $value)
&& self::thatWillBeSatisfiedByEverythingBelow($this->other, $value);
Expand Down
18 changes: 9 additions & 9 deletions src/Specification/CompositeSpecification.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ abstract class CompositeSpecification implements SpecificationInterface, Prunabl
* Returns a specification that satisfies the original specification
* as well as the other specification
*/
public function andSpecification(SpecificationInterface $other) : AndSpecification
public function andSpecification(SpecificationInterface $other): AndSpecification
{
return new AndSpecification($this, $other);
}
Expand All @@ -33,7 +33,7 @@ public function andSpecification(SpecificationInterface $other) : AndSpecificati
* Returns a specification that satisfies the original specification
* or the other specification
*/
public function orSpecification(SpecificationInterface $other) : OrSpecification
public function orSpecification(SpecificationInterface $other): OrSpecification
{
return new OrSpecification($this, $other);
}
Expand All @@ -42,19 +42,19 @@ public function orSpecification(SpecificationInterface $other) : OrSpecification
* Returns a specification that is the inverse of the original specification
* i.e. does not meet the original criteria
*/
public function notSpecification() : NotSpecification
public function notSpecification(): NotSpecification
{
return new NotSpecification($this);
}

/** {@inheritDoc} */
public function canBeSatisfiedBySomethingBelow(array $value) : bool
public function canBeSatisfiedBySomethingBelow(array $value): bool
{
return true;
}

/** {@inheritDoc} */
public function willBeSatisfiedByEverythingBelow(array $value) : bool
public function willBeSatisfiedByEverythingBelow(array $value): bool
{
return false;
}
Expand All @@ -64,11 +64,11 @@ public function willBeSatisfiedByEverythingBelow(array $value) : bool
* that don't implement PrunableInterface
*
* @param mixed[] $value
*
* @psalm-param array{basename: string, path: string, stream: resource, dirname: string, type: string, extension: string} $value
*
* @psalm-mutation-free
*/
public static function thatCanBeSatisfiedBySomethingBelow(SpecificationInterface $that, array $value) : bool
public static function thatCanBeSatisfiedBySomethingBelow(SpecificationInterface $that, array $value): bool
{
return $that instanceof PrunableInterface
? $that->canBeSatisfiedBySomethingBelow($value)
Expand All @@ -80,11 +80,11 @@ public static function thatCanBeSatisfiedBySomethingBelow(SpecificationInterface
* that don't implement PrunableInterface
*
* @param mixed[] $value
*
* @psalm-param array{basename: string, path: string, stream: resource, dirname: string, type: string, extension: string} $value
*
* @psalm-mutation-free
*/
public static function thatWillBeSatisfiedByEverythingBelow(SpecificationInterface $that, array $value) : bool
public static function thatWillBeSatisfiedByEverythingBelow(SpecificationInterface $that, array $value): bool
{
return $that instanceof PrunableInterface
&& $that->willBeSatisfiedByEverythingBelow($value);
Expand Down
30 changes: 17 additions & 13 deletions src/Specification/Glob.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
namespace Flyfinder\Specification;

use InvalidArgumentException;

use function array_slice;
use function count;
use function explode;
Expand Down Expand Up @@ -76,7 +77,7 @@ public function __construct(string $glob)
/**
* @inheritDoc
*/
public function isSatisfiedBy(array $value) : bool
public function isSatisfiedBy(array $value): bool
{
//Flysystem paths are not absolute, so make it that way.
$path = '/' . $value['path'];
Expand All @@ -101,7 +102,7 @@ public function isSatisfiedBy(array $value) : bool
*
* @psalm-pure
*/
private static function getStaticPrefix(string $glob) : string
private static function getStaticPrefix(string $glob): string
{
self::assertValidGlob($glob);
$prefix = '';
Expand Down Expand Up @@ -135,7 +136,7 @@ private static function getStaticPrefix(string $glob) : string
return $prefix;
}

private static function getBoundedPrefix(string $glob) : string
private static function getBoundedPrefix(string $glob): string
{
self::assertValidGlob($glob);
$prefix = '';
Expand Down Expand Up @@ -165,23 +166,23 @@ private static function getBoundedPrefix(string $glob) : string
return $prefix;
}

private static function getTotalPrefix(string $glob) : ?string
private static function getTotalPrefix(string $glob): ?string
{
self::assertValidGlob($glob);
$matches = [];

return preg_match('~(?<!\\\\)/\\*\\*(?:/\\*\\*?)+$~', $glob, $matches)
? substr($glob, 0, strlen($glob)-strlen($matches[0]))
? substr($glob, 0, strlen($glob) - strlen($matches[0]))
: null;
}

/**
* @return mixed[]
*
* @psalm-return array{0: string, 1:int}
*
* @psalm-pure
*/
private static function scanBackslashSequence(string $glob, int $offset) : array
private static function scanBackslashSequence(string $glob, int $offset): array
{
$startOffset = $offset;
$result = '';
Expand Down Expand Up @@ -212,7 +213,7 @@ private static function scanBackslashSequence(string $glob, int $offset) : array
*
* @psalm-pure
*/
private static function assertValidGlob(string $glob) : void
private static function assertValidGlob(string $glob): void
{
if (strpos($glob, '/') !== 0 && strpos($glob, '://') === false) {
throw new InvalidArgumentException(sprintf(
Expand All @@ -227,7 +228,7 @@ private static function assertValidGlob(string $glob) : void
*
* @psalm-pure
*/
private static function isRecursiveWildcard(string $glob, int $i) : bool
private static function isRecursiveWildcard(string $glob, int $i): bool
{
return isset($glob[$i + 3]) && $glob[$i + 1] . $glob[$i + 2] . $glob[$i + 3] === '**/';
}
Expand All @@ -243,7 +244,7 @@ private static function isRecursiveWildcard(string $glob, int $i) : bool
*
* @psalm-pure
*/
private static function toRegEx(string $glob) : string
private static function toRegEx(string $glob): string
{
$delimiter = '~';
$inSquare = false;
Expand Down Expand Up @@ -357,13 +358,16 @@ private static function toRegEx(string $glob) : string
}

/** @inheritDoc */
public function canBeSatisfiedBySomethingBelow(array $value) : bool
public function canBeSatisfiedBySomethingBelow(array $value): bool
{
$valueSegments = explode('/', '/' . $value['path']);
$boundedPrefixSegments = explode('/', rtrim($this->boundedPrefix, '/'));
$howManySegmentsToConsider = min(count($valueSegments), count($boundedPrefixSegments));
$boundedPrefixGlob = implode('/', array_slice($boundedPrefixSegments, 0, $howManySegmentsToConsider));
$valuePathPrefix = implode('/', array_slice($valueSegments, 1, max($howManySegmentsToConsider-1, 0)));
$valuePathPrefix = implode(
'/',
array_slice($valueSegments, 1, max($howManySegmentsToConsider - 1, 0))
);
$prefixValue = $value;
$prefixValue['path'] = $valuePathPrefix;

Expand All @@ -377,7 +381,7 @@ public function canBeSatisfiedBySomethingBelow(array $value) : bool
}

/** @inheritDoc */
public function willBeSatisfiedByEverythingBelow(array $value) : bool
public function willBeSatisfiedByEverythingBelow(array $value): bool
{
if ($this->totalPrefix === null) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/Specification/HasExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(array $extensions)
/**
* {@inheritDoc}
*/
public function isSatisfiedBy(array $value) : bool
public function isSatisfiedBy(array $value): bool
{
return isset($value['extension']) && in_array($value['extension'], $this->extensions, false);
}
Expand Down
7 changes: 4 additions & 3 deletions src/Specification/InPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Flyfinder\Specification;

use Flyfinder\Path;

use function array_slice;
use function count;
use function explode;
Expand Down Expand Up @@ -46,7 +47,7 @@ public function __construct(Path $path)
/**
* {@inheritDoc}
*/
public function isSatisfiedBy(array $value) : bool
public function isSatisfiedBy(array $value): bool
{
if (in_array($this->path, ['', '.', './'], false)) {
/*
Expand Down Expand Up @@ -90,7 +91,7 @@ public function isSatisfiedBy(array $value) : bool
}

/** @inheritDoc */
public function canBeSatisfiedBySomethingBelow(array $value) : bool
public function canBeSatisfiedBySomethingBelow(array $value): bool
{
$pathSegments = explode('/', (string) $this->path);
$valueSegments = explode('/', $value['path']);
Expand All @@ -101,7 +102,7 @@ public function canBeSatisfiedBySomethingBelow(array $value) : bool
}

/** @inheritDoc */
public function willBeSatisfiedByEverythingBelow(array $value) : bool
public function willBeSatisfiedByEverythingBelow(array $value): bool
{
return $this->isSatisfiedBy($value);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Specification/IsHidden.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class IsHidden extends CompositeSpecification
/**
* {@inheritDoc}
*/
public function isSatisfiedBy(array $value) : bool
public function isSatisfiedBy(array $value): bool
{
return isset($value['basename']) && substr($value['basename'], 0, 1) === '.';
}
Expand Down
6 changes: 3 additions & 3 deletions src/Specification/NotSpecification.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ public function __construct(SpecificationInterface $wrapped)
/**
* {@inheritDoc}
*/
public function isSatisfiedBy(array $value) : bool
public function isSatisfiedBy(array $value): bool
{
return !$this->wrapped->isSatisfiedBy($value);
}

/** @inheritDoc */
public function canBeSatisfiedBySomethingBelow(array $value) : bool
public function canBeSatisfiedBySomethingBelow(array $value): bool
{
return !self::thatWillBeSatisfiedByEverythingBelow($this->wrapped, $value);
}

/** @inheritDoc */
public function willBeSatisfiedByEverythingBelow(array $value) : bool
public function willBeSatisfiedByEverythingBelow(array $value): bool
{
return !self::thatCanBeSatisfiedBySomethingBelow($this->wrapped, $value);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Specification/OrSpecification.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,20 @@ public function __construct(SpecificationInterface $one, SpecificationInterface
/**
* {@inheritDoc}
*/
public function isSatisfiedBy(array $value) : bool
public function isSatisfiedBy(array $value): bool
{
return $this->one->isSatisfiedBy($value) || $this->other->isSatisfiedBy($value);
}

/** @inheritDoc */
public function canBeSatisfiedBySomethingBelow(array $value) : bool
public function canBeSatisfiedBySomethingBelow(array $value): bool
{
return self::thatCanBeSatisfiedBySomethingBelow($this->one, $value)
|| self::thatCanBeSatisfiedBySomethingBelow($this->other, $value);
}

/** @inheritDoc */
public function willBeSatisfiedByEverythingBelow(array $value) : bool
public function willBeSatisfiedByEverythingBelow(array $value): bool
{
return self::thatWillBeSatisfiedByEverythingBelow($this->one, $value)
|| self::thatWillBeSatisfiedByEverythingBelow($this->other, $value);
Expand Down
Loading