diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 66651fb0e0256e1b639c9fc8c623dcf5d667a6d3..841d0dd91876a192b29cd056bf29551ba1ab9d27 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,6 +6,9 @@ on: name: "CI" +env: + COMPOSER_ROOT_VERSION: "4.0-dev" + permissions: contents: read @@ -17,12 +20,12 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install PHP uses: shivammathur/setup-php@v2 with: - php-version: 8.1 + php-version: 8.3 coverage: none - name: Run PHP-CS-Fixer @@ -35,12 +38,12 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install PHP uses: shivammathur/setup-php@v2 with: - php-version: 8.1 + php-version: 8.3 coverage: none - name: Install dependencies with composer @@ -58,13 +61,13 @@ jobs: fail-fast: false matrix: php-version: - - "8.1" - "8.2" - "8.3" + - "8.4" steps: - name: "Checkout" - uses: "actions/checkout@v3" + uses: "actions/checkout@v4" - name: "Install PHP with extensions" uses: "shivammathur/setup-php@v2" @@ -72,13 +75,6 @@ jobs: php-version: "${{ matrix.php-version }}" coverage: "pcov" - - name: "Cache dependencies installed with Composer" - uses: "actions/cache@v2" - with: - path: "~/.composer/cache" - key: "php${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('**/composer.json') }}" - restore-keys: "php${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-" - - name: "Install dependencies with Composer" run: "./tools/composer update --no-ansi --no-interaction --no-progress" diff --git a/.phive/phars.xml b/.phive/phars.xml index c3faedd9f8b1f111f1ab3b3df21eea1c45ec0cef..e9c9ac614ce23a493db0e191ef7f71bdc5974af7 100644 --- a/.phive/phars.xml +++ b/.phive/phars.xml @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <phive xmlns="https://phar.io/phive"> - <phar name="php-cs-fixer" version="^3.0" installed="3.14.3" location="./tools/php-cs-fixer" copy="true"/> - <phar name="psalm" version="^5.0" installed="5.6.0" location="./tools/psalm" copy="true"/> - <phar name="composer" version="^2.0.3" installed="2.5.1" location="./tools/composer" copy="true"/> + <phar name="php-cs-fixer" version="^3.0" installed="3.41.1" location="./tools/php-cs-fixer" copy="true"/> + <phar name="psalm" version="^5.0" installed="5.18.0" location="./tools/psalm" copy="true"/> + <phar name="composer" version="^2.0.3" installed="2.6.6" location="./tools/composer" copy="true"/> </phive> diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 8ec0b2fcfe0c507980a101e7338925468dbb326d..46e3f336501fce4520b5f5f5cbc4941bbb5ff5d8 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -25,6 +25,10 @@ $config->setFinder($finder) 'backtick_to_shell_exec' => true, 'binary_operator_spaces' => [ 'operators' => [ + '*=' => 'align_single_space_minimal', + '+=' => 'align_single_space_minimal', + '-=' => 'align_single_space_minimal', + '/=' => 'align_single_space_minimal', '=' => 'align_single_space_minimal', '=>' => 'align_single_space_minimal', ], @@ -33,6 +37,7 @@ $config->setFinder($finder) 'blank_line_before_statement' => [ 'statements' => [ 'break', + 'case', 'continue', 'declare', 'default', @@ -44,6 +49,7 @@ $config->setFinder($finder) 'if', 'include', 'include_once', + 'phpdoc', 'require', 'require_once', 'return', @@ -52,15 +58,21 @@ $config->setFinder($finder) 'try', 'while', 'yield', + 'yield_from', ], ], - 'braces' => [ - 'position_after_anonymous_constructs' => 'next', + 'blank_lines_before_namespace' => [ + 'max_line_breaks' => 1, + 'min_line_breaks' => 0, + ], + 'braces_position' => [ + 'anonymous_classes_opening_brace' => 'next_line_unless_newline_at_signature_end', + 'anonymous_functions_opening_brace' => 'next_line_unless_newline_at_signature_end', ], 'cast_spaces' => true, 'class_attributes_separation' => [ 'elements' => [ - 'const' => 'one', + 'const' => 'none', 'method' => 'one', 'property' => 'only_if_meta' ] @@ -70,10 +82,13 @@ $config->setFinder($finder) 'combine_consecutive_issets' => true, 'combine_consecutive_unsets' => true, 'combine_nested_dirname' => true, - 'compact_nullable_typehint' => true, + 'compact_nullable_type_declaration' => true, 'concat_space' => ['spacing' => 'one'], 'constant_case' => true, + 'control_structure_braces' => true, + 'control_structure_continuation_position' => true, 'declare_equal_normalize' => ['space' => 'none'], + 'declare_parentheses' => true, 'declare_strict_types' => true, 'dir_constant' => true, 'echo_tag_syntax' => true, @@ -87,7 +102,6 @@ $config->setFinder($finder) 'fully_qualified_strict_types' => true, 'function_declaration' => true, 'function_to_constant' => true, - 'function_typehint_space' => true, 'get_class_to_class_keyword' => true, 'global_namespace_import' => [ 'import_classes' => true, @@ -99,9 +113,10 @@ $config->setFinder($finder) 'implode_call' => true, 'include' => true, 'increment_style' => [ - 'style' => PhpCsFixer\Fixer\Operator\IncrementStyleFixer::STYLE_POST, + 'style' => 'post', ], 'indentation_type' => true, + 'integer_literal_case' => true, 'is_null' => true, 'lambda_not_used_import' => true, 'line_ending' => true, @@ -115,6 +130,8 @@ $config->setFinder($finder) 'method_argument_space' => [ 'on_multiline' => 'ensure_fully_multiline', ], + 'method_chaining_indentation' => true, + 'modernize_strpos' => true, 'modernize_types_casting' => true, 'multiline_comment_opening_closing' => true, 'multiline_whitespace_before_semicolons' => true, @@ -125,10 +142,10 @@ $config->setFinder($finder) '@internal', ], ], - 'native_function_type_declaration_casing' => true, - 'new_with_braces' => [ - 'named_class' => false, + 'native_type_declaration_casing' => true, + 'new_with_parentheses' => [ 'anonymous_class' => false, + 'named_class' => false, ], 'no_alias_functions' => true, 'no_alias_language_construct_call' => true, @@ -136,7 +153,6 @@ $config->setFinder($finder) 'no_binary_string' => true, 'no_blank_lines_after_class_opening' => true, 'no_blank_lines_after_phpdoc' => true, - 'no_blank_lines_before_namespace' => true, 'no_break_comment' => true, 'no_closing_tag' => true, 'no_empty_comment' => true, @@ -148,13 +164,14 @@ $config->setFinder($finder) 'no_leading_namespace_whitespace' => true, 'no_mixed_echo_print' => ['use' => 'print'], 'no_multiline_whitespace_around_double_arrow' => true, + 'no_multiple_statements_per_line' => true, 'no_null_property_initialization' => true, 'no_php4_constructor' => true, 'no_short_bool_cast' => true, 'no_singleline_whitespace_before_semicolons' => true, + 'no_space_around_double_colon' => true, 'no_spaces_after_function_name' => true, 'no_spaces_around_offset' => true, - 'no_spaces_inside_parenthesis' => true, 'no_superfluous_elseif' => true, 'no_superfluous_phpdoc_tags' => [ 'allow_mixed' => true, @@ -163,15 +180,17 @@ $config->setFinder($finder) 'no_trailing_whitespace' => true, 'no_trailing_whitespace_in_comment' => true, 'no_trailing_whitespace_in_string' => true, + 'no_unneeded_braces' => true, 'no_unneeded_control_parentheses' => true, - 'no_unneeded_curly_braces' => true, 'no_unneeded_final_method' => true, 'no_unneeded_import_alias' => true, 'no_unreachable_default_argument_value' => true, 'no_unset_cast' => true, 'no_unset_on_property' => true, 'no_unused_imports' => true, + 'no_useless_concat_operator' => true, 'no_useless_else' => true, + 'no_useless_nullsafe_operator' => true, 'no_useless_return' => true, 'no_useless_sprintf' => true, 'no_whitespace_before_comma_in_array' => true, @@ -179,6 +198,7 @@ $config->setFinder($finder) 'non_printable_character' => true, 'normalize_index_brace' => true, 'object_operator_without_whitespace' => true, + 'octal_notation' => true, 'operator_linebreak' => [ 'only_booleans' => true, 'position' => 'end', @@ -209,9 +229,9 @@ $config->setFinder($finder) ], 'ordered_imports' => [ 'imports_order' => [ - PhpCsFixer\Fixer\Import\OrderedImportsFixer::IMPORT_TYPE_CONST, - PhpCsFixer\Fixer\Import\OrderedImportsFixer::IMPORT_TYPE_FUNCTION, - PhpCsFixer\Fixer\Import\OrderedImportsFixer::IMPORT_TYPE_CLASS, + 'const', + 'function', + 'class', ] ], 'ordered_interfaces' => [ @@ -219,6 +239,7 @@ $config->setFinder($finder) 'order' => 'alpha', ], 'ordered_traits' => true, + 'ordered_types' => true, 'php_unit_set_up_tear_down_visibility' => true, 'php_unit_test_case_static_method_calls' => [ 'call_type' => 'this', @@ -242,6 +263,7 @@ $config->setFinder($finder) 'uses', ], ], + 'phpdoc_param_order' => true, 'phpdoc_return_self_reference' => true, 'phpdoc_scalar' => true, 'phpdoc_separation' => true, @@ -249,7 +271,7 @@ $config->setFinder($finder) 'phpdoc_summary' => true, 'phpdoc_tag_casing' => true, 'phpdoc_tag_type' => true, - 'phpdoc_to_comment' => true, + 'phpdoc_to_comment' => false, 'phpdoc_trim' => true, 'phpdoc_trim_consecutive_blank_line_separation' => true, 'phpdoc_types' => ['groups' => ['simple', 'meta']], @@ -271,14 +293,20 @@ $config->setFinder($finder) 'single_class_element_per_statement' => true, 'single_import_per_statement' => true, 'single_line_after_imports' => true, + 'single_line_comment_spacing' => true, 'single_quote' => true, - 'single_space_after_construct' => true, + 'single_space_around_construct' => true, 'single_trait_insert_per_statement' => true, 'space_after_semicolon' => true, + 'spaces_inside_parentheses' => [ + 'space' => 'none', + ], 'standardize_increment' => true, 'standardize_not_equals' => true, + 'statement_indentation' => true, 'static_lambda' => true, 'strict_param' => true, + 'string_length_to_empty'=> true, 'string_line_ending' => true, 'switch_case_semicolon_to_colon' => true, 'switch_case_space' => true, @@ -288,13 +316,18 @@ $config->setFinder($finder) 'ternary_to_null_coalescing' => true, 'trailing_comma_in_multiline' => [ 'elements' => [ - 'arrays' + 'arguments', + 'arrays', + 'match', ] ], 'trim_array_spaces' => true, - 'types_spaces' => [ - 'space' => 'none', + 'type_declaration_spaces' => [ + 'elements' => [ + 'function', + ], ], + 'types_spaces' => true, 'unary_operator_spaces' => true, 'visibility_required' => [ 'elements' => [ @@ -307,4 +340,6 @@ $config->setFinder($finder) 'whitespace_after_comma_in_array' => true, ]); +$config->setCacheFile(__DIR__ . '/.php-cs-fixer.cache/' . sha1(@trim((string) @shell_exec('git rev-parse --abbrev-ref HEAD')))); + return $config; diff --git a/.psalm/config.xml b/.psalm/config.xml index a2312368927875601649cf6dcefd85feeaec616f..343cc8e3ed28b3bb8dcaaec70244b56f6daf71a5 100644 --- a/.psalm/config.xml +++ b/.psalm/config.xml @@ -5,6 +5,8 @@ xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" resolveFromConfigFile="false" errorBaseline=".psalm/baseline.xml" + findUnusedBaselineEntry="true" + findUnusedCode="false" > <projectFiles> <directory name="src" /> diff --git a/ChangeLog.md b/ChangeLog.md index 4ff97182d690bc15a8c115afe17349a730bcc6f0..e2572fd3823e69d4f7dc25e2625f9c2ed8bd4e6b 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -2,6 +2,12 @@ All notable changes to `sebastianbergmann/code-unit-reverse-lookup` are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles. +## [4.0.0] - 2024-02-02 + +### Removed + +* This component is no longer supported on PHP 8.1 + ## [3.0.0] - 2023-02-03 ### Removed @@ -38,6 +44,7 @@ All notable changes to `sebastianbergmann/code-unit-reverse-lookup` are document * Initial release +[4.0.0]: https://github.com/sebastianbergmann/code-unit-reverse-lookup/compare/3.0...4.0.0 [3.0.0]: https://github.com/sebastianbergmann/code-unit-reverse-lookup/compare/2.0.3...3.0.0 [2.0.3]: https://github.com/sebastianbergmann/code-unit-reverse-lookup/compare/2.0.2...2.0.3 [2.0.2]: https://github.com/sebastianbergmann/code-unit-reverse-lookup/compare/2.0.1...2.0.2 diff --git a/LICENSE b/LICENSE index 16e1ba9a2b23c9b959bfce7b2d1af62da0596c75..86c455d71ed8c75ee1fb77219507a5149f931ee8 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ BSD 3-Clause License -Copyright (c) 2016-2023, Sebastian Bergmann +Copyright (c) 2016-2024, Sebastian Bergmann All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/SECURITY.md b/SECURITY.md index d4ee967bfd2bbeb6b066646e289511de1a9f9eb4..d88ff0019ab197dfcdae122a01b634db778d591d 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -1,9 +1,30 @@ # Security Policy -This library is intended to be used in development environments only. For instance, it is used by the testing framework PHPUnit. There is no reason why this library should be installed on a webserver. +If you believe you have found a security vulnerability in the library that is developed in this repository, please report it to us through coordinated disclosure. -**If you upload this library to a webserver then your deployment process is broken. On a more general note, if your `vendor` directory is publicly accessible on your webserver then your deployment process is also broken.** +**Please do not report security vulnerabilities through public GitHub issues, discussions, or pull requests.** -## Security Contact Information +Instead, please email `sebastian@phpunit.de`. + +Please include as much of the information listed below as you can to help us better understand and resolve the issue: + +* The type of issue +* Full paths of source file(s) related to the manifestation of the issue +* The location of the affected source code (tag/branch/commit or direct URL) +* Any special configuration required to reproduce the issue +* Step-by-step instructions to reproduce the issue +* Proof-of-concept or exploit code (if possible) +* Impact of the issue, including how an attacker might exploit the issue + +This information will help us triage your report more quickly. + +## Web Context + +The library that is developed in this repository was either extracted from [PHPUnit](https://github.com/sebastianbergmann/phpunit) or developed specifically as a dependency for PHPUnit. + +The library is developed with a focus on development environments and the command-line. No specific testing or hardening with regard to using the library in an HTTP or web context or with untrusted input data is performed. The library might also contain functionality that intentionally exposes internal application data for debugging purposes. + +If the library is used in a web application, the application developer is responsible for filtering inputs or escaping outputs as necessary and for verifying that the used functionality is safe for use within the intended context. + +Vulnerabilities specific to the use outside a development context will be fixed as applicable, provided that the fix does not have an averse effect on the primary use case for development purposes. -After the above, if you still would like to report a security vulnerability, please email `sebastian@phpunit.de`. diff --git a/composer.json b/composer.json index 37cc1ccf187149339ce2c09dab6818b7a8271e34..bf05a9e9252dcbb64347650dc7196eafcbf4b2be 100644 --- a/composer.json +++ b/composer.json @@ -9,19 +9,23 @@ "email": "sebastian@phpunit.de" } ], + "support": { + "issues": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/issues", + "security": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/security/policy" + }, "config": { "platform": { - "php": "8.1.0" + "php": "8.2.0" }, "optimize-autoloader": true, "sort-packages": true }, "prefer-stable": true, "require": { - "php": ">=8.1" + "php": ">=8.2" }, "require-dev": { - "phpunit/phpunit": "^10.0" + "phpunit/phpunit": "^11.0" }, "autoload": { "classmap": [ @@ -30,7 +34,7 @@ }, "extra": { "branch-alias": { - "dev-main": "3.0-dev" + "dev-main": "4.0-dev" } } } diff --git a/phpunit.xml b/phpunit.xml index bf94af03817ad36bfbe8e0c99a756d57250f807f..911e767835b1224b2c7100d1e25eb41adfa89c9a 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" + xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" bootstrap="vendor/autoload.php" cacheDirectory=".phpunit.cache" executionOrder="depends,defects" @@ -16,9 +16,9 @@ </testsuite> </testsuites> - <coverage> + <source> <include> - <directory suffix=".php">src</directory> + <directory>src</directory> </include> - </coverage> + </source> </phpunit> diff --git a/src/Wizard.php b/src/Wizard.php index 355405edbd0ac5a0694575812e6586b328945d77..cf8ddb9f193d082e9a87d6cb5124c24f12282757 100644 --- a/src/Wizard.php +++ b/src/Wizard.php @@ -11,17 +11,20 @@ namespace SebastianBergmann\CodeUnitReverseLookup; use function array_merge; use function assert; +use function class_exists; +use function function_exists; use function get_declared_classes; use function get_declared_traits; use function get_defined_functions; use function is_array; use function range; +use function trait_exists; use ReflectionClass; use ReflectionFunction; use ReflectionFunctionAbstract; use ReflectionMethod; -class Wizard +final class Wizard { /** * @psalm-var array<string,array<int,string>> @@ -62,10 +65,11 @@ class Wizard $classes = get_declared_classes(); $traits = get_declared_traits(); - /* @noinspection PhpConditionAlreadyCheckedInspection */ assert(is_array($traits)); foreach (array_merge($classes, $traits) as $classOrTrait) { + assert(class_exists($classOrTrait) || trait_exists($classOrTrait)); + if (isset($this->processedClasses[$classOrTrait])) { continue; } @@ -81,6 +85,8 @@ class Wizard private function processFunctions(): void { foreach (get_defined_functions()['user'] as $function) { + assert(function_exists($function)); + if (isset($this->processedFunctions[$function])) { continue; } diff --git a/tests/WizardTest.php b/tests/WizardTest.php index 528e60908ef2616f3aa7e3b01a7e2ffe26d3e89b..c00474cb094708e114fa1c91c0acd57677e85340 100644 --- a/tests/WizardTest.php +++ b/tests/WizardTest.php @@ -31,8 +31,8 @@ final class WizardTest extends TestCase 'Foo::method', $this->wizard->lookup( __DIR__ . '/_fixture/Foo.php', - 12 - ) + 12, + ), ); return $this->wizard; @@ -47,8 +47,8 @@ final class WizardTest extends TestCase 'Bar::method', $wizard->lookup( __DIR__ . '/_fixture/Bar.php', - 12 - ) + 12, + ), ); } @@ -56,7 +56,7 @@ final class WizardTest extends TestCase { $this->assertEquals( 'file.php:1', - $this->wizard->lookup('file.php', 1) + $this->wizard->lookup('file.php', 1), ); } }