Skip to content

Commit

Permalink
added PHP 8 typehints
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Mar 7, 2021
1 parent 1d8c07c commit 90bf1ba
Showing 1 changed file with 12 additions and 25 deletions.
37 changes: 12 additions & 25 deletions src/Utils/Finder.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ class Finder implements \IteratorAggregate, \Countable
/**
* Begins search for files matching mask and all directories.
* @param string|string[] $masks
* @return static
*/
public static function find(...$masks): self
public static function find(...$masks): static
{
$masks = $masks && is_array($masks[0]) ? $masks[0] : $masks;
return (new static)->select($masks, 'isDir')->select($masks, 'isFile');
Expand All @@ -61,9 +60,8 @@ public static function find(...$masks): self
/**
* Begins search for files matching mask.
* @param string|string[] $masks
* @return static
*/
public static function findFiles(...$masks): self
public static function findFiles(...$masks): static
{
$masks = $masks && is_array($masks[0]) ? $masks[0] : $masks;
return (new static)->select($masks, 'isFile');
Expand All @@ -73,9 +71,8 @@ public static function findFiles(...$masks): self
/**
* Begins search for directories matching mask.
* @param string|string[] $masks
* @return static
*/
public static function findDirectories(...$masks): self
public static function findDirectories(...$masks): static
{
$masks = $masks && is_array($masks[0]) ? $masks[0] : $masks;
return (new static)->select($masks, 'isDir');
Expand All @@ -84,9 +81,8 @@ public static function findDirectories(...$masks): self

/**
* Creates filtering group by mask & type selector.
* @return static
*/
private function select(array $masks, string $type): self
private function select(array $masks, string $type): static
{
$this->cursor = &$this->groups[];
$pattern = self::buildPattern($masks);
Expand All @@ -100,9 +96,8 @@ private function select(array $masks, string $type): self
/**
* Searches in the given folder(s).
* @param string|string[] $paths
* @return static
*/
public function in(...$paths): self
public function in(...$paths): static
{
$this->maxDepth = 0;
return $this->from(...$paths);
Expand All @@ -112,9 +107,8 @@ public function in(...$paths): self
/**
* Searches recursively from the given folder(s).
* @param string|string[] $paths
* @return static
*/
public function from(...$paths): self
public function from(...$paths): static
{
if ($this->paths) {
throw new Nette\InvalidStateException('Directory to search has already been specified.');
Expand All @@ -127,9 +121,8 @@ public function from(...$paths): self

/**
* Shows folder content prior to the folder.
* @return static
*/
public function childFirst(): self
public function childFirst(): static
{
$this->order = RecursiveIteratorIterator::CHILD_FIRST;
return $this;
Expand Down Expand Up @@ -248,9 +241,8 @@ private function buildIterator(string $path): \Iterator
* Restricts the search using mask.
* Excludes directories from recursive traversing.
* @param string|string[] $masks
* @return static
*/
public function exclude(...$masks): self
public function exclude(...$masks): static
{
$masks = $masks && is_array($masks[0]) ? $masks[0] : $masks;
$pattern = self::buildPattern($masks);
Expand All @@ -264,9 +256,8 @@ public function exclude(...$masks): self
/**
* Restricts the search using callback.
* @param callable $callback function (RecursiveDirectoryIterator $file): bool
* @return static
*/
public function filter(callable $callback): self
public function filter(callable $callback): static
{
$this->cursor[] = $callback;
return $this;
Expand All @@ -275,9 +266,8 @@ public function filter(callable $callback): self

/**
* Limits recursion level.
* @return static
*/
public function limitDepth(int $depth): self
public function limitDepth(int $depth): static
{
$this->maxDepth = $depth;
return $this;
Expand All @@ -287,9 +277,8 @@ public function limitDepth(int $depth): self
/**
* Restricts the search by size.
* @param string $operator "[operator] [size] [unit]" example: >=10kB
* @return static
*/
public function size(string $operator, int $size = null): self
public function size(string $operator, int $size = null): static
{
if (func_num_args() === 1) { // in $operator is predicate
if (!preg_match('#^(?:([=<>!]=?|<>)\s*)?((?:\d*\.)?\d+)\s*(K|M|G|)B?$#Di', $operator, $matches)) {
Expand All @@ -307,10 +296,8 @@ public function size(string $operator, int $size = null): self
/**
* Restricts the search by modified time.
* @param string $operator "[operator] [date]" example: >1978-01-23
* @param string|int|\DateTimeInterface $date
* @return static
*/
public function date(string $operator, $date = null): self
public function date(string $operator, string|int|\DateTimeInterface $date = null): static
{
if (func_num_args() === 1) { // in $operator is predicate
if (!preg_match('#^(?:([=<>!]=?|<>)\s*)?(.+)$#Di', $operator, $matches)) {
Expand Down

0 comments on commit 90bf1ba

Please sign in to comment.