Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/Analyzer/Dto/Yanked.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace Exan\Moock\Analyzer\Dto;

readonly class Yanked
{
public function __construct(
public ?array $namespace,
public array $uses,
public ?array $args,
) {}
}
5 changes: 5 additions & 0 deletions src/Analyzer/Exception/EvaldCodeException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

declare(strict_types=1);

class EvaldCodeException extends RuntimeException {}
190 changes: 0 additions & 190 deletions src/Analyzer/Extractor.php

This file was deleted.

48 changes: 48 additions & 0 deletions src/Analyzer/Extractor/Imports.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace Exan\Moock\Analyzer\Extractor;

use Exan\Moock\Analyzer\TokenEmitter;
use Exan\Moock\Analyzer\TokenFilter;

/** @internal */
class Imports
{
private int $blockLevel = 0;

public function __construct(
public readonly TokenEmitter $tokenEmitter,
public array &$imports,
) {
$tokenEmitter->counter(TokenFilter::eq('{'), TokenFilter::eq('}'), $this->blockLevel);

$tokenEmitter->on(
TokenFilter::ofType(T_USE),
$this->handleUse(...),
);
}

private function handleUse(array $token): void
{
if ($this->blockLevel > 0) {
return;
}

$statement = [$token];

$capture = $this->tokenEmitter->all(function (string|array $token) use (&$statement): void {
$statement[] = $token;
});

$this->tokenEmitter->once(
TokenFilter::eq(';'),
function () use ($capture, &$statement): void {
$this->imports[] = $statement;

$this->tokenEmitter->remove($capture);
}
);
}
}
Loading
Loading