revs = $revs; return $this; } public function addIterationWithTimeResult(int $netTime, int $revs): VariantBuilder { $this->iteration()->setResult(new TimeResult($netTime, $revs)); return $this; } public function iteration(): IterationBuilder { return (function (IterationBuilder $builder) { $this->iterations[] = $builder; return $builder; })(new IterationBuilder($this)); } /** * @param array $parameters */ public function withParameterSet(string $name, array $parameters): VariantBuilder { $this->parameterSet = ParameterSet::fromUnserializedValues($name, $parameters); return $this; } public function build(?Subject $subject = null): Variant { if (null === $subject) { $suite = new Suite( 'testSuite', new DateTime() ); $benchmark = new Benchmark($suite, 'testBenchmark'); $subject = new Subject($benchmark, 'foo'); } $variant = new Variant( $subject, $this->parameterSet ?? ParameterSet::fromSerializedParameters($this->name ?? '0', []), $this->revs, 1, [] ); foreach ($this->iterations as $iteration) { $iteration->build($variant); } $variant->computeStats(); if ($this->errors) { $variant->createErrorStack($this->errors); } return $variant; } public function end(): SubjectBuilder { if (null === $this->subjectBuilder) { throw new RuntimeException( 'This variant builder was not created by a subject builder, end() cannot return anything' ); } return $this->subjectBuilder; } public static function forSubjectBuilder(SubjectBuilder $subjectBuilder, ?string $name = null): self { return new self($subjectBuilder, $name); } public function withError(Error $error): self { $this->errors[] = $error; return $this; } }