pax_global_header00006660000000000000000000000064137677211570014532gustar00rootroot0000000000000052 comment=9deb73a402262f62e0a836cabbec7e508ba5e33e phpunit-recursion-context-4.0.4/000077500000000000000000000000001376772115700167175ustar00rootroot00000000000000phpunit-recursion-context-4.0.4/.github/000077500000000000000000000000001376772115700202575ustar00rootroot00000000000000phpunit-recursion-context-4.0.4/.github/FUNDING.yml000066400000000000000000000000321376772115700220670ustar00rootroot00000000000000github: sebastianbergmann phpunit-recursion-context-4.0.4/.github/workflows/000077500000000000000000000000001376772115700223145ustar00rootroot00000000000000phpunit-recursion-context-4.0.4/.github/workflows/ci.yml000066400000000000000000000052441376772115700234370ustar00rootroot00000000000000# https://help.github.com/en/categories/automating-your-workflow-with-github-actions on: - "pull_request" - "push" name: "CI" jobs: coding-guidelines: name: "Coding Guidelines" runs-on: "ubuntu-latest" steps: - name: "Checkout" uses: "actions/checkout@v2" - name: "Run friendsofphp/php-cs-fixer" run: "php7.4 ./tools/php-cs-fixer fix --diff-format=udiff --dry-run --show-progress=dots --using-cache=no --verbose" type-checker: name: "Type Checker" runs-on: "ubuntu-latest" steps: - name: "Checkout" uses: "actions/checkout@v2" - name: "Update dependencies with composer" run: "php7.4 ./tools/composer update --no-ansi --no-interaction --no-progress" - name: "Run vimeo/psalm" run: "php7.4 ./tools/psalm --config=.psalm/config.xml --no-progress --shepherd --show-info=false --stats" backward-compatibility: name: Backward Compatibility runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v2 with: fetch-depth: 0 - name: Fetch tags run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* - name: Install PHP with extensions uses: shivammathur/setup-php@v2 with: php-version: 7.4 coverage: none extensions: intl - name: Run roave/backward-compatibility-check run: ./tools/roave-backward-compatibility-check --from=4.0.0 tests: name: "Tests" runs-on: "ubuntu-latest" strategy: fail-fast: false matrix: php-version: - "7.3" - "7.4" - "8.0" - "8.1" steps: - name: "Checkout" uses: "actions/checkout@v2" - name: "Install PHP with extensions" uses: "shivammathur/setup-php@v2" with: php-version: "${{ matrix.php-version }}" coverage: "pcov" - name: "Cache dependencies installed with composer" uses: "actions/cache@v1" 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" - name: "Run tests with phpunit/phpunit" run: "vendor/bin/phpunit --coverage-clover=coverage.xml" - name: "Send code coverage report to Codecov.io" env: CODECOV_TOKEN: "${{ secrets.CODECOV_TOKEN }}" run: "bash <(curl -s https://codecov.io/bash) || true" phpunit-recursion-context-4.0.4/.gitignore000066400000000000000000000001041376772115700207020ustar00rootroot00000000000000/.idea /composer.lock /vendor /.php_cs.cache /.phpunit.result.cache phpunit-recursion-context-4.0.4/.phive/000077500000000000000000000000001376772115700201105ustar00rootroot00000000000000phpunit-recursion-context-4.0.4/.phive/phars.xml000066400000000000000000000006671376772115700217600ustar00rootroot00000000000000 phpunit-recursion-context-4.0.4/.php_cs.dist000066400000000000000000000174051376772115700211450ustar00rootroot00000000000000 For the full copyright and license information, please view the LICENSE file that was distributed with this source code. EOF; $finder = PhpCsFixer\Finder::create() ->files() ->in(__DIR__ . '/src') ->in(__DIR__ . '/tests'); return PhpCsFixer\Config::create() ->setFinder($finder) ->setRiskyAllowed(true) ->setRules([ 'align_multiline_comment' => true, 'array_indentation' => true, 'array_syntax' => ['syntax' => 'short'], 'binary_operator_spaces' => [ 'operators' => [ '=' => 'align', '=>' => 'align', ], ], 'blank_line_after_namespace' => true, 'blank_line_before_statement' => [ 'statements' => [ 'break', 'continue', 'declare', 'do', 'for', 'foreach', 'if', 'include', 'include_once', 'require', 'require_once', 'return', 'switch', 'throw', 'try', 'while', 'yield', ], ], 'braces' => true, 'cast_spaces' => true, 'class_attributes_separation' => ['elements' => ['const', 'method', 'property']], 'combine_consecutive_issets' => true, 'combine_consecutive_unsets' => true, 'compact_nullable_typehint' => true, 'concat_space' => ['spacing' => 'one'], 'declare_equal_normalize' => ['space' => 'none'], 'declare_strict_types' => true, 'dir_constant' => true, 'elseif' => true, 'encoding' => true, 'full_opening_tag' => true, 'function_declaration' => true, 'global_namespace_import' => [ 'import_classes' => true, 'import_constants' => true, 'import_functions' => true, ], 'header_comment' => ['header' => $header, 'separate' => 'none'], 'indentation_type' => true, 'is_null' => true, 'line_ending' => true, 'list_syntax' => ['syntax' => 'short'], 'logical_operators' => true, 'lowercase_cast' => true, 'lowercase_constants' => true, 'lowercase_keywords' => true, 'lowercase_static_reference' => true, 'magic_constant_casing' => true, 'method_argument_space' => ['ensure_fully_multiline' => true], 'modernize_types_casting' => true, 'multiline_comment_opening_closing' => true, 'multiline_whitespace_before_semicolons' => true, 'native_constant_invocation' => false, 'native_function_casing' => false, 'native_function_invocation' => false, 'new_with_braces' => false, 'no_alias_functions' => true, 'no_alternative_syntax' => true, 'no_blank_lines_after_class_opening' => true, 'no_blank_lines_after_phpdoc' => true, 'no_blank_lines_before_namespace' => true, 'no_closing_tag' => true, 'no_empty_comment' => true, 'no_empty_phpdoc' => true, 'no_empty_statement' => true, 'no_extra_blank_lines' => true, 'no_homoglyph_names' => true, 'no_leading_import_slash' => true, 'no_leading_namespace_whitespace' => true, 'no_mixed_echo_print' => ['use' => 'print'], 'no_multiline_whitespace_around_double_arrow' => true, 'no_null_property_initialization' => true, 'no_php4_constructor' => true, 'no_short_bool_cast' => true, 'no_short_echo_tag' => true, 'no_singleline_whitespace_before_semicolons' => true, 'no_spaces_after_function_name' => true, 'no_spaces_inside_parenthesis' => true, 'no_superfluous_elseif' => true, 'no_superfluous_phpdoc_tags' => [ 'allow_mixed' => true, ], 'no_trailing_comma_in_list_call' => true, 'no_trailing_comma_in_singleline_array' => true, 'no_trailing_whitespace' => true, 'no_trailing_whitespace_in_comment' => true, 'no_unneeded_control_parentheses' => true, 'no_unneeded_curly_braces' => true, 'no_unneeded_final_method' => true, 'no_unreachable_default_argument_value' => true, 'no_unset_on_property' => true, 'no_unused_imports' => true, 'no_useless_else' => true, 'no_useless_return' => true, 'no_whitespace_before_comma_in_array' => true, 'no_whitespace_in_blank_line' => true, 'non_printable_character' => true, 'normalize_index_brace' => true, 'object_operator_without_whitespace' => true, 'ordered_class_elements' => [ 'order' => [ 'use_trait', 'constant_public', 'constant_protected', 'constant_private', 'property_public_static', 'property_protected_static', 'property_private_static', 'property_public', 'property_protected', 'property_private', 'method_public_static', 'construct', 'destruct', 'magic', 'phpunit', 'method_public', 'method_protected', 'method_private', 'method_protected_static', 'method_private_static', ], ], '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, ] ], 'ordered_interfaces' => [ 'direction' => 'ascend', 'order' => 'alpha', ], 'phpdoc_add_missing_param_annotation' => false, 'phpdoc_align' => true, 'phpdoc_annotation_without_dot' => true, 'phpdoc_indent' => true, 'phpdoc_no_access' => true, 'phpdoc_no_empty_return' => true, 'phpdoc_no_package' => true, 'phpdoc_order' => true, 'phpdoc_return_self_reference' => true, 'phpdoc_scalar' => true, 'phpdoc_separation' => true, 'phpdoc_single_line_var_spacing' => true, 'phpdoc_summary' => true, 'phpdoc_to_comment' => true, 'phpdoc_trim' => true, 'phpdoc_trim_consecutive_blank_line_separation' => true, 'phpdoc_types' => ['groups' => ['simple', 'meta']], 'phpdoc_types_order' => true, 'phpdoc_var_without_name' => true, 'pow_to_exponentiation' => true, 'protected_to_private' => true, 'return_assignment' => true, 'return_type_declaration' => ['space_before' => 'none'], 'self_accessor' => true, 'semicolon_after_instruction' => true, 'set_type_to_cast' => true, 'short_scalar_cast' => true, 'simplified_null_return' => false, 'single_blank_line_at_eof' => true, 'single_import_per_statement' => true, 'single_line_after_imports' => true, 'single_quote' => true, 'standardize_not_equals' => true, 'ternary_to_null_coalescing' => true, 'trailing_comma_in_multiline_array' => true, 'trim_array_spaces' => true, 'unary_operator_spaces' => true, 'visibility_required' => [ 'elements' => [ 'const', 'method', 'property', ], ], 'void_return' => true, 'whitespace_after_comma_in_array' => true, ]); phpunit-recursion-context-4.0.4/.psalm/000077500000000000000000000000001376772115700201115ustar00rootroot00000000000000phpunit-recursion-context-4.0.4/.psalm/baseline.xml000066400000000000000000000004511376772115700224150ustar00rootroot00000000000000 is_array($array) phpunit-recursion-context-4.0.4/.psalm/config.xml000066400000000000000000000007531376772115700221050ustar00rootroot00000000000000 phpunit-recursion-context-4.0.4/ChangeLog.md000066400000000000000000000017531376772115700210760ustar00rootroot00000000000000# ChangeLog All notable changes are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles. ## [4.0.4] - 2020-10-26 ### Fixed * `SebastianBergmann\RecursionContext\Exception` now correctly extends `\Throwable` ## [4.0.3] - 2020-09-28 ### Changed * [#21](https://github.com/sebastianbergmann/recursion-context/pull/21): Add type annotations for in/out parameters * Changed PHP version constraint in `composer.json` from `^7.3 || ^8.0` to `>=7.3` ## [4.0.2] - 2020-06-26 ### Added * This component is now supported on PHP 8 ## [4.0.1] - 2020-06-15 ### Changed * Tests etc. are now ignored for archive exports [4.0.4]: https://github.com/sebastianbergmann/recursion-context/compare/4.0.3...4.0.4 [4.0.3]: https://github.com/sebastianbergmann/recursion-context/compare/4.0.2...4.0.3 [4.0.2]: https://github.com/sebastianbergmann/recursion-context/compare/4.0.1...4.0.2 [4.0.1]: https://github.com/sebastianbergmann/recursion-context/compare/4.0.0...4.0.1 phpunit-recursion-context-4.0.4/LICENSE000066400000000000000000000030201376772115700177170ustar00rootroot00000000000000Recursion Context Copyright (c) 2002-2020, Sebastian Bergmann . All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Sebastian Bergmann nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. phpunit-recursion-context-4.0.4/README.md000066400000000000000000000013661376772115700202040ustar00rootroot00000000000000# sebastian/recursion-context [![CI Status](https://github.com/sebastianbergmann/recursion-context/workflows/CI/badge.svg)](https://github.com/sebastianbergmann/recursion-context/actions) [![Type Coverage](https://shepherd.dev/github/sebastianbergmann/recursion-context/coverage.svg)](https://shepherd.dev/github/sebastianbergmann/recursion-context) ## Installation You can add this library as a local, per-project dependency to your project using [Composer](https://getcomposer.org/): ``` composer require sebastian/recursion-context ``` If you only need this library during development, for instance to run your project's test suite, then you should add it as a development-time dependency: ``` composer require --dev sebastian/recursion-context ``` phpunit-recursion-context-4.0.4/build.xml000066400000000000000000000020631376772115700205410ustar00rootroot00000000000000 phpunit-recursion-context-4.0.4/composer.json000066400000000000000000000017711376772115700214470ustar00rootroot00000000000000{ "name": "sebastian/recursion-context", "description": "Provides functionality to recursively process PHP variables", "homepage": "http://www.github.com/sebastianbergmann/recursion-context", "license": "BSD-3-Clause", "authors": [ { "name": "Sebastian Bergmann", "email": "sebastian@phpunit.de" }, { "name": "Jeff Welch", "email": "whatthejeff@gmail.com" }, { "name": "Adam Harvey", "email": "aharvey@php.net" } ], "prefer-stable": true, "config": { "platform": { "php": "7.3.0" }, "optimize-autoloader": true, "sort-packages": true }, "require": { "php": ">=7.3" }, "require-dev": { "phpunit/phpunit": "^9.3" }, "autoload": { "classmap": [ "src/" ] }, "extra": { "branch-alias": { "dev-master": "4.0-dev" } } } phpunit-recursion-context-4.0.4/phpunit.xml000066400000000000000000000015121376772115700211270ustar00rootroot00000000000000 tests src phpunit-recursion-context-4.0.4/src/000077500000000000000000000000001376772115700175065ustar00rootroot00000000000000phpunit-recursion-context-4.0.4/src/Context.php000066400000000000000000000104131376772115700216420ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\RecursionContext; use const PHP_INT_MAX; use const PHP_INT_MIN; use function array_pop; use function array_slice; use function count; use function is_array; use function is_object; use function random_int; use function spl_object_hash; use SplObjectStorage; /** * A context containing previously processed arrays and objects * when recursively processing a value. */ final class Context { /** * @var array[] */ private $arrays; /** * @var SplObjectStorage */ private $objects; /** * Initialises the context. */ public function __construct() { $this->arrays = []; $this->objects = new SplObjectStorage; } /** * @codeCoverageIgnore */ public function __destruct() { foreach ($this->arrays as &$array) { if (is_array($array)) { array_pop($array); array_pop($array); } } } /** * Adds a value to the context. * * @param array|object $value the value to add * * @throws InvalidArgumentException Thrown if $value is not an array or object * * @return bool|int|string the ID of the stored value, either as a string or integer * * @psalm-template T * @psalm-param T $value * @param-out T $value */ public function add(&$value) { if (is_array($value)) { return $this->addArray($value); } if (is_object($value)) { return $this->addObject($value); } throw new InvalidArgumentException( 'Only arrays and objects are supported' ); } /** * Checks if the given value exists within the context. * * @param array|object $value the value to check * * @throws InvalidArgumentException Thrown if $value is not an array or object * * @return false|int|string the string or integer ID of the stored value if it has already been seen, or false if the value is not stored * * @psalm-template T * @psalm-param T $value * @param-out T $value */ public function contains(&$value) { if (is_array($value)) { return $this->containsArray($value); } if (is_object($value)) { return $this->containsObject($value); } throw new InvalidArgumentException( 'Only arrays and objects are supported' ); } /** * @return bool|int */ private function addArray(array &$array) { $key = $this->containsArray($array); if ($key !== false) { return $key; } $key = count($this->arrays); $this->arrays[] = &$array; if (!isset($array[PHP_INT_MAX]) && !isset($array[PHP_INT_MAX - 1])) { $array[] = $key; $array[] = $this->objects; } else { /* cover the improbable case too */ do { $key = random_int(PHP_INT_MIN, PHP_INT_MAX); } while (isset($array[$key])); $array[$key] = $key; do { $key = random_int(PHP_INT_MIN, PHP_INT_MAX); } while (isset($array[$key])); $array[$key] = $this->objects; } return $key; } /** * @param object $object */ private function addObject($object): string { if (!$this->objects->contains($object)) { $this->objects->attach($object); } return spl_object_hash($object); } /** * @return false|int */ private function containsArray(array &$array) { $end = array_slice($array, -2); return isset($end[1]) && $end[1] === $this->objects ? $end[0] : false; } /** * @param object $value * * @return false|string */ private function containsObject($value) { if ($this->objects->contains($value)) { return spl_object_hash($value); } return false; } } phpunit-recursion-context-4.0.4/src/Exception.php000066400000000000000000000005741376772115700221630ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\RecursionContext; use Throwable; interface Exception extends Throwable { } phpunit-recursion-context-4.0.4/src/InvalidArgumentException.php000066400000000000000000000006421376772115700251710ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\RecursionContext; final class InvalidArgumentException extends \InvalidArgumentException implements Exception { } phpunit-recursion-context-4.0.4/tests/000077500000000000000000000000001376772115700200615ustar00rootroot00000000000000phpunit-recursion-context-4.0.4/tests/ContextTest.php000066400000000000000000000073301376772115700230610ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\RecursionContext; use const PHP_INT_MAX; use function fopen; use function spl_object_hash; use PHPUnit\Framework\TestCase; use SplObjectStorage; use stdClass; /** * @covers SebastianBergmann\RecursionContext\Context */ class ContextTest extends TestCase { /** * @var \SebastianBergmann\RecursionContext\Context */ private $context; protected function setUp(): void { $this->context = new Context; } public function failsProvider(): array { return [ [true], [false], [null], ['string'], [1], [1.5], [fopen('php://memory', 'r')], ]; } public function valuesProvider(): array { $obj2 = new stdClass; $obj2->foo = 'bar'; $obj3 = (object) [1, 2, "Test\r\n", 4, 5, 6, 7, 8]; $obj = new stdClass; //@codingStandardsIgnoreStart $obj->null = null; //@codingStandardsIgnoreEnd $obj->boolean = true; $obj->integer = 1; $obj->double = 1.2; $obj->string = '1'; $obj->text = "this\nis\na\nvery\nvery\nvery\nvery\nvery\nvery\rlong\n\rtext"; $obj->object = $obj2; $obj->objectagain = $obj2; $obj->array = ['foo' => 'bar']; $obj->array2 = [1, 2, 3, 4, 5, 6]; $obj->array3 = [$obj, $obj2, $obj3]; $obj->self = $obj; $storage = new SplObjectStorage; $storage->attach($obj2); $storage->foo = $obj2; return [ [$obj, spl_object_hash($obj)], [$obj2, spl_object_hash($obj2)], [$obj3, spl_object_hash($obj3)], [$storage, spl_object_hash($storage)], [$obj->array, 0], [$obj->array2, 0], [$obj->array3, 0], ]; } /** * @dataProvider failsProvider */ public function testAddFails($value): void { $this->expectException(Exception::class); $this->expectExceptionMessage('Only arrays and objects are supported'); $this->context->add($value); } /** * @dataProvider failsProvider */ public function testContainsFails($value): void { $this->expectException(Exception::class); $this->expectExceptionMessage('Only arrays and objects are supported'); $this->context->contains($value); } /** * @dataProvider valuesProvider */ public function testAdd($value, $key): void { $this->assertEquals($key, $this->context->add($value)); // Test we get the same key on subsequent adds $this->assertEquals($key, $this->context->add($value)); } public function testAdd2(): void { $a = [PHP_INT_MAX => 'foo']; $this->context->add($a); $this->assertIsInt($this->context->contains($a)); } /** * @depends testAdd * @dataProvider valuesProvider */ public function testContainsFound($value, $key): void { $this->context->add($value); $this->assertEquals($key, $this->context->contains($value)); // Test we get the same key on subsequent calls $this->assertEquals($key, $this->context->contains($value)); } /** * @dataProvider valuesProvider */ public function testContainsNotFound($value): void { $this->assertFalse($this->context->contains($value)); } }