From 834d205c0e0b2c04c8609d5aec3f6abd3065c04d Mon Sep 17 00:00:00 2001 From: Greg Bowler Date: Thu, 9 May 2024 11:31:23 +0100 Subject: [PATCH 1/5] ci: remove old artifacts --- .github/workflows/ci.yml | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a74e714..3b78953 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -159,18 +159,17 @@ jobs: path: src/ standard: phpcs.xml -# TODO: Figure this one out: -# remove_old_artifacts: -# runs-on: ubuntu-latest -# -# steps: -# - name: Remove old artifacts for prior workflow runs on this repository -# env: -# GH_TOKEN: ${{ github.token }} -# run: | -# gh api "/repos/${{ github.repository }}/actions/artifacts?name=build-artifact" | jq ".artifacts[] | select(.name | startswith(\"build-artifact\")) | .id" > artifact-id-list.txt -# while read id -# do -# echo -n "Deleting artifact ID $id ... " -# gh api --method DELETE /repos/${{ github.repository }}/actions/artifacts/$id && echo "Done" -# done artifact-id-list.txt + while read id + do + echo -n "Deleting artifact ID $id ... " + gh api --method DELETE /repos/${{ github.repository }}/actions/artifacts/$id && echo "Done" + done Date: Mon, 10 Feb 2025 14:35:53 +0000 Subject: [PATCH 2/5] ci: run all php versions --- .github/workflows/ci.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3b78953..dff0d36 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,13 +7,13 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: [ 8.1, 8.2, 8.3 ] + php: [ 8.1, 8.2, 8.3, 8.4 ] steps: - uses: actions/checkout@v4 - name: Cache Composer dependencies - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: /tmp/composer-cache key: ${{ runner.os }}-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }} @@ -37,7 +37,7 @@ jobs: needs: [ composer ] strategy: matrix: - php: [ 8.1, 8.2, 8.3 ] + php: [ 8.1, 8.2, 8.3, 8.4 ] outputs: coverage: ${{ steps.store-coverage.outputs.coverage_text }} @@ -52,7 +52,7 @@ jobs: run: tar -xvf /tmp/github-actions/build.tar ./ - name: PHP Unit tests - uses: php-actions/phpunit@v3 + uses: php-actions/phpunit@v4 env: XDEBUG_MODE: cover with: @@ -73,7 +73,7 @@ jobs: needs: [ phpunit ] strategy: matrix: - php: [ 8.1, 8.2, 8.3 ] + php: [ 8.1, 8.2, 8.3, 8.4 ] steps: - uses: actions/download-artifact@v4 @@ -94,7 +94,7 @@ jobs: needs: [ composer ] strategy: matrix: - php: [ 8.1, 8.2, 8.3 ] + php: [ 8.1, 8.2, 8.3, 8.4 ] steps: - uses: actions/download-artifact@v4 @@ -117,7 +117,7 @@ jobs: needs: [ composer ] strategy: matrix: - php: [ 8.1, 8.2, 8.3 ] + php: [ 8.1, 8.2, 8.3, 8.4 ] steps: - uses: actions/download-artifact@v4 @@ -141,7 +141,7 @@ jobs: needs: [ composer ] strategy: matrix: - php: [ 8.1, 8.2, 8.3 ] + php: [ 8.1, 8.2, 8.3, 8.4 ] steps: - uses: actions/download-artifact@v4 From 0c31ab83df903403339371c008345b8cd7f42991 Mon Sep 17 00:00:00 2001 From: Greg Bowler Date: Wed, 26 Mar 2025 10:53:34 +0000 Subject: [PATCH 3/5] feature: implement selectPrefix closes #13 --- src/Input.php | 20 +++++++++++++++++++- src/Trigger/NeverTrigger.php | 16 ++++++++++++++++ test/phpunit/InputTest.php | 24 ++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/Trigger/NeverTrigger.php diff --git a/src/Input.php b/src/Input.php index 3ed042c..10eb55f 100644 --- a/src/Input.php +++ b/src/Input.php @@ -3,6 +3,7 @@ use ArrayAccess; use Countable; +use Gt\Input\Trigger\NeverTrigger; use Gt\Json\JsonDecodeException; use Gt\Json\JsonObject; use Gt\Json\JsonObjectBuilder; @@ -243,7 +244,7 @@ public function select(string...$keys):Trigger { } } - return $this->newTrigger("with", ...$keys); + return $this->newTrigger("select", ...$keys); } /** @deprecated Use select() instead to avoid ambiguity with immutable `with` functions */ @@ -251,6 +252,23 @@ public function with(string...$keys):Trigger { return $this->select(...$keys); } + public function selectPrefix(string $prefix):Trigger { + $keys = []; + + foreach($this->parameters as $key => $param) { + if(str_starts_with($key, $prefix)) { + array_push($keys, $key); + } + } + + if($keys) { + return $this->when(...$keys); + } + else { + return new NeverTrigger($this); + } + } + /** * Return a Trigger that will pass all keys apart from the provided * keys to its callback. diff --git a/src/Trigger/NeverTrigger.php b/src/Trigger/NeverTrigger.php new file mode 100644 index 0000000..68ef526 --- /dev/null +++ b/src/Trigger/NeverTrigger.php @@ -0,0 +1,16 @@ +getInt("id")); } + public function testSelectPrefix_noMatch():void { + $sut = new Input(["id" => 123]); + $trigger = $sut->selectPrefix("io_"); + + $triggered = false; + $trigger->call(function(...$args)use(&$triggered) { + $triggered = true; + }); + $trigger->fire(); + self::assertFalse($triggered); + } + + public function testSelectPrefix_match():void { + $sut = new Input(["id" => 123, "io_database" => "connect"]); + $trigger = $sut->selectPrefix("io_"); + + $triggered = false; + $trigger->call(function(...$args)use(&$triggered) { + $triggered = true; + }); + $trigger->fire(); + self::assertTrue($triggered); + } + public static function dataRandomGetPost():array { $data = []; From d57f4d8db2a37278fb8211bb235a9ec757d3185b Mon Sep 17 00:00:00 2001 From: Greg Bowler Date: Wed, 26 Mar 2025 11:17:42 +0000 Subject: [PATCH 4/5] tweak: ignore unused function parameter --- src/Input.php | 2 +- src/Trigger/NeverTrigger.php | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Input.php b/src/Input.php index 10eb55f..080376f 100644 --- a/src/Input.php +++ b/src/Input.php @@ -255,7 +255,7 @@ public function with(string...$keys):Trigger { public function selectPrefix(string $prefix):Trigger { $keys = []; - foreach($this->parameters as $key => $param) { + foreach(array_keys($this->parameters) as $key) { if(str_starts_with($key, $prefix)) { array_push($keys, $key); } diff --git a/src/Trigger/NeverTrigger.php b/src/Trigger/NeverTrigger.php index 68ef526..742b319 100644 --- a/src/Trigger/NeverTrigger.php +++ b/src/Trigger/NeverTrigger.php @@ -2,10 +2,12 @@ namespace Gt\Input\Trigger; class NeverTrigger extends Trigger { + // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter public function call(callable $callback, string ...$args):Trigger { return $this; } + // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter public function orCall(callable $callback, string ...$args):Trigger { return $this; } From 9a5fc01e1be5bfa7a93bee3ced08d0c5d5aefb99 Mon Sep 17 00:00:00 2001 From: Greg Bowler Date: Wed, 26 Mar 2025 11:22:59 +0000 Subject: [PATCH 5/5] tweak: improve looping over parameters --- src/Input.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Input.php b/src/Input.php index 080376f..bcb2c7a 100644 --- a/src/Input.php +++ b/src/Input.php @@ -252,10 +252,11 @@ public function with(string...$keys):Trigger { return $this->select(...$keys); } + /** @SuppressWarnings(PHPMD.UnusedLocalVariable) */ public function selectPrefix(string $prefix):Trigger { $keys = []; - foreach(array_keys($this->parameters) as $key) { + foreach($this->parameters as $key => $param) { if(str_starts_with($key, $prefix)) { array_push($keys, $key); }