Skip to content

Commit

Permalink
job use caller
Browse files Browse the repository at this point in the history
  • Loading branch information
rodber committed Jan 22, 2025
1 parent a9b5876 commit b8faec1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Interfaces/JobInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function isSync(): bool;
*/
public function runIf(): VectorInterface;

public function caller(): string;
public function caller(): CallerInterface;

public function shift(): int;
}
9 changes: 5 additions & 4 deletions src/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Chevere\DataStructure\Vector;
use Chevere\Parameter\Interfaces\ParameterInterface;
use Chevere\Parameter\Interfaces\ParametersInterface;
use Chevere\Workflow\Interfaces\CallerInterface;
use Chevere\Workflow\Interfaces\JobInterface;
use Chevere\Workflow\Interfaces\ResponseReferenceInterface;
use Chevere\Workflow\Interfaces\VariableInterface;
Expand Down Expand Up @@ -49,7 +50,7 @@ final class Job implements JobInterface

private bool $isSync;

private string $caller;
private CallerInterface $caller;

private int $shift;

Expand Down Expand Up @@ -84,7 +85,7 @@ public function shift(): int
return $this->shift;
}

public function caller(): string
public function caller(): CallerInterface
{
return $this->caller;
}
Expand Down Expand Up @@ -170,8 +171,8 @@ private function setCaller(): void
array_shift($debugBacktrace);
}
$file = $debugBacktrace[0]['file'] ?? 'unknown';
$line = $debugBacktrace[0]['line'] ?? '0';
$this->caller = "{$file}:{$line}";
$line = $debugBacktrace[0]['line'] ?? 0;
$this->caller = new Caller($file, (int) $line);
}

private function setArguments(mixed ...$argument): void
Expand Down
4 changes: 2 additions & 2 deletions tests/FunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function testFunctionSync(): void
$action = new TestActionNoParamsIntResponse();
$job = sync($action);
$fileLine = __FILE__ . ':' . (__LINE__ - 1);
$this->assertSame($fileLine, $job->caller());
$this->assertSame($fileLine, $job->caller()->__toString());
$alt = (new Job($action))
->withShift(1)
->withIsSync(true);
Expand All @@ -47,7 +47,7 @@ public function testFunctionAsync(): void
$action = new TestActionNoParamsIntResponse();
$job = async($action);
$fileLine = __FILE__ . ':' . (__LINE__ - 1);
$this->assertSame($fileLine, $job->caller());
$this->assertSame($fileLine, $job->caller()->__toString());
$alt = (new Job($action))->withShift(1);
$this->assertSame($alt->shift(), $job->shift());
}
Expand Down
2 changes: 1 addition & 1 deletion tests/JobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function testRawArguments(): void
];
$job = new Job($action, ...$success);
$fileLine = __FILE__ . ':' . (__LINE__ - 1);
$this->assertSame($fileLine, $job->caller());
$this->assertSame($fileLine, $job->caller()->__toString());
$this->assertSame($action, $job->action());
$this->assertSame($success, $job->arguments());
$success = [
Expand Down

0 comments on commit b8faec1

Please sign in to comment.