Skip to content

Commit

Permalink
`\LastDragon_ru\LaraASP\Documentator\Processor\Contracts\Task::__invo…
Browse files Browse the repository at this point in the history
…ke()` cannot return `null` anymore.

Reverts: 9028c23
  • Loading branch information
LastDragon-ru committed Dec 13, 2024
1 parent 2dab326 commit 44765c2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 116 deletions.
14 changes: 4 additions & 10 deletions packages/documentator/src/Processor/Contracts/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,13 @@ public static function getExtensions(): array;
* or failed (`false`).
*
* The {@see Generator} means that the task has dependencies (= other files
* which should be processed before the task). Each returned value will be
* which should be processed before the current). Each returned value will be
* resolved relative to the directory where the `$file` located, processed,
* and then send back into the generator.
*
* And, finally, the `null`. Special value that will postpone processing
* until all other files (and their dependencies) are processed. It may be
* useful, for example, if the task should collect information from all
* other files. Please note, the `null` can be returned only once, the
* second time will automatically mark the task as failed.
*
* @return Generator<mixed, Dependency<*>, mixed, bool>|bool|null
* fixme(documentator): The correct type is `Generator<mixed, Dependency<V>, V, bool>|bool|null`
* @return Generator<mixed, Dependency<*>, mixed, bool>|bool
* fixme(documentator): The correct type is `Generator<mixed, Dependency<V>, V, bool>|bool`
* but it is not yet supported by phpstan (see https://github.com/phpstan/phpstan/issues/4245)
*/
public function __invoke(Directory $root, File $file): Generator|bool|null;
public function __invoke(Directory $root, File $file): Generator|bool;
}
9 changes: 1 addition & 8 deletions packages/documentator/src/Processor/Executor.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,10 @@ private function runFile(File $file): float {
foreach ($tasks as $task) {
try {
// Run
$result = false;
$generator = $task($this->root, $file);

// Postponed?
if ($generator === null) {
$paused += $this->runIterator();
$generator = $task($this->root, $file) ?? false;
}

// Dependencies?
$result = false;

if ($generator instanceof Generator) {
while ($generator->valid()) {
$dependency = $generator->current();
Expand Down
98 changes: 0 additions & 98 deletions packages/documentator/src/Processor/ProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,104 +179,6 @@ static function (FilePath $path, Result $result) use (&$count, &$events): void {
);
}

public function testRunPostpone(): void {
$task = new class() implements Task {
/**
* @var array<array-key, string>
*/
public array $processed = [];
/**
* @var array<string, bool>
*/
public array $postponed = [];

/**
* @inheritDoc
*/
#[Override]
public static function getExtensions(): array {
return ['txt', 'htm', 'html'];
}

/**
* @inheritDoc
*/
#[Override]
public function __invoke(Directory $root, File $file): ?bool {
// Postponed?
$path = (string) $root->getRelativePath($file);

if ($file->getExtension() === 'html' && !isset($this->postponed[$path])) {
$this->postponed[$path] = true;

return null;
}

// Process
$this->processed[] = $path;

return true;
}
};

$root = (new DirectoryPath(self::getTestData()->path('')))->getNormalizedPath();
$count = 0;
$events = [];

(new Processor($this->app()->make(ContainerResolver::class)))
->task($task)
->exclude(['excluded.txt', '**/**/excluded.txt'])
->run(
$root,
static function (FilePath $path, Result $result) use (&$count, &$events): void {
$events[(string) $path] = $result;
$count++;
},
);

self::assertEquals(
[
'b/a/ba.txt' => Result::Success,
'c.txt' => Result::Success,
'b/b/bb.txt' => Result::Success,
'a/a.txt' => Result::Success,
'a/a/aa.txt' => Result::Success,
'a/b/ab.txt' => Result::Success,
'b/b.txt' => Result::Success,
'c.htm' => Result::Success,
'c.html' => Result::Success,
'b/b.html' => Result::Success,
'a/a.html' => Result::Success,
],
$events,
);
self::assertCount($count, $events);
self::assertEquals(
[
'a/a.txt',
'a/a/aa.txt',
'a/b/ab.txt',
'b/a/ba.txt',
'b/b.txt',
'b/b/bb.txt',
'c.htm',
'c.txt',
'c.html',
'b/b.html',
'a/a.html',
],
$task->processed,
);
self::assertEquals(
[
'c.html' => true,
'b/b.html' => true,
'a/a.html' => true,
],
$task->postponed,
);
}

public function testRunWildcard(): void {
$taskA = new class([
'b.html' => [
Expand Down

0 comments on commit 44765c2

Please sign in to comment.