Skip to content

Commit

Permalink
Simplify Reader codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Jan 10, 2024
1 parent 3fe8c69 commit 950f862
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 23 deletions.
27 changes: 4 additions & 23 deletions src/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,7 @@ public function fetchColumnByOffset(int $offset = 0): Iterator

public function value(int|string $column = 0): mixed
{
return match (true) {
is_string($column) => $this->first()[$column] ?? null,
default => array_values($this->first())[$column] ?? null,
};
return ResultSet::createFromTabularDataReader($this)->value($column);
}

/**
Expand Down Expand Up @@ -300,27 +297,15 @@ public function jsonSerialize(): array
*/
public function each(Closure $closure): bool
{
foreach ($this as $offset => $record) {
if (false === $closure($record, $offset)) {
return false;
}
}

return true;
return ResultSet::createFromTabularDataReader($this)->each($closure);
}

/**
* @param Closure(array<mixed>, array-key=): bool $closure
*/
public function exists(Closure $closure): bool
{
foreach ($this as $offset => $record) {
if (true === $closure($record, $offset)) {
return true;
}
}

return false;
return ResultSet::createFromTabularDataReader($this)->exists($closure);
}

/**
Expand All @@ -333,11 +318,7 @@ public function exists(Closure $closure): bool
*/
public function reduce(Closure $closure, mixed $initial = null): mixed
{
foreach ($this as $offset => $record) {
$initial = $closure($initial, $record, $offset);
}

return $initial;
return ResultSet::createFromTabularDataReader($this)->reduce($closure, $initial);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Serializer/ArrayShape.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace League\Csv\Serializer;

use function in_array;

enum ArrayShape: string
{
case List = 'list';
Expand Down

0 comments on commit 950f862

Please sign in to comment.