From 4b924a49781ced70ff5041fc579d7f20c094002f Mon Sep 17 00:00:00 2001 From: remorhaz Date: Sat, 17 Jun 2023 00:50:06 +0300 Subject: [PATCH] Dropped PHP 7 --- .github/workflows/build.yml | 15 ++- CHANGELOG.md | 4 + README.md | 4 +- composer.json | 24 ++-- docker-compose.yml | 17 +-- generated/TokenMatcher.php | 94 +++++++++++----- infection.json.dist | 4 +- php-7.3.Dockerfile | 18 --- php-8.0.Dockerfile | 2 +- php-8.1.Dockerfile | 2 +- php-7.4.Dockerfile => php-8.2.Dockerfile | 6 +- .../ParserCreationFailedException.php | 3 +- .../Exception/QueryAstNotBuiltException.php | 12 +- src/Parser/Ll1ParserFactory.php | 11 +- src/Parser/Ll1ParserFactoryInterface.php | 1 - src/Parser/Parser.php | 9 +- src/Parser/ParserInterface.php | 1 - src/Parser/TokenType.php | 1 - src/Parser/TranslationScheme.php | 10 +- .../Exception/IndefiniteQueryException.php | 10 +- .../Exception/InvalidPathElementException.php | 14 +-- .../QueryNotAddressableException.php | 10 +- src/Processor/Mutator/DeleteMutation.php | 21 +++- .../ReplaceAtNestedPathsException.php | 14 +-- src/Processor/Mutator/Mutator.php | 15 +-- src/Processor/Mutator/MutatorInterface.php | 3 +- src/Processor/Mutator/ReplaceMutation.php | 46 +++++--- src/Processor/PathEncoder.php | 3 +- src/Processor/Processor.php | 39 ++++--- src/Processor/ProcessorInterface.php | 3 +- .../MoreThanOneValueInListException.php | 10 +- .../PathNotFoundInValueException.php | 10 +- .../SelectedValueNotFoundException.php | 3 +- .../Result/ExistingSelectOnePathResult.php | 13 +-- src/Processor/Result/ExistingValueResult.php | 18 +-- .../Result/NonExistingSelectOnePathResult.php | 1 - .../Result/NonExistingValueResult.php | 3 +- src/Processor/Result/OneResultInterface.php | 1 - src/Processor/Result/ResultFactory.php | 40 ++----- .../Result/ResultFactoryInterface.php | 1 - .../Result/SelectOnePathResultInterface.php | 3 - src/Processor/Result/SelectPathsResult.php | 26 +++-- .../Result/SelectPathsResultInterface.php | 5 +- src/Processor/Result/SelectResult.php | 27 ++--- .../Result/SelectResultInterface.php | 9 +- src/Processor/Result/ValueResultInterface.php | 3 +- src/Query/AstBuilder.php | 106 +++--------------- src/Query/AstBuilderInterface.php | 1 - src/Query/AstNodeType.php | 1 - src/Query/AstTranslator.php | 3 +- src/Query/AstTranslatorInterface.php | 3 +- src/Query/CallbackBuilder.php | 90 ++++++++------- src/Query/CallbackBuilderInterface.php | 10 +- src/Query/Capabilities.php | 19 +--- src/Query/CapabilitiesInterface.php | 1 - .../CapabilitiesNotFoundException.php | 3 +- .../QueryAstNotTranslatedException.php | 10 +- .../QueryCallbackCodeNotFoundException.php | 3 +- .../QueryExecutionFailedException.php | 16 +-- .../ReferenceAlreadyExistsException.php | 12 +- .../Exception/ReferenceNotFoundException.php | 12 +- src/Query/LazyQuery.php | 29 +---- src/Query/Query.php | 19 +--- src/Query/QueryFactory.php | 13 +-- src/Query/QueryFactoryInterface.php | 1 - src/Query/QueryInterface.php | 1 - src/Query/QueryValidator.php | 17 +-- src/Query/QueryValidatorInterface.php | 1 - .../Aggregator/AggregatorCollection.php | 27 ++--- .../AggregatorCollectionInterface.php | 1 - src/Runtime/Aggregator/AvgAggregator.php | 8 +- .../AggregateFunctionNotFoundException.php | 12 +- .../Exception/MaxElementNotFoundException.php | 19 ++-- .../Exception/MinElementNotFoundException.php | 18 ++- src/Runtime/Aggregator/LengthAggregator.php | 1 - src/Runtime/Aggregator/MaxAggregator.php | 15 +-- src/Runtime/Aggregator/MinAggregator.php | 15 +-- src/Runtime/Aggregator/NumericAggregator.php | 46 +++++--- src/Runtime/Aggregator/StdDevAggregator.php | 6 +- .../Aggregator/UniqueNumericAggregator.php | 3 +- .../Aggregator/ValueAggregatorInterface.php | 1 - src/Runtime/ComparatorCollection.php | 9 +- src/Runtime/ComparatorCollectionInterface.php | 1 - src/Runtime/Evaluator.php | 50 ++++----- src/Runtime/EvaluatorInterface.php | 11 +- .../IndexMapMatchFailedException.php | 13 +-- .../InvalidContextValueException.php | 10 +- .../Exception/InvalidFilterValueException.php | 10 +- .../Exception/InvalidRegExpException.php | 12 +- .../LiteralEvaluationFailedException.php | 10 +- .../UnexpectedNodeValueFetchedException.php | 10 +- src/Runtime/LiteralFactory.php | 14 +-- src/Runtime/LiteralFactoryInterface.php | 1 - src/Runtime/Matcher/AnyChildMatcher.php | 3 +- src/Runtime/Matcher/ChildMatcherInterface.php | 3 +- .../Exception/AddressNotSortableException.php | 19 +--- src/Runtime/Matcher/MatcherFactory.php | 1 - .../Matcher/MatcherFactoryInterface.php | 1 - src/Runtime/Matcher/SliceElementMatcher.php | 46 +++----- .../Matcher/SortedChildMatcherInterface.php | 3 +- src/Runtime/Matcher/StrictElementMatcher.php | 13 +-- src/Runtime/Matcher/StrictPropertyMatcher.php | 11 +- src/Runtime/Runtime.php | 21 +--- src/Runtime/RuntimeInterface.php | 1 - src/Runtime/ValueFetcher.php | 18 ++- src/Runtime/ValueFetcherInterface.php | 16 ++- src/Runtime/ValueListFetcher.php | 19 ++-- src/Runtime/ValueListFetcherInterface.php | 1 - src/Value/EvaluatedValue.php | 9 +- src/Value/EvaluatedValueInterface.php | 1 - src/Value/EvaluatedValueList.php | 56 +++++---- src/Value/EvaluatedValueListBuilder.php | 13 ++- src/Value/EvaluatedValueListInterface.php | 2 +- .../Exception/InvalidScalarDataException.php | 12 +- .../Exception/OuterIndexNotFoundException.php | 16 +-- .../Exception/ResultNotFoundException.php | 16 +-- ...ueInListWithAnotherOuterIndexException.php | 20 +--- .../Exception/ValueNotFoundException.php | 16 +-- src/Value/IndexMap.php | 28 +++-- src/Value/IndexMapInterface.php | 7 +- src/Value/LiteralArrayValue.php | 14 ++- src/Value/LiteralScalarValue.php | 14 +-- src/Value/LiteralValueList.php | 23 ++-- src/Value/LiteralValueListInterface.php | 6 +- src/Value/NodeValueList.php | 27 +++-- src/Value/NodeValueListBuilder.php | 17 +-- src/Value/NodeValueListInterface.php | 6 + src/Value/ValueList.php | 30 ++--- src/Value/ValueListBuilder.php | 13 ++- src/Value/ValueListInterface.php | 3 +- tests/JsonPathTest.php | 1 - tests/MemoryLeakTest.php | 1 - .../ParserCreationFailedExceptionTest.php | 1 - .../QueryAstNotBuiltExceptionTest.php | 1 - tests/Parser/Ll1ParserFactoryTest.php | 1 - tests/Parser/ParserTest.php | 1 - tests/Parser/TranslationSchemeTest.php | 1 - .../IndefiniteQueryExceptionTest.php | 1 - .../InvalidPathElementExceptionTest.php | 1 - .../QueryNotAddressableExceptionTest.php | 1 - .../ReplaceAtNestedPathsExceptionTest.php | 1 - tests/Processor/PathEncoderTest.php | 1 - tests/Processor/ProcessorTest.php | 1 - .../MoreThanOneValueInListExceptionTest.php | 1 - .../PathNotFoundInValueExceptionTest.php | 1 - .../SelectedValueNotFoundExceptionTest.php | 1 - .../ExistingSelectOnePathResultTest.php | 1 - .../Result/ExistingValueResultTest.php | 1 - .../NonExistingSelectOnePathResultTest.php | 1 - .../Result/NonExistingValueResultTest.php | 1 - tests/Processor/Result/ResultFactoryTest.php | 1 - .../Result/SelectPathsResultTest.php | 1 - tests/Processor/Result/SelectResultTest.php | 1 - tests/Query/AstTranslatorTest.php | 1 - tests/Query/CallbackBuilderTest.php | 1 - tests/Query/CapabilitiesTest.php | 1 - .../PropertiesNotFoundExceptionTest.php | 1 - .../QueryAstNotTranslatedExceptionTest.php | 1 - ...QueryCallbackCodeNotFoundExceptionTest.php | 1 - .../QueryExecutionFailedExceptionTest.php | 1 - .../ReferenceAlreadyExistsExceptionTest.php | 1 - .../ReferenceNotFoundExceptionTest.php | 1 - tests/Query/LazyQueryTest.php | 1 - tests/Query/QueryFactoryTest.php | 1 - tests/Query/QueryTest.php | 1 - tests/Query/QueryValidatorTest.php | 1 - .../Aggregator/AggregatorCollectionTest.php | 1 - .../Runtime/Aggregator/AvgAggregatorTest.php | 1 - ...AggregateFunctionNotFoundExceptionTest.php | 1 - .../MaxElementNotFoundExceptionTest.php | 1 - .../MinElementNotFoundExceptionTest.php | 1 - .../Aggregator/LengthAggregatorTest.php | 1 - .../Runtime/Aggregator/MaxAggregatorTest.php | 1 - .../Runtime/Aggregator/MinAggregatorTest.php | 1 - .../Aggregator/NumericAggregatorTest.php | 1 - .../Aggregator/StdDevAggregatorTest.php | 1 - .../UniqueNumericAggregatorTest.php | 1 - tests/Runtime/ComparatorCollectionTest.php | 1 - tests/Runtime/EvaluatorTest.php | 1 - .../IndexMapMatchFailedExceptionTest.php | 1 - .../InvalidContextValueExceptionTest.php | 1 - .../InvalidFilterValueExceptionTest.php | 1 - .../Exception/InvalidRegExpExceptionTest.php | 1 - .../LiteralEvaluationFailedExceptionTest.php | 1 - ...nexpectedNodeValueFetchedExceptionTest.php | 1 - tests/Runtime/Matcher/AnyChildMatcherTest.php | 1 - .../AddressNotSortableExceptionTest.php | 1 - tests/Runtime/Matcher/MatcherFactoryTest.php | 1 - .../Matcher/SliceElementMatcherTest.php | 3 +- .../Matcher/StrictElementMatcherTest.php | 1 - .../Matcher/StrictPropertyMatcherTest.php | 1 - tests/Runtime/RuntimeTest.php | 1 - tests/TokenMatcherTest.php | 1 - tests/Value/EvaluatedValueListBuilderTest.php | 1 - tests/Value/EvaluatedValueListTest.php | 1 - tests/Value/EvaluatedValueTest.php | 1 - .../InvalidScalarDataExceptionTest.php | 1 - .../OuterIndexNotFoundExceptionTest.php | 1 - .../Exception/ResultNotFoundExceptionTest.php | 1 - ...ListWithAnotherOuterIndexExceptionTest.php | 1 - .../Exception/ValueNotFoundExceptionTest.php | 1 - tests/Value/IndexMapTest.php | 1 - .../LiteralArrayValueListExceptionTest.php | 1 - tests/Value/LiteralArrayValueTest.php | 1 - tests/Value/LiteralScalarValueTest.php | 1 - tests/Value/LiteralValueListTest.php | 1 - tests/Value/NodeValueListBuilderTest.php | 1 - tests/Value/NodeValueListTest.php | 1 - tests/Value/ValueListBuilderTest.php | 1 - 209 files changed, 809 insertions(+), 1080 deletions(-) delete mode 100644 php-7.3.Dockerfile rename php-7.4.Dockerfile => php-8.2.Dockerfile (85%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a70893c..1846ecf 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,10 +14,9 @@ jobs: strategy: matrix: php-version: - - "7.3" - - "7.4" - "8.0" - "8.1" + - "8.2" dependencies: - lowest - highest @@ -57,3 +56,15 @@ jobs: - name: Run Infection run: composer infection + env: + INFECTION_DASHBOARD_API_KEY: ${{ secrets.INFECTION_DASHBOARD_API_KEY }} + + - name: Upload coverage to Codecov.io + run: bash <(curl -s https://codecov.io/bash -s "build/logs") + continue-on-error: true + + - name: Upload coverage to Scrutinizer + uses: sudo-bot/action-scrutinizer@latest + with: + cli-args: --format=php-clover build/logs/clover.xml + continue-on-error: true diff --git a/CHANGELOG.md b/CHANGELOG.md index fce9ad1..a329350 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] +### Removed +- Dropped support for PHP 7. + ## [0.7.7] - 2021-10-13 ### Fixed - Queries now don't share same caching callback builder instance. diff --git a/README.md b/README.md index 1f8ce3c..5de6003 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Build](https://github.com/remorhaz/php-json-path/actions/workflows/build.yml/badge.svg)](https://github.com/remorhaz/php-json-path/actions/workflows/build.yml) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/remorhaz/php-json-path/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/remorhaz/php-json-path/?branch=master) [![codecov](https://codecov.io/gh/remorhaz/php-json-path/branch/master/graph/badge.svg)](https://codecov.io/gh/remorhaz/php-json-path) -[![Infection MSI](https://badge.stryker-mutator.io/github.com/remorhaz/php-json-path/master)](https://infection.github.io) +[![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fremorhaz%2Fphp-json-path%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/remorhaz/php-json-path/master) [![Total Downloads](https://poser.pugx.org/remorhaz/php-json-path/downloads)](https://packagist.org/packages/remorhaz/php-json-path) [![License](https://poser.pugx.org/remorhaz/php-json-path/license)](https://packagist.org/packages/remorhaz/php-json-path) @@ -16,7 +16,7 @@ JSONPath is a simple query language for JSON documents, inspired by XPath for XM - Transforms indefinite JSONPath query to set of definite queries for given JSON document. ## Requirements -- PHP 7.3+ +- PHP 8 - [JSON extension](https://www.php.net/manual/en/book.json.php) (ext-json) - required by [remorhaz/php-json-data](https://github.com/remorhaz/php-json-data) that is used to access JSON documents. - [Internationalization functions](https://www.php.net/manual/en/book.intl.php) (ext-intl) - [Tokenizer extension](https://www.php.net/manual/en/book.tokenizer.php) (ext-tokenizer) - required by [nikic/php-parser](https://github.com/nikic/PHP-Parser) that is used for code generation. diff --git a/composer.json b/composer.json index 6eb3186..9187f7a 100644 --- a/composer.json +++ b/composer.json @@ -16,17 +16,17 @@ } ], "require": { - "php": "^7.3 || ^8", + "php": "~8.0.0 || ~8.1.0 || ~8.2.0", "ext-intl": "*", "ext-json": "*", - "remorhaz/php-unilex": "^0.4.1", - "remorhaz/php-json-data": "^0.5.3", + "remorhaz/php-unilex": "^0.5.2", + "remorhaz/php-json-data": "^0.6", "nikic/php-parser": "^4.12" }, "require-dev": { - "infection/infection": "^0.18 || ^0.24 || ^0.25", - "phpunit/phpunit": "^9.5.10", - "squizlabs/php_codesniffer": "^3.6.1" + "infection/infection": "^0.26 || ^0.27", + "phpunit/phpunit": "^9.6 || ^10", + "squizlabs/php_codesniffer": "^3.7.2" }, "autoload": { "psr-4": { @@ -51,16 +51,24 @@ "vendor/bin/phpcs -sp" ], "test-unit": [ - "vendor/bin/phpunit --coverage-xml=build/log/coverage-xml --log-junit=build/log/junit.xml" + "vendor/bin/phpunit --coverage-xml=build/log/coverage-xml --coverage-clover=build/log/clover.xml --log-junit=build/log/junit.xml" ], "test": [ "@test-cs", "@test-unit" ], "infection": [ - "@test-unit", "mkdir -p build/log/infection", "vendor/bin/infection --threads=4 --coverage=build/log --no-progress --skip-initial-tests" + ], + "test-infection": [ + "@test-unit", + "@infection" ] + }, + "config": { + "allow-plugins": { + "infection/extension-installer": true + } } } diff --git a/docker-compose.yml b/docker-compose.yml index acd7060..92abc6e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,28 +4,21 @@ services: php: build: context: . - dockerfile: php-7.3.Dockerfile - volumes: - - .:/app - working_dir: /app - php7.4: - build: - context: . - dockerfile: php-7.4.Dockerfile + dockerfile: php-8.0.Dockerfile volumes: - .:/app working_dir: /app - php8.0: + php8.1: build: context: . - dockerfile: php-8.0.Dockerfile + dockerfile: php-8.1.Dockerfile volumes: - .:/app working_dir: /app - php8.1: + php8.2: build: context: . - dockerfile: php-8.1.Dockerfile + dockerfile: php-8.2.Dockerfile volumes: - .:/app working_dir: /app diff --git a/generated/TokenMatcher.php b/generated/TokenMatcher.php index a37b2c8..05ff001 100644 --- a/generated/TokenMatcher.php +++ b/generated/TokenMatcher.php @@ -19,7 +19,6 @@ class TokenMatcher extends TokenMatcherTemplate { - public function match(CharBufferInterface $buffer, TokenFactoryInterface $tokenFactory): bool { $context = $this->createContext($buffer, $tokenFactory); @@ -1790,8 +1789,9 @@ private function isModeDefaultSymbol21(int $char): bool 0x0828 == $char || 0x0840 <= $char && $char <= 0x0858 || 0x0860 <= $char && $char <= 0x086A || - 0x08A0 <= $char && $char <= 0x08B4 || - 0x08B6 <= $char && $char <= 0x08C7 || + 0x0870 <= $char && $char <= 0x0887 || + 0x0889 <= $char && $char <= 0x088E || + 0x08A0 <= $char && $char <= 0x08C9 || 0x0904 <= $char && $char <= 0x0939 || 0x093D == $char || 0x0950 == $char || @@ -1871,6 +1871,7 @@ private function isModeDefaultSymbol21(int $char): bool 0x0C2A <= $char && $char <= 0x0C39 || 0x0C3D == $char || 0x0C58 <= $char && $char <= 0x0C5A || + 0x0C5D == $char || 0x0C60 == $char || 0x0C61 == $char || 0x0C80 == $char || @@ -1880,6 +1881,7 @@ private function isModeDefaultSymbol21(int $char): bool 0x0CAA <= $char && $char <= 0x0CB3 || 0x0CB5 <= $char && $char <= 0x0CB9 || 0x0CBD == $char || + 0x0CDD == $char || 0x0CDE == $char || 0x0CE0 == $char || 0x0CE1 == $char || @@ -1957,9 +1959,8 @@ private function isModeDefaultSymbol21(int $char): bool 0x1681 <= $char && $char <= 0x169A || 0x16A0 <= $char && $char <= 0x16EA || 0x16EE <= $char && $char <= 0x16F8 || - 0x1700 <= $char && $char <= 0x170C || - 0x170E <= $char && $char <= 0x1711 || - 0x1720 <= $char && $char <= 0x1731 || + 0x1700 <= $char && $char <= 0x1711 || + 0x171F <= $char && $char <= 0x1731 || 0x1740 <= $char && $char <= 0x1751 || 0x1760 <= $char && $char <= 0x176C || 0x176E <= $char && $char <= 0x1770 || @@ -1979,7 +1980,7 @@ private function isModeDefaultSymbol21(int $char): bool 0x1A20 <= $char && $char <= 0x1A54 || 0x1AA7 == $char || 0x1B05 <= $char && $char <= 0x1B33 || - 0x1B45 <= $char && $char <= 0x1B4B || + 0x1B45 <= $char && $char <= 0x1B4C || 0x1B83 <= $char && $char <= 0x1BA0 || 0x1BAE == $char || 0x1BAF == $char || @@ -2031,9 +2032,7 @@ private function isModeDefaultSymbol21(int $char): bool 0x2145 <= $char && $char <= 0x2149 || 0x214E == $char || 0x2160 <= $char && $char <= 0x2188 || - 0x2C00 <= $char && $char <= 0x2C2E || - 0x2C30 <= $char && $char <= 0x2C5E || - 0x2C60 <= $char && $char <= 0x2CE4 || + 0x2C00 <= $char && $char <= 0x2CE4 || 0x2CEB <= $char && $char <= 0x2CEE || 0x2CF2 == $char || 0x2CF3 == $char || @@ -2064,8 +2063,7 @@ private function isModeDefaultSymbol21(int $char): bool 0x31A0 <= $char && $char <= 0x31BF || 0x31F0 <= $char && $char <= 0x31FF || 0x3400 <= $char && $char <= 0x4DBF || - 0x4E00 <= $char && $char <= 0x9FFC || - 0xA000 <= $char && $char <= 0xA48C || + 0x4E00 <= $char && $char <= 0xA48C || 0xA4D0 <= $char && $char <= 0xA4FD || 0xA500 <= $char && $char <= 0xA60C || 0xA610 <= $char && $char <= 0xA61F || @@ -2076,9 +2074,12 @@ private function isModeDefaultSymbol21(int $char): bool 0xA6A0 <= $char && $char <= 0xA6EF || 0xA717 <= $char && $char <= 0xA71F || 0xA722 <= $char && $char <= 0xA788 || - 0xA78B <= $char && $char <= 0xA7BF || - 0xA7C2 <= $char && $char <= 0xA7CA || - 0xA7F5 <= $char && $char <= 0xA801 || + 0xA78B <= $char && $char <= 0xA7CA || + 0xA7D0 == $char || + 0xA7D1 == $char || + 0xA7D3 == $char || + 0xA7D5 <= $char && $char <= 0xA7D9 || + 0xA7F2 <= $char && $char <= 0xA801 || 0xA803 <= $char && $char <= 0xA805 || 0xA807 <= $char && $char <= 0xA80A || 0xA80C <= $char && $char <= 0xA822 || @@ -2172,9 +2173,22 @@ private function isModeDefaultSymbol21(int $char): bool 0x0104D8 <= $char && $char <= 0x0104FB || 0x010500 <= $char && $char <= 0x010527 || 0x010530 <= $char && $char <= 0x010563 || + 0x010570 <= $char && $char <= 0x01057A || + 0x01057C <= $char && $char <= 0x01058A || + 0x01058C <= $char && $char <= 0x010592 || + 0x010594 == $char || + 0x010595 == $char || + 0x010597 <= $char && $char <= 0x0105A1 || + 0x0105A3 <= $char && $char <= 0x0105B1 || + 0x0105B3 <= $char && $char <= 0x0105B9 || + 0x0105BB == $char || + 0x0105BC == $char || 0x010600 <= $char && $char <= 0x010736 || 0x010740 <= $char && $char <= 0x010755 || 0x010760 <= $char && $char <= 0x010767 || + 0x010780 <= $char && $char <= 0x010785 || + 0x010787 <= $char && $char <= 0x0107B0 || + 0x0107B2 <= $char && $char <= 0x0107BA || 0x010800 <= $char && $char <= 0x010805 || 0x010808 == $char || 0x01080A <= $char && $char <= 0x010835 || @@ -2214,9 +2228,13 @@ private function isModeDefaultSymbol21(int $char): bool 0x010F00 <= $char && $char <= 0x010F1C || 0x010F27 == $char || 0x010F30 <= $char && $char <= 0x010F45 || + 0x010F70 <= $char && $char <= 0x010F81 || 0x010FB0 <= $char && $char <= 0x010FC4 || 0x010FE0 <= $char && $char <= 0x010FF6 || 0x011003 <= $char && $char <= 0x011037 || + 0x011071 == $char || + 0x011072 == $char || + 0x011075 == $char || 0x011083 <= $char && $char <= 0x0110AF || 0x0110D0 <= $char && $char <= 0x0110E8 || 0x011103 <= $char && $char <= 0x011126 || @@ -2261,6 +2279,7 @@ private function isModeDefaultSymbol21(int $char): bool 0x011680 <= $char && $char <= 0x0116AA || 0x0116B8 == $char || 0x011700 <= $char && $char <= 0x01171A || + 0x011740 <= $char && $char <= 0x011746 || 0x011800 <= $char && $char <= 0x01182B || 0x0118A0 <= $char && $char <= 0x0118DF || 0x0118FF <= $char && $char <= 0x011906 || @@ -2281,7 +2300,7 @@ private function isModeDefaultSymbol21(int $char): bool 0x011A50 == $char || 0x011A5C <= $char && $char <= 0x011A89 || 0x011A9D == $char || - 0x011AC0 <= $char && $char <= 0x011AF8 || + 0x011AB0 <= $char && $char <= 0x011AF8 || 0x011C00 <= $char && $char <= 0x011C08 || 0x011C0A <= $char && $char <= 0x011C2E || 0x011C40 == $char || @@ -2301,10 +2320,12 @@ private function isModeDefaultSymbol21(int $char): bool 0x012000 <= $char && $char <= 0x012399 || 0x012400 <= $char && $char <= 0x01246E || 0x012480 <= $char && $char <= 0x012543 || + 0x012F90 <= $char && $char <= 0x012FF0 || 0x013000 <= $char && $char <= 0x01342E || 0x014400 <= $char && $char <= 0x014646 || 0x016800 <= $char && $char <= 0x016A38 || 0x016A40 <= $char && $char <= 0x016A5E || + 0x016A70 <= $char && $char <= 0x016ABE || 0x016AD0 <= $char && $char <= 0x016AED || 0x016B00 <= $char && $char <= 0x016B2F || 0x016B40 <= $char && $char <= 0x016B43 || @@ -2320,7 +2341,11 @@ private function isModeDefaultSymbol21(int $char): bool 0x017000 <= $char && $char <= 0x0187F7 || 0x018800 <= $char && $char <= 0x018CD5 || 0x018D00 <= $char && $char <= 0x018D08 || - 0x01B000 <= $char && $char <= 0x01B11E || + 0x01AFF0 <= $char && $char <= 0x01AFF3 || + 0x01AFF5 <= $char && $char <= 0x01AFFB || + 0x01AFFD == $char || + 0x01AFFE == $char || + 0x01B000 <= $char && $char <= 0x01B122 || 0x01B150 <= $char && $char <= 0x01B152 || 0x01B164 <= $char && $char <= 0x01B167 || 0x01B170 <= $char && $char <= 0x01B2FB || @@ -2360,10 +2385,17 @@ private function isModeDefaultSymbol21(int $char): bool 0x01D78A <= $char && $char <= 0x01D7A8 || 0x01D7AA <= $char && $char <= 0x01D7C2 || 0x01D7C4 <= $char && $char <= 0x01D7CB || + 0x01DF00 <= $char && $char <= 0x01DF1E || 0x01E100 <= $char && $char <= 0x01E12C || 0x01E137 <= $char && $char <= 0x01E13D || 0x01E14E == $char || + 0x01E290 <= $char && $char <= 0x01E2AD || 0x01E2C0 <= $char && $char <= 0x01E2EB || + 0x01E7E0 <= $char && $char <= 0x01E7E6 || + 0x01E7E8 <= $char && $char <= 0x01E7EB || + 0x01E7ED == $char || + 0x01E7EE == $char || + 0x01E7F0 <= $char && $char <= 0x01E7FE || 0x01E800 <= $char && $char <= 0x01E8C4 || 0x01E900 <= $char && $char <= 0x01E943 || 0x01E94B == $char || @@ -2403,8 +2435,8 @@ private function isModeDefaultSymbol21(int $char): bool 0x01EEA1 <= $char && $char <= 0x01EEA3 || 0x01EEA5 <= $char && $char <= 0x01EEA9 || 0x01EEAB <= $char && $char <= 0x01EEBB || - 0x020000 <= $char && $char <= 0x02A6DD || - 0x02A700 <= $char && $char <= 0x02B734 || + 0x020000 <= $char && $char <= 0x02A6DF || + 0x02A700 <= $char && $char <= 0x02B738 || 0x02B740 <= $char && $char <= 0x02B81D || 0x02B820 <= $char && $char <= 0x02CEA1 || 0x02CEB0 <= $char && $char <= 0x02EBE0 || @@ -2446,7 +2478,8 @@ private function isModeDefaultSymbol22(int $char): bool 0x0825 <= $char && $char <= 0x0827 || 0x0829 <= $char && $char <= 0x082D || 0x0859 <= $char && $char <= 0x085B || - 0x08D3 <= $char && $char <= 0x08E1 || + 0x0898 <= $char && $char <= 0x089F || + 0x08CA <= $char && $char <= 0x08E1 || 0x08E3 <= $char && $char <= 0x0903 || 0x093A <= $char && $char <= 0x093C || 0x093E <= $char && $char <= 0x094F || @@ -2500,6 +2533,7 @@ private function isModeDefaultSymbol22(int $char): bool 0x0BD7 == $char || 0x0BE6 <= $char && $char <= 0x0BEF || 0x0C00 <= $char && $char <= 0x0C04 || + 0x0C3C == $char || 0x0C3E <= $char && $char <= 0x0C44 || 0x0C46 <= $char && $char <= 0x0C48 || 0x0C4A <= $char && $char <= 0x0C4D || @@ -2569,7 +2603,7 @@ private function isModeDefaultSymbol22(int $char): bool 0x108F <= $char && $char <= 0x109D || 0x135D <= $char && $char <= 0x135F || 0x1369 <= $char && $char <= 0x1371 || - 0x1712 <= $char && $char <= 0x1714 || + 0x1712 <= $char && $char <= 0x1715 || 0x1732 <= $char && $char <= 0x1734 || 0x1752 == $char || 0x1753 == $char || @@ -2579,7 +2613,7 @@ private function isModeDefaultSymbol22(int $char): bool 0x17DD == $char || 0x17E0 <= $char && $char <= 0x17E9 || 0x180B <= $char && $char <= 0x180D || - 0x1810 <= $char && $char <= 0x1819 || + 0x180F <= $char && $char <= 0x1819 || 0x18A9 == $char || 0x1920 <= $char && $char <= 0x192B || 0x1930 <= $char && $char <= 0x193B || @@ -2591,8 +2625,7 @@ private function isModeDefaultSymbol22(int $char): bool 0x1A7F <= $char && $char <= 0x1A89 || 0x1A90 <= $char && $char <= 0x1A99 || 0x1AB0 <= $char && $char <= 0x1ABD || - 0x1ABF == $char || - 0x1AC0 == $char || + 0x1ABF <= $char && $char <= 0x1ACE || 0x1B00 <= $char && $char <= 0x1B04 || 0x1B34 <= $char && $char <= 0x1B44 || 0x1B50 <= $char && $char <= 0x1B59 || @@ -2609,8 +2642,7 @@ private function isModeDefaultSymbol22(int $char): bool 0x1CED == $char || 0x1CF4 == $char || 0x1CF7 <= $char && $char <= 0x1CF9 || - 0x1DC0 <= $char && $char <= 0x1DF9 || - 0x1DFB <= $char && $char <= 0x1DFF || + 0x1DC0 <= $char && $char <= 0x1DFF || 0x203F == $char || 0x2040 == $char || 0x2054 == $char || @@ -2693,11 +2725,15 @@ private function isModeDefaultSymbol22(int $char): bool 0x010EAB == $char || 0x010EAC == $char || 0x010F46 <= $char && $char <= 0x010F50 || + 0x010F82 <= $char && $char <= 0x010F85 || 0x011000 <= $char && $char <= 0x011002 || 0x011038 <= $char && $char <= 0x011046 || - 0x011066 <= $char && $char <= 0x01106F || + 0x011066 <= $char && $char <= 0x011070 || + 0x011073 == $char || + 0x011074 == $char || 0x01107F <= $char && $char <= 0x011082 || 0x0110B0 <= $char && $char <= 0x0110BA || + 0x0110C2 == $char || 0x0110F0 <= $char && $char <= 0x0110F9 || 0x011100 <= $char && $char <= 0x011102 || 0x011127 <= $char && $char <= 0x011134 || @@ -2778,6 +2814,7 @@ private function isModeDefaultSymbol22(int $char): bool 0x011DA0 <= $char && $char <= 0x011DA9 || 0x011EF3 <= $char && $char <= 0x011EF6 || 0x016A60 <= $char && $char <= 0x016A69 || + 0x016AC0 <= $char && $char <= 0x016AC9 || 0x016AF0 <= $char && $char <= 0x016AF4 || 0x016B30 <= $char && $char <= 0x016B36 || 0x016B50 <= $char && $char <= 0x016B59 || @@ -2789,6 +2826,8 @@ private function isModeDefaultSymbol22(int $char): bool 0x016FF1 == $char || 0x01BC9D == $char || 0x01BC9E == $char || + 0x01CF00 <= $char && $char <= 0x01CF2D || + 0x01CF30 <= $char && $char <= 0x01CF46 || 0x01D165 <= $char && $char <= 0x01D169 || 0x01D16D <= $char && $char <= 0x01D172 || 0x01D17B <= $char && $char <= 0x01D182 || @@ -2810,6 +2849,7 @@ private function isModeDefaultSymbol22(int $char): bool 0x01E026 <= $char && $char <= 0x01E02A || 0x01E130 <= $char && $char <= 0x01E136 || 0x01E140 <= $char && $char <= 0x01E149 || + 0x01E2AE == $char || 0x01E2EC <= $char && $char <= 0x01E2F9 || 0x01E8D0 <= $char && $char <= 0x01E8D6 || 0x01E944 <= $char && $char <= 0x01E94A || diff --git a/infection.json.dist b/infection.json.dist index b9398ec..77fb72d 100644 --- a/infection.json.dist +++ b/infection.json.dist @@ -9,8 +9,8 @@ "text": "build/logs/infection/infection.log", "summary": "build/logs/infection/summary.log", "perMutator": "build/logs/infection/per-mutator.md", - "badge": { - "branch": "master" + "stryker": { + "badge": "/^master$/" } } } \ No newline at end of file diff --git a/php-7.3.Dockerfile b/php-7.3.Dockerfile deleted file mode 100644 index 8cbda5f..0000000 --- a/php-7.3.Dockerfile +++ /dev/null @@ -1,18 +0,0 @@ -FROM php:7.3-cli - -RUN apt-get update && apt-get install -y \ - zip \ - git \ - libicu-dev && \ - pecl install xdebug && \ - docker-php-ext-enable xdebug && \ - docker-php-ext-configure intl --enable-intl && \ - docker-php-ext-install intl && \ - echo "xdebug.mode = develop,coverage,debug" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" && \ - echo "xdebug.max_nesting_level = 1024" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" - -ENV COMPOSER_ALLOW_SUPERUSER=1 \ - COMPOSER_PROCESS_TIMEOUT=1200 - -RUN curl --silent --show-error https://getcomposer.org/installer | php -- \ - --install-dir=/usr/bin --filename=composer diff --git a/php-8.0.Dockerfile b/php-8.0.Dockerfile index feb43eb..ed7e0f3 100644 --- a/php-8.0.Dockerfile +++ b/php-8.0.Dockerfile @@ -7,7 +7,7 @@ RUN apt-get update && apt-get install -y \ pecl install xdebug && \ docker-php-ext-enable xdebug && \ docker-php-ext-configure intl --enable-intl && \ - docker-php-ext-install intl && \ + docker-php-ext-install intl pcntl && \ echo "xdebug.mode = develop,coverage,debug" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" && \ echo "xdebug.max_nesting_level = 1024" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" diff --git a/php-8.1.Dockerfile b/php-8.1.Dockerfile index a95f759..6faad4b 100644 --- a/php-8.1.Dockerfile +++ b/php-8.1.Dockerfile @@ -7,7 +7,7 @@ RUN apt-get update && apt-get install -y \ pecl install -f -o xdebug && \ docker-php-ext-enable xdebug && \ docker-php-ext-configure intl --enable-intl && \ - docker-php-ext-install intl && \ + docker-php-ext-install intl pcntl && \ echo "xdebug.mode = develop,coverage,debug" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" && \ echo "xdebug.max_nesting_level = 1024" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" diff --git a/php-7.4.Dockerfile b/php-8.2.Dockerfile similarity index 85% rename from php-7.4.Dockerfile rename to php-8.2.Dockerfile index 4e2d6ae..6faad4b 100644 --- a/php-7.4.Dockerfile +++ b/php-8.2.Dockerfile @@ -1,13 +1,13 @@ -FROM php:7.4-cli +FROM php:8.1-rc-cli RUN apt-get update && apt-get install -y \ zip \ git \ libicu-dev && \ - pecl install xdebug && \ + pecl install -f -o xdebug && \ docker-php-ext-enable xdebug && \ docker-php-ext-configure intl --enable-intl && \ - docker-php-ext-install intl && \ + docker-php-ext-install intl pcntl && \ echo "xdebug.mode = develop,coverage,debug" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" && \ echo "xdebug.max_nesting_level = 1024" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" diff --git a/src/Parser/Exception/ParserCreationFailedException.php b/src/Parser/Exception/ParserCreationFailedException.php index aa76a11..20f9ecf 100644 --- a/src/Parser/Exception/ParserCreationFailedException.php +++ b/src/Parser/Exception/ParserCreationFailedException.php @@ -9,8 +9,7 @@ final class ParserCreationFailedException extends LogicException implements ExceptionInterface { - - public function __construct(Throwable $previous = null) + public function __construct(?Throwable $previous = null) { parent::__construct("Failed to create JSONPath parser", 0, $previous); } diff --git a/src/Parser/Exception/QueryAstNotBuiltException.php b/src/Parser/Exception/QueryAstNotBuiltException.php index b9e144e..64af814 100644 --- a/src/Parser/Exception/QueryAstNotBuiltException.php +++ b/src/Parser/Exception/QueryAstNotBuiltException.php @@ -9,13 +9,11 @@ final class QueryAstNotBuiltException extends RuntimeException implements ExceptionInterface { - - private $source; - - public function __construct(string $source, Throwable $previous = null) - { - $this->source = $source; - parent::__construct("Failed to build AST from JSONPath query: {$source}", 0, $previous); + public function __construct( + private string $source, + ?Throwable $previous = null, + ) { + parent::__construct("Failed to build AST from JSONPath query: $this->source", 0, $previous); } public function getSource(): string diff --git a/src/Parser/Ll1ParserFactory.php b/src/Parser/Ll1ParserFactory.php index e997f57..40bc437 100644 --- a/src/Parser/Ll1ParserFactory.php +++ b/src/Parser/Ll1ParserFactory.php @@ -20,8 +20,7 @@ final class Ll1ParserFactory implements Ll1ParserFactoryInterface { - - private $grammar; + private ?GrammarInterface $grammar = null; public function createParser(string $source, Tree $queryAst): Ll1Parser { @@ -30,7 +29,7 @@ public function createParser(string $source, Tree $queryAst): Ll1Parser $parser = new Ll1Parser( $this->getGrammar(), $this->createSourceReader($source), - new TranslationSchemeApplier($scheme) + new TranslationSchemeApplier($scheme), ); $parser->loadLookupTable(__DIR__ . '/../../generated/LookupTable.php'); } catch (Throwable $e) { @@ -46,11 +45,7 @@ public function createParser(string $source, Tree $queryAst): Ll1Parser */ private function getGrammar(): GrammarInterface { - if (!isset($this->grammar)) { - $this->grammar = GrammarLoader::loadFile(__DIR__ . '/../../spec/GrammarSpec.php'); - } - - return $this->grammar; + return $this->grammar ??= GrammarLoader::loadFile(__DIR__ . '/../../spec/GrammarSpec.php'); } /** diff --git a/src/Parser/Ll1ParserFactoryInterface.php b/src/Parser/Ll1ParserFactoryInterface.php index 16a417a..b119102 100644 --- a/src/Parser/Ll1ParserFactoryInterface.php +++ b/src/Parser/Ll1ParserFactoryInterface.php @@ -9,6 +9,5 @@ interface Ll1ParserFactoryInterface { - public function createParser(string $path, Tree $queryAst): Ll1Parser; } diff --git a/src/Parser/Parser.php b/src/Parser/Parser.php index b1dbf01..dc905a5 100644 --- a/src/Parser/Parser.php +++ b/src/Parser/Parser.php @@ -9,12 +9,9 @@ final class Parser implements ParserInterface { - - private $ll1ParserFactory; - - public function __construct(Ll1ParserFactoryInterface $ll1ParserFactory) - { - $this->ll1ParserFactory = $ll1ParserFactory; + public function __construct( + private Ll1ParserFactoryInterface $ll1ParserFactory, + ) { } public function buildQueryAst(string $path): Tree diff --git a/src/Parser/ParserInterface.php b/src/Parser/ParserInterface.php index 35d50d5..b65332a 100644 --- a/src/Parser/ParserInterface.php +++ b/src/Parser/ParserInterface.php @@ -8,6 +8,5 @@ interface ParserInterface { - public function buildQueryAst(string $path): Tree; } diff --git a/src/Parser/TokenType.php b/src/Parser/TokenType.php index 4cd82d8..71b5aa4 100644 --- a/src/Parser/TokenType.php +++ b/src/Parser/TokenType.php @@ -4,7 +4,6 @@ abstract class TokenType { - public const WS = 0x01; public const DOT = 0x02; public const DOUBLE_DOT = 0x03; diff --git a/src/Parser/TranslationScheme.php b/src/Parser/TranslationScheme.php index c3f06ec..f18cff9 100644 --- a/src/Parser/TranslationScheme.php +++ b/src/Parser/TranslationScheme.php @@ -16,12 +16,9 @@ class TranslationScheme implements TranslationSchemeInterface { - - private $queryAstBuilder; - - public function __construct(AstBuilderInterface $queryAstBuilder) - { - $this->queryAstBuilder = $queryAstBuilder; + public function __construct( + private AstBuilderInterface $queryAstBuilder, + ) { } /** @@ -279,6 +276,7 @@ public function applyProductionActions(Production $production): void break; case SymbolType::NT_INT_OPT . '.1': + // [] $header['s.int'] = null; break; diff --git a/src/Processor/Exception/IndefiniteQueryException.php b/src/Processor/Exception/IndefiniteQueryException.php index 84ac84a..a4c0d59 100644 --- a/src/Processor/Exception/IndefiniteQueryException.php +++ b/src/Processor/Exception/IndefiniteQueryException.php @@ -10,12 +10,10 @@ final class IndefiniteQueryException extends RuntimeException implements ExceptionInterface { - - private $query; - - public function __construct(QueryInterface $query, Throwable $previous = null) - { - $this->query = $query; + public function __construct( + private QueryInterface $query, + ?Throwable $previous = null, + ) { parent::__construct("Query is indefinite", 0, $previous); } diff --git a/src/Processor/Exception/InvalidPathElementException.php b/src/Processor/Exception/InvalidPathElementException.php index fe5e97a..1e3b6c7 100644 --- a/src/Processor/Exception/InvalidPathElementException.php +++ b/src/Processor/Exception/InvalidPathElementException.php @@ -11,12 +11,10 @@ final class InvalidPathElementException extends DomainException implements ExceptionInterface { - - private $pathElement; - - public function __construct($pathElement, Throwable $previous = null) - { - $this->pathElement = $pathElement; + public function __construct( + private mixed $pathElement, + ?Throwable $previous = null, + ) { parent::__construct($this->buildMessage(), 0, $previous); } @@ -24,10 +22,10 @@ private function buildMessage(): string { $type = gettype($this->pathElement); - return "Invalid path element type: {$type}"; + return "Invalid path element type: $type"; } - public function getPathElement() + public function getPathElement(): mixed { return $this->pathElement; } diff --git a/src/Processor/Exception/QueryNotAddressableException.php b/src/Processor/Exception/QueryNotAddressableException.php index 1e57c84..e3c01bd 100644 --- a/src/Processor/Exception/QueryNotAddressableException.php +++ b/src/Processor/Exception/QueryNotAddressableException.php @@ -10,12 +10,10 @@ final class QueryNotAddressableException extends LogicException implements ExceptionInterface { - - private $query; - - public function __construct(QueryInterface $query, Throwable $previous = null) - { - $this->query = $query; + public function __construct( + private QueryInterface $query, + ?Throwable $previous = null, + ) { parent::__construct("Query is not addressable", 0, $previous); } diff --git a/src/Processor/Mutator/DeleteMutation.php b/src/Processor/Mutator/DeleteMutation.php index 817735b..0232d0c 100644 --- a/src/Processor/Mutator/DeleteMutation.php +++ b/src/Processor/Mutator/DeleteMutation.php @@ -11,16 +11,25 @@ use Remorhaz\JSON\Data\Walker\MutationInterface; use Remorhaz\JSON\Data\Walker\ValueWalkerInterface; +use function array_values; + final class DeleteMutation implements MutationInterface { - - private $paths; + /** + * @var list + */ + private array $paths; public function __construct(PathInterface ...$paths) { - $this->paths = $paths; + $this->paths = array_values($paths); } + /** + * @param EventInterface $event + * @param ValueWalkerInterface $valueWalker + * @return Iterator + */ public function __invoke(EventInterface $event, ValueWalkerInterface $valueWalker): Iterator { return $this->createEventGenerator($event); @@ -30,7 +39,11 @@ public function reset(): void { } - private function createEventGenerator(EventInterface $event): Generator + /** + * @param EventInterface $event + * @return Iterator + */ + private function createEventGenerator(EventInterface $event): Iterator { foreach ($this->paths as $path) { if ($path->contains($event->getPath())) { diff --git a/src/Processor/Mutator/Exception/ReplaceAtNestedPathsException.php b/src/Processor/Mutator/Exception/ReplaceAtNestedPathsException.php index f58f85b..c18fefe 100644 --- a/src/Processor/Mutator/Exception/ReplaceAtNestedPathsException.php +++ b/src/Processor/Mutator/Exception/ReplaceAtNestedPathsException.php @@ -10,15 +10,11 @@ final class ReplaceAtNestedPathsException extends LogicException implements ExceptionInterface { - - private $parentPath; - - private $nestedPath; - - public function __construct(PathInterface $parentPath, PathInterface $nestedPath, Throwable $previous = null) - { - $this->parentPath = $parentPath; - $this->nestedPath = $nestedPath; + public function __construct( + private PathInterface $parentPath, + private PathInterface $nestedPath, + ?Throwable $previous = null, + ) { parent::__construct("Attempt of replacing value at nested paths", 0, $previous); } diff --git a/src/Processor/Mutator/Mutator.php b/src/Processor/Mutator/Mutator.php index 3976245..f385169 100644 --- a/src/Processor/Mutator/Mutator.php +++ b/src/Processor/Mutator/Mutator.php @@ -12,15 +12,10 @@ final class Mutator implements MutatorInterface { - - private $valueWalker; - - private $eventDecoder; - - public function __construct(ValueWalkerInterface $walker, EventDecoderInterface $eventDecoder) - { - $this->valueWalker = $walker; - $this->eventDecoder = $eventDecoder; + public function __construct( + private ValueWalkerInterface $valueWalker, + private EventDecoderInterface $eventDecoder, + ) { } public function deletePaths(NodeValueInterface $rootNode, PathInterface ...$paths): ?NodeValueInterface @@ -38,7 +33,7 @@ public function deletePaths(NodeValueInterface $rootNode, PathInterface ...$path public function replacePaths( NodeValueInterface $rootNode, NodeValueInterface $newNode, - PathInterface ...$paths + PathInterface ...$paths, ): NodeValueInterface { $modifier = new ReplaceMutation($newNode, ...$paths); $events = $this diff --git a/src/Processor/Mutator/MutatorInterface.php b/src/Processor/Mutator/MutatorInterface.php index 6dcb1c7..8feff8f 100644 --- a/src/Processor/Mutator/MutatorInterface.php +++ b/src/Processor/Mutator/MutatorInterface.php @@ -9,12 +9,11 @@ interface MutatorInterface { - public function deletePaths(NodeValueInterface $rootNode, PathInterface ...$paths): ?NodeValueInterface; public function replacePaths( NodeValueInterface $rootNode, NodeValueInterface $newNode, - PathInterface ...$paths + PathInterface ...$paths, ): NodeValueInterface; } diff --git a/src/Processor/Mutator/ReplaceMutation.php b/src/Processor/Mutator/ReplaceMutation.php index 767d24e..7424eae 100644 --- a/src/Processor/Mutator/ReplaceMutation.php +++ b/src/Processor/Mutator/ReplaceMutation.php @@ -4,7 +4,6 @@ namespace Remorhaz\JSON\Path\Processor\Mutator; -use Generator; use Iterator; use Remorhaz\JSON\Data\Event\AfterElementEventInterface; use Remorhaz\JSON\Data\Event\AfterPropertyEventInterface; @@ -20,21 +19,27 @@ use Remorhaz\JSON\Data\Walker\ValueWalkerInterface; use function array_reverse; +use function array_values; use function count; final class ReplaceMutation implements MutationInterface { + /** + * @var list + */ + private array $paths; - private $newNode; - - private $paths; - - public function __construct(NodeValueInterface $newNode, PathInterface ...$paths) - { - $this->newNode = $newNode; + public function __construct( + private NodeValueInterface $newNode, + PathInterface ...$paths, + ) { $this->paths = $this->getNonNestedPaths(...$paths); } + /** + * @param PathInterface ...$paths + * @return list + */ private function getNonNestedPaths(PathInterface ...$paths): array { foreach ($this->createPathPairIterator(...$paths) as $pathPair) { @@ -44,14 +49,14 @@ private function getNonNestedPaths(PathInterface ...$paths): array } } - return $paths; + return array_values($paths); } /** * @param PathInterface ...$paths - * @return Generator|PathInterface[][] + * @return Iterator */ - private function createPathPairIterator(PathInterface ...$paths): Generator + private function createPathPairIterator(PathInterface ...$paths): Iterator { $pathsCount = count($paths); for ($i = 0; $i < $pathsCount; $i++) { @@ -63,6 +68,11 @@ private function createPathPairIterator(PathInterface ...$paths): Generator } } + /** + * @param EventInterface $event + * @param ValueWalkerInterface $valueWalker + * @return Iterator + */ public function __invoke(EventInterface $event, ValueWalkerInterface $valueWalker): Iterator { return $this->createEventGenerator($event, $valueWalker); @@ -72,7 +82,12 @@ public function reset(): void { } - private function createEventGenerator(EventInterface $event, ValueWalkerInterface $valueWalker): Generator + /** + * @param EventInterface $event + * @param ValueWalkerInterface $valueWalker + * @return Iterator + */ + private function createEventGenerator(EventInterface $event, ValueWalkerInterface $valueWalker): Iterator { foreach ($this->paths as $path) { if ($path->equals($event->getPath())) { @@ -87,7 +102,12 @@ private function createEventGenerator(EventInterface $event, ValueWalkerInterfac yield $event; } - private function createReplaceEventGenerator(EventInterface $event, ValueWalkerInterface $valueWalker): Generator + /** + * @param EventInterface $event + * @param ValueWalkerInterface $valueWalker + * @return Iterator + */ + private function createReplaceEventGenerator(EventInterface $event, ValueWalkerInterface $valueWalker): Iterator { switch (true) { case $event instanceof BeforeElementEventInterface: diff --git a/src/Processor/PathEncoder.php b/src/Processor/PathEncoder.php index 0b9a2b2..b9ebfd5 100644 --- a/src/Processor/PathEncoder.php +++ b/src/Processor/PathEncoder.php @@ -14,7 +14,6 @@ final class PathEncoder implements PathEncoderInterface { - public function encodePath(PathInterface $path): string { return '$' . implode('', array_map([$this, 'encodePathElement'], $path->getElements())); @@ -23,7 +22,7 @@ public function encodePath(PathInterface $path): string private function encodePathElement($pathElement): string { if (is_int($pathElement)) { - return "[{$pathElement}]"; + return "[$pathElement]"; } if (is_string($pathElement)) { diff --git a/src/Processor/Processor.php b/src/Processor/Processor.php index 3a4bd9e..b3f35dd 100644 --- a/src/Processor/Processor.php +++ b/src/Processor/Processor.php @@ -18,6 +18,7 @@ use Remorhaz\JSON\Path\Processor\Result\SelectOnePathResultInterface; use Remorhaz\JSON\Path\Processor\Result\SelectPathsResultInterface; use Remorhaz\JSON\Path\Processor\Result\SelectResultInterface; +use Remorhaz\JSON\Path\Query\Exception\ExceptionInterface; use Remorhaz\JSON\Path\Query\QueryInterface; use Remorhaz\JSON\Path\Query\QueryValidator; use Remorhaz\JSON\Path\Query\QueryValidatorInterface; @@ -33,15 +34,6 @@ final class Processor implements ProcessorInterface { - - private $runtime; - - private $resultFactory; - - private $queryValidator; - - private $mutator; - public static function create(): ProcessorInterface { $runtime = new Runtime( @@ -65,17 +57,16 @@ public static function create(): ProcessorInterface } public function __construct( - RuntimeInterface $runtime, - ResultFactoryInterface $resultFactory, - QueryValidatorInterface $queryValidator, - MutatorInterface $mutator + private RuntimeInterface $runtime, + private ResultFactoryInterface $resultFactory, + private QueryValidatorInterface $queryValidator, + private MutatorInterface $mutator, ) { - $this->runtime = $runtime; - $this->resultFactory = $resultFactory; - $this->queryValidator = $queryValidator; - $this->mutator = $mutator; } + /** + * @throws ExceptionInterface + */ public function select(QueryInterface $query, NodeValueInterface $rootNode): SelectResultInterface { $values = $query($rootNode, $this->runtime); @@ -85,6 +76,9 @@ public function select(QueryInterface $query, NodeValueInterface $rootNode): Sel ->createSelectResult($values); } + /** + * @throws ExceptionInterface + */ public function selectOne(QueryInterface $query, NodeValueInterface $rootNode): ValueResultInterface { $values = $this @@ -96,6 +90,9 @@ public function selectOne(QueryInterface $query, NodeValueInterface $rootNode): ->createSelectOneResult($values); } + /** + * @throws ExceptionInterface + */ public function selectPaths(QueryInterface $query, NodeValueInterface $rootNode): SelectPathsResultInterface { $values = $this @@ -107,6 +104,9 @@ public function selectPaths(QueryInterface $query, NodeValueInterface $rootNode) ->createSelectPathsResult($values); } + /** + * @throws ExceptionInterface + */ public function selectOnePath(QueryInterface $query, NodeValueInterface $rootNode): SelectOnePathResultInterface { $query = $this @@ -135,10 +135,13 @@ public function delete(QueryInterface $query, NodeValueInterface $rootNode): Val ->createValueResult($value); } + /** + * @throws ExceptionInterface + */ public function replace( QueryInterface $query, NodeValueInterface $rootNode, - NodeValueInterface $newNode + NodeValueInterface $newNode, ): ValueResultInterface { $paths = $this ->selectPaths($query, $rootNode) diff --git a/src/Processor/ProcessorInterface.php b/src/Processor/ProcessorInterface.php index 9dac37f..823c07f 100644 --- a/src/Processor/ProcessorInterface.php +++ b/src/Processor/ProcessorInterface.php @@ -13,7 +13,6 @@ interface ProcessorInterface { - public function select(QueryInterface $query, NodeValueInterface $rootNode): SelectResultInterface; public function selectOne(QueryInterface $query, NodeValueInterface $rootNode): ValueResultInterface; @@ -27,6 +26,6 @@ public function delete(QueryInterface $query, NodeValueInterface $rootNode): Val public function replace( QueryInterface $query, NodeValueInterface $rootNode, - NodeValueInterface $newNode + NodeValueInterface $newNode, ): ValueResultInterface; } diff --git a/src/Processor/Result/Exception/MoreThanOneValueInListException.php b/src/Processor/Result/Exception/MoreThanOneValueInListException.php index 92d5344..969a488 100644 --- a/src/Processor/Result/Exception/MoreThanOneValueInListException.php +++ b/src/Processor/Result/Exception/MoreThanOneValueInListException.php @@ -10,12 +10,10 @@ final class MoreThanOneValueInListException extends RuntimeException implements ExceptionInterface { - - private $values; - - public function __construct(ValueListInterface $values, Throwable $previous = null) - { - $this->values = $values; + public function __construct( + private ValueListInterface $values, + ?Throwable $previous = null, + ) { parent::__construct("More than 1 value in list", 0, $previous); } diff --git a/src/Processor/Result/Exception/PathNotFoundInValueException.php b/src/Processor/Result/Exception/PathNotFoundInValueException.php index 836bbf4..ccde88e 100644 --- a/src/Processor/Result/Exception/PathNotFoundInValueException.php +++ b/src/Processor/Result/Exception/PathNotFoundInValueException.php @@ -10,12 +10,10 @@ final class PathNotFoundInValueException extends LogicException implements ExceptionInterface { - - private $value; - - public function __construct(ValueInterface $value, Throwable $previous = null) - { - $this->value = $value; + public function __construct( + private ValueInterface $value, + ?Throwable $previous = null, + ) { parent::__construct("Path not found in value", 0, $previous); } diff --git a/src/Processor/Result/Exception/SelectedValueNotFoundException.php b/src/Processor/Result/Exception/SelectedValueNotFoundException.php index 3f94f3d..5f9eff5 100644 --- a/src/Processor/Result/Exception/SelectedValueNotFoundException.php +++ b/src/Processor/Result/Exception/SelectedValueNotFoundException.php @@ -9,8 +9,7 @@ final class SelectedValueNotFoundException extends LogicException implements ExceptionInterface { - - public function __construct(Throwable $previous = null) + public function __construct(?Throwable $previous = null) { parent::__construct("Selected value not found", 0, $previous); } diff --git a/src/Processor/Result/ExistingSelectOnePathResult.php b/src/Processor/Result/ExistingSelectOnePathResult.php index 728a1b2..3c8a0fc 100644 --- a/src/Processor/Result/ExistingSelectOnePathResult.php +++ b/src/Processor/Result/ExistingSelectOnePathResult.php @@ -9,20 +9,15 @@ final class ExistingSelectOnePathResult implements SelectOnePathResultInterface { - - private $path; - - private $encoder; - public function exists(): bool { return true; } - public function __construct(PathEncoderInterface $encoder, PathInterface $path) - { - $this->encoder = $encoder; - $this->path = $path; + public function __construct( + private PathEncoderInterface $encoder, + private PathInterface $path, + ) { } public function get(): PathInterface diff --git a/src/Processor/Result/ExistingValueResult.php b/src/Processor/Result/ExistingValueResult.php index fc60e77..64fc328 100644 --- a/src/Processor/Result/ExistingValueResult.php +++ b/src/Processor/Result/ExistingValueResult.php @@ -10,21 +10,11 @@ final class ExistingValueResult implements ValueResultInterface { - - private $jsonEncoder; - - private $jsonDecoder; - - private $value; - public function __construct( - ValueEncoderInterface $jsonEncoder, - ValueDecoderInterface $jsonDecoder, - ValueInterface $value + private ValueEncoderInterface $jsonEncoder, + private ValueDecoderInterface $jsonDecoder, + private ValueInterface $value ) { - $this->jsonEncoder = $jsonEncoder; - $this->jsonDecoder = $jsonDecoder; - $this->value = $value; } public function exists(): bool @@ -39,7 +29,7 @@ public function encode(): string ->exportValue($this->value); } - public function decode() + public function decode(): mixed { return $this ->jsonDecoder diff --git a/src/Processor/Result/NonExistingSelectOnePathResult.php b/src/Processor/Result/NonExistingSelectOnePathResult.php index 7612bb7..9d94141 100644 --- a/src/Processor/Result/NonExistingSelectOnePathResult.php +++ b/src/Processor/Result/NonExistingSelectOnePathResult.php @@ -8,7 +8,6 @@ final class NonExistingSelectOnePathResult implements SelectOnePathResultInterface { - public function exists(): bool { return false; diff --git a/src/Processor/Result/NonExistingValueResult.php b/src/Processor/Result/NonExistingValueResult.php index 1a45c39..41d9c07 100644 --- a/src/Processor/Result/NonExistingValueResult.php +++ b/src/Processor/Result/NonExistingValueResult.php @@ -8,7 +8,6 @@ final class NonExistingValueResult implements ValueResultInterface { - public function exists(): bool { return false; @@ -19,7 +18,7 @@ public function encode(): string throw new Exception\SelectedValueNotFoundException(); } - public function decode() + public function decode(): mixed { throw new Exception\SelectedValueNotFoundException(); } diff --git a/src/Processor/Result/OneResultInterface.php b/src/Processor/Result/OneResultInterface.php index d042f2b..d6a324d 100644 --- a/src/Processor/Result/OneResultInterface.php +++ b/src/Processor/Result/OneResultInterface.php @@ -6,6 +6,5 @@ interface OneResultInterface { - public function exists(): bool; } diff --git a/src/Processor/Result/ResultFactory.php b/src/Processor/Result/ResultFactory.php index 89fab25..68cfdcb 100644 --- a/src/Processor/Result/ResultFactory.php +++ b/src/Processor/Result/ResultFactory.php @@ -17,21 +17,11 @@ final class ResultFactory implements ResultFactoryInterface { - - private $jsonEncoder; - - private $jsonDecoder; - - private $pathsEncoder; - public function __construct( - ValueEncoderInterface $jsonEncoder, - ValueDecoderInterface $jsonDecoder, - PathEncoderInterface $pathEncoder + private ValueEncoderInterface $jsonEncoder, + private ValueDecoderInterface $jsonDecoder, + private PathEncoderInterface $pathsEncoder, ) { - $this->jsonEncoder = $jsonEncoder; - $this->jsonDecoder = $jsonDecoder; - $this->pathsEncoder = $pathEncoder; } public function createSelectResult(ValueListInterface $values): SelectResultInterface @@ -48,17 +38,15 @@ public function createSelectPathsResult(ValueListInterface $values): SelectPaths { return new SelectPathsResult( $this->pathsEncoder, - ...array_map([$this, 'getValuePath'], $values->getValues()) + ...array_map([$this, 'getValuePath'], $values->getValues()), ); } private function getValuePath(ValueInterface $value): PathInterface { - if (!$value instanceof NodeValueInterface) { - throw new Exception\PathNotFoundInValueException($value); - } - - return $value->getPath(); + return $value instanceof NodeValueInterface + ? $value->getPath() + : throw new Exception\PathNotFoundInValueException($value); } public function createSelectOnePathResult(ValueListInterface $values): SelectOnePathResultInterface @@ -75,15 +63,11 @@ public function createSelectOnePathResult(ValueListInterface $values): SelectOne private function findSingleValue(ValueListInterface $values): ?ValueInterface { - switch (count($values->getValues())) { - case 0: - return null; - - case 1: - return $values->getValue(0); - } - - throw new Exception\MoreThanOneValueInListException($values); + return match (count($values->getValues())) { + 0 => null, + 1 => $values->getValue(0), + default => throw new Exception\MoreThanOneValueInListException($values), + }; } public function createValueResult(?ValueInterface $value): ValueResultInterface diff --git a/src/Processor/Result/ResultFactoryInterface.php b/src/Processor/Result/ResultFactoryInterface.php index 4408a65..1dd0263 100644 --- a/src/Processor/Result/ResultFactoryInterface.php +++ b/src/Processor/Result/ResultFactoryInterface.php @@ -9,7 +9,6 @@ interface ResultFactoryInterface { - public function createSelectResult(ValueListInterface $values): SelectResultInterface; public function createSelectOneResult(ValueListInterface $values): ValueResultInterface; diff --git a/src/Processor/Result/SelectOnePathResultInterface.php b/src/Processor/Result/SelectOnePathResultInterface.php index c44ab84..5889e88 100644 --- a/src/Processor/Result/SelectOnePathResultInterface.php +++ b/src/Processor/Result/SelectOnePathResultInterface.php @@ -8,13 +8,10 @@ interface SelectOnePathResultInterface extends OneResultInterface { - public function get(): PathInterface; /** * Returns definite JSONPath query. - * - * @return string */ public function encode(): string; } diff --git a/src/Processor/Result/SelectPathsResult.php b/src/Processor/Result/SelectPathsResult.php index 4f57c04..b429205 100644 --- a/src/Processor/Result/SelectPathsResult.php +++ b/src/Processor/Result/SelectPathsResult.php @@ -8,25 +8,33 @@ use Remorhaz\JSON\Path\Processor\PathEncoderInterface; use function array_map; +use function array_values; final class SelectPathsResult implements SelectPathsResultInterface { - - private $paths; - - private $encoder; - - public function __construct(PathEncoderInterface $encoder, PathInterface ...$paths) - { - $this->encoder = $encoder; - $this->paths = $paths; + /** + * @var list + */ + private array $paths; + + public function __construct( + private PathEncoderInterface $encoder, + PathInterface ...$paths, + ) { + $this->paths = array_values($paths); } + /** + * @return list + */ public function get(): array { return $this->paths; } + /** + * @return list + */ public function encode(): array { return array_map([$this->encoder, 'encodePath'], $this->paths); diff --git a/src/Processor/Result/SelectPathsResultInterface.php b/src/Processor/Result/SelectPathsResultInterface.php index 2089734..83f79bf 100644 --- a/src/Processor/Result/SelectPathsResultInterface.php +++ b/src/Processor/Result/SelectPathsResultInterface.php @@ -8,18 +8,17 @@ interface SelectPathsResultInterface { - /** * Returns list of paths. * - * @return PathInterface[] + * @return list */ public function get(): array; /** * Returns list of definite JSONPath queries. * - * @return string[] + * @return list */ public function encode(): array; } diff --git a/src/Processor/Result/SelectResult.php b/src/Processor/Result/SelectResult.php index fdb4a8d..fa359c1 100644 --- a/src/Processor/Result/SelectResult.php +++ b/src/Processor/Result/SelectResult.php @@ -9,30 +9,27 @@ use Remorhaz\JSON\Data\Value\ValueInterface; use function array_map; +use function array_values; final class SelectResult implements SelectResultInterface { - - private $encoder; - - private $decoder; - - private $values; + /** + * @var list + */ + private array $values; public function __construct( - ValueEncoderInterface $encoder, - ValueDecoderInterface $decoder, - ValueInterface ...$values + private ValueEncoderInterface $encoder, + private ValueDecoderInterface $decoder, + ValueInterface ...$values, ) { - $this->encoder = $encoder; - $this->decoder = $decoder; - $this->values = $values; + $this->values = array_values($values); } /** * {@inheritDoc} * - * @return array + * @return list */ public function decode(): array { @@ -42,7 +39,7 @@ public function decode(): array /** * {@inheritDoc} * - * @return string[] + * @return list */ public function encode(): array { @@ -52,7 +49,7 @@ public function encode(): array /** * {@inheritDoc} * - * @return ValueInterface[] + * @return list */ public function get(): array { diff --git a/src/Processor/Result/SelectResultInterface.php b/src/Processor/Result/SelectResultInterface.php index 3e0b234..3bbb7c3 100644 --- a/src/Processor/Result/SelectResultInterface.php +++ b/src/Processor/Result/SelectResultInterface.php @@ -8,19 +8,18 @@ interface SelectResultInterface { - /** - * @return mixed + * @return list */ - public function decode(); + public function decode(): array; /** - * @return string[] + * @return list */ public function encode(): array; /** - * @return ValueInterface[] + * @return list */ public function get(): array; } diff --git a/src/Processor/Result/ValueResultInterface.php b/src/Processor/Result/ValueResultInterface.php index d4b720d..98bd15f 100644 --- a/src/Processor/Result/ValueResultInterface.php +++ b/src/Processor/Result/ValueResultInterface.php @@ -8,10 +8,9 @@ interface ValueResultInterface extends OneResultInterface { - public function encode(): string; - public function decode(); + public function decode(): mixed; public function get(): ValueInterface; } diff --git a/src/Query/AstBuilder.php b/src/Query/AstBuilder.php index 133c979..4eb1ae7 100644 --- a/src/Query/AstBuilder.php +++ b/src/Query/AstBuilder.php @@ -9,35 +9,22 @@ final class AstBuilder implements AstBuilderInterface { + private ?int $inputId = null; - private $inputId; - - private $tree; - - public function __construct(Tree $tree) - { - $this->tree = $tree; + public function __construct( + private Tree $tree, + ) { } - /** - * @return int - */ public function getInput(): int { - if (!isset($this->inputId)) { - $this->inputId = $this - ->tree - ->createNode(AstNodeType::GET_INPUT) - ->getId(); - } - - return $this->inputId; + return $this->inputId ??= $this + ->tree + ->createNode(AstNodeType::GET_INPUT) + ->getId(); } /** - * @param int $id - * @param bool $isDefinite - * @param bool $isAddressable * @throws UniLexException */ public function setOutput(int $id, bool $isDefinite, bool $isAddressable): void @@ -54,8 +41,6 @@ public function setOutput(int $id, bool $isDefinite, bool $isAddressable): void } /** - * @param int $id - * @return int * @throws UniLexException */ public function fetchFilterContext(int $id): int @@ -68,8 +53,6 @@ public function fetchFilterContext(int $id): int } /** - * @param int $id - * @return int * @throws UniLexException */ public function splitFilterContext(int $id): int @@ -82,9 +65,6 @@ public function splitFilterContext(int $id): int } /** - * @param int $evaluatedId - * @param int $contextId - * @return int * @throws UniLexException */ public function joinFilterResults(int $evaluatedId, int $contextId): int @@ -98,9 +78,6 @@ public function joinFilterResults(int $evaluatedId, int $contextId): int } /** - * @param int $sourceId - * @param int $id - * @return int * @throws UniLexException */ public function evaluate(int $sourceId, int $id): int @@ -114,9 +91,6 @@ public function evaluate(int $sourceId, int $id): int } /** - * @param int $contextId - * @param int $evaluatedId - * @return int * @throws UniLexException */ public function filter(int $contextId, int $evaluatedId): int @@ -130,55 +104,44 @@ public function filter(int $contextId, int $evaluatedId): int } /** - * @param int $leftEvaluatedId - * @param int $rightEvaluatedId - * @return int * @throws UniLexException */ - public function evaluateLogicalOr(int $leftEvaluatedId, int $rightEvaluatedId): int + public function evaluateLogicalOr(int $leftId, int $rightId): int { return $this ->tree ->createNode(AstNodeType::EVALUATE_LOGICAL_OR) - ->addChild($this->tree->getNode($leftEvaluatedId)) - ->addChild($this->tree->getNode($rightEvaluatedId)) + ->addChild($this->tree->getNode($leftId)) + ->addChild($this->tree->getNode($rightId)) ->getId(); } /** - * @param int $leftEvaluatedId - * @param int $rightEvaluatedId - * @return int * @throws UniLexException */ - public function evaluateLogicalAnd(int $leftEvaluatedId, int $rightEvaluatedId): int + public function evaluateLogicalAnd(int $leftId, int $rightId): int { return $this ->tree ->createNode(AstNodeType::EVALUATE_LOGICAL_AND) - ->addChild($this->tree->getNode($leftEvaluatedId)) - ->addChild($this->tree->getNode($rightEvaluatedId)) + ->addChild($this->tree->getNode($leftId)) + ->addChild($this->tree->getNode($rightId)) ->getId(); } /** - * @param int $evaluatedId - * @return int * @throws UniLexException */ - public function evaluateLogicalNot(int $evaluatedId): int + public function evaluateLogicalNot(int $id): int { return $this ->tree ->createNode(AstNodeType::EVALUATE_LOGICAL_NOT) - ->addChild($this->tree->getNode($evaluatedId)) + ->addChild($this->tree->getNode($id)) ->getId(); } /** - * @param int $leftId - * @param int $rightId - * @return int * @throws UniLexException */ public function calculateIsEqual(int $leftId, int $rightId): int @@ -192,9 +155,6 @@ public function calculateIsEqual(int $leftId, int $rightId): int } /** - * @param int $leftId - * @param int $rightId - * @return int * @throws UniLexException */ public function calculateIsGreater(int $leftId, int $rightId): int @@ -208,9 +168,6 @@ public function calculateIsGreater(int $leftId, int $rightId): int } /** - * @param string $pattern - * @param int $id - * @return int * @throws UniLexException */ public function calculateIsRegExp(string $pattern, int $id): int @@ -224,9 +181,6 @@ public function calculateIsRegExp(string $pattern, int $id): int } /** - * @param int $id - * @param int $matcherId - * @return int * @throws UniLexException */ public function fetchChildren(int $id, int $matcherId): int @@ -240,9 +194,6 @@ public function fetchChildren(int $id, int $matcherId): int } /** - * @param int $id - * @param int $matcherId - * @return int * @throws UniLexException */ public function fetchChildrenDeep(int $id, int $matcherId): int @@ -256,8 +207,6 @@ public function fetchChildrenDeep(int $id, int $matcherId): int } /** - * @param int ...$idList - * @return int * @throws UniLexException */ public function merge(int ...$idList): int @@ -272,9 +221,6 @@ public function merge(int ...$idList): int return $node->getId(); } - /** - * @return int - */ public function matchAnyChild(): int { return $this @@ -284,8 +230,6 @@ public function matchAnyChild(): int } /** - * @param string ...$names - * @return int * @throws UniLexException */ public function matchPropertyStrictly(string ...$names): int @@ -298,8 +242,6 @@ public function matchPropertyStrictly(string ...$names): int } /** - * @param int ...$indexes - * @return int * @throws UniLexException */ public function matchElementStrictly(int ...$indexes): int @@ -312,10 +254,6 @@ public function matchElementStrictly(int ...$indexes): int } /** - * @param int|null $start - * @param int|null $end - * @param int|null $step - * @return int * @throws UniLexException */ public function matchElementSlice(?int $start, ?int $end, ?int $step): int @@ -332,9 +270,6 @@ public function matchElementSlice(?int $start, ?int $end, ?int $step): int } /** - * @param string $name - * @param int $id - * @return int * @throws UniLexException */ public function aggregate(string $name, int $id): int @@ -348,9 +283,6 @@ public function aggregate(string $name, int $id): int } /** - * @param int $sourceId - * @param mixed $value - * @return int * @throws UniLexException */ public function createScalar(int $sourceId, $value): int @@ -364,9 +296,6 @@ public function createScalar(int $sourceId, $value): int } /** - * @param int $sourceId - * @param int $arrayId - * @return int * @throws UniLexException */ public function createLiteralArray(int $sourceId, int $arrayId): int @@ -388,9 +317,6 @@ public function createArray(): int } /** - * @param int $arrayId - * @param int $valueId - * @return int * @throws UniLexException */ public function appendToArray(int $arrayId, int $valueId): int diff --git a/src/Query/AstBuilderInterface.php b/src/Query/AstBuilderInterface.php index 8d20380..ab6c486 100644 --- a/src/Query/AstBuilderInterface.php +++ b/src/Query/AstBuilderInterface.php @@ -6,7 +6,6 @@ interface AstBuilderInterface { - public function getInput(): int; public function setOutput(int $id, bool $isDefinite, bool $isAddressable): void; diff --git a/src/Query/AstNodeType.php b/src/Query/AstNodeType.php index d495524..f967d35 100644 --- a/src/Query/AstNodeType.php +++ b/src/Query/AstNodeType.php @@ -6,7 +6,6 @@ abstract class AstNodeType { - public const GET_INPUT = 'get_input'; public const SET_OUTPUT = 'set_output'; public const FETCH_FILTER_CONTEXT = 'fetch_filter_context'; diff --git a/src/Query/AstTranslator.php b/src/Query/AstTranslator.php index 48b15b9..18550d2 100644 --- a/src/Query/AstTranslator.php +++ b/src/Query/AstTranslator.php @@ -10,11 +10,10 @@ final class AstTranslator implements AstTranslatorInterface { - public function buildQuery( string $source, Tree $queryAst, - CallbackBuilderInterface $callbackBuilder + CallbackBuilderInterface $callbackBuilder, ): QueryInterface { try { $translator = new Translator($queryAst, $callbackBuilder); diff --git a/src/Query/AstTranslatorInterface.php b/src/Query/AstTranslatorInterface.php index 47a511f..4e51154 100644 --- a/src/Query/AstTranslatorInterface.php +++ b/src/Query/AstTranslatorInterface.php @@ -8,10 +8,9 @@ interface AstTranslatorInterface { - public function buildQuery( string $source, Tree $queryAst, - CallbackBuilderInterface $callbackBuilder + CallbackBuilderInterface $callbackBuilder, ): QueryInterface; } diff --git a/src/Query/CallbackBuilder.php b/src/Query/CallbackBuilder.php index 2a2fe7c..1878b4b 100644 --- a/src/Query/CallbackBuilder.php +++ b/src/Query/CallbackBuilder.php @@ -4,6 +4,7 @@ namespace Remorhaz\JSON\Path\Query; +use Closure; use PhpParser\BuilderFactory; use PhpParser\Node as PhpAstNode; use PhpParser\Node\Arg; @@ -25,10 +26,10 @@ use function array_map; use function array_reverse; +use function array_values; final class CallbackBuilder extends AbstractTranslatorListener implements CallbackBuilderInterface { - private const ARG_INPUT = 'input'; private const ARG_VALUE_LIST_FETCHER = 'valueListFetcher'; @@ -41,25 +42,31 @@ final class CallbackBuilder extends AbstractTranslatorListener implements Callba private $php; - private $references = []; + /** + * @var array + */ + private array $references = []; - private $input; + private ?Expr $input = null; - private $valueListFetcher; + private ?Expr $valueListFetcher = null; - private $evaluator; + private ?Expr $evaluator = null; - private $literalFactory; + private ?Expr $literalFactory = null; - private $matcherFactory; + private ?Expr $matcherFactory = null; - private $stmts = []; + /** + * @var list + */ + private array $stmts = []; - private $callback; + private ?Closure $callback = null; - private $callbackCode; + private ?string $callbackCode = null; - private $capabilities; + private ?CapabilitiesInterface $capabilities = null; public function __construct() { @@ -67,41 +74,36 @@ public function __construct() } /** + * @return callable( + * NodeValueListInterface, + * ValueListFetcherInterface, + * EvaluatorInterface, + * LiteralFactoryInterface, + * MatcherFactoryInterface, + * ): ValueListInterface * @noinspection PhpUnusedParameterInspection */ public function getCallback(): callable { - if (!isset($this->callback)) { - $this->callback = function ( - NodeValueListInterface $input, - ValueListFetcherInterface $valueListFetcher, - EvaluatorInterface $evaluator, - LiteralFactoryInterface $literalFactory, - MatcherFactoryInterface $matcherFactory - ): ValueListInterface { - return eval($this->getCallbackCode()); - }; - } - - return $this->callback; + return $this->callback ??= function ( + NodeValueListInterface $input, + ValueListFetcherInterface $valueListFetcher, + EvaluatorInterface $evaluator, + LiteralFactoryInterface $literalFactory, + MatcherFactoryInterface $matcherFactory, + ): ValueListInterface { + return eval($this->getCallbackCode()); + }; } public function getCallbackCode(): string { - if (isset($this->callbackCode)) { - return $this->callbackCode; - } - - throw new Exception\QueryCallbackCodeNotFoundException(); + return $this->callbackCode ?? throw new Exception\QueryCallbackCodeNotFoundException(); } public function getCapabilities(): CapabilitiesInterface { - if (isset($this->capabilities)) { - return $this->capabilities; - } - - throw new Exception\CapabilitiesNotFoundException(); + return $this->capabilities ?? throw new Exception\CapabilitiesNotFoundException(); } public function onStart(QueryAstNode $node): void @@ -143,6 +145,7 @@ public function onFinishProduction(QueryAstNode $node): void if ($this->hasReference($node)) { return; } + switch ($node->getName()) { case AstNodeType::GET_INPUT: $this->setReference($node, $this->input); @@ -435,11 +438,9 @@ private function createReference(QueryAstNode $node): Expr private function setReference(QueryAstNode $node, Expr $expr): void { - if (isset($this->references[$node->getId()])) { - throw new Exception\ReferenceAlreadyExistsException($node->getId()); - } - - $this->references[$node->getId()] = $expr; + $this->references[$node->getId()] = isset($this->references[$node->getId()]) + ? throw new Exception\ReferenceAlreadyExistsException($node->getId()) + : $expr; } private function hasReference(QueryAstNode $node): bool @@ -449,20 +450,17 @@ private function hasReference(QueryAstNode $node): bool private function getReference(QueryAstNode $node): Expr { - if (!isset($this->references[$node->getId()])) { - throw new Exception\ReferenceNotFoundException($node->getId()); - } - - return $this->references[$node->getId()]; + return $this->references[$node->getId()] + ?? throw new Exception\ReferenceNotFoundException($node->getId()); } /** * @param QueryAstNode ...$nodes - * @return Expr[] + * @return list */ private function getReferences(QueryAstNode ...$nodes): array { - return array_map([$this, 'getReference'], $nodes); + return array_map([$this, 'getReference'], array_values($nodes)); } private function addMethodCall(QueryAstNode $node, Expr $object, string $method, PhpAstNode ...$args): void diff --git a/src/Query/CallbackBuilderInterface.php b/src/Query/CallbackBuilderInterface.php index db0364d..7bccfc1 100644 --- a/src/Query/CallbackBuilderInterface.php +++ b/src/Query/CallbackBuilderInterface.php @@ -8,7 +8,15 @@ interface CallbackBuilderInterface extends TranslatorListenerInterface { - + /** + * @return callable( + * NodeValueListInterface, + * ValueListFetcherInterface, + * EvaluatorInterface, + * LiteralFactoryInterface, + * MatcherFactoryInterface, + * ): ValueListInterface + */ public function getCallback(): callable; public function getCallbackCode(): string; diff --git a/src/Query/Capabilities.php b/src/Query/Capabilities.php index 2de017d..9a082fe 100644 --- a/src/Query/Capabilities.php +++ b/src/Query/Capabilities.php @@ -6,28 +6,17 @@ final class Capabilities implements CapabilitiesInterface { - - private $isDefinite; - - private $isAddressable; - - public function __construct(bool $isDefinite, bool $isAddressable) - { - $this->isDefinite = $isDefinite; - $this->isAddressable = $isAddressable; + public function __construct( + private bool $isDefinite, + private bool $isAddressable, + ) { } - /** - * @return bool - */ public function isDefinite(): bool { return $this->isDefinite; } - /** - * @return bool - */ public function isAddressable(): bool { return $this->isAddressable; diff --git a/src/Query/CapabilitiesInterface.php b/src/Query/CapabilitiesInterface.php index b430f66..5767d6d 100644 --- a/src/Query/CapabilitiesInterface.php +++ b/src/Query/CapabilitiesInterface.php @@ -6,7 +6,6 @@ interface CapabilitiesInterface { - public function isDefinite(): bool; public function isAddressable(): bool; diff --git a/src/Query/Exception/CapabilitiesNotFoundException.php b/src/Query/Exception/CapabilitiesNotFoundException.php index fc23682..0dda4a2 100644 --- a/src/Query/Exception/CapabilitiesNotFoundException.php +++ b/src/Query/Exception/CapabilitiesNotFoundException.php @@ -9,8 +9,7 @@ final class CapabilitiesNotFoundException extends LogicException implements ExceptionInterface { - - public function __construct(Throwable $previous = null) + public function __construct(?Throwable $previous = null) { parent::__construct("Properties are accessed before being set", 0, $previous); } diff --git a/src/Query/Exception/QueryAstNotTranslatedException.php b/src/Query/Exception/QueryAstNotTranslatedException.php index fa3acc8..1f281ae 100644 --- a/src/Query/Exception/QueryAstNotTranslatedException.php +++ b/src/Query/Exception/QueryAstNotTranslatedException.php @@ -10,12 +10,10 @@ final class QueryAstNotTranslatedException extends LogicException implements ExceptionInterface { - - private $queryAst; - - public function __construct(Tree $queryAst, Throwable $previous = null) - { - $this->queryAst = $queryAst; + public function __construct( + private Tree $queryAst, + ?Throwable $previous = null, + ) { parent::__construct("Query AST was not translated to callback function", 0, $previous); } diff --git a/src/Query/Exception/QueryCallbackCodeNotFoundException.php b/src/Query/Exception/QueryCallbackCodeNotFoundException.php index 33507eb..54ca15b 100644 --- a/src/Query/Exception/QueryCallbackCodeNotFoundException.php +++ b/src/Query/Exception/QueryCallbackCodeNotFoundException.php @@ -9,8 +9,7 @@ final class QueryCallbackCodeNotFoundException extends LogicException implements ExceptionInterface { - - public function __construct(Throwable $previous = null) + public function __construct(?Throwable $previous = null) { parent::__construct("Query callback code is accessed before being generated", 0, $previous); } diff --git a/src/Query/Exception/QueryExecutionFailedException.php b/src/Query/Exception/QueryExecutionFailedException.php index 06de58d..9dc53c0 100644 --- a/src/Query/Exception/QueryExecutionFailedException.php +++ b/src/Query/Exception/QueryExecutionFailedException.php @@ -10,21 +10,17 @@ final class QueryExecutionFailedException extends LogicException implements ExceptionInterface { - - private $source; - - private $callbackCode; - - public function __construct(string $source, string $callbackCode, Throwable $previous = null) - { - $this->source = $source; - $this->callbackCode = $callbackCode; + public function __construct( + private string $source, + private string $callbackCode, + ?Throwable $previous = null, + ) { parent::__construct($this->buildMessage(), 0, $previous); } private function buildMessage(): string { - return "Failed to execute JSONPath query: {$this->source}\n\n{$this->callbackCode}"; + return "Failed to execute JSONPath query: $this->source\n\n$this->callbackCode"; } public function getSource(): string diff --git a/src/Query/Exception/ReferenceAlreadyExistsException.php b/src/Query/Exception/ReferenceAlreadyExistsException.php index a11f6c3..7fb8495 100644 --- a/src/Query/Exception/ReferenceAlreadyExistsException.php +++ b/src/Query/Exception/ReferenceAlreadyExistsException.php @@ -9,13 +9,11 @@ final class ReferenceAlreadyExistsException extends LogicException implements ExceptionInterface { - - private $referenceId; - - public function __construct(int $referenceId, Throwable $previous = null) - { - $this->referenceId = $referenceId; - parent::__construct("Reference #{$this->referenceId} already exists", 0, $previous); + public function __construct( + private int $referenceId, + ?Throwable $previous = null, + ) { + parent::__construct("Reference #$this->referenceId already exists", 0, $previous); } public function getReferenceId(): int diff --git a/src/Query/Exception/ReferenceNotFoundException.php b/src/Query/Exception/ReferenceNotFoundException.php index 2c58df7..e8630f5 100644 --- a/src/Query/Exception/ReferenceNotFoundException.php +++ b/src/Query/Exception/ReferenceNotFoundException.php @@ -9,13 +9,11 @@ final class ReferenceNotFoundException extends OutOfRangeException implements ExceptionInterface { - - private $referenceId; - - public function __construct(int $referenceId, Throwable $previous = null) - { - $this->referenceId = $referenceId; - parent::__construct("Reference #{$this->referenceId} not found", 0, $previous); + public function __construct( + private int $referenceId, + ?Throwable $previous = null, + ) { + parent::__construct("Reference #$this->referenceId not found", 0, $previous); } public function getReferenceId(): int diff --git a/src/Query/LazyQuery.php b/src/Query/LazyQuery.php index 20e6843..0e5a998 100644 --- a/src/Query/LazyQuery.php +++ b/src/Query/LazyQuery.php @@ -11,27 +11,14 @@ final class LazyQuery implements QueryInterface { - - private $loadedQuery; - - private $source; - - private $parser; - - private $astTranslator; - - private $callbackBuilder; + private ?QueryInterface $loadedQuery = null; public function __construct( - string $source, - ParserInterface $parser, - AstTranslatorInterface $astTranslator, - CallbackBuilderInterface $callbackBuilder + private string $source, + private ParserInterface $parser, + private AstTranslatorInterface $astTranslator, + private CallbackBuilderInterface $callbackBuilder, ) { - $this->source = $source; - $this->parser = $parser; - $this->astTranslator = $astTranslator; - $this->callbackBuilder = $callbackBuilder; } public function __invoke(NodeValueInterface $rootNode, RuntimeInterface $runtime): ValueListInterface @@ -53,11 +40,7 @@ public function getSource(): string private function getLoadedQuery(): QueryInterface { - if (!isset($this->loadedQuery)) { - $this->loadedQuery = $this->loadQuery(); - } - - return $this->loadedQuery; + return $this->loadedQuery ??= $this->loadQuery(); } private function loadQuery(): QueryInterface diff --git a/src/Query/Query.php b/src/Query/Query.php index 8750ea3..056c934 100644 --- a/src/Query/Query.php +++ b/src/Query/Query.php @@ -14,15 +14,10 @@ final class Query implements QueryInterface { - - private $source; - - private $callbackBuilder; - - public function __construct(string $source, CallbackBuilderInterface $callbackBuilder) - { - $this->source = $source; - $this->callbackBuilder = $callbackBuilder; + public function __construct( + private string $source, + private CallbackBuilderInterface $callbackBuilder, + ) { } public function __invoke(NodeValueInterface $rootNode, RuntimeInterface $runtime): ValueListInterface @@ -32,7 +27,7 @@ public function __invoke(NodeValueInterface $rootNode, RuntimeInterface $runtime ->callbackBuilder ->getCallback(); - $args = [ + return $callback( (new NodeValueListBuilder()) ->addValue($rootNode, 0) ->build(), @@ -40,9 +35,7 @@ public function __invoke(NodeValueInterface $rootNode, RuntimeInterface $runtime $runtime->getEvaluator(), $runtime->getLiteralFactory(), $runtime->getMatcherFactory(), - ]; - - return call_user_func($callback, ...$args); + ); } catch (Throwable $e) { throw new Exception\QueryExecutionFailedException( $this->source, diff --git a/src/Query/QueryFactory.php b/src/Query/QueryFactory.php index 2231bbe..7f50058 100644 --- a/src/Query/QueryFactory.php +++ b/src/Query/QueryFactory.php @@ -10,11 +10,6 @@ final class QueryFactory implements QueryFactoryInterface { - - private $parser; - - private $astTranslator; - public static function create(): QueryFactoryInterface { return new QueryFactory( @@ -23,10 +18,10 @@ public static function create(): QueryFactoryInterface ); } - public function __construct(ParserInterface $parser, AstTranslatorInterface $astTranslator) - { - $this->parser = $parser; - $this->astTranslator = $astTranslator; + public function __construct( + private ParserInterface $parser, + private AstTranslatorInterface $astTranslator, + ) { } public function createQuery(string $path): QueryInterface diff --git a/src/Query/QueryFactoryInterface.php b/src/Query/QueryFactoryInterface.php index 779ff67..f3e7094 100644 --- a/src/Query/QueryFactoryInterface.php +++ b/src/Query/QueryFactoryInterface.php @@ -6,6 +6,5 @@ interface QueryFactoryInterface { - public function createQuery(string $path): QueryInterface; } diff --git a/src/Query/QueryInterface.php b/src/Query/QueryInterface.php index 4e6f062..7780e59 100644 --- a/src/Query/QueryInterface.php +++ b/src/Query/QueryInterface.php @@ -10,7 +10,6 @@ interface QueryInterface { - /** * @param NodeValueInterface $rootNode * @param RuntimeInterface $runtime diff --git a/src/Query/QueryValidator.php b/src/Query/QueryValidator.php index 0449cdb..b3ba1be 100644 --- a/src/Query/QueryValidator.php +++ b/src/Query/QueryValidator.php @@ -8,22 +8,17 @@ final class QueryValidator implements QueryValidatorInterface { - public function getDefiniteQuery(QueryInterface $query): QueryInterface { - if (!$query->getCapabilities()->isDefinite()) { - throw new Exception\IndefiniteQueryException($query); - } - - return $query; + return $query->getCapabilities()->isDefinite() + ? $query + : throw new Exception\IndefiniteQueryException($query); } public function getAddressableQuery(QueryInterface $query): QueryInterface { - if (!$query->getCapabilities()->isAddressable()) { - throw new Exception\QueryNotAddressableException($query); - } - - return $query; + return $query->getCapabilities()->isAddressable() + ? $query + : throw new Exception\QueryNotAddressableException($query); } } diff --git a/src/Query/QueryValidatorInterface.php b/src/Query/QueryValidatorInterface.php index cc7b171..5ed5f22 100644 --- a/src/Query/QueryValidatorInterface.php +++ b/src/Query/QueryValidatorInterface.php @@ -6,7 +6,6 @@ interface QueryValidatorInterface { - public function getDefiniteQuery(QueryInterface $query): QueryInterface; public function getAddressableQuery(QueryInterface $query): QueryInterface; diff --git a/src/Runtime/Aggregator/AggregatorCollection.php b/src/Runtime/Aggregator/AggregatorCollection.php index 2f3e267..dde9cae 100644 --- a/src/Runtime/Aggregator/AggregatorCollection.php +++ b/src/Runtime/Aggregator/AggregatorCollection.php @@ -6,7 +6,6 @@ final class AggregatorCollection implements AggregatorCollectionInterface { - private const MIN = 'min'; private const MAX = 'max'; private const LENGTH = 'length'; @@ -15,23 +14,13 @@ final class AggregatorCollection implements AggregatorCollectionInterface public function byName(string $name): ValueAggregatorInterface { - switch ($name) { - case self::MIN: - return new MinAggregator(); - - case self::MAX: - return new MaxAggregator(); - - case self::LENGTH: - return new LengthAggregator(); - - case self::AVG: - return new AvgAggregator(); - - case self::STDDEV: - return new StdDevAggregator(); - } - - throw new Exception\AggregateFunctionNotFoundException($name); + return match ($name) { + self::MIN => new MinAggregator(), + self::MAX => new MaxAggregator(), + self::LENGTH => new LengthAggregator(), + self::AVG => new AvgAggregator(), + self::STDDEV => new StdDevAggregator(), + default => throw new Exception\AggregateFunctionNotFoundException($name), + }; } } diff --git a/src/Runtime/Aggregator/AggregatorCollectionInterface.php b/src/Runtime/Aggregator/AggregatorCollectionInterface.php index 815b084..fba2e63 100644 --- a/src/Runtime/Aggregator/AggregatorCollectionInterface.php +++ b/src/Runtime/Aggregator/AggregatorCollectionInterface.php @@ -6,6 +6,5 @@ interface AggregatorCollectionInterface { - public function byName(string $name): ValueAggregatorInterface; } diff --git a/src/Runtime/Aggregator/AvgAggregator.php b/src/Runtime/Aggregator/AvgAggregator.php index 6b3c3a3..8d9a20c 100644 --- a/src/Runtime/Aggregator/AvgAggregator.php +++ b/src/Runtime/Aggregator/AvgAggregator.php @@ -13,13 +13,15 @@ final class AvgAggregator extends NumericAggregator { - + /** + * @param list $dataList + * @param ScalarValueInterface ...$elements + * @return ValueInterface|null + */ protected function aggregateNumericData(array $dataList, ScalarValueInterface ...$elements): ?ValueInterface { return empty($dataList) - // @codeCoverageIgnoreStart ? null - // @codeCoverageIgnoreEnd : new LiteralScalarValue(array_sum($dataList) / count($dataList)); } } diff --git a/src/Runtime/Aggregator/Exception/AggregateFunctionNotFoundException.php b/src/Runtime/Aggregator/Exception/AggregateFunctionNotFoundException.php index fcb14ca..5309f41 100644 --- a/src/Runtime/Aggregator/Exception/AggregateFunctionNotFoundException.php +++ b/src/Runtime/Aggregator/Exception/AggregateFunctionNotFoundException.php @@ -9,13 +9,11 @@ final class AggregateFunctionNotFoundException extends DomainException implements ExceptionInterface { - - private $name; - - public function __construct(string $name, Throwable $previous = null) - { - $this->name = $name; - parent::__construct("Aggregate function not found: {$this->name}", 0, $previous); + public function __construct( + private string $name, + ?Throwable $previous = null, + ) { + parent::__construct("Aggregate function not found: $this->name", 0, $previous); } public function getName(): string diff --git a/src/Runtime/Aggregator/Exception/MaxElementNotFoundException.php b/src/Runtime/Aggregator/Exception/MaxElementNotFoundException.php index 47cc857..173fb85 100644 --- a/src/Runtime/Aggregator/Exception/MaxElementNotFoundException.php +++ b/src/Runtime/Aggregator/Exception/MaxElementNotFoundException.php @@ -10,20 +10,17 @@ final class MaxElementNotFoundException extends LogicException implements ExceptionInterface { - - private $dataList; - - private $elements; - /** * @param array $dataList - * @param ScalarValueInterface[] $elements + * @param list $elements * @param Throwable|null $previous */ - public function __construct(array $dataList, array $elements, Throwable $previous = null) - { - $this->dataList = $dataList; - $this->elements = $elements; + public function __construct( + private array $dataList, + private array $elements, + ?Throwable $previous = null, + ) { + parent::__construct("Max element not found", 0, $previous); } @@ -33,7 +30,7 @@ public function getDataList(): array } /** - * @return ScalarValueInterface[] + * @return list */ public function getElements(): array { diff --git a/src/Runtime/Aggregator/Exception/MinElementNotFoundException.php b/src/Runtime/Aggregator/Exception/MinElementNotFoundException.php index da3a698..b1447fd 100644 --- a/src/Runtime/Aggregator/Exception/MinElementNotFoundException.php +++ b/src/Runtime/Aggregator/Exception/MinElementNotFoundException.php @@ -10,20 +10,16 @@ final class MinElementNotFoundException extends LogicException implements ExceptionInterface { - - private $dataList; - - private $elements; - /** * @param array $dataList - * @param ScalarValueInterface[] $elements + * @param list $elements * @param Throwable|null $previous */ - public function __construct(array $dataList, array $elements, Throwable $previous = null) - { - $this->dataList = $dataList; - $this->elements = $elements; + public function __construct( + private array $dataList, + private array $elements, + ?Throwable $previous = null, + ) { parent::__construct("Min element not found", 0, $previous); } @@ -33,7 +29,7 @@ public function getDataList(): array } /** - * @return ScalarValueInterface[] + * @return list */ public function getElements(): array { diff --git a/src/Runtime/Aggregator/LengthAggregator.php b/src/Runtime/Aggregator/LengthAggregator.php index 2a8b7ee..36470ea 100644 --- a/src/Runtime/Aggregator/LengthAggregator.php +++ b/src/Runtime/Aggregator/LengthAggregator.php @@ -12,7 +12,6 @@ final class LengthAggregator implements ValueAggregatorInterface { - public function tryAggregate(ValueInterface $value): ?ValueInterface { if (!$value instanceof ArrayValueInterface) { diff --git a/src/Runtime/Aggregator/MaxAggregator.php b/src/Runtime/Aggregator/MaxAggregator.php index 5167728..dfcf752 100644 --- a/src/Runtime/Aggregator/MaxAggregator.php +++ b/src/Runtime/Aggregator/MaxAggregator.php @@ -12,17 +12,18 @@ final class MaxAggregator extends UniqueNumericAggregator { - + /** + * @param list $dataList + * @param ScalarValueInterface ...$elements + * @return ValueInterface|null + */ protected function aggregateNumericData(array $dataList, ScalarValueInterface ...$elements): ?ValueInterface { $elementIndex = $this->findElementIndex($dataList); - if (isset($elementIndex, $elements[$elementIndex])) { - return $elements[$elementIndex]; - } - // @codeCoverageIgnoreStart - throw new Exception\MaxElementNotFoundException($dataList, $elements); - // @codeCoverageIgnoreEnd + return isset($elementIndex, $elements[$elementIndex]) + ? $elements[$elementIndex] + : throw new Exception\MaxElementNotFoundException($dataList, $elements); } private function findElementIndex(array $dataList): ?int diff --git a/src/Runtime/Aggregator/MinAggregator.php b/src/Runtime/Aggregator/MinAggregator.php index c889ec5..e1f7c11 100644 --- a/src/Runtime/Aggregator/MinAggregator.php +++ b/src/Runtime/Aggregator/MinAggregator.php @@ -12,17 +12,18 @@ final class MinAggregator extends UniqueNumericAggregator { - + /** + * @param list $dataList + * @param ScalarValueInterface ...$elements + * @return ValueInterface|null + */ protected function aggregateNumericData(array $dataList, ScalarValueInterface ...$elements): ?ValueInterface { $elementIndex = $this->findElementIndex($dataList); - if (isset($elementIndex, $elements[$elementIndex])) { - return $elements[$elementIndex]; - } - // @codeCoverageIgnoreStart - throw new Exception\MaxElementNotFoundException($dataList, $elements); - // @codeCoverageIgnoreEnd + return isset($elementIndex, $elements[$elementIndex]) + ? $elements[$elementIndex] + : throw new Exception\MaxElementNotFoundException($dataList, $elements); } private function findElementIndex(array $dataList): ?int diff --git a/src/Runtime/Aggregator/NumericAggregator.php b/src/Runtime/Aggregator/NumericAggregator.php index 9f45475..9e2599c 100644 --- a/src/Runtime/Aggregator/NumericAggregator.php +++ b/src/Runtime/Aggregator/NumericAggregator.php @@ -8,29 +8,34 @@ use Remorhaz\JSON\Data\Value\ScalarValueInterface; use Remorhaz\JSON\Data\Value\ValueInterface; +use function array_filter; use function array_map; +use function array_values; use function is_float; use function is_int; abstract class NumericAggregator implements ValueAggregatorInterface { - + /** + * @param list $dataList + * @param ScalarValueInterface ...$elements + * @return ValueInterface|null + */ abstract protected function aggregateNumericData( array $dataList, - ScalarValueInterface ...$elements + ScalarValueInterface ...$elements, ): ?ValueInterface; final public function tryAggregate(ValueInterface $value): ?ValueInterface { $numericElements = $this->findNumericElements($value); - if (empty($numericElements)) { - return null; - } - return $this->aggregateNumericData( - $this->getElementDataList(...$numericElements), - ...$numericElements - ); + return empty($numericElements) + ? null + : $this->aggregateNumericData( + $this->getElementDataList(...$numericElements), + ...$numericElements, + ); } protected function findNumericElement(ValueInterface $element): ?ScalarValueInterface @@ -38,6 +43,7 @@ protected function findNumericElement(ValueInterface $element): ?ScalarValueInte if (!$element instanceof ScalarValueInterface) { return null; } + $elementData = $element->getData(); return is_int($elementData) || is_float($elementData) ? $element @@ -46,7 +52,7 @@ protected function findNumericElement(ValueInterface $element): ?ScalarValueInte /** * @param ValueInterface $value - * @return ScalarValueInterface[] + * @return list */ protected function findNumericElements(ValueInterface $value): array { @@ -54,22 +60,36 @@ protected function findNumericElements(ValueInterface $value): array if (!$value instanceof ArrayValueInterface) { return $numericElements; } + foreach ($value->createChildIterator() as $element) { $numericElement = $this->findNumericElement($element); if (isset($numericElement)) { $numericElements[] = $numericElement; } } + return $numericElements; } + /** + * @param ScalarValueInterface ...$elements + * @return list + */ protected function getElementDataList(ScalarValueInterface ...$elements): array { - return array_map([$this, 'getElementData'], $elements); + return array_values( + array_filter( + array_map([$this, 'findElementData'], $elements), + ), + ); } - private function getElementData(ScalarValueInterface $element) + private function findElementData(ScalarValueInterface $element): int|float|null { - return $element->getData(); + $data = $element->getData(); + + return is_int($data) || is_float($data) + ? $data + : null; } } diff --git a/src/Runtime/Aggregator/StdDevAggregator.php b/src/Runtime/Aggregator/StdDevAggregator.php index cf0cdb2..60c142c 100644 --- a/src/Runtime/Aggregator/StdDevAggregator.php +++ b/src/Runtime/Aggregator/StdDevAggregator.php @@ -15,7 +15,11 @@ final class StdDevAggregator extends NumericAggregator { - + /** + * @param list $dataList + * @param ScalarValueInterface ...$elements + * @return ValueInterface|null + */ protected function aggregateNumericData(array $dataList, ScalarValueInterface ...$elements): ?ValueInterface { $count = count($dataList); diff --git a/src/Runtime/Aggregator/UniqueNumericAggregator.php b/src/Runtime/Aggregator/UniqueNumericAggregator.php index e10777a..5affb0d 100644 --- a/src/Runtime/Aggregator/UniqueNumericAggregator.php +++ b/src/Runtime/Aggregator/UniqueNumericAggregator.php @@ -9,10 +9,9 @@ abstract class UniqueNumericAggregator extends NumericAggregator { - /** * @param ValueInterface $value - * @return ScalarValueInterface[] + * @return list */ protected function findNumericElements(ValueInterface $value): array { diff --git a/src/Runtime/Aggregator/ValueAggregatorInterface.php b/src/Runtime/Aggregator/ValueAggregatorInterface.php index 785012e..c452f2f 100644 --- a/src/Runtime/Aggregator/ValueAggregatorInterface.php +++ b/src/Runtime/Aggregator/ValueAggregatorInterface.php @@ -8,6 +8,5 @@ interface ValueAggregatorInterface { - public function tryAggregate(ValueInterface $value): ?ValueInterface; } diff --git a/src/Runtime/ComparatorCollection.php b/src/Runtime/ComparatorCollection.php index f56f8ec..4f2103a 100644 --- a/src/Runtime/ComparatorCollection.php +++ b/src/Runtime/ComparatorCollection.php @@ -11,12 +11,9 @@ final class ComparatorCollection implements ComparatorCollectionInterface { - - private $collator; - - public function __construct(Collator $collator) - { - $this->collator = $collator; + public function __construct( + private Collator $collator, + ) { } public function equal(): ComparatorInterface diff --git a/src/Runtime/ComparatorCollectionInterface.php b/src/Runtime/ComparatorCollectionInterface.php index db9c30c..4fe991f 100644 --- a/src/Runtime/ComparatorCollectionInterface.php +++ b/src/Runtime/ComparatorCollectionInterface.php @@ -8,7 +8,6 @@ interface ComparatorCollectionInterface { - public function equal(): ComparatorInterface; public function greater(): ComparatorInterface; diff --git a/src/Runtime/Evaluator.php b/src/Runtime/Evaluator.php index cc1f7a6..54a2714 100644 --- a/src/Runtime/Evaluator.php +++ b/src/Runtime/Evaluator.php @@ -21,22 +21,15 @@ final class Evaluator implements EvaluatorInterface { - - private $comparators; - - private $aggregators; - public function __construct( - ComparatorCollectionInterface $comparators, - Aggregator\AggregatorCollectionInterface $aggregators + private ComparatorCollectionInterface $comparators, + private Aggregator\AggregatorCollectionInterface $aggregators, ) { - $this->comparators = $comparators; - $this->aggregators = $aggregators; } public function logicalOr( EvaluatedValueListInterface $leftValues, - EvaluatedValueListInterface $rightValues + EvaluatedValueListInterface $rightValues, ): EvaluatedValueListInterface { $results = []; foreach ($leftValues->getResults() as $index => $leftResult) { @@ -45,13 +38,13 @@ public function logicalOr( return new EvaluatedValueList( $this->getEqualIndexMap($leftValues, $rightValues), - ...$results + ...$results, ); } public function logicalAnd( EvaluatedValueListInterface $leftValues, - EvaluatedValueListInterface $rightValues + EvaluatedValueListInterface $rightValues, ): EvaluatedValueListInterface { $results = []; foreach ($leftValues->getResults() as $index => $leftResult) { @@ -60,7 +53,7 @@ public function logicalAnd( return new EvaluatedValueList( $this->getEqualIndexMap($leftValues, $rightValues), - ...$results + ...$results, ); } @@ -76,23 +69,23 @@ public function logicalNot(EvaluatedValueListInterface $values): EvaluatedValueL public function isEqual( ValueListInterface $leftValues, - ValueListInterface $rightValues + ValueListInterface $rightValues, ): EvaluatedValueListInterface { return $this->compare( $leftValues, $rightValues, - $this->comparators->equal() + $this->comparators->equal(), ); } public function isGreater( ValueListInterface $leftValues, - ValueListInterface $rightValues + ValueListInterface $rightValues, ): EvaluatedValueListInterface { return $this->compare( $leftValues, $rightValues, - $this->comparators->greater() + $this->comparators->greater(), ); } @@ -114,7 +107,7 @@ private function compare( $valueListBuilder->addResult( $comparator->compare( $leftValues->getValue($leftInnerIndex), - $rightValues->getValue($rightInnerIndex) + $rightValues->getValue($rightInnerIndex), ), $leftOuterIndex ); @@ -150,7 +143,7 @@ public function isRegExp(string $regExp, ValueListInterface $values): EvaluatedV public function evaluate( ValueListInterface $sourceValues, - ValueListInterface $resultValues + ValueListInterface $resultValues, ): EvaluatedValueListInterface { if ($resultValues instanceof EvaluatedValueListInterface) { return $resultValues; @@ -162,9 +155,7 @@ public function evaluate( $results = []; foreach ($sourceValues->getIndexMap()->getOuterIndexes() as $outerIndex) { - $results[] = isset($outerIndex) - ? $resultValues->getIndexMap()->outerIndexExists($outerIndex) - : false; + $results[] = isset($outerIndex) && $resultValues->getIndexMap()->outerIndexExists($outerIndex); } return new EvaluatedValueList($sourceValues->getIndexMap(), ...$results); @@ -172,7 +163,7 @@ public function evaluate( private function evaluateLiteralValues( ValueListInterface $sourceValues, - LiteralValueListInterface $resultValues + LiteralValueListInterface $resultValues, ): EvaluatedValueListInterface { $indexMap = $this->getEqualIndexMap($sourceValues, $resultValues); $literal = $resultValues->getLiteral(); @@ -181,7 +172,7 @@ private function evaluateLiteralValues( if (is_bool($data)) { return new EvaluatedValueList( $indexMap, - ...array_fill(0, count($indexMap), $data) + ...array_fill(0, count($indexMap), $data), ); } } @@ -191,14 +182,13 @@ private function evaluateLiteralValues( private function getEqualIndexMap( ValueListInterface $leftValues, - ValueListInterface $rightValues + ValueListInterface $rightValues, ): IndexMapInterface { $indexMap = $leftValues->getIndexMap(); - if ($indexMap->equals($rightValues->getIndexMap())) { - return $indexMap; - } - throw new Exception\IndexMapMatchFailedException($leftValues, $rightValues); + return $indexMap->equals($rightValues->getIndexMap()) + ? $indexMap + : throw new Exception\IndexMapMatchFailedException($leftValues, $rightValues); } public function aggregate(string $functionName, ValueListInterface $values): ValueListInterface @@ -210,7 +200,7 @@ public function aggregate(string $functionName, ValueListInterface $values): Val if (isset($aggregatedValue)) { $valuesBuilder->addValue( $aggregatedValue, - $values->getIndexMap()->getOuterIndex($innerIndex) + $values->getIndexMap()->getOuterIndex($innerIndex), ); } } diff --git a/src/Runtime/EvaluatorInterface.php b/src/Runtime/EvaluatorInterface.php index f5fd600..4165eca 100644 --- a/src/Runtime/EvaluatorInterface.php +++ b/src/Runtime/EvaluatorInterface.php @@ -9,34 +9,33 @@ interface EvaluatorInterface { - public function logicalOr( EvaluatedValueListInterface $leftValues, - EvaluatedValueListInterface $rightValues + EvaluatedValueListInterface $rightValues, ): EvaluatedValueListInterface; public function logicalAnd( EvaluatedValueListInterface $leftValues, - EvaluatedValueListInterface $rightValues + EvaluatedValueListInterface $rightValues, ): EvaluatedValueListInterface; public function logicalNot(EvaluatedValueListInterface $values): EvaluatedValueListInterface; public function isEqual( ValueListInterface $leftValues, - ValueListInterface $rightValues + ValueListInterface $rightValues, ): EvaluatedValueListInterface; public function isGreater( ValueListInterface $leftValues, - ValueListInterface $rightValues + ValueListInterface $rightValues, ): EvaluatedValueListInterface; public function isRegExp(string $regExp, ValueListInterface $values): EvaluatedValueListInterface; public function evaluate( ValueListInterface $sourceValues, - ValueListInterface $resultValues + ValueListInterface $resultValues, ): EvaluatedValueListInterface; public function aggregate(string $functionName, ValueListInterface $values): ValueListInterface; diff --git a/src/Runtime/Exception/IndexMapMatchFailedException.php b/src/Runtime/Exception/IndexMapMatchFailedException.php index 0e51a98..9565c44 100644 --- a/src/Runtime/Exception/IndexMapMatchFailedException.php +++ b/src/Runtime/Exception/IndexMapMatchFailedException.php @@ -10,18 +10,11 @@ final class IndexMapMatchFailedException extends LogicException implements ExceptionInterface { - - private $leftValues; - - private $rightValues; - public function __construct( - ValueListInterface $leftValues, - ValueListInterface $rightValues, - Throwable $previous = null + private ValueListInterface $leftValues, + private ValueListInterface $rightValues, + ?Throwable $previous = null, ) { - $this->leftValues = $leftValues; - $this->rightValues = $rightValues; parent::__construct("Index map match failed", 0, $previous); } diff --git a/src/Runtime/Exception/InvalidContextValueException.php b/src/Runtime/Exception/InvalidContextValueException.php index 563691f..0fc07b0 100644 --- a/src/Runtime/Exception/InvalidContextValueException.php +++ b/src/Runtime/Exception/InvalidContextValueException.php @@ -10,12 +10,10 @@ final class InvalidContextValueException extends LogicException implements ExceptionInterface { - - private $value; - - public function __construct(ValueInterface $value, Throwable $previous = null) - { - $this->value = $value; + public function __construct( + private ValueInterface $value, + ?Throwable $previous = null, + ) { parent::__construct("Invalid context value", 0, $previous); } diff --git a/src/Runtime/Exception/InvalidFilterValueException.php b/src/Runtime/Exception/InvalidFilterValueException.php index 5fb219d..33df694 100644 --- a/src/Runtime/Exception/InvalidFilterValueException.php +++ b/src/Runtime/Exception/InvalidFilterValueException.php @@ -10,12 +10,10 @@ final class InvalidFilterValueException extends LogicException implements ExceptionInterface { - - private $value; - - public function __construct(ValueInterface $value, Throwable $previous = null) - { - $this->value = $value; + public function __construct( + private ValueInterface $value, + ?Throwable $previous = null, + ) { parent::__construct("Invalid filter value", 0, $previous); } diff --git a/src/Runtime/Exception/InvalidRegExpException.php b/src/Runtime/Exception/InvalidRegExpException.php index 1c09787..d7ed0e5 100644 --- a/src/Runtime/Exception/InvalidRegExpException.php +++ b/src/Runtime/Exception/InvalidRegExpException.php @@ -9,13 +9,11 @@ final class InvalidRegExpException extends RuntimeException implements ExceptionInterface { - - private $pattern; - - public function __construct(string $pattern, Throwable $previous = null) - { - $this->pattern = $pattern; - parent::__construct("Error processing regular expression: {$this->pattern}", 0, $previous); + public function __construct( + private string $pattern, + ?Throwable $previous = null, + ) { + parent::__construct("Error processing regular expression: $this->pattern", 0, $previous); } public function getPattern(): string diff --git a/src/Runtime/Exception/LiteralEvaluationFailedException.php b/src/Runtime/Exception/LiteralEvaluationFailedException.php index 25b9213..ae08ddc 100644 --- a/src/Runtime/Exception/LiteralEvaluationFailedException.php +++ b/src/Runtime/Exception/LiteralEvaluationFailedException.php @@ -10,12 +10,10 @@ final class LiteralEvaluationFailedException extends LogicException implements ExceptionInterface { - - private $literal; - - public function __construct(LiteralValueInterface $literal, Throwable $previous = null) - { - $this->literal = $literal; + public function __construct( + private LiteralValueInterface $literal, + ?Throwable $previous = null, + ) { parent::__construct("Failed to evaluate literal value", 0, $previous); } diff --git a/src/Runtime/Exception/UnexpectedNodeValueFetchedException.php b/src/Runtime/Exception/UnexpectedNodeValueFetchedException.php index 3014893..1cb8456 100644 --- a/src/Runtime/Exception/UnexpectedNodeValueFetchedException.php +++ b/src/Runtime/Exception/UnexpectedNodeValueFetchedException.php @@ -10,12 +10,10 @@ final class UnexpectedNodeValueFetchedException extends LogicException implements ExceptionInterface { - - private $value; - - public function __construct(NodeValueInterface $value, Throwable $previous = null) - { - $this->value = $value; + public function __construct( + private NodeValueInterface $value, + ?Throwable $previous = null, + ) { parent::__construct("Unexpected node value fetched", 0, $previous); } diff --git a/src/Runtime/LiteralFactory.php b/src/Runtime/LiteralFactory.php index 27b359f..2393063 100644 --- a/src/Runtime/LiteralFactory.php +++ b/src/Runtime/LiteralFactory.php @@ -14,7 +14,6 @@ class LiteralFactory implements LiteralFactoryInterface { - public function createScalar(NodeValueListInterface $source, $value): ValueListInterface { return new LiteralValueList($source->getIndexMap(), new LiteralScalarValue($value)); @@ -22,19 +21,20 @@ public function createScalar(NodeValueListInterface $source, $value): ValueListI public function createArray(NodeValueListInterface $source, ValueListInterface ...$valueLists): ValueListInterface { - $createArrayElement = function (array $elements): ValueInterface { - return new LiteralArrayValue(...$elements); - }; - return new ValueList( $source->getIndexMap(), ...array_map( - $createArrayElement, - $this->buildArrayElementLists($source, ...$valueLists) + fn (array $elements): ValueInterface => new LiteralArrayValue(...$elements), + $this->buildArrayElementLists($source, ...$valueLists), ) ); } + /** + * @param NodeValueListInterface $source + * @param ValueListInterface ...$valueLists + * @return array> + */ private function buildArrayElementLists(NodeValueListInterface $source, ValueListInterface ...$valueLists): array { $elementLists = array_fill_keys($source->getIndexMap()->getInnerIndexes(), []); diff --git a/src/Runtime/LiteralFactoryInterface.php b/src/Runtime/LiteralFactoryInterface.php index 80446c6..efcde41 100644 --- a/src/Runtime/LiteralFactoryInterface.php +++ b/src/Runtime/LiteralFactoryInterface.php @@ -9,7 +9,6 @@ interface LiteralFactoryInterface { - public function createScalar(NodeValueListInterface $source, $value): ValueListInterface; public function createArray(NodeValueListInterface $source, ValueListInterface ...$values): ValueListInterface; diff --git a/src/Runtime/Matcher/AnyChildMatcher.php b/src/Runtime/Matcher/AnyChildMatcher.php index 9e4e7d7..1e30f88 100644 --- a/src/Runtime/Matcher/AnyChildMatcher.php +++ b/src/Runtime/Matcher/AnyChildMatcher.php @@ -8,8 +8,7 @@ final class AnyChildMatcher implements ChildMatcherInterface { - - public function match($address, NodeValueInterface $value, NodeValueInterface $container): bool + public function match(int|string $address, NodeValueInterface $value, NodeValueInterface $container): bool { return true; } diff --git a/src/Runtime/Matcher/ChildMatcherInterface.php b/src/Runtime/Matcher/ChildMatcherInterface.php index 94e6584..25fccbc 100644 --- a/src/Runtime/Matcher/ChildMatcherInterface.php +++ b/src/Runtime/Matcher/ChildMatcherInterface.php @@ -8,6 +8,5 @@ interface ChildMatcherInterface { - - public function match($address, NodeValueInterface $value, NodeValueInterface $container): bool; + public function match(int|string $address, NodeValueInterface $value, NodeValueInterface $container): bool; } diff --git a/src/Runtime/Matcher/Exception/AddressNotSortableException.php b/src/Runtime/Matcher/Exception/AddressNotSortableException.php index 6545ed6..a4b21ed 100644 --- a/src/Runtime/Matcher/Exception/AddressNotSortableException.php +++ b/src/Runtime/Matcher/Exception/AddressNotSortableException.php @@ -9,23 +9,14 @@ final class AddressNotSortableException extends DomainException implements ExceptionInterface { - - private $address; - - /** - * @param int|string $address - * @param Throwable|null $previous - */ - public function __construct($address, Throwable $previous = null) - { - $this->address = $address; + public function __construct( + private int|string $address, + ?Throwable $previous = null, + ) { parent::__construct("Index/property is not sortable: {$this->address}", 0, $previous); } - /** - * @return int|string - */ - public function getAddress() + public function getAddress(): int|string { return $this->address; } diff --git a/src/Runtime/Matcher/MatcherFactory.php b/src/Runtime/Matcher/MatcherFactory.php index 17993ee..a6c7454 100644 --- a/src/Runtime/Matcher/MatcherFactory.php +++ b/src/Runtime/Matcher/MatcherFactory.php @@ -6,7 +6,6 @@ final class MatcherFactory implements MatcherFactoryInterface { - public function matchAnyChild(): ChildMatcherInterface { return new AnyChildMatcher(); diff --git a/src/Runtime/Matcher/MatcherFactoryInterface.php b/src/Runtime/Matcher/MatcherFactoryInterface.php index b6518d3..303ae60 100644 --- a/src/Runtime/Matcher/MatcherFactoryInterface.php +++ b/src/Runtime/Matcher/MatcherFactoryInterface.php @@ -6,7 +6,6 @@ interface MatcherFactoryInterface { - public function matchAnyChild(): ChildMatcherInterface; public function matchPropertyStrictly(string ...$nameList): ChildMatcherInterface; diff --git a/src/Runtime/Matcher/SliceElementMatcher.php b/src/Runtime/Matcher/SliceElementMatcher.php index 60ef8db..8afb2dd 100644 --- a/src/Runtime/Matcher/SliceElementMatcher.php +++ b/src/Runtime/Matcher/SliceElementMatcher.php @@ -13,25 +13,20 @@ final class SliceElementMatcher implements SortedChildMatcherInterface { + private int $step; - private $start; + private bool $isReverse; - private $end; - - private $step; - - private $isReverse; - - public function __construct(?int $start, ?int $end, ?int $step) - { + public function __construct( + private ?int $start, + private ?int $end, + ?int $step, + ) { $this->step = $step ?? 1; $this->isReverse = $this->step < 0; - - $this->start = $start; - $this->end = $end; } - public function match($address, NodeValueInterface $value, NodeValueInterface $container): bool + public function match(int|string $address, NodeValueInterface $value, NodeValueInterface $container): bool { if (0 == $this->step || !is_int($address)) { return false; @@ -61,23 +56,16 @@ private function findArrayLength(NodeValueInterface $value): ?int private function detectStart(int $count): int { - $start = $this->start; - if (!isset($start)) { - $start = $this->isReverse ? -1 : 0; - } - if ($start < 0) { - $start = max($start + $count, 0); - } + $start = $this->start ?? ($this->isReverse ? -1 : 0); - return $start; + return $start < 0 + ? max($start + $count, 0) + : $start; } private function detectEnd(int $count): int { - $end = $this->end; - if (!isset($end)) { - $end = $this->isReverse ? -$count - 1 : $count; - } + $end = $this->end ?? ($this->isReverse ? -$count - 1 : $count); if ($end > $count) { return $count; } @@ -104,12 +92,10 @@ private function getIndex(int $address, int $start): int return $this->isReverse ? $start - $address : $address - $start; } - public function getSortIndex($address, NodeValueInterface $value, NodeValueInterface $container): int + public function getSortIndex(int|string $address, NodeValueInterface $value, NodeValueInterface $container): int { - $count = $this->findArrayLength($container); - if (!isset($count)) { - throw new Exception\AddressNotSortableException($address); - } + $count = $this->findArrayLength($container) + ?? throw new Exception\AddressNotSortableException($address); return $this->getIndex($address, $this->detectStart($count)); } diff --git a/src/Runtime/Matcher/SortedChildMatcherInterface.php b/src/Runtime/Matcher/SortedChildMatcherInterface.php index 26be858..f42b81e 100644 --- a/src/Runtime/Matcher/SortedChildMatcherInterface.php +++ b/src/Runtime/Matcher/SortedChildMatcherInterface.php @@ -8,6 +8,5 @@ interface SortedChildMatcherInterface extends ChildMatcherInterface { - - public function getSortIndex($address, NodeValueInterface $value, NodeValueInterface $container): int; + public function getSortIndex(int|string $address, NodeValueInterface $value, NodeValueInterface $container): int; } diff --git a/src/Runtime/Matcher/StrictElementMatcher.php b/src/Runtime/Matcher/StrictElementMatcher.php index 898d2fc..17621c0 100644 --- a/src/Runtime/Matcher/StrictElementMatcher.php +++ b/src/Runtime/Matcher/StrictElementMatcher.php @@ -12,7 +12,6 @@ final class StrictElementMatcher implements SortedChildMatcherInterface { - private $indexes; public function __construct(int ...$indexes) @@ -20,19 +19,17 @@ public function __construct(int ...$indexes) $this->indexes = $indexes; } - public function match($address, NodeValueInterface $value, NodeValueInterface $container): bool + public function match(int|string $address, NodeValueInterface $value, NodeValueInterface $container): bool { return in_array($address, $this->indexes, true); } - public function getSortIndex($address, NodeValueInterface $value, NodeValueInterface $container): int + public function getSortIndex(int|string $address, NodeValueInterface $value, NodeValueInterface $container): int { $index = array_search($address, $this->indexes); - if (is_int($index)) { - return $index; - } - - throw new Exception\AddressNotSortableException($address); + return is_int($index) + ? $index + : throw new Exception\AddressNotSortableException($address); } } diff --git a/src/Runtime/Matcher/StrictPropertyMatcher.php b/src/Runtime/Matcher/StrictPropertyMatcher.php index 18bca84..0abe68d 100644 --- a/src/Runtime/Matcher/StrictPropertyMatcher.php +++ b/src/Runtime/Matcher/StrictPropertyMatcher.php @@ -10,7 +10,6 @@ final class StrictPropertyMatcher implements SortedChildMatcherInterface { - private $properties; public function __construct(string ...$properties) @@ -18,7 +17,7 @@ public function __construct(string ...$properties) $this->properties = $properties; } - public function match($address, NodeValueInterface $value, NodeValueInterface $container): bool + public function match(int|string $address, NodeValueInterface $value, NodeValueInterface $container): bool { return in_array($address, $this->properties, true); } @@ -27,10 +26,8 @@ public function getSortIndex($address, NodeValueInterface $value, NodeValueInter { $index = array_search($address, $this->properties); - if (is_int($index)) { - return $index; - } - - throw new Exception\AddressNotSortableException($address); + return is_int($index) + ? $index + : throw new Exception\AddressNotSortableException($address); } } diff --git a/src/Runtime/Runtime.php b/src/Runtime/Runtime.php index 470f29b..4b7b92e 100644 --- a/src/Runtime/Runtime.php +++ b/src/Runtime/Runtime.php @@ -6,25 +6,12 @@ final class Runtime implements RuntimeInterface { - - private $valueListFetcher; - - private $evaluator; - - private $literalFactory; - - private $matcherFactory; - public function __construct( - ValueListFetcherInterface $valueListFetcher, - EvaluatorInterface $evaluator, - LiteralFactoryInterface $literalFactory, - Matcher\MatcherFactoryInterface $matcherFactory + private ValueListFetcherInterface $valueListFetcher, + private EvaluatorInterface $evaluator, + private LiteralFactoryInterface $literalFactory, + private Matcher\MatcherFactoryInterface $matcherFactory, ) { - $this->valueListFetcher = $valueListFetcher; - $this->evaluator = $evaluator; - $this->literalFactory = $literalFactory; - $this->matcherFactory = $matcherFactory; } public function getEvaluator(): EvaluatorInterface diff --git a/src/Runtime/RuntimeInterface.php b/src/Runtime/RuntimeInterface.php index e165f4a..70b2665 100644 --- a/src/Runtime/RuntimeInterface.php +++ b/src/Runtime/RuntimeInterface.php @@ -6,7 +6,6 @@ interface RuntimeInterface { - public function getValueListFetcher(): ValueListFetcherInterface; public function getEvaluator(): EvaluatorInterface; diff --git a/src/Runtime/ValueFetcher.php b/src/Runtime/ValueFetcher.php index f05405d..864247c 100644 --- a/src/Runtime/ValueFetcher.php +++ b/src/Runtime/ValueFetcher.php @@ -8,6 +8,7 @@ use Remorhaz\JSON\Data\Value\StructValueInterface; use Remorhaz\JSON\Data\Value\NodeValueInterface; use Remorhaz\JSON\Data\Value\ScalarValueInterface; +use Remorhaz\JSON\Data\Value\ValueInterface; use Remorhaz\JSON\Path\Runtime\Matcher\SortedChildMatcherInterface; use function ksort; @@ -17,11 +18,10 @@ final class ValueFetcher implements ValueFetcherInterface { - /** * @param Matcher\ChildMatcherInterface $matcher * @param NodeValueInterface $value - * @return NodeValueInterface[]|Iterator + * @return Iterator */ public function createChildrenIterator( Matcher\ChildMatcherInterface $matcher, @@ -57,9 +57,14 @@ private function createUnsortedChildStructIterator( } } + /** + * @param SortedChildMatcherInterface $matcher + * @param NodeValueInterface $value + * @return Iterator + */ private function createSortedChildStructIterator( Matcher\SortedChildMatcherInterface $matcher, - NodeValueInterface $value + NodeValueInterface $value, ): Iterator { if (!$value instanceof StructValueInterface) { return; @@ -76,9 +81,14 @@ private function createSortedChildStructIterator( yield from $sortableElements; } + /** + * @param Matcher\ChildMatcherInterface $matcher + * @param NodeValueInterface $value + * @return Iterator + */ public function createDeepChildrenIterator( Matcher\ChildMatcherInterface $matcher, - NodeValueInterface $value + NodeValueInterface $value, ): Iterator { if ($value instanceof ScalarValueInterface) { return; diff --git a/src/Runtime/ValueFetcherInterface.php b/src/Runtime/ValueFetcherInterface.php index a64d084..282c36e 100644 --- a/src/Runtime/ValueFetcherInterface.php +++ b/src/Runtime/ValueFetcherInterface.php @@ -6,17 +6,27 @@ use Iterator; use Remorhaz\JSON\Data\Value\NodeValueInterface; +use Remorhaz\JSON\Data\Value\ValueInterface; interface ValueFetcherInterface { - + /** + * @param Matcher\ChildMatcherInterface $matcher + * @param NodeValueInterface $value + * @return Iterator + */ public function createChildrenIterator( Matcher\ChildMatcherInterface $matcher, - NodeValueInterface $value + NodeValueInterface $value, ): Iterator; + /** + * @param Matcher\ChildMatcherInterface $matcher + * @param NodeValueInterface $value + * @return Iterator + */ public function createDeepChildrenIterator( Matcher\ChildMatcherInterface $matcher, - NodeValueInterface $value + NodeValueInterface $value, ): Iterator; } diff --git a/src/Runtime/ValueListFetcher.php b/src/Runtime/ValueListFetcher.php index 02afb6c..4aafea9 100644 --- a/src/Runtime/ValueListFetcher.php +++ b/src/Runtime/ValueListFetcher.php @@ -15,12 +15,9 @@ final class ValueListFetcher implements ValueListFetcherInterface { - - private $valueFetcher; - - public function __construct(ValueFetcherInterface $valueFetcher) - { - $this->valueFetcher = $valueFetcher; + public function __construct( + private ValueFetcherInterface $valueFetcher, + ) { } /** @@ -30,7 +27,7 @@ public function __construct(ValueFetcherInterface $valueFetcher) */ public function fetchChildren( NodeValueListInterface $source, - Matcher\ChildMatcherInterface $matcher + Matcher\ChildMatcherInterface $matcher, ): NodeValueListInterface { $nodesBuilder = new NodeValueListBuilder(); foreach ($source->getValues() as $sourceIndex => $sourceValue) { @@ -48,7 +45,7 @@ public function fetchChildren( public function fetchChildrenDeep( NodeValueListInterface $source, - Matcher\ChildMatcherInterface $matcher + Matcher\ChildMatcherInterface $matcher, ): NodeValueListInterface { $nodesBuilder = new NodeValueListBuilder(); foreach ($source->getValues() as $sourceIndex => $sourceValue) { @@ -102,7 +99,7 @@ public function fetchFilterContext(NodeValueListInterface $source): NodeValueLis public function fetchFilteredValues( NodeValueListInterface $values, - EvaluatedValueListInterface $results + EvaluatedValueListInterface $results, ): NodeValueListInterface { if (!$values->getIndexMap()->isCompatible($results->getIndexMap())) { throw new Exception\IndexMapMatchFailedException($values, $results); @@ -128,7 +125,7 @@ public function fetchFilteredValues( } $nodesBuilder->addValue( $value, - $values->getIndexMap()->getOuterIndex($index) + $values->getIndexMap()->getOuterIndex($index), ); } @@ -149,7 +146,7 @@ public function joinFilterResults( ): EvaluatedValueListInterface { return new EvaluatedValueList( $evaluatedValues->getIndexMap()->join($contextValues->getIndexMap()), - ...$evaluatedValues->getResults() + ...$evaluatedValues->getResults(), ); } } diff --git a/src/Runtime/ValueListFetcherInterface.php b/src/Runtime/ValueListFetcherInterface.php index ed88eb8..d620eeb 100644 --- a/src/Runtime/ValueListFetcherInterface.php +++ b/src/Runtime/ValueListFetcherInterface.php @@ -9,7 +9,6 @@ interface ValueListFetcherInterface { - /** * @param NodeValueListInterface $source * @param Matcher\ChildMatcherInterface $matcher diff --git a/src/Value/EvaluatedValue.php b/src/Value/EvaluatedValue.php index eebe136..9971839 100644 --- a/src/Value/EvaluatedValue.php +++ b/src/Value/EvaluatedValue.php @@ -6,12 +6,9 @@ final class EvaluatedValue implements EvaluatedValueInterface { - - private $value; - - public function __construct(bool $value) - { - $this->value = $value; + public function __construct( + private bool $value, + ) { } public function getData(): bool diff --git a/src/Value/EvaluatedValueInterface.php b/src/Value/EvaluatedValueInterface.php index d275c53..d7af6e7 100644 --- a/src/Value/EvaluatedValueInterface.php +++ b/src/Value/EvaluatedValueInterface.php @@ -8,6 +8,5 @@ interface EvaluatedValueInterface extends ScalarValueInterface { - public function getData(): bool; } diff --git a/src/Value/EvaluatedValueList.php b/src/Value/EvaluatedValueList.php index a9fab9f..3f7fe0d 100644 --- a/src/Value/EvaluatedValueList.php +++ b/src/Value/EvaluatedValueList.php @@ -4,31 +4,30 @@ namespace Remorhaz\JSON\Path\Value; -use Remorhaz\JSON\Data\Value\ValueInterface; +use function array_values; final class EvaluatedValueList implements EvaluatedValueListInterface { - - private $results; - - private $indexMap; - - private $values; - - public function __construct(IndexMapInterface $indexMap, bool ...$results) - { - $this->indexMap = $indexMap; - $this->results = $results; + /** + * @var list + */ + private array $results; + + /** + * @var list + */ + private array $values; + + public function __construct( + private IndexMapInterface $indexMap, + bool ...$results, + ) { + $this->results = array_values($results); } - public function getValue(int $index): ValueInterface + public function getValue(int $index): EvaluatedValueInterface { - $values = $this->getValues(); - if (!isset($values[$index])) { - throw new Exception\ValueNotFoundException($index, $this); - } - - return $values[$index]; + return $this->getValues()[$index] ?? throw new Exception\ValueNotFoundException($index, $this); } public function getIndexMap(): IndexMapInterface @@ -36,6 +35,9 @@ public function getIndexMap(): IndexMapInterface return $this->indexMap; } + /** + * @return list + */ public function getResults(): array { return $this->results; @@ -43,20 +45,16 @@ public function getResults(): array public function getResult(int $index): bool { - if (!isset($this->results[$index])) { - throw new Exception\ResultNotFoundException($index, $this); - } - - return $this->results[$index]; + return $this->results[$index] + ?? throw new Exception\ResultNotFoundException($index, $this); } + /** + * @return list + */ public function getValues(): array { - if (!isset($this->values)) { - $this->values = array_map([$this, 'createResultValue'], $this->results); - } - - return $this->values; + return $this->values ??= array_map([$this, 'createResultValue'], $this->results); } private function createResultValue(bool $result): EvaluatedValueInterface diff --git a/src/Value/EvaluatedValueListBuilder.php b/src/Value/EvaluatedValueListBuilder.php index 62e3826..05aa0e8 100644 --- a/src/Value/EvaluatedValueListBuilder.php +++ b/src/Value/EvaluatedValueListBuilder.php @@ -6,10 +6,15 @@ final class EvaluatedValueListBuilder { - - private $indexMap = []; - - private $results = []; + /** + * @var list + */ + private array $indexMap = []; + + /** + * @var list + */ + private array $results = []; public function addResult(bool $result, int $outerIndex): self { diff --git a/src/Value/EvaluatedValueListInterface.php b/src/Value/EvaluatedValueListInterface.php index 2168bd5..fe361f0 100644 --- a/src/Value/EvaluatedValueListInterface.php +++ b/src/Value/EvaluatedValueListInterface.php @@ -7,7 +7,7 @@ interface EvaluatedValueListInterface extends ValueListInterface { /** - * @return bool[] + * @return list */ public function getResults(): array; diff --git a/src/Value/Exception/InvalidScalarDataException.php b/src/Value/Exception/InvalidScalarDataException.php index 3355e89..c0d0ac5 100644 --- a/src/Value/Exception/InvalidScalarDataException.php +++ b/src/Value/Exception/InvalidScalarDataException.php @@ -12,12 +12,10 @@ final class InvalidScalarDataException extends DomainException implements ExceptionInterface, DataAwareInterface { - - private $data; - - public function __construct($data, Throwable $previous = null) - { - $this->data = $data; + public function __construct( + private mixed $data, + ?Throwable $previous = null, + ) { parent::__construct($this->buildMessage(), 0, $previous); } @@ -26,7 +24,7 @@ private function buildMessage(): string return "Invalid scalar data"; } - public function getData() + public function getData(): mixed { return $this->data; } diff --git a/src/Value/Exception/OuterIndexNotFoundException.php b/src/Value/Exception/OuterIndexNotFoundException.php index ac60c10..75d299c 100644 --- a/src/Value/Exception/OuterIndexNotFoundException.php +++ b/src/Value/Exception/OuterIndexNotFoundException.php @@ -10,21 +10,17 @@ final class OuterIndexNotFoundException extends OutOfRangeException implements ExceptionInterface { - - private $innerIndex; - - private $indexMap; - - public function __construct(int $innerIndex, IndexMapInterface $indexMap, Throwable $previous = null) - { - $this->innerIndex = $innerIndex; - $this->indexMap = $indexMap; + public function __construct( + private int $innerIndex, + private IndexMapInterface $indexMap, + ?Throwable $previous = null, + ) { parent::__construct($this->buildMessage(), 0, $previous); } private function buildMessage(): string { - return "Outer index not found in index map for inner index {$this->innerIndex}"; + return "Outer index not found in index map for inner index $this->innerIndex"; } public function getInnerIndex(): int diff --git a/src/Value/Exception/ResultNotFoundException.php b/src/Value/Exception/ResultNotFoundException.php index 9959192..4ee0e30 100644 --- a/src/Value/Exception/ResultNotFoundException.php +++ b/src/Value/Exception/ResultNotFoundException.php @@ -10,21 +10,17 @@ final class ResultNotFoundException extends OutOfRangeException implements ExceptionInterface { - - private $index; - - private $values; - - public function __construct(int $index, ValueListInterface $valueList, Throwable $previous = null) - { - $this->index = $index; - $this->values = $valueList; + public function __construct( + private int $index, + private ValueListInterface $values, + ?Throwable $previous = null, + ) { parent::__construct($this->buildMessage(), 0, $previous); } private function buildMessage(): string { - return "Result not found in list at position {$this->index}"; + return "Result not found in list at position $this->index"; } public function getIndex(): int diff --git a/src/Value/Exception/ValueInListWithAnotherOuterIndexException.php b/src/Value/Exception/ValueInListWithAnotherOuterIndexException.php index 575564a..62cbe69 100644 --- a/src/Value/Exception/ValueInListWithAnotherOuterIndexException.php +++ b/src/Value/Exception/ValueInListWithAnotherOuterIndexException.php @@ -10,28 +10,18 @@ final class ValueInListWithAnotherOuterIndexException extends LogicException implements ExceptionInterface { - - private $value; - - private $expectedIndex; - - private $actualIndex; - public function __construct( - NodeValueInterface $value, - int $expectedIndex, - int $actualIndex, - Throwable $previous = null + private NodeValueInterface $value, + private int $expectedIndex, + private int $actualIndex, + ?Throwable $previous = null, ) { - $this->value = $value; - $this->expectedIndex = $expectedIndex; - $this->actualIndex = $actualIndex; parent::__construct($this->buildMessage(), 0, $previous); } private function buildMessage(): string { - return "Value is already in list with outer index {$this->expectedIndex}, not {$this->actualIndex}"; + return "Value is already in list with outer index $this->expectedIndex, not $this->actualIndex"; } public function getValue(): NodeValueInterface diff --git a/src/Value/Exception/ValueNotFoundException.php b/src/Value/Exception/ValueNotFoundException.php index b18796a..b30134c 100644 --- a/src/Value/Exception/ValueNotFoundException.php +++ b/src/Value/Exception/ValueNotFoundException.php @@ -10,21 +10,17 @@ final class ValueNotFoundException extends OutOfRangeException implements ExceptionInterface { - - private $index; - - private $values; - - public function __construct(int $index, ValueListInterface $valueList, Throwable $previous = null) - { - $this->index = $index; - $this->values = $valueList; + public function __construct( + private int $index, + private ValueListInterface $values, + ?Throwable $previous = null, + ) { parent::__construct($this->buildMessage(), 0, $previous); } private function buildMessage(): string { - return "Value not found in list at position {$this->index}"; + return "Value not found in list at position $this->index"; } public function getIndex(): int diff --git a/src/Value/IndexMap.php b/src/Value/IndexMap.php index f3bb790..f05ec13 100644 --- a/src/Value/IndexMap.php +++ b/src/Value/IndexMap.php @@ -4,33 +4,40 @@ namespace Remorhaz\JSON\Path\Value; -use ReturnTypeWillChange; - use function array_keys; +use function array_values; use function count; use function in_array; final class IndexMap implements IndexMapInterface { - - private $outerIndexes; + /** + * @var list + */ + private array $outerIndexes; public function __construct(?int ...$outerIndexes) { - $this->outerIndexes = $outerIndexes; + $this->outerIndexes = array_values($outerIndexes); } - #[ReturnTypeWillChange] - public function count() + #[\ReturnTypeWillChange] + public function count(): int { return count($this->outerIndexes); } + /** + * @return list + */ public function getInnerIndexes(): array { return array_keys($this->outerIndexes); } + /** + * @return list + */ public function getOuterIndexes(): array { return $this->outerIndexes; @@ -38,11 +45,8 @@ public function getOuterIndexes(): array public function getOuterIndex(int $innerIndex): int { - if (!isset($this->outerIndexes[$innerIndex])) { - throw new Exception\OuterIndexNotFoundException($innerIndex, $this); - } - - return $this->outerIndexes[$innerIndex]; + return $this->outerIndexes[$innerIndex] + ?? throw new Exception\OuterIndexNotFoundException($innerIndex, $this); } public function outerIndexExists(int $outerIndex): bool diff --git a/src/Value/IndexMapInterface.php b/src/Value/IndexMapInterface.php index b316223..cc2f1d0 100644 --- a/src/Value/IndexMapInterface.php +++ b/src/Value/IndexMapInterface.php @@ -8,9 +8,14 @@ interface IndexMapInterface extends Countable { - + /** + * @return list + */ public function getInnerIndexes(): array; + /** + * @return list + */ public function getOuterIndexes(): array; public function getOuterIndex(int $innerIndex): int; diff --git a/src/Value/LiteralArrayValue.php b/src/Value/LiteralArrayValue.php index 4dc181a..5abd3b2 100644 --- a/src/Value/LiteralArrayValue.php +++ b/src/Value/LiteralArrayValue.php @@ -7,18 +7,26 @@ use ArrayIterator; use Iterator; use Remorhaz\JSON\Data\Value\ArrayValueInterface; +use Remorhaz\JSON\Data\Value\NodeValueInterface; use Remorhaz\JSON\Data\Value\ValueInterface; +use function array_values; + final class LiteralArrayValue implements ArrayValueInterface, LiteralValueInterface { - - private $values; + /** + * @var list + */ + private array $values; public function __construct(ValueInterface ...$values) { - $this->values = $values; + $this->values = array_values($values); } + /** + * @return Iterator + */ public function createChildIterator(): Iterator { return new ArrayIterator($this->values); diff --git a/src/Value/LiteralScalarValue.php b/src/Value/LiteralScalarValue.php index ae276d5..602e247 100644 --- a/src/Value/LiteralScalarValue.php +++ b/src/Value/LiteralScalarValue.php @@ -10,18 +10,16 @@ final class LiteralScalarValue implements LiteralValueInterface, ScalarValueInterface { + private string|int|float|bool|null $data; - private $data; - - public function __construct($data) + public function __construct(mixed $data) { - if (null !== $data && !is_scalar($data)) { - throw new Exception\InvalidScalarDataException($data); - } - $this->data = $data; + $this->data = null === $data || is_scalar($data) + ? $data + : throw new Exception\InvalidScalarDataException($data); } - public function getData() + public function getData(): string|int|float|bool|null { return $this->data; } diff --git a/src/Value/LiteralValueList.php b/src/Value/LiteralValueList.php index 33e2a74..0a32c2f 100644 --- a/src/Value/LiteralValueList.php +++ b/src/Value/LiteralValueList.php @@ -10,15 +10,10 @@ final class LiteralValueList implements LiteralValueListInterface { - - private $indexMap; - - private $value; - - public function __construct(IndexMapInterface $indexMap, LiteralValueInterface $value) - { - $this->indexMap = $indexMap; - $this->value = $value; + public function __construct( + private IndexMapInterface $indexMap, + private LiteralValueInterface $value, + ) { } public function getLiteral(): LiteralValueInterface @@ -29,13 +24,15 @@ public function getLiteral(): LiteralValueInterface public function getValue(int $index): ValueInterface { $innerIndexes = $this->indexMap->getInnerIndexes(); - if (!isset($innerIndexes[$index])) { - throw new Exception\ValueNotFoundException($index, $this); - } - return $this->value; + return isset($innerIndexes[$index]) + ? $this->value + : throw new Exception\ValueNotFoundException($index, $this); } + /** + * @return list + */ public function getValues(): array { return array_fill_keys($this->indexMap->getInnerIndexes(), $this->value); diff --git a/src/Value/LiteralValueListInterface.php b/src/Value/LiteralValueListInterface.php index 08507d3..df2653d 100644 --- a/src/Value/LiteralValueListInterface.php +++ b/src/Value/LiteralValueListInterface.php @@ -6,6 +6,10 @@ interface LiteralValueListInterface extends ValueListInterface { - public function getLiteral(): LiteralValueInterface; + + /** + * @return list + */ + public function getValues(): array; } diff --git a/src/Value/NodeValueList.php b/src/Value/NodeValueList.php index 34d8147..08fc28c 100644 --- a/src/Value/NodeValueList.php +++ b/src/Value/NodeValueList.php @@ -7,30 +7,29 @@ use Remorhaz\JSON\Data\Value\NodeValueInterface; use Remorhaz\JSON\Data\Value\ValueInterface; +use function array_values; + final class NodeValueList implements NodeValueListInterface { + /** + * @var list + */ + private array $values; - private $values; - - private $indexMap; - - public function __construct(IndexMapInterface $indexMap, NodeValueInterface ...$values) - { - $this->values = $values; - $this->indexMap = $indexMap; + public function __construct( + private IndexMapInterface $indexMap, + NodeValueInterface ...$values, + ) { + $this->values = array_values($values); } public function getValue(int $index): ValueInterface { - if (!isset($this->values[$index])) { - throw new Exception\ValueNotFoundException($index, $this); - } - - return $this->values[$index]; + return $this->values[$index] ?? throw new Exception\ValueNotFoundException($index, $this); } /** - * @return ValueInterface[] + * @return list */ public function getValues(): array { diff --git a/src/Value/NodeValueListBuilder.php b/src/Value/NodeValueListBuilder.php index dcb701e..6d3a0a1 100644 --- a/src/Value/NodeValueListBuilder.php +++ b/src/Value/NodeValueListBuilder.php @@ -8,13 +8,15 @@ final class NodeValueListBuilder { - - private $outerIndexes = []; + /** + * @var list + */ + private array $outerIndexes = []; /** - * @var NodeValueInterface[] + * @var list */ - private $values = []; + private array $values = []; public function addValue(NodeValueInterface $value, int $outerIndex): self { @@ -40,11 +42,10 @@ private function valueExists(NodeValueInterface $value, int $outerIndex): bool continue; } $addedOuterIndex = $this->outerIndexes[$innerIndex]; - if ($outerIndex == $addedOuterIndex) { - return true; - } - throw new Exception\ValueInListWithAnotherOuterIndexException($value, $addedOuterIndex, $outerIndex); + return $outerIndex == $addedOuterIndex + ? true + : throw new Exception\ValueInListWithAnotherOuterIndexException($value, $addedOuterIndex, $outerIndex); } return false; diff --git a/src/Value/NodeValueListInterface.php b/src/Value/NodeValueListInterface.php index 165a31d..5086352 100644 --- a/src/Value/NodeValueListInterface.php +++ b/src/Value/NodeValueListInterface.php @@ -4,6 +4,12 @@ namespace Remorhaz\JSON\Path\Value; +use Remorhaz\JSON\Data\Value\NodeValueInterface; + interface NodeValueListInterface extends ValueListInterface { + /** + * @return list + */ + public function getValues(): array; } diff --git a/src/Value/ValueList.php b/src/Value/ValueList.php index e2d49e6..15b37f0 100644 --- a/src/Value/ValueList.php +++ b/src/Value/ValueList.php @@ -6,17 +6,20 @@ use Remorhaz\JSON\Data\Value\ValueInterface; +use function array_values; + final class ValueList implements ValueListInterface { - - private $indexMap; - - private $values; - - public function __construct(IndexMapInterface $indexMap, ValueInterface ...$values) - { - $this->indexMap = $indexMap; - $this->values = $values; + /** + * @var list + */ + private array $values; + + public function __construct( + private IndexMapInterface $indexMap, + ValueInterface ...$values, + ) { + $this->values = array_values($values); } public function getIndexMap(): IndexMapInterface @@ -24,6 +27,9 @@ public function getIndexMap(): IndexMapInterface return $this->indexMap; } + /** + * @return list + */ public function getValues(): array { return $this->values; @@ -31,10 +37,6 @@ public function getValues(): array public function getValue(int $index): ValueInterface { - if (!isset($this->values[$index])) { - throw new Exception\ValueNotFoundException($index, $this); - } - - return $this->values[$index]; + return $this->values[$index] ?? throw new Exception\ValueNotFoundException($index, $this); } } diff --git a/src/Value/ValueListBuilder.php b/src/Value/ValueListBuilder.php index 1c8a48f..c246501 100644 --- a/src/Value/ValueListBuilder.php +++ b/src/Value/ValueListBuilder.php @@ -8,10 +8,15 @@ final class ValueListBuilder { - - private $outerIndexes = []; - - private $values = []; + /** + * @var list + */ + private array $outerIndexes = []; + + /** + * @var list + */ + private array $values = []; public function addValue(ValueInterface $value, int $outerIndex): self { diff --git a/src/Value/ValueListInterface.php b/src/Value/ValueListInterface.php index 9b89afa..1fee582 100644 --- a/src/Value/ValueListInterface.php +++ b/src/Value/ValueListInterface.php @@ -8,11 +8,10 @@ interface ValueListInterface { - public function getValue(int $index): ValueInterface; /** - * @return ValueInterface[] + * @return list */ public function getValues(): array; diff --git a/tests/JsonPathTest.php b/tests/JsonPathTest.php index b371163..c6addb7 100644 --- a/tests/JsonPathTest.php +++ b/tests/JsonPathTest.php @@ -16,7 +16,6 @@ */ class JsonPathTest extends TestCase { - private $example; public function setUp(): void diff --git a/tests/MemoryLeakTest.php b/tests/MemoryLeakTest.php index 5dbe681..817ec08 100644 --- a/tests/MemoryLeakTest.php +++ b/tests/MemoryLeakTest.php @@ -16,7 +16,6 @@ */ class MemoryLeakTest extends TestCase { - public function testQueryCompilation(): void { $queryFactory = QueryFactory::create(); diff --git a/tests/Parser/Exception/ParserCreationFailedExceptionTest.php b/tests/Parser/Exception/ParserCreationFailedExceptionTest.php index 0a991de..21b8f13 100644 --- a/tests/Parser/Exception/ParserCreationFailedExceptionTest.php +++ b/tests/Parser/Exception/ParserCreationFailedExceptionTest.php @@ -13,7 +13,6 @@ */ class ParserCreationFailedExceptionTest extends TestCase { - public function testGetMessage_Constructed_ReturnsMatchingValue(): void { $exception = new ParserCreationFailedException(); diff --git a/tests/Parser/Exception/QueryAstNotBuiltExceptionTest.php b/tests/Parser/Exception/QueryAstNotBuiltExceptionTest.php index 9226b14..cd93c1e 100644 --- a/tests/Parser/Exception/QueryAstNotBuiltExceptionTest.php +++ b/tests/Parser/Exception/QueryAstNotBuiltExceptionTest.php @@ -13,7 +13,6 @@ */ class QueryAstNotBuiltExceptionTest extends TestCase { - public function testGetMessage_Constructed_ReturnsMatchingValue(): void { $exception = new QueryAstNotBuiltException('a'); diff --git a/tests/Parser/Ll1ParserFactoryTest.php b/tests/Parser/Ll1ParserFactoryTest.php index b07fa84..307c820 100644 --- a/tests/Parser/Ll1ParserFactoryTest.php +++ b/tests/Parser/Ll1ParserFactoryTest.php @@ -15,7 +15,6 @@ */ class Ll1ParserFactoryTest extends TestCase { - /** * @param string $source * @param bool $isDefinite diff --git a/tests/Parser/ParserTest.php b/tests/Parser/ParserTest.php index 88a3bf7..445f4ff 100644 --- a/tests/Parser/ParserTest.php +++ b/tests/Parser/ParserTest.php @@ -17,7 +17,6 @@ */ class ParserTest extends TestCase { - public function testBuildQueryAst_Constructed_ReturnsTreeInstancePassedToLl1ParserFactory(): void { $ll1ParserFactory = $this->createMock(Ll1ParserFactoryInterface::class); diff --git a/tests/Parser/TranslationSchemeTest.php b/tests/Parser/TranslationSchemeTest.php index 32d6323..594239f 100644 --- a/tests/Parser/TranslationSchemeTest.php +++ b/tests/Parser/TranslationSchemeTest.php @@ -13,7 +13,6 @@ */ class TranslationSchemeTest extends TestCase { - /** * @param string $path * @param bool $expectedValue diff --git a/tests/Processor/Exception/IndefiniteQueryExceptionTest.php b/tests/Processor/Exception/IndefiniteQueryExceptionTest.php index d63af80..b102943 100644 --- a/tests/Processor/Exception/IndefiniteQueryExceptionTest.php +++ b/tests/Processor/Exception/IndefiniteQueryExceptionTest.php @@ -14,7 +14,6 @@ */ class IndefiniteQueryExceptionTest extends TestCase { - public function testGetMessage_Constructed_ReturnsMatchingValue(): void { $exception = new IndefiniteQueryException( diff --git a/tests/Processor/Exception/InvalidPathElementExceptionTest.php b/tests/Processor/Exception/InvalidPathElementExceptionTest.php index 3aa2ebf..8e3466a 100644 --- a/tests/Processor/Exception/InvalidPathElementExceptionTest.php +++ b/tests/Processor/Exception/InvalidPathElementExceptionTest.php @@ -13,7 +13,6 @@ */ class InvalidPathElementExceptionTest extends TestCase { - public function testGetMessage_Constructed_ReturnsMatchingValue(): void { $exception = new InvalidPathElementException(1); diff --git a/tests/Processor/Exception/QueryNotAddressableExceptionTest.php b/tests/Processor/Exception/QueryNotAddressableExceptionTest.php index 43a986f..24b6363 100644 --- a/tests/Processor/Exception/QueryNotAddressableExceptionTest.php +++ b/tests/Processor/Exception/QueryNotAddressableExceptionTest.php @@ -14,7 +14,6 @@ */ class QueryNotAddressableExceptionTest extends TestCase { - public function testGetMessage_Constructed_ReturnsMatchingValue(): void { $exception = new QueryNotAddressableException( diff --git a/tests/Processor/Mutator/Exception/ReplaceAtNestedPathsExceptionTest.php b/tests/Processor/Mutator/Exception/ReplaceAtNestedPathsExceptionTest.php index 539fdcc..ff24754 100644 --- a/tests/Processor/Mutator/Exception/ReplaceAtNestedPathsExceptionTest.php +++ b/tests/Processor/Mutator/Exception/ReplaceAtNestedPathsExceptionTest.php @@ -14,7 +14,6 @@ */ class ReplaceAtNestedPathsExceptionTest extends TestCase { - public function testGetMessage_Constructed_ReturnsMatchingValue(): void { $exception = new ReplaceAtNestedPathsException( diff --git a/tests/Processor/PathEncoderTest.php b/tests/Processor/PathEncoderTest.php index ad2cae1..953b129 100644 --- a/tests/Processor/PathEncoderTest.php +++ b/tests/Processor/PathEncoderTest.php @@ -15,7 +15,6 @@ */ class PathEncoderTest extends TestCase { - /** * @param array $pathElements * @param string $expectedValue diff --git a/tests/Processor/ProcessorTest.php b/tests/Processor/ProcessorTest.php index 6f8c168..d4858f7 100644 --- a/tests/Processor/ProcessorTest.php +++ b/tests/Processor/ProcessorTest.php @@ -17,7 +17,6 @@ */ class ProcessorTest extends TestCase { - /** * @param string $json * @param string $path diff --git a/tests/Processor/Result/Exception/MoreThanOneValueInListExceptionTest.php b/tests/Processor/Result/Exception/MoreThanOneValueInListExceptionTest.php index 19eb2f0..010f71f 100644 --- a/tests/Processor/Result/Exception/MoreThanOneValueInListExceptionTest.php +++ b/tests/Processor/Result/Exception/MoreThanOneValueInListExceptionTest.php @@ -14,7 +14,6 @@ */ class MoreThanOneValueInListExceptionTest extends TestCase { - public function testGetMessage_Constructed_ReturnsMatchingValue(): void { $exception = new MoreThanOneValueInListException( diff --git a/tests/Processor/Result/Exception/PathNotFoundInValueExceptionTest.php b/tests/Processor/Result/Exception/PathNotFoundInValueExceptionTest.php index e4bdc87..a09a24f 100644 --- a/tests/Processor/Result/Exception/PathNotFoundInValueExceptionTest.php +++ b/tests/Processor/Result/Exception/PathNotFoundInValueExceptionTest.php @@ -14,7 +14,6 @@ */ class PathNotFoundInValueExceptionTest extends TestCase { - public function testGetMessage_Constructed_ReturnsMatchingValue(): void { $exception = new PathNotFoundInValueException( diff --git a/tests/Processor/Result/Exception/SelectedValueNotFoundExceptionTest.php b/tests/Processor/Result/Exception/SelectedValueNotFoundExceptionTest.php index 2facafc..157a111 100644 --- a/tests/Processor/Result/Exception/SelectedValueNotFoundExceptionTest.php +++ b/tests/Processor/Result/Exception/SelectedValueNotFoundExceptionTest.php @@ -13,7 +13,6 @@ */ class SelectedValueNotFoundExceptionTest extends TestCase { - public function testGetMessage_Constructed_ReturnsMatchingValue(): void { $exception = new SelectedValueNotFoundException(); diff --git a/tests/Processor/Result/ExistingSelectOnePathResultTest.php b/tests/Processor/Result/ExistingSelectOnePathResultTest.php index 8538625..5c30888 100644 --- a/tests/Processor/Result/ExistingSelectOnePathResultTest.php +++ b/tests/Processor/Result/ExistingSelectOnePathResultTest.php @@ -14,7 +14,6 @@ */ class ExistingSelectOnePathResultTest extends TestCase { - public function testExists_Always_ReturnsTrue(): void { $result = new ExistingSelectOnePathResult( diff --git a/tests/Processor/Result/ExistingValueResultTest.php b/tests/Processor/Result/ExistingValueResultTest.php index 81f8642..175de8f 100644 --- a/tests/Processor/Result/ExistingValueResultTest.php +++ b/tests/Processor/Result/ExistingValueResultTest.php @@ -15,7 +15,6 @@ */ class ExistingValueResultTest extends TestCase { - public function testExists_Always_ReturnsTrue(): void { $result = new ExistingValueResult( diff --git a/tests/Processor/Result/NonExistingSelectOnePathResultTest.php b/tests/Processor/Result/NonExistingSelectOnePathResultTest.php index d5b076b..f329ef5 100644 --- a/tests/Processor/Result/NonExistingSelectOnePathResultTest.php +++ b/tests/Processor/Result/NonExistingSelectOnePathResultTest.php @@ -13,7 +13,6 @@ */ class NonExistingSelectOnePathResultTest extends TestCase { - public function testExists_Always_ReturnsFalse(): void { $result = new NonExistingSelectOnePathResult(); diff --git a/tests/Processor/Result/NonExistingValueResultTest.php b/tests/Processor/Result/NonExistingValueResultTest.php index c054fdd..07dffb9 100644 --- a/tests/Processor/Result/NonExistingValueResultTest.php +++ b/tests/Processor/Result/NonExistingValueResultTest.php @@ -13,7 +13,6 @@ */ class NonExistingValueResultTest extends TestCase { - public function testExists_Always_ReturnsFalse(): void { $result = new NonExistingValueResult(); diff --git a/tests/Processor/Result/ResultFactoryTest.php b/tests/Processor/Result/ResultFactoryTest.php index 56dbc60..23bd0cf 100644 --- a/tests/Processor/Result/ResultFactoryTest.php +++ b/tests/Processor/Result/ResultFactoryTest.php @@ -21,7 +21,6 @@ */ class ResultFactoryTest extends TestCase { - public function testCreateSelectResult_NoValuesInList_ResultEncodesToEmptyArray(): void { $factory = new ResultFactory( diff --git a/tests/Processor/Result/SelectPathsResultTest.php b/tests/Processor/Result/SelectPathsResultTest.php index 7bb2d80..13fd127 100644 --- a/tests/Processor/Result/SelectPathsResultTest.php +++ b/tests/Processor/Result/SelectPathsResultTest.php @@ -14,7 +14,6 @@ */ class SelectPathsResultTest extends TestCase { - public function testGet_ConstructedWithoutPaths_ReturnsEmptyArray(): void { $result = new SelectPathsResult( diff --git a/tests/Processor/Result/SelectResultTest.php b/tests/Processor/Result/SelectResultTest.php index f6c1b67..85a9925 100644 --- a/tests/Processor/Result/SelectResultTest.php +++ b/tests/Processor/Result/SelectResultTest.php @@ -15,7 +15,6 @@ */ class SelectResultTest extends TestCase { - public function testGet_ConstructedWithoutValues_ReturnsEmptyArray(): void { $result = new SelectResult( diff --git a/tests/Query/AstTranslatorTest.php b/tests/Query/AstTranslatorTest.php index 8f99212..3567c08 100644 --- a/tests/Query/AstTranslatorTest.php +++ b/tests/Query/AstTranslatorTest.php @@ -28,7 +28,6 @@ */ class AstTranslatorTest extends TestCase { - /** * @throws UniLexException */ diff --git a/tests/Query/CallbackBuilderTest.php b/tests/Query/CallbackBuilderTest.php index 3404ab6..9e6f61e 100644 --- a/tests/Query/CallbackBuilderTest.php +++ b/tests/Query/CallbackBuilderTest.php @@ -18,7 +18,6 @@ */ class CallbackBuilderTest extends TestCase { - public function testGetCallbackCode_CallbackIsNotSet_ThrowsException(): void { $callbackBuilder = new CallbackBuilder(); diff --git a/tests/Query/CapabilitiesTest.php b/tests/Query/CapabilitiesTest.php index 260e656..97b9419 100644 --- a/tests/Query/CapabilitiesTest.php +++ b/tests/Query/CapabilitiesTest.php @@ -12,7 +12,6 @@ */ class CapabilitiesTest extends TestCase { - /** * @param bool $isDefinite * @param bool $expectedValue diff --git a/tests/Query/Exception/PropertiesNotFoundExceptionTest.php b/tests/Query/Exception/PropertiesNotFoundExceptionTest.php index 4fa7208..19606ce 100644 --- a/tests/Query/Exception/PropertiesNotFoundExceptionTest.php +++ b/tests/Query/Exception/PropertiesNotFoundExceptionTest.php @@ -13,7 +13,6 @@ */ class PropertiesNotFoundExceptionTest extends TestCase { - public function testGetMessage_Constructed_ReturnsMatchingValue(): void { $exception = new CapabilitiesNotFoundException(); diff --git a/tests/Query/Exception/QueryAstNotTranslatedExceptionTest.php b/tests/Query/Exception/QueryAstNotTranslatedExceptionTest.php index 143c5ef..35209e3 100644 --- a/tests/Query/Exception/QueryAstNotTranslatedExceptionTest.php +++ b/tests/Query/Exception/QueryAstNotTranslatedExceptionTest.php @@ -14,7 +14,6 @@ */ class QueryAstNotTranslatedExceptionTest extends TestCase { - public function testGetMessage_Constructed_ReturnsMatchingValue(): void { $exception = new QueryAstNotTranslatedException(new Tree()); diff --git a/tests/Query/Exception/QueryCallbackCodeNotFoundExceptionTest.php b/tests/Query/Exception/QueryCallbackCodeNotFoundExceptionTest.php index fd81dd1..af06606 100644 --- a/tests/Query/Exception/QueryCallbackCodeNotFoundExceptionTest.php +++ b/tests/Query/Exception/QueryCallbackCodeNotFoundExceptionTest.php @@ -13,7 +13,6 @@ */ class QueryCallbackCodeNotFoundExceptionTest extends TestCase { - public function testGetMessage_Constructed_ReturnsMatchingValue(): void { $exception = new QueryCallbackCodeNotFoundException(); diff --git a/tests/Query/Exception/QueryExecutionFailedExceptionTest.php b/tests/Query/Exception/QueryExecutionFailedExceptionTest.php index ee07fbd..95df2a7 100644 --- a/tests/Query/Exception/QueryExecutionFailedExceptionTest.php +++ b/tests/Query/Exception/QueryExecutionFailedExceptionTest.php @@ -13,7 +13,6 @@ */ class QueryExecutionFailedExceptionTest extends TestCase { - public function testGetSource_ConstructedWithGivenSource_ReturnsSameValue(): void { $exception = new QueryExecutionFailedException('a', 'b'); diff --git a/tests/Query/Exception/ReferenceAlreadyExistsExceptionTest.php b/tests/Query/Exception/ReferenceAlreadyExistsExceptionTest.php index 800fc73..b6099d0 100644 --- a/tests/Query/Exception/ReferenceAlreadyExistsExceptionTest.php +++ b/tests/Query/Exception/ReferenceAlreadyExistsExceptionTest.php @@ -13,7 +13,6 @@ */ class ReferenceAlreadyExistsExceptionTest extends TestCase { - public function testGetMessage_Constructed_ReturnsMatchingValue(): void { $exception = new ReferenceAlreadyExistsException(1); diff --git a/tests/Query/Exception/ReferenceNotFoundExceptionTest.php b/tests/Query/Exception/ReferenceNotFoundExceptionTest.php index e86b40c..492a18c 100644 --- a/tests/Query/Exception/ReferenceNotFoundExceptionTest.php +++ b/tests/Query/Exception/ReferenceNotFoundExceptionTest.php @@ -13,7 +13,6 @@ */ class ReferenceNotFoundExceptionTest extends TestCase { - public function testGetMessage_Constructed_ReturnsMatchingValue(): void { $exception = new ReferenceNotFoundException(1); diff --git a/tests/Query/LazyQueryTest.php b/tests/Query/LazyQueryTest.php index 560c641..c372edb 100644 --- a/tests/Query/LazyQueryTest.php +++ b/tests/Query/LazyQueryTest.php @@ -21,7 +21,6 @@ */ class LazyQueryTest extends TestCase { - /** * @throws ExceptionInterface */ diff --git a/tests/Query/QueryFactoryTest.php b/tests/Query/QueryFactoryTest.php index ebe06eb..bb5d911 100644 --- a/tests/Query/QueryFactoryTest.php +++ b/tests/Query/QueryFactoryTest.php @@ -19,7 +19,6 @@ */ class QueryFactoryTest extends TestCase { - public function testCreate_Always_ReturnsQueryFactoryInstance(): void { self::assertInstanceOf(QueryFactory::class, QueryFactory::create()); diff --git a/tests/Query/QueryTest.php b/tests/Query/QueryTest.php index ac5e656..652787c 100644 --- a/tests/Query/QueryTest.php +++ b/tests/Query/QueryTest.php @@ -26,7 +26,6 @@ */ class QueryTest extends TestCase { - public function testInvoke_ConstructedWithCallback_CallsSameCallback(): void { $rootValue = $this->createMock(NodeValueInterface::class); diff --git a/tests/Query/QueryValidatorTest.php b/tests/Query/QueryValidatorTest.php index 8871caa..923414f 100644 --- a/tests/Query/QueryValidatorTest.php +++ b/tests/Query/QueryValidatorTest.php @@ -16,7 +16,6 @@ */ class QueryValidatorTest extends TestCase { - public function testGetDefiniteQuery_GivenDefiniteQuery_ReturnsSameInstance(): void { $capabilities = new Capabilities(true, false); diff --git a/tests/Runtime/Aggregator/AggregatorCollectionTest.php b/tests/Runtime/Aggregator/AggregatorCollectionTest.php index dc8fd10..1f3fb05 100644 --- a/tests/Runtime/Aggregator/AggregatorCollectionTest.php +++ b/tests/Runtime/Aggregator/AggregatorCollectionTest.php @@ -18,7 +18,6 @@ */ class AggregatorCollectionTest extends TestCase { - /** * @param string $name * @param string $expectedClass diff --git a/tests/Runtime/Aggregator/AvgAggregatorTest.php b/tests/Runtime/Aggregator/AvgAggregatorTest.php index 0be012b..2a467a0 100644 --- a/tests/Runtime/Aggregator/AvgAggregatorTest.php +++ b/tests/Runtime/Aggregator/AvgAggregatorTest.php @@ -16,7 +16,6 @@ */ class AvgAggregatorTest extends TestCase { - public function testTryAggregate_EmptyArray_ReturnsNull(): void { $aggregator = new AvgAggregator(); diff --git a/tests/Runtime/Aggregator/Exception/AggregateFunctionNotFoundExceptionTest.php b/tests/Runtime/Aggregator/Exception/AggregateFunctionNotFoundExceptionTest.php index 5332ac6..11b0a5b 100644 --- a/tests/Runtime/Aggregator/Exception/AggregateFunctionNotFoundExceptionTest.php +++ b/tests/Runtime/Aggregator/Exception/AggregateFunctionNotFoundExceptionTest.php @@ -13,7 +13,6 @@ */ class AggregateFunctionNotFoundExceptionTest extends TestCase { - public function testGetMessage_Constructed_ReturnsMatchingValue(): void { $exception = new AggregateFunctionNotFoundException('a'); diff --git a/tests/Runtime/Aggregator/Exception/MaxElementNotFoundExceptionTest.php b/tests/Runtime/Aggregator/Exception/MaxElementNotFoundExceptionTest.php index 640de8b..76804a2 100644 --- a/tests/Runtime/Aggregator/Exception/MaxElementNotFoundExceptionTest.php +++ b/tests/Runtime/Aggregator/Exception/MaxElementNotFoundExceptionTest.php @@ -14,7 +14,6 @@ */ class MaxElementNotFoundExceptionTest extends TestCase { - public function testGetMessage_Constructed_ReturnsMatchingValue(): void { $exception = new MaxElementNotFoundException([], []); diff --git a/tests/Runtime/Aggregator/Exception/MinElementNotFoundExceptionTest.php b/tests/Runtime/Aggregator/Exception/MinElementNotFoundExceptionTest.php index aca0188..f7ca6ba 100644 --- a/tests/Runtime/Aggregator/Exception/MinElementNotFoundExceptionTest.php +++ b/tests/Runtime/Aggregator/Exception/MinElementNotFoundExceptionTest.php @@ -14,7 +14,6 @@ */ class MinElementNotFoundExceptionTest extends TestCase { - public function testGetMessage_Constructed_ReturnsMatchingValue(): void { $exception = new MinElementNotFoundException([], []); diff --git a/tests/Runtime/Aggregator/LengthAggregatorTest.php b/tests/Runtime/Aggregator/LengthAggregatorTest.php index 5b902ec..7b0aa64 100644 --- a/tests/Runtime/Aggregator/LengthAggregatorTest.php +++ b/tests/Runtime/Aggregator/LengthAggregatorTest.php @@ -18,7 +18,6 @@ */ class LengthAggregatorTest extends TestCase { - public function testTryAggregate_NonArrayValue_ReturnsNull(): void { $aggregator = new LengthAggregator(); diff --git a/tests/Runtime/Aggregator/MaxAggregatorTest.php b/tests/Runtime/Aggregator/MaxAggregatorTest.php index 71ab57e..d25a92a 100644 --- a/tests/Runtime/Aggregator/MaxAggregatorTest.php +++ b/tests/Runtime/Aggregator/MaxAggregatorTest.php @@ -15,7 +15,6 @@ */ class MaxAggregatorTest extends TestCase { - public function testTryAggregate_ArrayWithZeroElement_ReturnsNull(): void { $aggregator = new MaxAggregator(); diff --git a/tests/Runtime/Aggregator/MinAggregatorTest.php b/tests/Runtime/Aggregator/MinAggregatorTest.php index 59430fd..7022e99 100644 --- a/tests/Runtime/Aggregator/MinAggregatorTest.php +++ b/tests/Runtime/Aggregator/MinAggregatorTest.php @@ -15,7 +15,6 @@ */ class MinAggregatorTest extends TestCase { - public function testTryAggregate_ArrayWithZeroElement_ReturnsNull(): void { $aggregator = new MinAggregator(); diff --git a/tests/Runtime/Aggregator/NumericAggregatorTest.php b/tests/Runtime/Aggregator/NumericAggregatorTest.php index 49b20af..8ef39b4 100644 --- a/tests/Runtime/Aggregator/NumericAggregatorTest.php +++ b/tests/Runtime/Aggregator/NumericAggregatorTest.php @@ -16,7 +16,6 @@ */ class NumericAggregatorTest extends TestCase { - public function testTryAggregate_NonArrayValue_ReturnsNull(): void { $aggregator = $this->getMockForAbstractClass(NumericAggregator::class); diff --git a/tests/Runtime/Aggregator/StdDevAggregatorTest.php b/tests/Runtime/Aggregator/StdDevAggregatorTest.php index 58dd83e..19ab230 100644 --- a/tests/Runtime/Aggregator/StdDevAggregatorTest.php +++ b/tests/Runtime/Aggregator/StdDevAggregatorTest.php @@ -16,7 +16,6 @@ */ class StdDevAggregatorTest extends TestCase { - public function testTryAggregate_EmptyArray_ReturnsNull(): void { $aggregator = new StdDevAggregator(); diff --git a/tests/Runtime/Aggregator/UniqueNumericAggregatorTest.php b/tests/Runtime/Aggregator/UniqueNumericAggregatorTest.php index 0998c47..561a43c 100644 --- a/tests/Runtime/Aggregator/UniqueNumericAggregatorTest.php +++ b/tests/Runtime/Aggregator/UniqueNumericAggregatorTest.php @@ -15,7 +15,6 @@ */ class UniqueNumericAggregatorTest extends TestCase { - public function testTryAggregate_ArrayWithDifferentValues_AggregatesBothValues(): void { $aggregator = $this->getMockForAbstractClass(UniqueNumericAggregator::class); diff --git a/tests/Runtime/ComparatorCollectionTest.php b/tests/Runtime/ComparatorCollectionTest.php index 51ff430..a8c3811 100644 --- a/tests/Runtime/ComparatorCollectionTest.php +++ b/tests/Runtime/ComparatorCollectionTest.php @@ -16,7 +16,6 @@ */ class ComparatorCollectionTest extends TestCase { - public function testEqual_Constructed_ReturnsEqualComparatorInstance(): void { $comparators = new ComparatorCollection( diff --git a/tests/Runtime/EvaluatorTest.php b/tests/Runtime/EvaluatorTest.php index fde9734..93ee910 100644 --- a/tests/Runtime/EvaluatorTest.php +++ b/tests/Runtime/EvaluatorTest.php @@ -29,7 +29,6 @@ */ class EvaluatorTest extends TestCase { - public function testLogicalOr_EmptyLists_ReturnsEmptyList(): void { $evaluator = new Evaluator( diff --git a/tests/Runtime/Exception/IndexMapMatchFailedExceptionTest.php b/tests/Runtime/Exception/IndexMapMatchFailedExceptionTest.php index 38807cc..c273c2d 100644 --- a/tests/Runtime/Exception/IndexMapMatchFailedExceptionTest.php +++ b/tests/Runtime/Exception/IndexMapMatchFailedExceptionTest.php @@ -14,7 +14,6 @@ */ class IndexMapMatchFailedExceptionTest extends TestCase { - public function testGetLeftValues_ConstructedWithGivenLeftValues_ReturnsSameInstance(): void { $leftValues = $this->createMock(ValueListInterface::class); diff --git a/tests/Runtime/Exception/InvalidContextValueExceptionTest.php b/tests/Runtime/Exception/InvalidContextValueExceptionTest.php index 1736d27..c02b543 100644 --- a/tests/Runtime/Exception/InvalidContextValueExceptionTest.php +++ b/tests/Runtime/Exception/InvalidContextValueExceptionTest.php @@ -14,7 +14,6 @@ */ class InvalidContextValueExceptionTest extends TestCase { - public function testGetMessage_Constructed_ReturnsMatchingValue(): void { $exception = new InvalidContextValueException( diff --git a/tests/Runtime/Exception/InvalidFilterValueExceptionTest.php b/tests/Runtime/Exception/InvalidFilterValueExceptionTest.php index f14b2cf..3b29002 100644 --- a/tests/Runtime/Exception/InvalidFilterValueExceptionTest.php +++ b/tests/Runtime/Exception/InvalidFilterValueExceptionTest.php @@ -14,7 +14,6 @@ */ class InvalidFilterValueExceptionTest extends TestCase { - public function testGetMessage_Constructed_ReturnsMatchingValue(): void { $exception = new InvalidFilterValueException( diff --git a/tests/Runtime/Exception/InvalidRegExpExceptionTest.php b/tests/Runtime/Exception/InvalidRegExpExceptionTest.php index 860ab34..e020c12 100644 --- a/tests/Runtime/Exception/InvalidRegExpExceptionTest.php +++ b/tests/Runtime/Exception/InvalidRegExpExceptionTest.php @@ -13,7 +13,6 @@ */ class InvalidRegExpExceptionTest extends TestCase { - public function testGetMessage_Constructed_ReturnsMatchingValue(): void { $exception = new InvalidRegExpException('a'); diff --git a/tests/Runtime/Exception/LiteralEvaluationFailedExceptionTest.php b/tests/Runtime/Exception/LiteralEvaluationFailedExceptionTest.php index b0f5dac..b9fb5a9 100644 --- a/tests/Runtime/Exception/LiteralEvaluationFailedExceptionTest.php +++ b/tests/Runtime/Exception/LiteralEvaluationFailedExceptionTest.php @@ -14,7 +14,6 @@ */ class LiteralEvaluationFailedExceptionTest extends TestCase { - public function testGetMessage_Constructed_ReturnsMatchingValue(): void { $exception = new LiteralEvaluationFailedException( diff --git a/tests/Runtime/Exception/UnexpectedNodeValueFetchedExceptionTest.php b/tests/Runtime/Exception/UnexpectedNodeValueFetchedExceptionTest.php index 56107a0..5962203 100644 --- a/tests/Runtime/Exception/UnexpectedNodeValueFetchedExceptionTest.php +++ b/tests/Runtime/Exception/UnexpectedNodeValueFetchedExceptionTest.php @@ -14,7 +14,6 @@ */ class UnexpectedNodeValueFetchedExceptionTest extends TestCase { - public function testGetMessage_Constructed_ReturnsMatchingValue(): void { $exception = new UnexpectedNodeValueFetchedException( diff --git a/tests/Runtime/Matcher/AnyChildMatcherTest.php b/tests/Runtime/Matcher/AnyChildMatcherTest.php index d3e8d0c..b208d86 100644 --- a/tests/Runtime/Matcher/AnyChildMatcherTest.php +++ b/tests/Runtime/Matcher/AnyChildMatcherTest.php @@ -13,7 +13,6 @@ */ class AnyChildMatcherTest extends TestCase { - public function testMatch_Always_ReturnsTrue(): void { $matcher = new AnyChildMatcher(); diff --git a/tests/Runtime/Matcher/Exception/AddressNotSortableExceptionTest.php b/tests/Runtime/Matcher/Exception/AddressNotSortableExceptionTest.php index cad7bde..f649fdf 100644 --- a/tests/Runtime/Matcher/Exception/AddressNotSortableExceptionTest.php +++ b/tests/Runtime/Matcher/Exception/AddressNotSortableExceptionTest.php @@ -13,7 +13,6 @@ */ class AddressNotSortableExceptionTest extends TestCase { - public function testGetMessage_ConstructedWithAddress_ReturnsMatchingValue(): void { $exception = new AddressNotSortableException(1); diff --git a/tests/Runtime/Matcher/MatcherFactoryTest.php b/tests/Runtime/Matcher/MatcherFactoryTest.php index ec1af94..d907f48 100644 --- a/tests/Runtime/Matcher/MatcherFactoryTest.php +++ b/tests/Runtime/Matcher/MatcherFactoryTest.php @@ -17,7 +17,6 @@ */ class MatcherFactoryTest extends TestCase { - public function testMatchAnyChild_Constructed_ReturnsAnyChildMatcherInstance(): void { $factory = new MatcherFactory(); diff --git a/tests/Runtime/Matcher/SliceElementMatcherTest.php b/tests/Runtime/Matcher/SliceElementMatcherTest.php index f6c0d87..cf7f91b 100644 --- a/tests/Runtime/Matcher/SliceElementMatcherTest.php +++ b/tests/Runtime/Matcher/SliceElementMatcherTest.php @@ -18,7 +18,6 @@ */ class SliceElementMatcherTest extends TestCase { - public function testMatch_MatchingIndexNonArrayContainer_ReturnsFalse(): void { $matcher = new SliceElementMatcher(0, 2, 1); @@ -82,7 +81,7 @@ private function createArrayValueOfLength(int $length): NodeValueInterface return new NodeArrayValue( array_fill(0, $length, null), $this->createMock(PathInterface::class), - $this->createMock(NodeValueFactoryInterface::class) + $this->createMock(NodeValueFactoryInterface::class), ); } diff --git a/tests/Runtime/Matcher/StrictElementMatcherTest.php b/tests/Runtime/Matcher/StrictElementMatcherTest.php index 37008a6..2c130df 100644 --- a/tests/Runtime/Matcher/StrictElementMatcherTest.php +++ b/tests/Runtime/Matcher/StrictElementMatcherTest.php @@ -13,7 +13,6 @@ */ class StrictElementMatcherTest extends TestCase { - public function testMatch_ConstructedWithGivenAddressInIndexes_ReturnsTrue(): void { $matcher = new StrictElementMatcher(1); diff --git a/tests/Runtime/Matcher/StrictPropertyMatcherTest.php b/tests/Runtime/Matcher/StrictPropertyMatcherTest.php index 444c2d9..7296197 100644 --- a/tests/Runtime/Matcher/StrictPropertyMatcherTest.php +++ b/tests/Runtime/Matcher/StrictPropertyMatcherTest.php @@ -13,7 +13,6 @@ */ class StrictPropertyMatcherTest extends TestCase { - public function testMatch_ConstructedWithGivenAddressInProperties_ReturnsTrue(): void { $matcher = new StrictPropertyMatcher('a'); diff --git a/tests/Runtime/RuntimeTest.php b/tests/Runtime/RuntimeTest.php index 25d6faa..ead0d9c 100644 --- a/tests/Runtime/RuntimeTest.php +++ b/tests/Runtime/RuntimeTest.php @@ -16,7 +16,6 @@ */ class RuntimeTest extends TestCase { - public function testGetEvaluator_ConstructedWithGivenEvaluator_ReturnsSameInstance(): void { $evaluator = $this->createMock(EvaluatorInterface::class); diff --git a/tests/TokenMatcherTest.php b/tests/TokenMatcherTest.php index a52e1ae..c025750 100644 --- a/tests/TokenMatcherTest.php +++ b/tests/TokenMatcherTest.php @@ -15,7 +15,6 @@ */ class TokenMatcherTest extends TestCase { - /** * @param string $input * @param array $expectedValue diff --git a/tests/Value/EvaluatedValueListBuilderTest.php b/tests/Value/EvaluatedValueListBuilderTest.php index 6d04c26..09bca26 100644 --- a/tests/Value/EvaluatedValueListBuilderTest.php +++ b/tests/Value/EvaluatedValueListBuilderTest.php @@ -12,7 +12,6 @@ */ class EvaluatedValueListBuilderTest extends TestCase { - public function testBuild_NoResultsAdded_ReturnsListWithEmptyIndexMap(): void { $builder = new EvaluatedValueListBuilder(); diff --git a/tests/Value/EvaluatedValueListTest.php b/tests/Value/EvaluatedValueListTest.php index 7068ee7..455b213 100644 --- a/tests/Value/EvaluatedValueListTest.php +++ b/tests/Value/EvaluatedValueListTest.php @@ -21,7 +21,6 @@ */ class EvaluatedValueListTest extends TestCase { - public function testGetIndexMap_ConstructedWithIndexMap_ReturnsSameInstance(): void { $indexMap = new IndexMap(); diff --git a/tests/Value/EvaluatedValueTest.php b/tests/Value/EvaluatedValueTest.php index af74b6a..2c7a6a8 100644 --- a/tests/Value/EvaluatedValueTest.php +++ b/tests/Value/EvaluatedValueTest.php @@ -12,7 +12,6 @@ */ class EvaluatedValueTest extends TestCase { - /** * @param bool $value * @param bool $expectedValue diff --git a/tests/Value/Exception/InvalidScalarDataExceptionTest.php b/tests/Value/Exception/InvalidScalarDataExceptionTest.php index f6fc161..dab2177 100644 --- a/tests/Value/Exception/InvalidScalarDataExceptionTest.php +++ b/tests/Value/Exception/InvalidScalarDataExceptionTest.php @@ -13,7 +13,6 @@ */ class InvalidScalarDataExceptionTest extends TestCase { - public function testGetMessage_Constructed_ReturnsMatchingValue(): void { $exception = new InvalidScalarDataException(null); diff --git a/tests/Value/Exception/OuterIndexNotFoundExceptionTest.php b/tests/Value/Exception/OuterIndexNotFoundExceptionTest.php index 8dedc62..a11753f 100644 --- a/tests/Value/Exception/OuterIndexNotFoundExceptionTest.php +++ b/tests/Value/Exception/OuterIndexNotFoundExceptionTest.php @@ -14,7 +14,6 @@ */ class OuterIndexNotFoundExceptionTest extends TestCase { - public function testGetMessage_Constructed_ReturnsMatchingValue(): void { $exception = new OuterIndexNotFoundException( diff --git a/tests/Value/Exception/ResultNotFoundExceptionTest.php b/tests/Value/Exception/ResultNotFoundExceptionTest.php index babac63..f57ea32 100644 --- a/tests/Value/Exception/ResultNotFoundExceptionTest.php +++ b/tests/Value/Exception/ResultNotFoundExceptionTest.php @@ -14,7 +14,6 @@ */ class ResultNotFoundExceptionTest extends TestCase { - public function testGetMessage_Constructed_ReturnsMatchingValue(): void { $exception = new ResultNotFoundException( diff --git a/tests/Value/Exception/ValueInListWithAnotherOuterIndexExceptionTest.php b/tests/Value/Exception/ValueInListWithAnotherOuterIndexExceptionTest.php index 1a1c25f..1e52ac7 100644 --- a/tests/Value/Exception/ValueInListWithAnotherOuterIndexExceptionTest.php +++ b/tests/Value/Exception/ValueInListWithAnotherOuterIndexExceptionTest.php @@ -14,7 +14,6 @@ */ class ValueInListWithAnotherOuterIndexExceptionTest extends TestCase { - public function testGetMessage_ConstructedWithIndexes_ReturnsMatchingValue(): void { $value = $this->createMock(NodeValueInterface::class); diff --git a/tests/Value/Exception/ValueNotFoundExceptionTest.php b/tests/Value/Exception/ValueNotFoundExceptionTest.php index 87d3447..26f15a9 100644 --- a/tests/Value/Exception/ValueNotFoundExceptionTest.php +++ b/tests/Value/Exception/ValueNotFoundExceptionTest.php @@ -14,7 +14,6 @@ */ class ValueNotFoundExceptionTest extends TestCase { - public function testGetMessage_Constructed_ReturnsMatchingValue(): void { $exception = new ValueNotFoundException( diff --git a/tests/Value/IndexMapTest.php b/tests/Value/IndexMapTest.php index fa4a373..df522f1 100644 --- a/tests/Value/IndexMapTest.php +++ b/tests/Value/IndexMapTest.php @@ -13,7 +13,6 @@ */ class IndexMapTest extends TestCase { - /** * @param array $outerIndexes * @param array $expectedValue diff --git a/tests/Value/LiteralArrayValueListExceptionTest.php b/tests/Value/LiteralArrayValueListExceptionTest.php index bbff7ef..47121b8 100644 --- a/tests/Value/LiteralArrayValueListExceptionTest.php +++ b/tests/Value/LiteralArrayValueListExceptionTest.php @@ -15,7 +15,6 @@ */ class LiteralArrayValueListExceptionTest extends TestCase { - public function testGetIndexMap_ConstructedWithGivenIndexMap_ReturnsSameInstance(): void { $indexMap = $this->createMock(IndexMapInterface::class); diff --git a/tests/Value/LiteralArrayValueTest.php b/tests/Value/LiteralArrayValueTest.php index e8e2a78..b8c07bc 100644 --- a/tests/Value/LiteralArrayValueTest.php +++ b/tests/Value/LiteralArrayValueTest.php @@ -15,7 +15,6 @@ */ class LiteralArrayValueTest extends TestCase { - public function testCreateChildIterator_ConstructedWithoutValues_ReturnsEmptyIterator(): void { $array = new LiteralArrayValue(); diff --git a/tests/Value/LiteralScalarValueTest.php b/tests/Value/LiteralScalarValueTest.php index d350d7e..a73f336 100644 --- a/tests/Value/LiteralScalarValueTest.php +++ b/tests/Value/LiteralScalarValueTest.php @@ -13,7 +13,6 @@ */ class LiteralScalarValueTest extends TestCase { - public function testConstruct_InvalidValue_ThrowsException(): void { $this->expectException(InvalidScalarDataException::class); diff --git a/tests/Value/LiteralValueListTest.php b/tests/Value/LiteralValueListTest.php index 8e5b070..a1091ff 100644 --- a/tests/Value/LiteralValueListTest.php +++ b/tests/Value/LiteralValueListTest.php @@ -16,7 +16,6 @@ */ class LiteralValueListTest extends TestCase { - public function testGetIndexMap_ConstructedWithGivenIndexMap_ReturnsSameInstance(): void { $indexMap = $this->createMock(IndexMapInterface::class); diff --git a/tests/Value/NodeValueListBuilderTest.php b/tests/Value/NodeValueListBuilderTest.php index 6e917a9..7cb475d 100644 --- a/tests/Value/NodeValueListBuilderTest.php +++ b/tests/Value/NodeValueListBuilderTest.php @@ -15,7 +15,6 @@ */ class NodeValueListBuilderTest extends TestCase { - public function testBuild_NoValuesAdded_ReturnsListWithEmptyIndexMap(): void { $builder = new NodeValueListBuilder(); diff --git a/tests/Value/NodeValueListTest.php b/tests/Value/NodeValueListTest.php index 5c51ead..efbc091 100644 --- a/tests/Value/NodeValueListTest.php +++ b/tests/Value/NodeValueListTest.php @@ -15,7 +15,6 @@ */ class NodeValueListTest extends TestCase { - public function testGetIndexMap_ConstructedWithGivenIndexMapInstance_ReturnsSameInstance(): void { $indexMap = $this->createMock(IndexMapInterface::class); diff --git a/tests/Value/ValueListBuilderTest.php b/tests/Value/ValueListBuilderTest.php index 4e5934d..c214fe5 100644 --- a/tests/Value/ValueListBuilderTest.php +++ b/tests/Value/ValueListBuilderTest.php @@ -13,7 +13,6 @@ */ class ValueListBuilderTest extends TestCase { - public function testBuild_NoValuesAdded_ReturnsListWithEmptyIndexMap(): void { $builder = new ValueListBuilder();