From 8f74ca518815ebf56bf529722905e455a3392a4e Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sun, 7 Feb 2021 12:57:27 +0100 Subject: [PATCH 1/9] use psalm 4 --- composer.json | 2 +- psalm.xml | 6 +----- src/Expression/Level3.php | 1 + src/Expression/Level4.php | 4 +++- src/Expression/Level4/Parameters.php | 1 + src/Expression/Level4/Query.php | 1 + src/Expression/Level4/QueryContinuation.php | 1 + src/Template.php | 13 +++++++++++-- 8 files changed, 20 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index 67b8389..d2b5920 100644 --- a/composer.json +++ b/composer.json @@ -32,6 +32,6 @@ "require-dev": { "phpunit/phpunit": "~8.0", "giorgiosironi/eris": "^0.11.0", - "vimeo/psalm": "~3.7.0" + "vimeo/psalm": "~4.4" } } diff --git a/psalm.xml b/psalm.xml index 408036f..3240886 100644 --- a/psalm.xml +++ b/psalm.xml @@ -1,6 +1,6 @@ - - - - diff --git a/src/Expression/Level3.php b/src/Expression/Level3.php index 1725231..cc415a8 100644 --- a/src/Expression/Level3.php +++ b/src/Expression/Level3.php @@ -73,6 +73,7 @@ public function expand(Map $variables): string public function regex(): string { + /** @psalm-suppress InvalidArgument */ return $this->regex ?? $this->regex = join( ',', $this->names->mapTo( diff --git a/src/Expression/Level4.php b/src/Expression/Level4.php index 33399b8..602fc76 100644 --- a/src/Expression/Level4.php +++ b/src/Expression/Level4.php @@ -217,6 +217,7 @@ private function expandList(Map $variables, ...$variablesToExpand): string return $this->explodeList($variables, $variablesToExpand); } + /** @var Sequence */ $flattenedVariables = Sequence::of('scalar|array', ...$variablesToExpand)->reduce( Sequence::of('scalar'), static function(Sequence $values, $variableToExpand): Sequence { @@ -229,8 +230,9 @@ static function(Sequence $values, $variableToExpand): Sequence { return ($values)($variableToExpand); }, ); + $expanded = $flattenedVariables - ->map(function(string $variableToExpand) use ($variables): string { + ->map(function($variableToExpand) use ($variables): string { // here we use the level1 expression to transform the variable to // be expanded to its string representation return $this->expression->expand( diff --git a/src/Expression/Level4/Parameters.php b/src/Expression/Level4/Parameters.php index 2fe71a4..0fa7b54 100644 --- a/src/Expression/Level4/Parameters.php +++ b/src/Expression/Level4/Parameters.php @@ -181,6 +181,7 @@ private function expandList(Map $variables, ...$variablesToExpand): string return $this->explodeList($variables, $variablesToExpand); } + /** @var Sequence */ $flattenedVariables = Sequence::of('scalar|array', ...$variablesToExpand)->reduce( Sequence::of('scalar'), static function(Sequence $values, $variableToExpand): Sequence { diff --git a/src/Expression/Level4/Query.php b/src/Expression/Level4/Query.php index 66242c1..c25b22e 100644 --- a/src/Expression/Level4/Query.php +++ b/src/Expression/Level4/Query.php @@ -181,6 +181,7 @@ private function expandList(Map $variables, ...$variablesToExpand): string return $this->explodeList($variables, $variablesToExpand); } + /** @var Sequence */ $flattenedVariables = Sequence::of('scalar|array', ...$variablesToExpand)->reduce( Sequence::of('scalar'), static function(Sequence $values, $variableToExpand): Sequence { diff --git a/src/Expression/Level4/QueryContinuation.php b/src/Expression/Level4/QueryContinuation.php index 216023d..c840990 100644 --- a/src/Expression/Level4/QueryContinuation.php +++ b/src/Expression/Level4/QueryContinuation.php @@ -181,6 +181,7 @@ private function expandList(Map $variables, ...$variablesToExpand): string return $this->explodeList($variables, $variablesToExpand); } + /** @var Sequence */ $flattenedVariables = Sequence::of('scalar|array', ...$variablesToExpand)->reduce( Sequence::of('scalar'), static function(Sequence $values, $variableToExpand): Sequence { diff --git a/src/Template.php b/src/Template.php index 3168c9f..55c6b4f 100644 --- a/src/Template.php +++ b/src/Template.php @@ -106,6 +106,9 @@ public function toString(): string /** * Recursively find the expressions as Str::capture doesnt capture all of * them at the same time + * @param Sequence $expressions + * + * @return Sequence */ private function extractExpressions( Sequence $expressions, @@ -133,7 +136,10 @@ private function regex(): string ->reduce( $this->template->replace('~', '\~'), static function(Str $template, Expression $expression) use (&$i): Str { - /** @psalm-suppress MixedOperand */ + /** + * @psalm-suppress MixedOperand + * @psalm-suppress MixedAssignment + */ ++$i; return $template->replace( @@ -146,7 +152,10 @@ static function(Str $template, Expression $expression) use (&$i): Str { $template = $this->expressions->reduce( $template, static function(Str $template, Expression $expression) use (&$j): Str { - /** @psalm-suppress MixedOperand */ + /** + * @psalm-suppress MixedOperand + * @psalm-suppress MixedAssignment + */ ++$j; return $template->replace( From c1dbe4abf91e6ff900ec685771e6f2714e82cd75 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sun, 7 Feb 2021 13:04:18 +0100 Subject: [PATCH 2/9] replace eris by blackbox --- composer.json | 4 +-- phpunit.xml.dist | 2 +- tests/Expression/Level4/FragmentTest.php | 10 +++---- tests/Expression/Level4/LabelTest.php | 10 +++---- tests/Expression/Level4/ParametersTest.php | 10 +++---- tests/Expression/Level4/PathTest.php | 10 +++---- .../Level4/QueryContinuationTest.php | 10 +++---- tests/Expression/Level4/QueryTest.php | 10 +++---- tests/Expression/Level4/ReservedTest.php | 10 +++---- tests/Expression/Level4Test.php | 10 +++---- tests/Expression/NameTest.php | 26 ++++++++++--------- tests/UrlEncodeTest.php | 12 ++++----- 12 files changed, 63 insertions(+), 61 deletions(-) diff --git a/composer.json b/composer.json index d2b5920..0c9720f 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ }, "require-dev": { "phpunit/phpunit": "~8.0", - "giorgiosironi/eris": "^0.11.0", - "vimeo/psalm": "~4.4" + "vimeo/psalm": "~4.4", + "innmind/black-box": "^4.16" } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 148afda..ec6415a 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,6 +1,6 @@ - + ./tests diff --git a/tests/Expression/Level4/FragmentTest.php b/tests/Expression/Level4/FragmentTest.php index 65fdf72..a475f52 100644 --- a/tests/Expression/Level4/FragmentTest.php +++ b/tests/Expression/Level4/FragmentTest.php @@ -15,14 +15,14 @@ Str, }; use PHPUnit\Framework\TestCase; -use Eris\{ - Generator, - TestTrait, +use Innmind\BlackBox\{ + PHPUnit\BlackBox, + Set, }; class FragmentTest extends TestCase { - use TestTrait; + use BlackBox; public function testInterface() { @@ -50,7 +50,7 @@ public function testStringCast() public function testThrowWhenNegativeLimit() { $this - ->forAll(Generator\neg()) + ->forAll(Set\Integers::below(1)) ->then(function(int $int): void { $this->expectException(DomainException::class); diff --git a/tests/Expression/Level4/LabelTest.php b/tests/Expression/Level4/LabelTest.php index 444de53..2775ecb 100644 --- a/tests/Expression/Level4/LabelTest.php +++ b/tests/Expression/Level4/LabelTest.php @@ -15,14 +15,14 @@ Str, }; use PHPUnit\Framework\TestCase; -use Eris\{ - Generator, - TestTrait, +use Innmind\BlackBox\{ + PHPUnit\BlackBox, + Set, }; class LabelTest extends TestCase { - use TestTrait; + use BlackBox; public function testInterface() { @@ -50,7 +50,7 @@ public function testStringCast() public function testThrowWhenNegativeLimit() { $this - ->forAll(Generator\neg()) + ->forAll(Set\Integers::below(1)) ->then(function(int $int): void { $this->expectException(DomainException::class); diff --git a/tests/Expression/Level4/ParametersTest.php b/tests/Expression/Level4/ParametersTest.php index 27e7ad4..ae6d2a4 100644 --- a/tests/Expression/Level4/ParametersTest.php +++ b/tests/Expression/Level4/ParametersTest.php @@ -15,14 +15,14 @@ Str, }; use PHPUnit\Framework\TestCase; -use Eris\{ - Generator, - TestTrait, +use Innmind\BlackBox\{ + PHPUnit\BlackBox, + Set, }; class ParametersTest extends TestCase { - use TestTrait; + use BlackBox; public function testInterface() { @@ -50,7 +50,7 @@ public function testStringCast() public function testThrowWhenNegativeLimit() { $this - ->forAll(Generator\neg()) + ->forAll(Set\Integers::below(1)) ->then(function(int $int): void { $this->expectException(DomainException::class); diff --git a/tests/Expression/Level4/PathTest.php b/tests/Expression/Level4/PathTest.php index 3b942fe..b0e7bf3 100644 --- a/tests/Expression/Level4/PathTest.php +++ b/tests/Expression/Level4/PathTest.php @@ -15,14 +15,14 @@ Str, }; use PHPUnit\Framework\TestCase; -use Eris\{ - Generator, - TestTrait, +use Innmind\BlackBox\{ + PHPUnit\BlackBox, + Set, }; class PathTest extends TestCase { - use TestTrait; + use BlackBox; public function testInterface() { @@ -50,7 +50,7 @@ public function testStringCast() public function testThrowWhenNegativeLimit() { $this - ->forAll(Generator\neg()) + ->forAll(Set\Integers::below(1)) ->then(function(int $int): void { $this->expectException(DomainException::class); diff --git a/tests/Expression/Level4/QueryContinuationTest.php b/tests/Expression/Level4/QueryContinuationTest.php index 7aac88a..4755e51 100644 --- a/tests/Expression/Level4/QueryContinuationTest.php +++ b/tests/Expression/Level4/QueryContinuationTest.php @@ -15,14 +15,14 @@ Str, }; use PHPUnit\Framework\TestCase; -use Eris\{ - Generator, - TestTrait, +use Innmind\BlackBox\{ + PHPUnit\BlackBox, + Set, }; class QueryContinuationTest extends TestCase { - use TestTrait; + use BlackBox; public function testInterface() { @@ -50,7 +50,7 @@ public function testStringCast() public function testThrowWhenNegativeLimit() { $this - ->forAll(Generator\neg()) + ->forAll(Set\Integers::below(1)) ->then(function(int $int): void { $this->expectException(DomainException::class); diff --git a/tests/Expression/Level4/QueryTest.php b/tests/Expression/Level4/QueryTest.php index 246d59c..b7471e2 100644 --- a/tests/Expression/Level4/QueryTest.php +++ b/tests/Expression/Level4/QueryTest.php @@ -15,14 +15,14 @@ Str, }; use PHPUnit\Framework\TestCase; -use Eris\{ - Generator, - TestTrait, +use Innmind\BlackBox\{ + PHPUnit\BlackBox, + Set, }; class QueryTest extends TestCase { - use TestTrait; + use BlackBox; public function testInterface() { @@ -50,7 +50,7 @@ public function testStringCast() public function testThrowWhenNegativeLimit() { $this - ->forAll(Generator\neg()) + ->forAll(Set\Integers::below(1)) ->then(function(int $int): void { $this->expectException(DomainException::class); diff --git a/tests/Expression/Level4/ReservedTest.php b/tests/Expression/Level4/ReservedTest.php index a0c9d5f..57f8dee 100644 --- a/tests/Expression/Level4/ReservedTest.php +++ b/tests/Expression/Level4/ReservedTest.php @@ -15,14 +15,14 @@ Str, }; use PHPUnit\Framework\TestCase; -use Eris\{ - Generator, - TestTrait, +use Innmind\BlackBox\{ + PHPUnit\BlackBox, + Set, }; class ReservedTest extends TestCase { - use TestTrait; + use BlackBox; public function testInterface() { @@ -50,7 +50,7 @@ public function testStringCast() public function testThrowWhenNegativeLimit() { $this - ->forAll(Generator\neg()) + ->forAll(Set\Integers::below(1)) ->then(function(int $int): void { $this->expectException(DomainException::class); diff --git a/tests/Expression/Level4Test.php b/tests/Expression/Level4Test.php index 0a8799c..19f4e61 100644 --- a/tests/Expression/Level4Test.php +++ b/tests/Expression/Level4Test.php @@ -15,14 +15,14 @@ Str, }; use PHPUnit\Framework\TestCase; -use Eris\{ - Generator, - TestTrait, +use Innmind\BlackBox\{ + PHPUnit\BlackBox, + Set, }; class Level4Test extends TestCase { - use TestTrait; + use BlackBox; public function testInterface() { @@ -50,7 +50,7 @@ public function testStringCast() public function testThrowWhenNegativeLimit() { $this - ->forAll(Generator\neg()) + ->forAll(Set\Integers::below(1)) ->then(function(int $int): void { $this->expectException(DomainException::class); diff --git a/tests/Expression/NameTest.php b/tests/Expression/NameTest.php index 6fcbeea..18b4e21 100644 --- a/tests/Expression/NameTest.php +++ b/tests/Expression/NameTest.php @@ -8,22 +8,23 @@ Exception\DomainException, }; use PHPUnit\Framework\TestCase; -use Eris\{ - Generator, - TestTrait, +use Innmind\BlackBox\{ + PHPUnit\BlackBox, + Set, }; class NameTest extends TestCase { - use TestTrait; + use BlackBox; public function testInterface() { $this - ->forAll(Generator\string()) - ->when(static function(string $string): bool { - return (bool) preg_match('~[a-zA-Z0-9_]+~', $string); - }) + ->forAll( + Set\Strings::atLeast(1)->filter(static function(string $string): bool { + return (bool) preg_match('~[a-zA-Z0-9_]+~', $string); + }), + ) ->then(function(string $string): void { $this->assertSame($string, (new Name($string))->toString()); }); @@ -32,10 +33,11 @@ public function testInterface() public function testThrowWhenInvalidName() { $this - ->forAll(Generator\string()) - ->when(static function(string $string): bool { - return !preg_match('~[a-zA-Z0-9_]+~', $string); - }) + ->forAll( + Set\Strings::any()->filter(static function(string $string): bool { + return (bool) !preg_match('~[a-zA-Z0-9_]+~', $string); + }), + ) ->then(function(string $string): void { $this->expectException(DomainException::class); $this->expectExceptionMessage($string); diff --git a/tests/UrlEncodeTest.php b/tests/UrlEncodeTest.php index bc29c86..da7f9b0 100644 --- a/tests/UrlEncodeTest.php +++ b/tests/UrlEncodeTest.php @@ -5,19 +5,19 @@ use Innmind\UrlTemplate\UrlEncode; use PHPUnit\Framework\TestCase; -use Eris\{ - Generator, - TestTrait, +use Innmind\BlackBox\{ + PHPUnit\BlackBox, + Set, }; class UrlEncodeTest extends TestCase { - use TestTrait; + use BlackBox; public function testStandardEncode() { $this - ->forAll(Generator\string()) + ->forAll(Set\Strings::any()) ->then(function(string $string): void { $encode = new UrlEncode; @@ -28,7 +28,7 @@ public function testStandardEncode() public function testSafeCharactersAreNotEncoded() { $this - ->forAll(Generator\elements( + ->forAll(Set\Elements::of( ':', '/', '?', From 96e56bc04b7101ea14c802ae3734ed4ed516b6e4 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sun, 7 Feb 2021 13:05:19 +0100 Subject: [PATCH 3/9] use phpunit 9 --- composer.json | 2 +- phpunit.xml.dist | 32 +++++++++++++++----------------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/composer.json b/composer.json index 0c9720f..ffd1432 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ } }, "require-dev": { - "phpunit/phpunit": "~8.0", + "phpunit/phpunit": "~9.0", "vimeo/psalm": "~4.4", "innmind/black-box": "^4.16" } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index ec6415a..51d31c5 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,19 +1,17 @@ - - - - - ./tests - - - - - - . - - ./tests - ./vendor - - - + + + + . + + + ./tests + ./vendor + + + + + ./tests + + From b1b496cd58226a08cca79451f3dcbca1a359d158 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sun, 7 Feb 2021 13:08:10 +0100 Subject: [PATCH 4/9] add coding standard --- .github/workflows/ci.yml | 27 +++++++++++++++++++++ .php_cs.dist | 6 +++++ composer.json | 3 ++- src/Expression/Level1.php | 6 ----- src/Expression/Level2/Fragment.php | 6 ----- src/Expression/Level2/Reserved.php | 6 ----- src/Expression/Level3.php | 6 ----- src/Expression/Level3/Fragment.php | 6 ----- src/Expression/Level3/Label.php | 6 ----- src/Expression/Level3/NamedValues.php | 6 ----- src/Expression/Level3/Parameters.php | 6 ----- src/Expression/Level3/Path.php | 6 ----- src/Expression/Level3/Query.php | 6 ----- src/Expression/Level3/QueryContinuation.php | 6 ----- src/Expression/Level3/Reserved.php | 6 ----- src/Expression/Level4.php | 8 +----- src/Expression/Level4/Composite.php | 3 --- src/Expression/Level4/Fragment.php | 6 ----- src/Expression/Level4/Label.php | 6 ----- src/Expression/Level4/Parameters.php | 3 --- src/Expression/Level4/Path.php | 6 ----- src/Expression/Level4/Query.php | 5 +--- src/Expression/Level4/QueryContinuation.php | 3 --- src/Expression/Level4/Reserved.php | 6 ----- src/Template.php | 2 +- src/UrlEncode.php | 16 ++++++------ tests/Expression/NameTest.php | 4 +-- tests/TemplateTest.php | 1 - tests/UrlEncodeTest.php | 2 +- 29 files changed, 49 insertions(+), 130 deletions(-) create mode 100644 .php_cs.dist diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 06739d4..9c2f253 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -62,3 +62,30 @@ jobs: run: composer install - name: Psalm run: vendor/bin/psalm + cs: + runs-on: ubuntu-latest + strategy: + matrix: + php-version: ['7.4'] + name: 'CS' + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + extensions: mbstring, intl + - name: Get Composer Cache Directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + - name: Cache dependencies + uses: actions/cache@v2 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-${{ matrix.php-version }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-${{ matrix.php-version }}-composer- + - name: Install Dependencies + run: composer install --no-progress + - name: CS + run: vendor/bin/php-cs-fixer fix --diff --dry-run --diff-format udiff diff --git a/.php_cs.dist b/.php_cs.dist new file mode 100644 index 0000000..1431d66 --- /dev/null +++ b/.php_cs.dist @@ -0,0 +1,6 @@ +encode = new UrlEncode; } - /** - * {@inheritdoc} - */ public static function of(Str $string): Expression { if (!$string->matches('~^\{[a-zA-Z0-9_]+\}$~')) { @@ -39,9 +36,6 @@ public static function of(Str $string): Expression return new self(new Name($string->trim('{}')->toString())); } - /** - * {@inheritdoc} - */ public function expand(Map $variables): string { if (!$variables->contains($this->name->toString())) { diff --git a/src/Expression/Level2/Fragment.php b/src/Expression/Level2/Fragment.php index 7af8230..61f6b28 100644 --- a/src/Expression/Level2/Fragment.php +++ b/src/Expression/Level2/Fragment.php @@ -28,9 +28,6 @@ public function __construct(Name $name) $this->encode = UrlEncode::allowReservedCharacters(); } - /** - * {@inheritdoc} - */ public static function of(Str $string): Expression { if (!$string->matches('~^\{#[a-zA-Z0-9_]+\}$~')) { @@ -40,9 +37,6 @@ public static function of(Str $string): Expression return new self(new Name($string->trim('{#}')->toString())); } - /** - * {@inheritdoc} - */ public function expand(Map $variables): string { if (!$variables->contains($this->name->toString())) { diff --git a/src/Expression/Level2/Reserved.php b/src/Expression/Level2/Reserved.php index 226a5ea..63e1a0a 100644 --- a/src/Expression/Level2/Reserved.php +++ b/src/Expression/Level2/Reserved.php @@ -28,9 +28,6 @@ public function __construct(Name $name) $this->encode = UrlEncode::allowReservedCharacters(); } - /** - * {@inheritdoc} - */ public static function of(Str $string): Expression { if (!$string->matches('~^\{\+[a-zA-Z0-9_]+\}$~')) { @@ -40,9 +37,6 @@ public static function of(Str $string): Expression return new self(new Name($string->trim('{+}')->toString())); } - /** - * {@inheritdoc} - */ public function expand(Map $variables): string { if (!$variables->contains($this->name->toString())) { diff --git a/src/Expression/Level3.php b/src/Expression/Level3.php index cc415a8..d370778 100644 --- a/src/Expression/Level3.php +++ b/src/Expression/Level3.php @@ -37,9 +37,6 @@ public function __construct(Name ...$names) ); } - /** - * {@inheritdoc} - */ public static function of(Str $string): Expression { if (!$string->matches('~^\{[a-zA-Z0-9_]+(,[a-zA-Z0-9_]+)+\}$~')) { @@ -58,9 +55,6 @@ public static function of(Str $string): Expression return new self(...unwrap($names)); } - /** - * {@inheritdoc} - */ public function expand(Map $variables): string { $expanded = $this->expressions->mapTo( diff --git a/src/Expression/Level3/Fragment.php b/src/Expression/Level3/Fragment.php index 1e678b2..bb52f24 100644 --- a/src/Expression/Level3/Fragment.php +++ b/src/Expression/Level3/Fragment.php @@ -39,9 +39,6 @@ public function __construct(Name ...$names) ); } - /** - * {@inheritdoc} - */ public static function of(Str $string): Expression { if (!$string->matches('~^\{#[a-zA-Z0-9_]+(,[a-zA-Z0-9_]+)+\}$~')) { @@ -60,9 +57,6 @@ public static function of(Str $string): Expression return new self(...unwrap($names)); } - /** - * {@inheritdoc} - */ public function expand(Map $variables): string { $expanded = $this->expressions->mapTo( diff --git a/src/Expression/Level3/Label.php b/src/Expression/Level3/Label.php index c9fa0eb..73d89a6 100644 --- a/src/Expression/Level3/Label.php +++ b/src/Expression/Level3/Label.php @@ -39,9 +39,6 @@ public function __construct(Name ...$names) ); } - /** - * {@inheritdoc} - */ public static function of(Str $string): Expression { if (!$string->matches('~^\{\.[a-zA-Z0-9_]+(,[a-zA-Z0-9_]+)+\}$~')) { @@ -60,9 +57,6 @@ public static function of(Str $string): Expression return new self(...unwrap($names)); } - /** - * {@inheritdoc} - */ public function expand(Map $variables): string { $expanded = $this->expressions->mapTo( diff --git a/src/Expression/Level3/NamedValues.php b/src/Expression/Level3/NamedValues.php index cb95f0f..530bd37 100644 --- a/src/Expression/Level3/NamedValues.php +++ b/src/Expression/Level3/NamedValues.php @@ -41,9 +41,6 @@ public function __construct(string $lead, string $separator, Name ...$names) ); } - /** - * {@inheritdoc} - */ public static function of(Str $string): Expression { throw new \LogicException('should not be used directly'); @@ -57,9 +54,6 @@ public static function keyOnlyWhenEmpty(string $lead, string $separator, Name .. return $self; } - /** - * {@inheritdoc} - */ public function expand(Map $variables): string { /** @var Sequence */ diff --git a/src/Expression/Level3/Parameters.php b/src/Expression/Level3/Parameters.php index 40baf30..247915d 100644 --- a/src/Expression/Level3/Parameters.php +++ b/src/Expression/Level3/Parameters.php @@ -24,9 +24,6 @@ public function __construct(Name ...$names) $this->expression = NamedValues::keyOnlyWhenEmpty(';', ';', ...$names); } - /** - * {@inheritdoc} - */ public static function of(Str $string): Expression { if (!$string->matches('~^\{;[a-zA-Z0-9_]+(,[a-zA-Z0-9_]+)+\}$~')) { @@ -45,9 +42,6 @@ public static function of(Str $string): Expression return new self(...unwrap($names)); } - /** - * {@inheritdoc} - */ public function expand(Map $variables): string { return $this->expression->expand($variables); diff --git a/src/Expression/Level3/Path.php b/src/Expression/Level3/Path.php index 34a1a41..0e97a90 100644 --- a/src/Expression/Level3/Path.php +++ b/src/Expression/Level3/Path.php @@ -39,9 +39,6 @@ public function __construct(Name ...$names) ); } - /** - * {@inheritdoc} - */ public static function of(Str $string): Expression { if (!$string->matches('~^\{/[a-zA-Z0-9_]+(,[a-zA-Z0-9_]+)+\}$~')) { @@ -60,9 +57,6 @@ public static function of(Str $string): Expression return new self(...unwrap($names)); } - /** - * {@inheritdoc} - */ public function expand(Map $variables): string { return join( diff --git a/src/Expression/Level3/Query.php b/src/Expression/Level3/Query.php index e45d4ac..a442c23 100644 --- a/src/Expression/Level3/Query.php +++ b/src/Expression/Level3/Query.php @@ -24,9 +24,6 @@ public function __construct(Name ...$names) $this->expression = new NamedValues('?', '&', ...$names); } - /** - * {@inheritdoc} - */ public static function of(Str $string): Expression { if (!$string->matches('~^\{\?[a-zA-Z0-9_]+(,[a-zA-Z0-9_]+)+\}$~')) { @@ -45,9 +42,6 @@ public static function of(Str $string): Expression return new self(...unwrap($names)); } - /** - * {@inheritdoc} - */ public function expand(Map $variables): string { return $this->expression->expand($variables); diff --git a/src/Expression/Level3/QueryContinuation.php b/src/Expression/Level3/QueryContinuation.php index 0b7bb89..fdb5ee6 100644 --- a/src/Expression/Level3/QueryContinuation.php +++ b/src/Expression/Level3/QueryContinuation.php @@ -24,9 +24,6 @@ public function __construct(Name ...$names) $this->expression = new NamedValues('&', '&', ...$names); } - /** - * {@inheritdoc} - */ public static function of(Str $string): Expression { if (!$string->matches('~^\{\&[a-zA-Z0-9_]+(,[a-zA-Z0-9_]+)+\}$~')) { @@ -45,9 +42,6 @@ public static function of(Str $string): Expression return new self(...unwrap($names)); } - /** - * {@inheritdoc} - */ public function expand(Map $variables): string { return $this->expression->expand($variables); diff --git a/src/Expression/Level3/Reserved.php b/src/Expression/Level3/Reserved.php index b697818..3412069 100644 --- a/src/Expression/Level3/Reserved.php +++ b/src/Expression/Level3/Reserved.php @@ -39,9 +39,6 @@ public function __construct(Name ...$names) ); } - /** - * {@inheritdoc} - */ public static function of(Str $string): Expression { if (!$string->matches('~^\{\+[a-zA-Z0-9_]+(,[a-zA-Z0-9_]+)+\}$~')) { @@ -60,9 +57,6 @@ public static function of(Str $string): Expression return new self(...unwrap($names)); } - /** - * {@inheritdoc} - */ public function expand(Map $variables): string { $expanded = $this->expressions->mapTo( diff --git a/src/Expression/Level4.php b/src/Expression/Level4.php index 602fc76..4a511f1 100644 --- a/src/Expression/Level4.php +++ b/src/Expression/Level4.php @@ -37,9 +37,6 @@ public function __construct(Name $name) $this->expression = new Level1($name); } - /** - * {@inheritdoc} - */ public static function of(Str $string): Expression { if ($string->matches('~^\{[a-zA-Z0-9_]+\}$~')) { @@ -116,7 +113,7 @@ public function withSeparator(string $separator): self */ public function withExpression(string $expression): self { - if (!is_a($expression, Expression::class, true)) { + if (!\is_a($expression, Expression::class, true)) { throw new DomainException($expression); } @@ -126,9 +123,6 @@ public function withExpression(string $expression): self return $self; } - /** - * {@inheritdoc} - */ public function expand(Map $variables): string { if (!$variables->contains($this->name->toString())) { diff --git a/src/Expression/Level4/Composite.php b/src/Expression/Level4/Composite.php index 3357a68..9e7a277 100644 --- a/src/Expression/Level4/Composite.php +++ b/src/Expression/Level4/Composite.php @@ -73,9 +73,6 @@ static function(Expression $level4, Str $expression): Expression { ); } - /** - * {@inheritdoc} - */ public function expand(Map $variables): string { $expanded = $this->expressions->mapTo( diff --git a/src/Expression/Level4/Fragment.php b/src/Expression/Level4/Fragment.php index 12f9dc3..42fa2a9 100644 --- a/src/Expression/Level4/Fragment.php +++ b/src/Expression/Level4/Fragment.php @@ -29,9 +29,6 @@ public function __construct(Name $name) ->withExpression(Level2\Reserved::class); } - /** - * {@inheritdoc} - */ public static function of(Str $string): Expression { if ($string->matches('~^\{#[a-zA-Z0-9_]+\}$~')) { @@ -93,9 +90,6 @@ public function regex(): string return $this->expression->regex(); } - /** - * {@inheritdoc} - */ public function expand(Map $variables): string { return $this->expression->expand($variables); diff --git a/src/Expression/Level4/Label.php b/src/Expression/Level4/Label.php index 7fbca13..84721c9 100644 --- a/src/Expression/Level4/Label.php +++ b/src/Expression/Level4/Label.php @@ -26,9 +26,6 @@ public function __construct(Name $name) $this->expression = (new Level4($name))->withLead('.'); } - /** - * {@inheritdoc} - */ public static function of(Str $string): Expression { if ($string->matches('~^\{\.[a-zA-Z0-9_]+\}$~')) { @@ -83,9 +80,6 @@ public function add(Str $pattern): Composite ); } - /** - * {@inheritdoc} - */ public function expand(Map $variables): string { return $this->expression->expand($variables); diff --git a/src/Expression/Level4/Parameters.php b/src/Expression/Level4/Parameters.php index 0fa7b54..45cab79 100644 --- a/src/Expression/Level4/Parameters.php +++ b/src/Expression/Level4/Parameters.php @@ -38,9 +38,6 @@ public function __construct(Name $name) $this->expression = new Level1($name); } - /** - * {@inheritdoc} - */ public static function of(Str $string): Expression { if ($string->matches('~^\{;[a-zA-Z0-9_]+\}$~')) { diff --git a/src/Expression/Level4/Path.php b/src/Expression/Level4/Path.php index 6b2f106..eb40380 100644 --- a/src/Expression/Level4/Path.php +++ b/src/Expression/Level4/Path.php @@ -26,9 +26,6 @@ public function __construct(Name $name) $this->expression = (new Level4($name))->withLead('/'); } - /** - * {@inheritdoc} - */ public static function of(Str $string): Expression { if ($string->matches('~^\{/[a-zA-Z0-9_]+\}$~')) { @@ -83,9 +80,6 @@ public function add(Str $pattern): Composite ); } - /** - * {@inheritdoc} - */ public function expand(Map $variables): string { return $this->expression->expand($variables); diff --git a/src/Expression/Level4/Query.php b/src/Expression/Level4/Query.php index c25b22e..dfd61cd 100644 --- a/src/Expression/Level4/Query.php +++ b/src/Expression/Level4/Query.php @@ -38,9 +38,6 @@ public function __construct(Name $name) $this->expression = new Level1($name); } - /** - * {@inheritdoc} - */ public static function of(Str $string): Expression { if ($string->matches('~^\{\?[a-zA-Z0-9_]+\}$~')) { @@ -142,7 +139,7 @@ public function regex(): string $regex = $this->expression->regex(); } - return $this->regex = sprintf( + return $this->regex = \sprintf( '\?%s=%s', $this->name->toString(), $regex, diff --git a/src/Expression/Level4/QueryContinuation.php b/src/Expression/Level4/QueryContinuation.php index c840990..a2b05bb 100644 --- a/src/Expression/Level4/QueryContinuation.php +++ b/src/Expression/Level4/QueryContinuation.php @@ -38,9 +38,6 @@ public function __construct(Name $name) $this->expression = new Level1($name); } - /** - * {@inheritdoc} - */ public static function of(Str $string): Expression { if ($string->matches('~^\{\&[a-zA-Z0-9_]+\}$~')) { diff --git a/src/Expression/Level4/Reserved.php b/src/Expression/Level4/Reserved.php index 1db65bf..b74d033 100644 --- a/src/Expression/Level4/Reserved.php +++ b/src/Expression/Level4/Reserved.php @@ -35,9 +35,6 @@ public function __construct(Name $name) ); } - /** - * {@inheritdoc} - */ public static function of(Str $string): Expression { if ($string->matches('~^\{\+[a-zA-Z0-9_]+\}$~')) { @@ -96,9 +93,6 @@ public function add(Str $pattern): Composite ); } - /** - * {@inheritdoc} - */ public function expand(Map $variables): string { return $this->expression->expand($variables); diff --git a/src/Template.php b/src/Template.php index 55c6b4f..7e41fd0 100644 --- a/src/Template.php +++ b/src/Template.php @@ -50,7 +50,7 @@ public function expand(Map $variables): Url $url = $this->expressions->reduce( $this->template, - function(Str $template, Expression $expression) use ($variables): Str { + static function(Str $template, Expression $expression) use ($variables): Str { return $template->replace( $expression->toString(), $expression->expand($variables), diff --git a/src/UrlEncode.php b/src/UrlEncode.php index 91d4ab3..b75df39 100644 --- a/src/UrlEncode.php +++ b/src/UrlEncode.php @@ -15,14 +15,6 @@ public function __construct() $this->safeCharacters = Str::of(''); } - public static function allowReservedCharacters(): self - { - $self = new self; - $self->safeCharacters = Str::of(':/?#[]@!$&\'()*+,;='); - - return $self; - } - public function __invoke(string $string): string { if ($this->safeCharacters->empty()) { @@ -55,4 +47,12 @@ public function __invoke(string $string): string return \rawurlencode($string->toString()); } + + public static function allowReservedCharacters(): self + { + $self = new self; + $self->safeCharacters = Str::of(':/?#[]@!$&\'()*+,;='); + + return $self; + } } diff --git a/tests/Expression/NameTest.php b/tests/Expression/NameTest.php index 18b4e21..5e6c3c2 100644 --- a/tests/Expression/NameTest.php +++ b/tests/Expression/NameTest.php @@ -22,7 +22,7 @@ public function testInterface() $this ->forAll( Set\Strings::atLeast(1)->filter(static function(string $string): bool { - return (bool) preg_match('~[a-zA-Z0-9_]+~', $string); + return (bool) \preg_match('~[a-zA-Z0-9_]+~', $string); }), ) ->then(function(string $string): void { @@ -35,7 +35,7 @@ public function testThrowWhenInvalidName() $this ->forAll( Set\Strings::any()->filter(static function(string $string): bool { - return (bool) !preg_match('~[a-zA-Z0-9_]+~', $string); + return (bool) !\preg_match('~[a-zA-Z0-9_]+~', $string); }), ) ->then(function(string $string): void { diff --git a/tests/TemplateTest.php b/tests/TemplateTest.php index 75d1824..0927047 100644 --- a/tests/TemplateTest.php +++ b/tests/TemplateTest.php @@ -13,7 +13,6 @@ Map, Sequence, }; -use function Innmind\Immutable\first; use PHPUnit\Framework\TestCase; class TemplateTest extends TestCase diff --git a/tests/UrlEncodeTest.php b/tests/UrlEncodeTest.php index da7f9b0..975dd73 100644 --- a/tests/UrlEncodeTest.php +++ b/tests/UrlEncodeTest.php @@ -21,7 +21,7 @@ public function testStandardEncode() ->then(function(string $string): void { $encode = new UrlEncode; - $this->assertSame(rawurlencode($string), $encode($string)); + $this->assertSame(\rawurlencode($string), $encode($string)); }); } From 5b0ff27f8c584ec534e3bcfa4f98629cdf3ec65f Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sun, 7 Feb 2021 13:08:22 +0100 Subject: [PATCH 5/9] publish type coverage --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9c2f253..bcb4a1d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,7 +61,7 @@ jobs: - name: Install Dependencies run: composer install - name: Psalm - run: vendor/bin/psalm + run: vendor/bin/psalm --shepherd cs: runs-on: ubuntu-latest strategy: From 6ba567fd33cb0c0786f61852999a1b2788fbc8dd Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sun, 7 Feb 2021 13:08:48 +0100 Subject: [PATCH 6/9] update actions version --- .github/workflows/ci.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bcb4a1d..5032bdb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,9 +12,9 @@ jobs: name: 'PHPUnit - PHP/${{ matrix.php-version }} - OS/${{ matrix.os }}' steps: - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v2 - name: Setup PHP - uses: shivammathur/setup-php@v1 + uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-version }} extensions: mbstring, intl @@ -23,7 +23,7 @@ jobs: id: composer-cache run: echo "::set-output name=dir::$(composer config cache-files-dir)" - name: Cache dependencies - uses: actions/cache@v1 + uses: actions/cache@v2 with: path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} @@ -43,9 +43,9 @@ jobs: name: 'Psalm - PHP/${{ matrix.php-version }}' steps: - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v2 - name: Setup PHP - uses: shivammathur/setup-php@v1 + uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-version }} extensions: mbstring, intl @@ -53,7 +53,7 @@ jobs: id: composer-cache run: echo "::set-output name=dir::$(composer config cache-files-dir)" - name: Cache dependencies - uses: actions/cache@v1 + uses: actions/cache@v2 with: path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} From 1e57f264239149f9476f23511b2dfc00f3905409 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sun, 7 Feb 2021 13:09:05 +0100 Subject: [PATCH 7/9] simplify jobs name --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5032bdb..5b6e04f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ jobs: matrix: os: [ubuntu-latest, macOS-latest] php-version: ['7.4'] - name: 'PHPUnit - PHP/${{ matrix.php-version }} - OS/${{ matrix.os }}' + name: 'PHPUnit' steps: - name: Checkout uses: actions/checkout@v2 @@ -40,7 +40,7 @@ jobs: strategy: matrix: php-version: ['7.4'] - name: 'Psalm - PHP/${{ matrix.php-version }}' + name: 'Psalm' steps: - name: Checkout uses: actions/checkout@v2 From 764c441a82e3a826e1eee8721a7d62a609abc36d Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sun, 7 Feb 2021 13:09:30 +0100 Subject: [PATCH 8/9] allow php 8 --- .github/workflows/ci.yml | 4 ++-- composer.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5b6e04f..85ef7d9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macOS-latest] - php-version: ['7.4'] + php-version: ['7.4', '8.0'] name: 'PHPUnit' steps: - name: Checkout @@ -39,7 +39,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-version: ['7.4'] + php-version: ['7.4', '8.0'] name: 'Psalm' steps: - name: Checkout diff --git a/composer.json b/composer.json index 477a2d7..31208c5 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "issues": "http://github.com/Innmind/UrlTemplate/issues" }, "require": { - "php": "~7.4", + "php": "~7.4|~8.0", "innmind/url": "~3.0", "innmind/immutable": "~3.1" }, From 4588ee45fb1aa83c4834b1336476cacf19751ef4 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sun, 7 Feb 2021 13:11:36 +0100 Subject: [PATCH 9/9] update badges --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9abd081..bf10adc 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,8 @@ # UrlTemplate -| `develop` | -|-----------| -| [![codecov](https://codecov.io/gh/Innmind/UrlTemplate/branch/develop/graph/badge.svg)](https://codecov.io/gh/Innmind/UrlTemplate) | -| [![Build Status](https://github.com/Innmind/UrlTemplate/workflows/CI/badge.svg)](https://github.com/Innmind/UrlTemplate/actions?query=workflow%3ACI) | +[![Build Status](https://github.com/innmind/urltemplate/workflows/CI/badge.svg?branch=master)](https://github.com/innmind/urltemplate/actions?query=workflow%3ACI) +[![codecov](https://codecov.io/gh/innmind/urltemplate/branch/develop/graph/badge.svg)](https://codecov.io/gh/innmind/urltemplate) +[![Type Coverage](https://shepherd.dev/github/innmind/urltemplate/coverage.svg)](https://shepherd.dev/github/innmind/urltemplate) [RFC6570](https://tools.ietf.org/html/rfc6570) implementation.