diff --git a/.github/diff.json b/.github/diff.json new file mode 100644 index 0000000..73a3348 --- /dev/null +++ b/.github/diff.json @@ -0,0 +1,14 @@ +{ + "problemMatcher": [ + { + "owner": "diff", + "pattern": [ + { + "regexp": "--- a/(.*)", + "file": 1, + "message": 1 + } + ] + } + ] +} diff --git a/.github/php-syntax.json b/.github/php-syntax.json new file mode 100644 index 0000000..c9c5738 --- /dev/null +++ b/.github/php-syntax.json @@ -0,0 +1,15 @@ +{ + "problemMatcher": [ + { + "owner": "php -l", + "pattern": [ + { + "regexp": "^\\s*(PHP\\s+)?([a-zA-Z\\s]+):\\s+(.*)\\s+in\\s+(\\S+)\\s+on\\s+line\\s+(\\d+)$", + "file": 4, + "line": 5, + "message": 3 + } + ] + } + ] +} diff --git a/.github/workflows/Test.yml b/.github/workflows/Test.yml index f07a044..dafc1eb 100644 --- a/.github/workflows/Test.yml +++ b/.github/workflows/Test.yml @@ -1,4 +1,3 @@ ---- name: Test on: @@ -12,8 +11,6 @@ on: paths: - '**.php' - 'composer.json' - branches: - - 'main' workflow_dispatch: jobs: @@ -21,7 +18,10 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: [ '8.0', '8.1', '8.2' ] + php: + - '8.0' + - '8.1' + - '8.2' continue-on-error: ${{ matrix.php == '8.2' }} name: PHP ${{ matrix.php }} Test @@ -34,10 +34,17 @@ jobs: with: php-version: ${{ matrix.php }} extensions: json + tools: phpcs coverage: pcov env: COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Setup problem matchers for PHP syntax check + run: echo "::add-matcher::.github/php-syntax.json" + + - run: | + ! find . -type f -name '*.php' -exec php -l '{}' \; 2>&1 |grep -v '^No syntax errors detected' + - name: Setup problem matchers for PHPUnit run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" @@ -45,7 +52,7 @@ jobs: run: composer update --prefer-dist --no-interaction - name: Run phpcs - run: composer cs-check -- -v + run: phpcs -- -v - name: Execute tests run: composer test -- -v --coverage-clover=coverage.xml diff --git a/.github/workflows/UpdateContributors.yml b/.github/workflows/UpdateContributors.yml index 3bf2bbb..3a2abfb 100644 --- a/.github/workflows/UpdateContributors.yml +++ b/.github/workflows/UpdateContributors.yml @@ -1,4 +1,3 @@ ---- name: Update Contributors on: [ push, workflow_dispatch] @@ -9,10 +8,10 @@ jobs: steps: - name: Git checkout - uses: actions/checkout@v2.4.2 + uses: actions/checkout@v3 - name: Update Contributors - uses: BobAnkh/add-contributors@v0.2.2 + uses: BobAnkh/add-contributors@master with: REPO_NAME: 'SoftCreatR/JSONPath' CONTRIBUTOR: '## Contributors ✨' diff --git a/.github/workflows/codestyle.yml b/.github/workflows/codestyle.yml new file mode 100644 index 0000000..5ef041c --- /dev/null +++ b/.github/workflows/codestyle.yml @@ -0,0 +1,30 @@ +name: Code Style + +on: + push: + paths: + - '**.php' + pull_request: + paths: + - '**.php' + +jobs: + php: + name: PHP + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Setup PHP with tools + uses: shivammathur/setup-php@v2 + with: + php-version: '8.1' + extensions: json + tools: cs2pr, phpcs, php-cs-fixer + + - name: phpcs + run: phpcs -n -q --report=checkstyle | cs2pr + + - name: php-cs-fixer + run: php-cs-fixer fix --dry-run --diff diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..77c3ad2 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,121 @@ +exclude('*/vendor/*') + ->exclude('node_modules') + ->in(__DIR__); + +return (new PhpCsFixer\Config()) + ->setRiskyAllowed(true) + ->setRules([ + '@PSR1' => true, + '@PSR2' => true, + '@PSR12' => true, + '@PER' => true, + + 'array_push' => true, + 'backtick_to_shell_exec' => true, + 'no_alias_language_construct_call' => true, + 'no_mixed_echo_print' => true, + 'pow_to_exponentiation' => true, + 'random_api_migration' => true, + + 'array_syntax' => ['syntax' => 'short'], + 'no_multiline_whitespace_around_double_arrow' => true, + 'no_trailing_comma_in_singleline_array' => true, + 'no_whitespace_before_comma_in_array' => true, + 'normalize_index_brace' => true, + 'whitespace_after_comma_in_array' => true, + + 'non_printable_character' => ['use_escape_sequences_in_strings' => true], + + 'magic_constant_casing' => true, + 'magic_method_casing' => true, + 'native_function_casing' => true, + 'native_function_type_declaration_casing' => true, + + 'cast_spaces' => ['space' => 'none'], + 'no_unset_cast' => true, + + 'class_attributes_separation' => true, + 'no_null_property_initialization' => true, + 'self_accessor' => true, + 'single_class_element_per_statement' => true, + + 'no_empty_comment' => true, + 'single_line_comment_style' => ['comment_types' => ['hash']], + + 'native_constant_invocation' => ['strict' => false], + + 'no_alternative_syntax' => true, + 'no_trailing_comma_in_list_call' => true, + 'no_unneeded_control_parentheses' => ['statements' => ['break', 'clone', 'continue', 'echo_print', 'return', 'switch_case', 'yield', 'yield_from']], + 'no_unneeded_curly_braces' => ['namespaces' => true], + 'switch_continue_to_break' => true, + 'trailing_comma_in_multiline' => ['elements' => ['arrays']], + + 'function_typehint_space' => true, + 'lambda_not_used_import' => true, + 'native_function_invocation' => ['include' => ['@internal']], + 'no_unreachable_default_argument_value' => true, + 'nullable_type_declaration_for_default_null_value' => true, + 'static_lambda' => true, + + 'fully_qualified_strict_types' => true, + 'no_unused_imports' => true, + + 'dir_constant' => true, + 'explicit_indirect_variable' => true, + 'function_to_constant' => true, + 'is_null' => true, + 'no_unset_on_property' => true, + + 'list_syntax' => ['syntax' => 'short'], + + 'clean_namespace' => true, + 'no_leading_namespace_whitespace' => true, + + 'no_homoglyph_names' => true, + + 'binary_operator_spaces' => true, + 'concat_space' => ['spacing' => 'one'], + 'increment_style' => ['style' => 'post'], + 'logical_operators' => true, + 'object_operator_without_whitespace' => true, + 'operator_linebreak' => true, + 'standardize_increment' => true, + 'standardize_not_equals' => true, + 'ternary_to_elvis_operator' => true, + 'ternary_to_null_coalescing' => true, + 'unary_operator_spaces' => true, + + 'no_useless_return' => true, + 'return_assignment' => true, + + 'multiline_whitespace_before_semicolons' => true, + 'no_empty_statement' => true, + 'no_singleline_whitespace_before_semicolons' => true, + 'space_after_semicolon' => ['remove_in_empty_for_expressions' => true], + + 'escape_implicit_backslashes' => true, + 'explicit_string_variable' => true, + 'heredoc_to_nowdoc' => true, + 'no_binary_string' => true, + 'simple_to_complex_string_variable' => true, + + 'array_indentation' => true, + 'blank_line_before_statement' => ['statements' => ['return', 'exit']], + 'method_chaining_indentation' => true, + 'no_extra_blank_lines' => ['tokens' => ['case', 'continue', 'curly_brace_block', 'default', 'extra', 'parenthesis_brace_block', 'square_brace_block', 'switch', 'throw', 'use']], + 'no_spaces_around_offset' => true, + + // SoftCreatR style + 'global_namespace_import' => [ + 'import_classes' => true, + 'import_constants' => true, + 'import_functions' => false, + ], + 'ordered_imports' => [ + 'imports_order' => ['class', 'function', 'const'], + ], + ]) + ->setFinder($finder); diff --git a/CHANGELOG.md b/CHANGELOG.md index 0dfa985..068a4b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +### 0.8.2 +- AccessHelper & RecursiveFilter now return a plain `object`, rather than an `ArrayAccess` object + ### 0.8.1 - Removed strict_types - Applied some PSR-12 related changes diff --git a/composer.json b/composer.json index 21f6446..f1855c1 100644 --- a/composer.json +++ b/composer.json @@ -1,8 +1,8 @@ { "name": "softcreatr/jsonpath", "description": "JSONPath implementation for parsing, searching and flattening arrays", - "version": "0.8.1", "license": "MIT", + "version": "0.8.2", "authors": [ { "name": "Stephen Frank", @@ -17,22 +17,24 @@ "role": "Developer" } ], + "support": { + "email": "hello@1-2.dev", + "issues": "https://github.com/SoftCreatR/JSONPath/issues", + "forum": "https://github.com/SoftCreatR/JSONPath/discussions", + "source": "https://github.com/SoftCreatR/JSONPath" + }, "require": { "php": ">=8.0", "ext-json": "*" }, - "replace": { - "flow/jsonpath": "*" - }, "require-dev": { - "phpunit/phpunit": "^9.5", - "roave/security-advisories": "dev-latest", - "squizlabs/php_codesniffer": "^3.7" + "phpunit/phpunit": "^9.6", + "roave/security-advisories": "dev-latest" }, - "config": { - "optimize-autoloader": true, - "preferred-install": "dist" + "replace": { + "flow/jsonpath": "*" }, + "minimum-stability": "stable", "autoload": { "psr-4": { "Flow\\JSONPath\\": "src/" @@ -43,16 +45,11 @@ "Flow\\JSONPath\\Test\\": "tests/" } }, - "minimum-stability": "stable", + "config": { + "optimize-autoloader": true, + "preferred-install": "dist" + }, "scripts": { - "cs-check": "phpcs", - "cs-fix": "phpcbf", "test": "phpunit" - }, - "support": { - "email": "hello@1-2.dev", - "forum": "https://github.com/SoftCreatR/JSONPath/discussions", - "issues": "https://github.com/SoftCreatR/JSONPath/issues", - "source": "https://github.com/SoftCreatR/JSONPath" } } diff --git a/src/Filters/RecursiveFilter.php b/src/Filters/RecursiveFilter.php index 440b3ef..b2ce2de 100644 --- a/src/Filters/RecursiveFilter.php +++ b/src/Filters/RecursiveFilter.php @@ -8,7 +8,6 @@ namespace Flow\JSONPath\Filters; -use ArrayAccess; use Flow\JSONPath\AccessHelper; use Flow\JSONPath\JSONPathException;