Skip to content

Commit

Permalink
refactor interface
Browse files Browse the repository at this point in the history
  • Loading branch information
rodber committed May 22, 2022
1 parent 0e6ffb9 commit cccefbf
Show file tree
Hide file tree
Showing 21 changed files with 70 additions and 492 deletions.
10 changes: 5 additions & 5 deletions src/JobsGraph.php → src/Graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
use Chevere\DataStructure\Traits\MapTrait;
use function Chevere\Message\message;
use Chevere\Throwable\Exceptions\InvalidArgumentException;
use Chevere\Workflow\Interfaces\JobsGraphInterface;
use Chevere\Workflow\Interfaces\GraphInterface;
use Chevere\Workflow\Traits\JobDependenciesTrait;
use Ds\Vector;

final class JobsGraph implements JobsGraphInterface
final class Graph implements GraphInterface
{
use JobDependenciesTrait;
use MapTrait;

public function withPut(string $job, string ...$dependencies): JobsGraphInterface
public function withPut(string $job, string ...$dependencies): GraphInterface
{
$this->assertDependencies(...$dependencies);
$vector = new Vector($dependencies);
Expand Down Expand Up @@ -106,11 +106,11 @@ public function toArray(): array
break;
}
}

$return[$toIndex][] = $job;
$previous[] = $job;
}

return $return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/**
* Describes the component in charge of defining jobs dependencies.
*/
interface JobsGraphInterface extends MappedInterface, ToArrayInterface
interface GraphInterface extends MappedInterface, ToArrayInterface
{
public function has(string $job): bool;

Expand All @@ -31,7 +31,7 @@ public function get(string $job): Vector;

public function hasDependencies(string $job, string ...$dependencies): bool;

public function withPut(string $job, string ...$dependencies): JobsGraphInterface;
public function withPut(string $job, string ...$dependencies): GraphInterface;

/**
* @return Array<int, string[]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/**
* Describes the component in charge of defining a workflow run, with arguments returned for each job.
*/
interface WorkflowRunInterface
interface RunInterface
{
/**
* @param mixed ...$vars Workflow variables.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
/**
* Describes the component in charge of running the workflow.
*/
interface WorkflowRunnerInterface
interface RunnerInterface
{
public function __construct(
WorkflowRunInterface $workflowRun,
RunInterface $workflowRun,
ContainerInterface $container
);

public function workflowRun(): WorkflowRunInterface;
public function run(): RunInterface;

public function withRun(): WorkflowRunnerInterface;
public function withRun(): RunnerInterface;

public function withRunJob(string $name): WorkflowRunnerInterface;
public function withRunJob(string $name): RunnerInterface;
}
69 changes: 0 additions & 69 deletions src/Interfaces/WorkflowMessageInterface.php

This file was deleted.

22 changes: 0 additions & 22 deletions src/Interfaces/WorkflowProviderInterface.php

This file was deleted.

32 changes: 0 additions & 32 deletions src/Interfaces/WorkflowResponseInterface.php

This file was deleted.

6 changes: 3 additions & 3 deletions src/Jobs.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
use Chevere\Throwable\Exceptions\InvalidArgumentException;
use Chevere\Throwable\Exceptions\OutOfBoundsException;
use Chevere\Throwable\Exceptions\OverflowException;
use Chevere\Workflow\Interfaces\GraphInterface;
use Chevere\Workflow\Interfaces\JobInterface;
use Chevere\Workflow\Interfaces\JobsGraphInterface;
use Chevere\Workflow\Interfaces\JobsInterface;
use Ds\Vector;
use Iterator;
Expand All @@ -36,13 +36,13 @@ final class Jobs implements JobsInterface
*/
private Vector $jobs;

private JobsGraphInterface $graph;
private GraphInterface $graph;

public function __construct(JobInterface ...$jobs)
{
$this->map = new Map();
$this->jobs = new Vector();
$this->graph = new JobsGraph();
$this->graph = new Graph();
$this->putAdded(...$jobs);
}

Expand Down
6 changes: 3 additions & 3 deletions src/WorkflowRun.php → src/Run.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
use Chevere\Throwable\Errors\TypeError;
use Chevere\Throwable\Exceptions\OutOfBoundsException;
use function Chevere\VarSupport\deepCopy;
use Chevere\Workflow\Interfaces\RunInterface;
use Chevere\Workflow\Interfaces\WorkflowInterface;
use Chevere\Workflow\Interfaces\WorkflowRunInterface;
use Ds\Map;
use Ramsey\Uuid\Uuid;

final class WorkflowRun implements WorkflowRunInterface
final class Run implements RunInterface
{
/**
* @var Map<string, ResponseInterface>
Expand Down Expand Up @@ -64,7 +64,7 @@ public function arguments(): ArgumentsInterface
return $this->arguments;
}

public function withJobResponse(string $job, ResponseInterface $response): WorkflowRunInterface
public function withJobResponse(string $job, ResponseInterface $response): RunInterface
{
$new = clone $this;
$new->workflow->jobs()->get($job);
Expand Down
22 changes: 11 additions & 11 deletions src/WorkflowRunner.php → src/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,28 @@
use Chevere\Throwable\Exceptions\RuntimeException;
use function Chevere\VarSupport\deepCopy;
use Chevere\Workflow\Interfaces\JobInterface;
use Chevere\Workflow\Interfaces\WorkflowRunInterface;
use Chevere\Workflow\Interfaces\WorkflowRunnerInterface;
use Chevere\Workflow\Interfaces\RunInterface;
use Chevere\Workflow\Interfaces\RunnerInterface;
use Psr\Container\ContainerInterface;
use Throwable;

final class WorkflowRunner implements WorkflowRunnerInterface
final class Runner implements RunnerInterface
{
/** @var WorkflowRunnerInterface[] */
/** @var RunnerInterface[] */
private array $responses;

public function __construct(
private WorkflowRunInterface $workflowRun,
private RunInterface $workflowRun,
private ContainerInterface $container
) {
}

public function workflowRun(): WorkflowRunInterface
public function run(): RunInterface
{
return $this->workflowRun;
}

public function withRun(): WorkflowRunnerInterface
public function withRun(): RunnerInterface
{
$new = clone $this;
$jobs = $new->workflowRun->workflow()->jobs();
Expand All @@ -60,7 +60,7 @@ public function withRun(): WorkflowRunnerInterface
}

try {
/** @var WorkflowRunnerInterface[] $responses */
/** @var RunnerInterface[] $responses */
$responses = wait(all($promises));
// @phpstan-ignore-next-line
$new->responses = $responses;
Expand All @@ -75,16 +75,16 @@ public function withRun(): WorkflowRunnerInterface
);
}
// @codeCoverageIgnoreEnd
/** @var WorkflowRunnerInterface $new */
/** @var RunnerInterface $new */
$new = end($new->responses);
}

return $new;
}

public function withRunJob(string $name): WorkflowRunnerInterface
public function withRunJob(string $name): RunnerInterface
{
$job = $this->workflowRun()->workflow()->jobs()->get($name);
$job = $this->run()->workflow()->jobs()->get($name);
$actionName = $job->action();
/** @var ActionInterface $action */
$action = new $actionName();
Expand Down
24 changes: 0 additions & 24 deletions src/Traits/WorkflowProviderTrait.php

This file was deleted.

Loading

0 comments on commit cccefbf

Please sign in to comment.