From 2d86af6cc6357a40671c0ea4ce87d0938112a898 Mon Sep 17 00:00:00 2001 From: Lode Claassen Date: Wed, 20 Dec 2023 14:47:29 +0100 Subject: [PATCH 1/6] move from docblocks to actual type hints --- src/Chances/Chance.php | 2 +- src/Chances/StandardChance.php | 13 ++---- src/Experiment.php | 72 ++++++++------------------------ src/Intern.php | 24 +++-------- src/Journals/StandardJournal.php | 8 +--- src/Laboratory.php | 33 ++++----------- src/Machine.php | 25 +++-------- src/Matchers/ClosureMatcher.php | 2 +- src/Matchers/Matcher.php | 4 +- src/Matchers/StandardMatcher.php | 4 +- src/Report.php | 24 +++-------- src/Result.php | 72 +++++++------------------------- src/Trial.php | 6 +-- 13 files changed, 70 insertions(+), 219 deletions(-) diff --git a/src/Chances/Chance.php b/src/Chances/Chance.php index 0af2cc0..a65e581 100644 --- a/src/Chances/Chance.php +++ b/src/Chances/Chance.php @@ -3,5 +3,5 @@ interface Chance { - public function shouldRun(); + public function shouldRun(): bool; } diff --git a/src/Chances/StandardChance.php b/src/Chances/StandardChance.php index 8b08cd7..5b4f96d 100644 --- a/src/Chances/StandardChance.php +++ b/src/Chances/StandardChance.php @@ -8,7 +8,7 @@ class StandardChance implements Chance /** * Determine whether or not the experiment should run */ - public function shouldRun() + public function shouldRun(): bool { if ($this->percentage == 0) { return false; @@ -19,19 +19,12 @@ public function shouldRun() return $random <= $this->percentage; } - /** - * @return int - */ - public function getPercentage() + public function getPercentage(): int { return $this->percentage; } - /** - * @param int $percentage - * @return $this - */ - public function setPercentage($percentage) + public function setPercentage(int $percentage): self { $this->percentage = $percentage; diff --git a/src/Experiment.php b/src/Experiment.php index 741a1d1..50568ee 100644 --- a/src/Experiment.php +++ b/src/Experiment.php @@ -2,6 +2,7 @@ namespace Scientist; +use Scientist\Report; use Scientist\Chances\Chance; use Scientist\Chances\StandardChance; use Scientist\Matchers\Matcher; @@ -75,11 +76,8 @@ class Experiment /** * Create a new experiment. - * - * @param string $name - * @param \Scientist\Laboratory $laboratory */ - public function __construct($name, Laboratory $laboratory) + public function __construct(string $name, Laboratory $laboratory) { $this->name = $name; $this->laboratory = $laboratory; @@ -89,20 +87,16 @@ public function __construct($name, Laboratory $laboratory) /** * Fetch the experiment name. - * - * @return string */ - public function getName() + public function getName(): string { return $this->name; } /** * Retrieve the laboratory instance. - * - * @return \Scientist\Laboratory|null */ - public function getLaboratory() + public function getLaboratory(): ?Laboratory { return $this->laboratory; } @@ -110,12 +104,9 @@ public function getLaboratory() /** * Register a control callback. * - * @param callable $callback * @param mixed $context - * - * @return $this */ - public function control(callable $callback, $context = null) + public function control(callable $callback, $context = null): self { $this->control = $callback; $this->controlContext = $context; @@ -125,10 +116,8 @@ public function control(callable $callback, $context = null) /** * Fetch the control callback. - * - * @return callable */ - public function getControl() + public function getControl(): callable { return $this->control; } @@ -140,13 +129,8 @@ public function getControlContext() /** * Register a trial callback. - * - * @param string $name - * @param callable $callback - * - * @return $this */ - public function trial($name, callable $callback, $context = null) + public function trial(string $name, callable $callback, $context = null): self { $this->trials[$name] = new Trial($name, $callback, $context); @@ -155,34 +139,26 @@ public function trial($name, callable $callback, $context = null) /** * Fetch a trial callback by name. - * - * @param string $name - * + * * @return mixed */ - public function getTrial($name) + public function getTrial(string $name) { return $this->trials[$name]->getCallback(); } /** * Fetch an array of trial callbacks. - * - * @return array */ - public function getTrials() + public function getTrials(): array { return $this->trials; } /** * Set a matcher for this experiment. - * - * @param \Scientist\Matchers\Matcher $matcher - * - * @return $this */ - public function matcher(Matcher $matcher) + public function matcher(Matcher $matcher): self { $this->matcher = $matcher; @@ -191,22 +167,16 @@ public function matcher(Matcher $matcher) /** * Get the matcher for this experiment. - * - * @return \Scientist\Matchers\Matcher */ - public function getMatcher() + public function getMatcher(): Matcher { return $this->matcher; } /** * Set the execution chance. - * - * @param Chances\Chance $chance - * - * @return $this */ - public function chance(Chance $chance) + public function chance(Chance $chance): self { $this->chance = $chance; @@ -215,20 +185,16 @@ public function chance(Chance $chance) /** * Get the execution chance. - * - * @return Chances\Chance */ - public function getChance() + public function getChance(): Chance { return $this->chance; } /** * Determine whether an experiment should run based on chance. - * - * @return boolean */ - public function shouldRun() + public function shouldRun(): bool { return $this->chance ->shouldRun(); @@ -236,10 +202,8 @@ public function shouldRun() /** * Get the experiment parameters. - * - * @return array */ - public function getParams() + public function getParams(): array { return $this->params; } @@ -258,10 +222,8 @@ public function run() /** * Execute the experiment and return a report. - * - * @return \Scientist\Report */ - public function report() + public function report(): Report { $this->params = func_get_args(); diff --git a/src/Intern.php b/src/Intern.php index 44091b4..da25abb 100644 --- a/src/Intern.php +++ b/src/Intern.php @@ -16,12 +16,8 @@ class Intern { /** * Run an experiment, and retrieve the result. - * - * @param \Scientist\Experiment $experiment - * - * @return \Scientist\Report */ - public function run(Experiment $experiment) + public function run(Experiment $experiment): Report { $control = $this->runControl($experiment); $trials = $this->runTrials($experiment); @@ -33,12 +29,8 @@ public function run(Experiment $experiment) /** * Run the control callback, and record its execution state. - * - * @param \Scientist\Experiment $experiment - * - * @return \Scientist\Result */ - protected function runControl(Experiment $experiment) + protected function runControl(Experiment $experiment): Result { return (new Machine( $experiment->getControl(), @@ -51,11 +43,9 @@ protected function runControl(Experiment $experiment) /** * Run trial callbacks and record their execution state. * - * @param \Scientist\Experiment $experiment - * - * @return \Scientist\Result[] + * @return Result[] */ - protected function runTrials(Experiment $experiment) + protected function runTrials(Experiment $experiment): array { $executions = []; @@ -74,11 +64,9 @@ protected function runTrials(Experiment $experiment) /** * Determine whether trial results match the control. * - * @param \Scientist\Matchers\Matcher $matcher - * @param \Scientist\Result $control - * @param \Scientist\Result[] $trials + * @param Result[] $trials */ - protected function determineMatches(Matcher $matcher, Result $control, array $trials = []) + protected function determineMatches(Matcher $matcher, Result $control, array $trials = []): void { foreach ($trials as $trial) { if ($matcher->match($control->getValue(), $trial->getValue())) { diff --git a/src/Journals/StandardJournal.php b/src/Journals/StandardJournal.php index 94977e6..67ab3a6 100644 --- a/src/Journals/StandardJournal.php +++ b/src/Journals/StandardJournal.php @@ -42,20 +42,16 @@ public function report(Experiment $experiment, Report $report) /** * Get the experiment. - * - * @return \Scientist\Experiment */ - public function getExperiment() + public function getExperiment(): Experiment { return $this->experiment; } /** * Get the experiment report. - * - * @return \Scientist\Report */ - public function getReport() + public function getReport(): Report { return $this->report; } diff --git a/src/Laboratory.php b/src/Laboratory.php index 489ad28..5869d2e 100644 --- a/src/Laboratory.php +++ b/src/Laboratory.php @@ -24,11 +24,9 @@ class Laboratory /** * Register a collection of journals. * - * @param array $journals - * - * @return $this + * @param Journal[] $journals */ - public function setJournals(array $journals = []) + public function setJournals(array $journals = []): self { $this->journals = []; foreach ($journals as $journal) { @@ -40,12 +38,8 @@ public function setJournals(array $journals = []) /** * Register a new journal. - * - * @param \Scientist\Journals\Journal $journal - * - * @return $this */ - public function addJournal(Journal $journal) + public function addJournal(Journal $journal): self { $this->journals[] = $journal; @@ -55,9 +49,9 @@ public function addJournal(Journal $journal) /** * Retrieve registers journals. * - * @return array + * @return Journal[] */ - public function getJournals() + public function getJournals(): array { return $this->journals; } @@ -65,11 +59,9 @@ public function getJournals() /** * Start a new experiment. * - * @param string $name - * * @return mixed */ - public function experiment($name) + public function experiment(string $name) { return (new Experiment($name, $this)); } @@ -96,12 +88,8 @@ public function runExperiment(Experiment $experiment) /** * Run an experiment and return the result. - * - * @param \Scientist\Experiment $experiment - * - * @return \Scientist\Report */ - public function getReport(Experiment $experiment) + public function getReport(Experiment $experiment): Report { $report = (new Intern)->run($experiment); $this->reportToJournals($experiment, $report); @@ -111,13 +99,8 @@ public function getReport(Experiment $experiment) /** * Report experiment result to registered journals. - * - * @param \Scientist\Experiment $experiment - * @param \Scientist\Report $report - * - * @return void */ - protected function reportToJournals(Experiment $experiment, Report $report) + protected function reportToJournals(Experiment $experiment, Report $report): void { foreach ($this->journals as $journal) { $journal->report($experiment, $report); diff --git a/src/Machine.php b/src/Machine.php index 8277b3a..70cf7cf 100644 --- a/src/Machine.php +++ b/src/Machine.php @@ -42,11 +42,8 @@ class Machine /** * Inject machine dependencies. * - * @param callable $callback - * @param array $params - * @param boolean $muted */ - public function __construct(callable $callback, array $params = [], $muted = false, $context = null) + public function __construct(callable $callback, array $params = [], bool $muted = false, $context = null) { $this->callback = $callback; $this->params = $params; @@ -56,10 +53,8 @@ public function __construct(callable $callback, array $params = [], $muted = fal /** * Execute the callback and retrieve a result. - * - * @return \Scientist\Result */ - public function execute() + public function execute(): Result { $this->setStartValues(); $this->executeCallback(); @@ -70,10 +65,8 @@ public function execute() /** * Set values before callback is executed. - * - * @return void */ - protected function setStartValues() + protected function setStartValues(): void { $this->result->setStartTime(microtime(true)); $this->result->setStartMemory(memory_get_usage()); @@ -81,10 +74,8 @@ protected function setStartValues() /** * Execute the callback with parameters. - * - * @return void */ - protected function executeCallback() + protected function executeCallback(): void { if ($this->muted) { return $this->executeMutedCallback(); @@ -95,10 +86,8 @@ protected function executeCallback() /** * Execute the callback, but swallow exceptions. - * - * @return void */ - protected function executeMutedCallback() + protected function executeMutedCallback(): void { try { $this->result->setValue(call_user_func_array($this->callback, $this->params)); @@ -110,10 +99,8 @@ protected function executeMutedCallback() /** * Set values after the callback has executed. - * - * @return void */ - protected function setEndValues() + protected function setEndValues(): void { $this->result->setEndTime(microtime(true)); $this->result->setEndMemory(memory_get_usage()); diff --git a/src/Matchers/ClosureMatcher.php b/src/Matchers/ClosureMatcher.php index 9069f73..485b4b2 100644 --- a/src/Matchers/ClosureMatcher.php +++ b/src/Matchers/ClosureMatcher.php @@ -27,7 +27,7 @@ public function __construct(\Closure $closure) /** * @inheritDoc */ - public function match($control, $trial) + public function match($control, $trial): bool { return call_user_func($this->closure, $control, $trial); } diff --git a/src/Matchers/Matcher.php b/src/Matchers/Matcher.php index 7e8fb3a..369d58c 100644 --- a/src/Matchers/Matcher.php +++ b/src/Matchers/Matcher.php @@ -16,8 +16,6 @@ interface Matcher * * @param mixed $control * @param mixed $trial - * - * @return boolean */ - public function match($control, $trial); + public function match($control, $trial): bool; } diff --git a/src/Matchers/StandardMatcher.php b/src/Matchers/StandardMatcher.php index a560377..9a8912a 100644 --- a/src/Matchers/StandardMatcher.php +++ b/src/Matchers/StandardMatcher.php @@ -14,10 +14,8 @@ class StandardMatcher implements Matcher * * @param mixed $control * @param mixed $trial - * - * @return boolean */ - public function match($control, $trial) + public function match($control, $trial): bool { return $control === $trial; } diff --git a/src/Report.php b/src/Report.php index fba2b5d..71b2691 100644 --- a/src/Report.php +++ b/src/Report.php @@ -35,12 +35,8 @@ class Report /** * Create a new result instance. - * - * @param string $name - * @param \Scientist\Result $control - * @param array $trials */ - public function __construct($name, Result $control, array $trials = []) + public function __construct(string $name, Result $control, array $trials = []) { $this->name = $name; $this->control = $control; @@ -49,32 +45,24 @@ public function __construct($name, Result $control, array $trials = []) /** * Get the experiment name. - * - * @return string */ - public function getName() + public function getName(): string { return $this->name; } /** * Get the control result instance. - * - * @return \Scientist\Result */ - public function getControl() + public function getControl(): Result { return $this->control; } /** * Get a trial result instance by name. - * - * @param string $name - * - * @return \Scientist\Result */ - public function getTrial($name) + public function getTrial(string $name): Result { return $this->trials[$name]; } @@ -82,9 +70,9 @@ public function getTrial($name) /** * Get the trial result instances. * - * @return array + * @return Result[] */ - public function getTrials() + public function getTrials(): array { return $this->trials; } diff --git a/src/Result.php b/src/Result.php index 6e78329..951aad1 100644 --- a/src/Result.php +++ b/src/Result.php @@ -86,10 +86,8 @@ public function getValue() * Set the callback result value. * * @param mixed $value - * - * @return $this */ - public function setValue($value) + public function setValue($value): self { $this->value = $value; @@ -98,22 +96,16 @@ public function setValue($value) /** * Get the callback execution start time. - * - * @return float */ - public function getStartTime() + public function getStartTime(): float { return $this->startTime; } /** * Set the callback execution start time. - * - * @param float $startTime - * - * @return $this */ - public function setStartTime($startTime) + public function setStartTime(float $startTime): self { $this->startTime = $startTime; @@ -122,22 +114,16 @@ public function setStartTime($startTime) /** * Get the callback execution end time. - * - * @return float */ - public function getEndTime() + public function getEndTime(): float { return $this->endTime; } /** * Set the callback execution end time. - * - * @param float $endTime - * - * @return $this */ - public function setEndTime($endTime) + public function setEndTime(float $endTime): self { $this->endTime = $endTime; @@ -146,32 +132,24 @@ public function setEndTime($endTime) /** * Get the execution time of the callback. - * - * @return float */ - public function getTime() + public function getTime(): float { return $this->endTime - $this->startTime; } /** * Get the callback execution starting memory usage. - * - * @return float */ - public function getStartMemory() + public function getStartMemory(): float { return $this->startMemory; } /** * Set the callback execution starting memory usage. - * - * @param float $startMemory - * - * @return $this */ - public function setStartMemory($startMemory) + public function setStartMemory(float $startMemory): self { $this->startMemory = $startMemory; @@ -180,22 +158,16 @@ public function setStartMemory($startMemory) /** * Get the callback execution ending memory usage. - * - * @return float */ - public function getEndMemory() + public function getEndMemory(): float { return $this->endMemory; } /** * Set the callback execution ending memory usage. - * - * @param float $endMemory - * - * @return $this */ - public function setEndMemory($endMemory) + public function setEndMemory(float $endMemory): self { $this->endMemory = $endMemory; @@ -204,32 +176,24 @@ public function setEndMemory($endMemory) /** * Get the memory spike amount of the callback. - * - * @return float */ - public function getMemory() + public function getMemory(): float { return $this->endMemory - $this->startMemory; } /** * Get the exception thrown by the callback. - * - * @return Exception|null */ - public function getException() + public function getException(): ?Exception { return $this->exception; } /** * Set the exception thrown by the callback. - * - * @param Exception|null $exception - * - * @return $this */ - public function setException($exception) + public function setException(?Exception $exception): self { $this->exception = $exception; @@ -243,22 +207,16 @@ public function getContext() /** * Determine whether the callback result matches the control. - * - * @return boolean */ - public function isMatch() + public function isMatch(): bool { return $this->match; } /** * Set whether the callback result matches the control. - * - * @param boolean $match - * - * @return $this */ - public function setMatch($match) + public function setMatch(bool $match): self { $this->match = $match; diff --git a/src/Trial.php b/src/Trial.php index c553687..8f9ac62 100644 --- a/src/Trial.php +++ b/src/Trial.php @@ -19,19 +19,19 @@ class Trial */ protected $context; - public function __construct($name, callable $callback, $context) + public function __construct(string $name, callable $callback, $context) { $this->name = $name; $this->callback = $callback; $this->context = $context; } - public function getName() + public function getName(): string { return $this->name; } - public function getCallback() + public function getCallback(): callable { return $this->callback; } From 7bd146a132596edc831a61557a70fa927752ab96 Mon Sep 17 00:00:00 2001 From: Lode Claassen Date: Wed, 20 Dec 2023 14:50:43 +0100 Subject: [PATCH 2/6] correct wrong type hints --- src/Experiment.php | 4 +--- src/Journals/StandardJournal.php | 4 +--- src/Result.php | 4 ++-- tests/LaboratoryTest.php | 12 ++++++------ tests/MachineTest.php | 4 ++-- 5 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/Experiment.php b/src/Experiment.php index 50568ee..3cb0505 100644 --- a/src/Experiment.php +++ b/src/Experiment.php @@ -139,10 +139,8 @@ public function trial(string $name, callable $callback, $context = null): self /** * Fetch a trial callback by name. - * - * @return mixed */ - public function getTrial(string $name) + public function getTrial(string $name): callable { return $this->trials[$name]->getCallback(); } diff --git a/src/Journals/StandardJournal.php b/src/Journals/StandardJournal.php index 67ab3a6..b87a4b2 100644 --- a/src/Journals/StandardJournal.php +++ b/src/Journals/StandardJournal.php @@ -31,10 +31,8 @@ class StandardJournal implements Journal * * @param \Scientist\Experiment $experiment * @param \Scientist\Report $report - * - * @return mixed */ - public function report(Experiment $experiment, Report $report) + public function report(Experiment $experiment, Report $report): void { $this->experiment = $experiment; $this->report = $report; diff --git a/src/Result.php b/src/Result.php index 951aad1..e8214fc 100644 --- a/src/Result.php +++ b/src/Result.php @@ -185,7 +185,7 @@ public function getMemory(): float /** * Get the exception thrown by the callback. */ - public function getException(): ?Exception + public function getException(): ?\Throwable { return $this->exception; } @@ -193,7 +193,7 @@ public function getException(): ?Exception /** * Set the exception thrown by the callback. */ - public function setException(?Exception $exception): self + public function setException(?\Throwable $exception): self { $this->exception = $exception; diff --git a/tests/LaboratoryTest.php b/tests/LaboratoryTest.php index 00f5254..eeb3309 100644 --- a/tests/LaboratoryTest.php +++ b/tests/LaboratoryTest.php @@ -39,12 +39,12 @@ public function test_laboratory_can_fetch_report_for_experiment_with_no_journals $this->assertIsFloat($r->getTrial('trial')->getStartTime()); $this->assertIsFloat($r->getTrial('trial')->getEndTime()); $this->assertIsFloat($r->getTrial('trial')->getTime()); - $this->assertIsInt($r->getControl()->getStartMemory()); - $this->assertIsInt($r->getControl()->getEndMemory()); - $this->assertIsInt($r->getControl()->getMemory()); - $this->assertIsInt($r->getTrial('trial')->getStartMemory()); - $this->assertIsInt($r->getTrial('trial')->getEndMemory()); - $this->assertIsInt($r->getTrial('trial')->getMemory()); + $this->assertIsFloat($r->getControl()->getStartMemory()); + $this->assertIsFloat($r->getControl()->getEndMemory()); + $this->assertIsFloat($r->getControl()->getMemory()); + $this->assertIsFloat($r->getTrial('trial')->getStartMemory()); + $this->assertIsFloat($r->getTrial('trial')->getEndMemory()); + $this->assertIsFloat($r->getTrial('trial')->getMemory()); $this->assertNull($r->getControl()->getException()); $this->assertNull($r->getTrial('trial')->getException()); $this->assertFalse($r->getTrial('trial')->isMatch()); diff --git a/tests/MachineTest.php b/tests/MachineTest.php index 30841d6..dbf78ca 100644 --- a/tests/MachineTest.php +++ b/tests/MachineTest.php @@ -107,7 +107,7 @@ public function test_that_machine_can_determine_memory_usage_changes() $r = $m->execute(); - $this->assertIsInt($r->getStartMemory()); - $this->assertIsInt($r->getEndMemory()); + $this->assertIsFloat($r->getStartMemory()); + $this->assertIsFloat($r->getEndMemory()); } } From 6ed454d30bdec37badaaabd70f9b952b48a0a55e Mon Sep 17 00:00:00 2001 From: Lode Claassen Date: Wed, 20 Dec 2023 14:54:56 +0100 Subject: [PATCH 3/6] improve and add missing type hints --- src/Chances/StandardChance.php | 3 +++ src/Experiment.php | 9 ++++++++- src/Machine.php | 5 +++-- src/Report.php | 2 +- src/Result.php | 8 +++++++- src/Trial.php | 6 ++++++ 6 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/Chances/StandardChance.php b/src/Chances/StandardChance.php index 5b4f96d..2b08e78 100644 --- a/src/Chances/StandardChance.php +++ b/src/Chances/StandardChance.php @@ -3,6 +3,9 @@ class StandardChance implements Chance { + /** + * @var int + */ private $percentage = 100; /** diff --git a/src/Experiment.php b/src/Experiment.php index 3cb0505..938e61f 100644 --- a/src/Experiment.php +++ b/src/Experiment.php @@ -42,7 +42,7 @@ class Experiment /** * Trial callbacks. * - * @var array + * @var callable[] */ protected $trials = []; @@ -122,6 +122,9 @@ public function getControl(): callable return $this->control; } + /** + * @return mixed + */ public function getControlContext() { return $this->controlContext; @@ -129,6 +132,8 @@ public function getControlContext() /** * Register a trial callback. + * + * @param mixed $context */ public function trial(string $name, callable $callback, $context = null): self { @@ -147,6 +152,8 @@ public function getTrial(string $name): callable /** * Fetch an array of trial callbacks. + * + * @return callable[] */ public function getTrials(): array { diff --git a/src/Machine.php b/src/Machine.php index 70cf7cf..43057de 100644 --- a/src/Machine.php +++ b/src/Machine.php @@ -28,7 +28,7 @@ class Machine /** * Should exceptions be muted. * - * @var boolean + * @var bool */ protected $muted = false; @@ -42,6 +42,7 @@ class Machine /** * Inject machine dependencies. * + * @param mixed $context */ public function __construct(callable $callback, array $params = [], bool $muted = false, $context = null) { @@ -91,7 +92,7 @@ protected function executeMutedCallback(): void { try { $this->result->setValue(call_user_func_array($this->callback, $this->params)); - } catch (Throwable $exception) { + } catch (\Throwable $exception) { $this->result->setException($exception); $this->result->setValue(null); } diff --git a/src/Report.php b/src/Report.php index 71b2691..dcc7708 100644 --- a/src/Report.php +++ b/src/Report.php @@ -29,7 +29,7 @@ class Report /** * The trial results. * - * @var array + * @var Result[] */ protected $trials = []; diff --git a/src/Result.php b/src/Result.php index e8214fc..0a95168 100644 --- a/src/Result.php +++ b/src/Result.php @@ -58,7 +58,7 @@ class Result /** * Does the callback result value match the control. * - * @var boolean + * @var bool */ protected $match = false; @@ -67,6 +67,9 @@ class Result */ protected $context; + /** + * @param ?mixed $context + */ public function __construct($context = null) { $this->context = $context; @@ -200,6 +203,9 @@ public function setException(?\Throwable $exception): self return $this; } + /** + * @return mixed + */ public function getContext() { return $this->context; diff --git a/src/Trial.php b/src/Trial.php index 8f9ac62..4ed7101 100644 --- a/src/Trial.php +++ b/src/Trial.php @@ -19,6 +19,9 @@ class Trial */ protected $context; + /** + * @param mixed $context + */ public function __construct(string $name, callable $callback, $context) { $this->name = $name; @@ -36,6 +39,9 @@ public function getCallback(): callable return $this->callback; } + /** + * @return mixed + */ public function getContext() { return $this->context; From b85473beb1de8e5f66867fdc983295188d25d66d Mon Sep 17 00:00:00 2001 From: Lode Claassen Date: Wed, 20 Dec 2023 14:55:16 +0100 Subject: [PATCH 4/6] cleanup --- src/Journals/Journal.php | 3 --- src/Journals/StandardJournal.php | 7 ++----- src/Laboratory.php | 2 -- src/Matchers/ClosureMatcher.php | 1 - 4 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/Journals/Journal.php b/src/Journals/Journal.php index 7b8151f..83f0399 100644 --- a/src/Journals/Journal.php +++ b/src/Journals/Journal.php @@ -18,9 +18,6 @@ interface Journal /** * Dispatch a report to storage. * - * @param \Scientist\Experiment $experiment - * @param \Scientist\Report $report - * * @return mixed */ public function report(Experiment $experiment, Report $report); diff --git a/src/Journals/StandardJournal.php b/src/Journals/StandardJournal.php index b87a4b2..a313ebe 100644 --- a/src/Journals/StandardJournal.php +++ b/src/Journals/StandardJournal.php @@ -15,22 +15,19 @@ class StandardJournal implements Journal /** * The executed experiment. * - * @var \Scientist\Experiment + * @var Experiment */ protected $experiment; /** * The experiment report. * - * @var \Scientist\Report + * @var Report */ protected $report; /** * Dispatch a report to storage. - * - * @param \Scientist\Experiment $experiment - * @param \Scientist\Report $report */ public function report(Experiment $experiment, Report $report): void { diff --git a/src/Laboratory.php b/src/Laboratory.php index 5869d2e..995b8e2 100644 --- a/src/Laboratory.php +++ b/src/Laboratory.php @@ -69,8 +69,6 @@ public function experiment(string $name) /** * Run an experiment. * - * @param \Scientist\Experiment $experiment - * * @return mixed */ public function runExperiment(Experiment $experiment) diff --git a/src/Matchers/ClosureMatcher.php b/src/Matchers/ClosureMatcher.php index 485b4b2..7c2788c 100644 --- a/src/Matchers/ClosureMatcher.php +++ b/src/Matchers/ClosureMatcher.php @@ -17,7 +17,6 @@ class ClosureMatcher implements Matcher /** * Create a new matcher instance based on a closure. - * @param \Closure $closure The closure to use */ public function __construct(\Closure $closure) { From 295fbe501a2da86e5bff70432a37942598dfbf5d Mon Sep 17 00:00:00 2001 From: Lode Claassen Date: Wed, 20 Dec 2023 14:55:46 +0100 Subject: [PATCH 5/6] enforce strict mode on ourselves --- src/Chances/Chance.php | 2 ++ src/Chances/StandardChance.php | 2 ++ src/Experiment.php | 1 + src/Intern.php | 1 + src/Journals/Journal.php | 1 + src/Journals/StandardJournal.php | 1 + src/Laboratory.php | 1 + src/Machine.php | 1 + src/Matchers/ClosureMatcher.php | 1 + src/Matchers/Matcher.php | 1 + src/Matchers/StandardMatcher.php | 1 + src/Report.php | 1 + src/Result.php | 2 ++ src/Trial.php | 1 + tests/Chances/StandardChanceTest.php | 2 ++ tests/ExperimentTest.php | 1 + tests/InternTest.php | 1 + tests/Journals/JournalTest.php | 1 + tests/LaboratoryTest.php | 1 + tests/MachineTest.php | 1 + tests/Matchers/ClosureMatcherTest.php | 1 + tests/Matchers/StandardMatcherTest.php | 1 + tests/ReportTest.php | 1 + tests/ResultTest.php | 1 + 24 files changed, 28 insertions(+) diff --git a/src/Chances/Chance.php b/src/Chances/Chance.php index a65e581..79cd8cd 100644 --- a/src/Chances/Chance.php +++ b/src/Chances/Chance.php @@ -1,4 +1,6 @@ Date: Wed, 20 Dec 2023 14:55:59 +0100 Subject: [PATCH 6/6] fix tests --- src/Machine.php | 3 ++- tests/ResultTest.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Machine.php b/src/Machine.php index 0db6811..1760c28 100644 --- a/src/Machine.php +++ b/src/Machine.php @@ -80,7 +80,8 @@ protected function setStartValues(): void protected function executeCallback(): void { if ($this->muted) { - return $this->executeMutedCallback(); + $this->executeMutedCallback(); + return; } $this->result->setValue(call_user_func_array($this->callback, $this->params)); diff --git a/tests/ResultTest.php b/tests/ResultTest.php index def5e7b..e279368 100644 --- a/tests/ResultTest.php +++ b/tests/ResultTest.php @@ -58,7 +58,7 @@ public function test_result_can_have_match_status() { $r = new Result; $r->setMatch(true); - $this->assertTrue(true, $r->isMatch()); + $this->assertTrue($r->isMatch()); } public function test_can_have_context()