Skip to content

Commit

Permalink
[Finder] Fix iterator return types
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander M. Turek <me@derrabus.de>
  • Loading branch information
derrabus committed Jul 15, 2021
1 parent 87ece50 commit cbf2e51
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
5 changes: 5 additions & 0 deletions Iterator/RecursiveDirectoryIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public function __construct(string $path, int $flags, bool $ignoreUnreadableDirs
*
* @return SplFileInfo File information
*/
#[\ReturnTypeWillChange]
public function current()
{
// the logic here avoids redoing the same work in all iterations
Expand All @@ -82,6 +83,7 @@ public function current()
*
* @throws AccessDeniedException
*/
#[\ReturnTypeWillChange]
public function getChildren()
{
try {
Expand Down Expand Up @@ -109,7 +111,10 @@ public function getChildren()

/**
* Do nothing for non rewindable stream.
*
* @return void
*/
#[\ReturnTypeWillChange]
public function rewind()
{
if (false === $this->isRewindable()) {
Expand Down
6 changes: 3 additions & 3 deletions Tests/Iterator/FileTypeFilterIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,17 @@ public function getAcceptData()

class InnerTypeIterator extends \ArrayIterator
{
public function current()
public function current(): \SplFileInfo
{
return new \SplFileInfo(parent::current());
}

public function isFile()
public function isFile(): bool
{
return $this->current()->isFile();
}

public function isDir()
public function isDir(): bool
{
return $this->current()->isDir();
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/Iterator/FilenameFilterIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function getAcceptData()

class InnerNameIterator extends \ArrayIterator
{
public function current()
public function current(): \SplFileInfo
{
return new \SplFileInfo(parent::current());
}
Expand Down
12 changes: 4 additions & 8 deletions Tests/Iterator/MockSplFileInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function __construct($param)
}
}

public function isFile()
public function isFile(): bool
{
if (null === $this->type) {
return false !== strpos($this->getFilename(), 'file');
Expand All @@ -57,7 +57,7 @@ public function isFile()
return self::TYPE_FILE === $this->type;
}

public function isDir()
public function isDir(): bool
{
if (null === $this->type) {
return false !== strpos($this->getFilename(), 'directory');
Expand All @@ -66,13 +66,9 @@ public function isDir()
return self::TYPE_DIRECTORY === $this->type;
}

public function isReadable()
public function isReadable(): bool
{
if (null === $this->mode) {
return preg_match('/r\+/', $this->getFilename());
}

return preg_match('/r\+/', $this->mode);
return (bool) preg_match('/r\+/', $this->mode ?? $this->getFilename());
}

public function getContents()
Expand Down
8 changes: 4 additions & 4 deletions Tests/Iterator/SizeRangeFilterIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,22 @@ public function getAcceptData()

class InnerSizeIterator extends \ArrayIterator
{
public function current()
public function current(): \SplFileInfo
{
return new \SplFileInfo(parent::current());
}

public function getFilename()
public function getFilename(): string
{
return parent::current();
}

public function isFile()
public function isFile(): bool
{
return $this->current()->isFile();
}

public function getSize()
public function getSize(): int
{
return $this->current()->getSize();
}
Expand Down

0 comments on commit cbf2e51

Please sign in to comment.