Skip to content
This repository has been archived by the owner on Mar 29, 2024. It is now read-only.

Commit

Permalink
Migrate to postfix type signature/annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
pinepain committed Nov 4, 2017
1 parent 90d8244 commit 344583c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
14 changes: 9 additions & 5 deletions src/Specs/Builder/ParameterSpecBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ class ParameterSpecBuilder implements ParameterSpecBuilderInterface
{
protected $regexp = '/
^
(?:
(?<type>(\w+\b(?:\(.*\))?)(?:\s*\|\s*(?-1))*)
\s*
)
(?:
(?<rest>\.{3})
\s*
Expand All @@ -54,6 +50,14 @@ class ParameterSpecBuilder implements ParameterSpecBuilderInterface
|
true | false | null
)
\s*
)?
(?:
\s*
\:
\s*
(?<type>(\w+\b(?:\(.*\))?)(?:\s*\|\s*(?-1))*)
\s*
)?
$
/xi';
Expand Down Expand Up @@ -102,7 +106,7 @@ public function build(string $definition): ParameterSpecInterface

protected function buildVariadicParameterSpec(array $matches): VariadicParameterSpec
{
if (isset($matches['default'])) {
if (isset($matches['default']) && '' !== $matches['default']) {
throw new ParameterSpecBuilderException('Variadic parameter should have no default value');
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Specs/Builder/FunctionSpecBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ public function testBuildingSpecWithNoReturnTypeIsTheSameAsWithAnyReturnType()

public function testBuildSpecWithParams()
{
$this->parameterSpecBuilderShouldBuildOn('param one', 'param two = "default"', 'rest ...params');
$this->parameterSpecBuilderShouldBuildOn('one: param', 'two = "default": param', '...params: rest');

$spec = $this->builder->build('(param one, param two = "default", rest ...params)');
$spec = $this->builder->build('(one: param, two = "default": param, ...params: rest)');

$this->assertInstanceOf(FunctionSpecInterface::class, $spec);
$this->assertFalse($spec->needsExecutionContext());
Expand Down
14 changes: 7 additions & 7 deletions tests/Specs/Builder/ParameterSpecBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function testBuildingMandatoryParameter()
{
$this->extractorDefinitionShouldBuildOn('type');

$spec = $this->builder->build('type param');
$spec = $this->builder->build('param: type');

$this->assertInstanceOf(MandatoryParameterSpec::class, $spec);

Expand All @@ -81,7 +81,7 @@ public function testBuildingMandatoryParameterWithComplexType()
{
$this->extractorDefinitionShouldBuildOn('instance( Some\Class )');

$spec = $this->builder->build('instance( Some\Class ) param');
$spec = $this->builder->build('param : instance( Some\Class )');

$this->assertInstanceOf(MandatoryParameterSpec::class, $spec);

Expand All @@ -93,7 +93,7 @@ public function testBuildingMandatoryParameterWithVaryingType()
{
$this->extractorDefinitionShouldBuildOn('foo|bar');

$spec = $this->builder->build('foo|bar param');
$spec = $this->builder->build('param: foo|bar');

$this->assertInstanceOf(MandatoryParameterSpec::class, $spec);

Expand All @@ -111,7 +111,7 @@ public function testBuildingOptionalParameter(string $raw_default, $expected_def
{
$this->extractorDefinitionShouldBuildOn('type');

$spec = $this->builder->build('type param = ' . $raw_default);
$spec = $this->builder->build('param = ' . $raw_default . ': type');

$this->assertInstanceOf(OptionalParameterSpec::class, $spec);

Expand All @@ -124,7 +124,7 @@ public function testBuildingVariadicParameter()
{
$this->extractorDefinitionShouldBuildOn('type');

$spec = $this->builder->build('type ...param');
$spec = $this->builder->build('...param: type');

$this->assertInstanceOf(VariadicParameterSpec::class, $spec);

Expand All @@ -138,7 +138,7 @@ public function testBuildingVariadicParameter()
*/
public function testBuildingVariadicParameterWithDefaultValueShouldThrowException()
{
$this->builder->build('type ...param = []');
$this->builder->build('...param = []: type');
}

/**
Expand All @@ -149,7 +149,7 @@ public function testBuildingWhenExtractorFailsShouldAlsoFail()
{
$this->extractorDefinitionShouldThrowOn('fail');

$this->builder->build('fail param');
$this->builder->build('param :fail');
}


Expand Down

0 comments on commit 344583c

Please sign in to comment.