Skip to content

Commit

Permalink
Dependency may return any \Traversable.
Browse files Browse the repository at this point in the history
  • Loading branch information
LastDragon-ru committed Aug 13, 2024
1 parent 770e9ea commit 719f465
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions packages/documentator/src/Processor/Contracts/Dependency.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

namespace LastDragon_ru\LaraASP\Documentator\Processor\Contracts;

use Iterator;
use LastDragon_ru\LaraASP\Documentator\Processor\Exceptions\DependencyNotFound;
use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\Directory;
use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\File;
use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\FileSystem;
use Stringable;
use Traversable;

/**
* Task dependency (= another file).
*
* @template TValue of Iterator<mixed, Directory|File>|Directory|File|null
* @template TValue of Traversable<mixed, Directory|File>|Directory|File|null
*/
interface Dependency extends Stringable {
/**
Expand Down
4 changes: 2 additions & 2 deletions packages/documentator/src/Processor/Dependencies/Optional.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

namespace LastDragon_ru\LaraASP\Documentator\Processor\Dependencies;

use Iterator;
use LastDragon_ru\LaraASP\Documentator\Processor\Contracts\Dependency;
use LastDragon_ru\LaraASP\Documentator\Processor\Exceptions\DependencyNotFound;
use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\Directory;
use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\File;
use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\FileSystem;
use Override;
use Traversable;

/**
* @template TValue of Iterator<mixed, Directory|File>|Directory|File|null
* @template TValue of Traversable<mixed, Directory|File>|Directory|File|null
*
* @implements Dependency<TValue|null>
*/
Expand Down
7 changes: 4 additions & 3 deletions packages/documentator/src/Processor/Executor.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\File;
use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\FileSystem;
use Throwable;
use Traversable;

use function array_merge;
use function array_values;
Expand Down Expand Up @@ -124,15 +125,15 @@ private function runFile(File $file): float {
$dependency = $generator->current();
$resolved = $dependency($this->fs, $this->root, $file);

if ($resolved instanceof Iterator) {
$resolved = new ExecutorIterator($dependency, $resolved, $this->runDependency(...));
if ($resolved instanceof Traversable) {
$resolved = new ExecutorTraversable($dependency, $resolved, $this->runDependency(...));
} else {
$paused += $this->runDependency($dependency, $resolved);
}

$generator->send($resolved);

if ($resolved instanceof ExecutorIterator) {
if ($resolved instanceof ExecutorTraversable) {
$paused += $resolved->getDuration();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

use Closure;
use Generator;
use Iterator;
use IteratorAggregate;
use LastDragon_ru\LaraASP\Documentator\Processor\Contracts\Dependency;
use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\Directory;
use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\File;
use Override;
use Traversable;

/**
* @internal
Expand All @@ -19,20 +19,20 @@
*
* @implements IteratorAggregate<TKey, TValue>
*/
class ExecutorIterator implements IteratorAggregate {
class ExecutorTraversable implements IteratorAggregate {
private float $duration = 0;

public function __construct(
/**
* @var Dependency<Iterator<TKey, TValue>>
* @var Dependency<Traversable<TKey, TValue>>
*/
private readonly Dependency $dependency,
/**
* @var Iterator<TKey, TValue>
* @var Traversable<TKey, TValue>
*/
private readonly Iterator $resolved,
private readonly Traversable $resolved,
/**
* @var Closure(Dependency<Iterator<TKey, TValue>>, TValue): float
* @var Closure(Dependency<Traversable<TKey, TValue>>, TValue): float
*/
private readonly Closure $handler,
) {
Expand Down
2 changes: 1 addition & 1 deletion phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ parameters:
path: packages/core/src/Observer/DispatcherTest.php

-
message: "#^Parameter \\#1 \\$dependency of class LastDragon_ru\\\\LaraASP\\\\Documentator\\\\Processor\\\\ExecutorIterator constructor expects LastDragon_ru\\\\LaraASP\\\\Documentator\\\\Processor\\\\Contracts\\\\Dependency\\<Iterator\\<mixed, LastDragon_ru\\\\LaraASP\\\\Documentator\\\\Processor\\\\FileSystem\\\\Directory\\|LastDragon_ru\\\\LaraASP\\\\Documentator\\\\Processor\\\\FileSystem\\\\File\\>\\>, LastDragon_ru\\\\LaraASP\\\\Documentator\\\\Processor\\\\Contracts\\\\Dependency\\<\\*\\> given\\.$#"
message: "#^Parameter \\#1 \\$dependency of class LastDragon_ru\\\\LaraASP\\\\Documentator\\\\Processor\\\\ExecutorTraversable constructor expects LastDragon_ru\\\\LaraASP\\\\Documentator\\\\Processor\\\\Contracts\\\\Dependency\\<Traversable\\<mixed, LastDragon_ru\\\\LaraASP\\\\Documentator\\\\Processor\\\\FileSystem\\\\Directory\\|LastDragon_ru\\\\LaraASP\\\\Documentator\\\\Processor\\\\FileSystem\\\\File\\>\\>, LastDragon_ru\\\\LaraASP\\\\Documentator\\\\Processor\\\\Contracts\\\\Dependency\\<\\*\\> given\\.$#"
count: 1
path: packages/documentator/src/Processor/Executor.php

Expand Down

0 comments on commit 719f465

Please sign in to comment.