This commit is contained in:
2025-02-04 12:40:43 +03:00
parent 4bcb4c60dd
commit 50343d5a87
372 changed files with 9019 additions and 6684 deletions

View File

@@ -2,12 +2,6 @@
All notable changes are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
## [4.0.0] - 2025-02-07
### Removed
* This component is no longer supported on PHP 8.2
## [3.0.2] - 2024-07-03
### Changed
@@ -48,7 +42,6 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
* Initial release
[4.0.0]: https://github.com/sebastianbergmann/cli-parser/compare/3.0...main
[3.0.2]: https://github.com/sebastianbergmann/cli-parser/compare/3.0.1...3.0.2
[3.0.1]: https://github.com/sebastianbergmann/cli-parser/compare/3.0.0...3.0.1
[3.0.0]: https://github.com/sebastianbergmann/cli-parser/compare/2.0...3.0.0

View File

@@ -1,6 +1,6 @@
BSD 3-Clause License
Copyright (c) 2020-2025, Sebastian Bergmann
Copyright (c) 2020-2024, Sebastian Bergmann
All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
[![Latest Stable Version](https://poser.pugx.org/sebastian/cli-parser/v)](https://packagist.org/packages/sebastian/cli-parser)
[![Latest Stable Version](https://poser.pugx.org/sebastian/cli-parser/v/stable.png)](https://packagist.org/packages/sebastian/cli-parser)
[![CI Status](https://github.com/sebastianbergmann/cli-parser/workflows/CI/badge.svg)](https://github.com/sebastianbergmann/cli-parser/actions)
[![codecov](https://codecov.io/gh/sebastianbergmann/cli-parser/branch/main/graph/badge.svg)](https://codecov.io/gh/sebastianbergmann/cli-parser)

View File

@@ -15,17 +15,16 @@
"issues": "https://github.com/sebastianbergmann/cli-parser/issues",
"security": "https://github.com/sebastianbergmann/cli-parser/security/policy"
},
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=8.3"
"php": ">=8.2"
},
"require-dev": {
"phpunit/phpunit": "^12.0-dev"
"phpunit/phpunit": "^11.0"
},
"config": {
"platform": {
"php": "8.3.0"
"php": "8.2.0"
},
"optimize-autoloader": true,
"sort-packages": true
@@ -37,7 +36,7 @@
},
"extra": {
"branch-alias": {
"dev-main": "4.0-dev"
"dev-main": "3.0-dev"
}
}
}

View File

@@ -19,6 +19,7 @@ use function current;
use function explode;
use function is_array;
use function is_int;
use function is_string;
use function key;
use function next;
use function preg_replace;
@@ -41,7 +42,7 @@ final class Parser
* @throws RequiredOptionArgumentMissingException
* @throws UnknownOptionException
*
* @return array{0: list<array{0: string, 1: ?string}>, 1: list<string>}
* @return array{0: list<array{0: non-empty-string, 1: ?non-empty-string}>, 1: list<non-empty-string>}
*/
public function parse(array $argv, string $shortOptions, ?array $longOptions = null): array
{
@@ -110,8 +111,8 @@ final class Parser
}
/**
* @param list<array{0: string, 1: ?string}> $options
* @param list<string> $argv
* @param list<array{0: non-empty-string, 1: ?non-empty-string}> $options
* @param list<string> $argv
*
* @throws RequiredOptionArgumentMissingException
*/
@@ -141,6 +142,8 @@ final class Parser
throw new RequiredOptionArgumentMissingException('-' . $option);
}
assert(is_string($optionArgument));
next($argv);
}
}
@@ -150,9 +153,9 @@ final class Parser
}
/**
* @param list<string> $longOptions
* @param list<array{0: string, 1: ?string}> $options
* @param list<string> $argv
* @param list<string> $longOptions
* @param list<array{0: non-empty-string, 1: ?non-empty-string}> $options
* @param list<string> $argv
*
* @throws AmbiguousOptionException
* @throws OptionDoesNotAllowArgumentException

View File

@@ -0,0 +1,59 @@
# Change Log
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.1] - 2024-07-03
### Changed
* This project now uses PHPStan instead of Psalm for static analysis
## [4.0.0] - 2024-02-02
### Removed
* This component is no longer supported on PHP 8.1
## [3.0.0] - 2023-02-03
### Removed
* This component is no longer supported on PHP 7.3, PHP 7.4, and PHP 8.0
## [2.0.3] - 2020-09-28
### Changed
* Changed PHP version constraint in `composer.json` from `^7.3 || ^8.0` to `>=7.3`
## [2.0.2] - 2020-06-26
### Added
* This component is now supported on PHP 8
## [2.0.1] - 2020-06-15
### Changed
* Tests etc. are now ignored for archive exports
## 2.0.0 - 2020-02-07
### Removed
* This component is no longer supported on PHP 5.6, PHP 7.0, PHP 7.1, and PHP 7.2
## 1.0.0 - 2016-02-13
### Added
* Initial release
[4.0.1]: https://github.com/sebastianbergmann/code-unit-reverse-lookup/compare/4.0.0...4.0.1
[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
[2.0.1]: https://github.com/sebastianbergmann/code-unit-reverse-lookup/compare/2.0.0...2.0.1
[2.0.0]: https://github.com/sebastianbergmann/code-unit-reverse-lookup/compare/1.0.0...2.0.0

View File

@@ -0,0 +1,29 @@
BSD 3-Clause License
Copyright (c) 2016-2024, 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:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. 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.
3. Neither the name of the copyright holder nor the names of its
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 HOLDER 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.

View File

@@ -0,0 +1,21 @@
[![Latest Stable Version](https://poser.pugx.org/sebastian/code-unit-reverse-lookup/v/stable.png)](https://packagist.org/packages/sebastian/code-unit-reverse-lookup)
[![CI Status](https://github.com/sebastianbergmann/code-unit-reverse-lookup/workflows/CI/badge.svg)](https://github.com/sebastianbergmann/code-unit-reverse-lookup/actions)
[![codecov](https://codecov.io/gh/sebastianbergmann/code-unit-reverse-lookup/branch/main/graph/badge.svg)](https://codecov.io/gh/sebastianbergmann/code-unit-reverse-lookup)
# sebastian/code-unit-reverse-lookup
Looks up which function or method a line of code belongs to.
## Installation
You can add this library as a local, per-project dependency to your project using [Composer](https://getcomposer.org/):
```
composer require sebastian/code-unit-reverse-lookup
```
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/code-unit-reverse-lookup
```

View File

@@ -0,0 +1,30 @@
# Security Policy
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.
**Please do not report security vulnerabilities through public GitHub issues, discussions, or pull requests.**
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.

View File

@@ -0,0 +1,40 @@
{
"name": "sebastian/code-unit-reverse-lookup",
"description": "Looks up which function or method a line of code belongs to",
"homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/",
"license": "BSD-3-Clause",
"authors": [
{
"name": "Sebastian Bergmann",
"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.2.0"
},
"optimize-autoloader": true,
"sort-packages": true
},
"prefer-stable": true,
"require": {
"php": ">=8.2"
},
"require-dev": {
"phpunit/phpunit": "^11.0"
},
"autoload": {
"classmap": [
"src/"
]
},
"extra": {
"branch-alias": {
"dev-main": "4.0-dev"
}
}
}

View File

@@ -0,0 +1,132 @@
<?php declare(strict_types=1);
/*
* This file is part of sebastian/code-unit-reverse-lookup.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
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 is_int;
use function is_string;
use function range;
use function trait_exists;
use ReflectionClass;
use ReflectionFunction;
use ReflectionMethod;
final class Wizard
{
/**
* @var array<string, array<int, string>>
*/
private array $lookupTable = [];
/**
* @var array<class-string, true>
*/
private array $processedClasses = [];
/**
* @var array<string, true>
*/
private array $processedFunctions = [];
public function lookup(string $filename, int $lineNumber): string
{
if (!isset($this->lookupTable[$filename][$lineNumber])) {
$this->updateLookupTable();
}
if (isset($this->lookupTable[$filename][$lineNumber])) {
return $this->lookupTable[$filename][$lineNumber];
}
return $filename . ':' . $lineNumber;
}
private function updateLookupTable(): void
{
$this->processClassesAndTraits();
$this->processFunctions();
}
private function processClassesAndTraits(): void
{
$classes = get_declared_classes();
$traits = get_declared_traits();
assert(is_array($traits));
foreach (array_merge($classes, $traits) as $classOrTrait) {
assert(class_exists($classOrTrait) || trait_exists($classOrTrait));
if (isset($this->processedClasses[$classOrTrait])) {
continue;
}
foreach ((new ReflectionClass($classOrTrait))->getMethods() as $method) {
$this->processFunctionOrMethod($method);
}
$this->processedClasses[$classOrTrait] = true;
}
}
private function processFunctions(): void
{
foreach (get_defined_functions()['user'] as $function) {
assert(function_exists($function));
if (isset($this->processedFunctions[$function])) {
continue;
}
$this->processFunctionOrMethod(new ReflectionFunction($function));
$this->processedFunctions[$function] = true;
}
}
private function processFunctionOrMethod(ReflectionFunction|ReflectionMethod $functionOrMethod): void
{
if ($functionOrMethod->isInternal()) {
return;
}
$name = $functionOrMethod->getName();
if ($functionOrMethod instanceof ReflectionMethod) {
$name = $functionOrMethod->getDeclaringClass()->getName() . '::' . $name;
}
$fileName = $functionOrMethod->getFileName();
assert(is_string($fileName));
if (!isset($this->lookupTable[$fileName])) {
$this->lookupTable[$fileName] = [];
}
$startLine = $functionOrMethod->getStartLine();
$endLine = $functionOrMethod->getEndLine();
assert(is_int($startLine));
assert(is_int($endLine));
assert($endLine >= $startLine);
foreach (range($startLine, $endLine) as $line) {
$this->lookupTable[$fileName][$line] = $name;
}
}
}

99
vendor/sebastian/code-unit/ChangeLog.md vendored Normal file
View File

@@ -0,0 +1,99 @@
# ChangeLog
All notable changes are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
## [3.0.2] - 2024-12-12
### Fixed
* [#8](https://github.com/sebastianbergmann/code-unit/issues/8): `Mapper::stringToCodeUnits()` does not consider "inheritance" between traits
## [3.0.1] - 2024-07-03
### Changed
* This project now uses PHPStan instead of Psalm for static analysis
## [3.0.0] - 2024-02-02
### Removed
* This component is no longer supported on PHP 8.1
## [2.0.0] - 2023-02-03
### Added
* Added `SebastianBergmann\CodeUnit\FileUnit` value object that represents a sourcecode file
### Removed
* `SebastianBergmann\CodeUnit\CodeUnitCollection::fromArray()` has been removed
* `SebastianBergmann\CodeUnit\Mapper::stringToCodeUnits()` no longer supports `ClassName<*>`
* This component is no longer supported on PHP 7.3, PHP 7.4, and PHP 8.0
## [1.0.8] - 2020-10-26
### Fixed
* `SebastianBergmann\CodeUnit\Exception` now correctly extends `\Throwable`
## [1.0.7] - 2020-10-02
### Fixed
* `SebastianBergmann\CodeUnit\Mapper::stringToCodeUnits()` no longer attempts to create `CodeUnit` objects for code units that are not declared in userland
## [1.0.6] - 2020-09-28
### Changed
* Changed PHP version constraint in `composer.json` from `^7.3 || ^8.0` to `>=7.3`
## [1.0.5] - 2020-06-26
### Fixed
* [#3](https://github.com/sebastianbergmann/code-unit/issues/3): Regression in 1.0.4
## [1.0.4] - 2020-06-26
### Added
* This component is now supported on PHP 8
## [1.0.3] - 2020-06-15
### Changed
* Tests etc. are now ignored for archive exports
## [1.0.2] - 2020-04-30
### Fixed
* `Mapper::stringToCodeUnits()` raised the wrong exception for `Class::method` when a class named `Class` exists but does not have a method named `method`
## [1.0.1] - 2020-04-27
### Fixed
* [#2](https://github.com/sebastianbergmann/code-unit/issues/2): `Mapper::stringToCodeUnits()` breaks when `ClassName<extended>` is used for class that extends built-in class
## [1.0.0] - 2020-03-30
* Initial release
[3.0.2]: https://github.com/sebastianbergmann/code-unit/compare/3.0.1...3.0.2
[3.0.1]: https://github.com/sebastianbergmann/code-unit/compare/3.0.0...3.0.1
[3.0.0]: https://github.com/sebastianbergmann/code-unit/compare/2.0...3.0.0
[2.0.0]: https://github.com/sebastianbergmann/code-unit/compare/1.0.8...2.0.0
[1.0.8]: https://github.com/sebastianbergmann/code-unit/compare/1.0.7...1.0.8
[1.0.7]: https://github.com/sebastianbergmann/code-unit/compare/1.0.6...1.0.7
[1.0.6]: https://github.com/sebastianbergmann/code-unit/compare/1.0.5...1.0.6
[1.0.5]: https://github.com/sebastianbergmann/code-unit/compare/1.0.4...1.0.5
[1.0.4]: https://github.com/sebastianbergmann/code-unit/compare/1.0.3...1.0.4
[1.0.3]: https://github.com/sebastianbergmann/code-unit/compare/1.0.2...1.0.3
[1.0.2]: https://github.com/sebastianbergmann/code-unit/compare/1.0.1...1.0.2
[1.0.1]: https://github.com/sebastianbergmann/code-unit/compare/1.0.0...1.0.1
[1.0.0]: https://github.com/sebastianbergmann/code-unit/compare/530c3900e5db9bcb8516da545bef0d62536cedaa...1.0.0

29
vendor/sebastian/code-unit/LICENSE vendored Normal file
View File

@@ -0,0 +1,29 @@
BSD 3-Clause License
Copyright (c) 2020-2024, 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:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. 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.
3. Neither the name of the copyright holder nor the names of its
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 HOLDER 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.

21
vendor/sebastian/code-unit/README.md vendored Normal file
View File

@@ -0,0 +1,21 @@
[![Latest Stable Version](https://poser.pugx.org/sebastian/code-unit/v)](https://packagist.org/packages/sebastian/code-unit)
[![CI Status](https://github.com/sebastianbergmann/code-unit/workflows/CI/badge.svg)](https://github.com/sebastianbergmann/code-unit/actions)
[![codecov](https://codecov.io/gh/sebastianbergmann/code-unit/branch/main/graph/badge.svg)](https://codecov.io/gh/sebastianbergmann/code-unit)
# sebastian/code-unit
Collection of value objects that represent the PHP code units.
## Installation
You can add this library as a local, per-project dependency to your project using [Composer](https://getcomposer.org/):
```
composer require sebastian/code-unit
```
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/code-unit
```

30
vendor/sebastian/code-unit/SECURITY.md vendored Normal file
View File

@@ -0,0 +1,30 @@
# Security Policy
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.
**Please do not report security vulnerabilities through public GitHub issues, discussions, or pull requests.**
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.

View File

@@ -0,0 +1,51 @@
{
"name": "sebastian/code-unit",
"description": "Collection of value objects that represent the PHP code units",
"type": "library",
"homepage": "https://github.com/sebastianbergmann/code-unit",
"license": "BSD-3-Clause",
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de",
"role": "lead"
}
],
"support": {
"issues": "https://github.com/sebastianbergmann/code-unit/issues",
"security": "https://github.com/sebastianbergmann/code-unit/security/policy"
},
"prefer-stable": true,
"require": {
"php": ">=8.2"
},
"require-dev": {
"phpunit/phpunit": "^11.5"
},
"config": {
"platform": {
"php": "8.2.0"
},
"optimize-autoloader": true,
"sort-packages": true
},
"autoload": {
"classmap": [
"src/"
]
},
"autoload-dev": {
"classmap": [
"tests/_fixture"
],
"files": [
"tests/_fixture/file_with_multiple_code_units.php",
"tests/_fixture/function.php"
]
},
"extra": {
"branch-alias": {
"dev-main": "3.0-dev"
}
}
}

View File

@@ -0,0 +1,21 @@
<?php declare(strict_types=1);
/*
* This file is part of sebastian/code-unit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\CodeUnit;
/**
* @immutable
*/
final readonly class ClassMethodUnit extends CodeUnit
{
public function isClassMethod(): bool
{
return true;
}
}

View File

@@ -0,0 +1,21 @@
<?php declare(strict_types=1);
/*
* This file is part of sebastian/code-unit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\CodeUnit;
/**
* @immutable
*/
final readonly class ClassUnit extends CodeUnit
{
public function isClass(): bool
{
return true;
}
}

View File

@@ -0,0 +1,528 @@
<?php declare(strict_types=1);
/*
* This file is part of sebastian/code-unit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\CodeUnit;
use function assert;
use function count;
use function file;
use function file_exists;
use function is_readable;
use function range;
use function sprintf;
use ReflectionClass;
use ReflectionFunction;
use ReflectionMethod;
/**
* @immutable
*/
abstract readonly class CodeUnit
{
/**
* @var non-empty-string
*/
private string $name;
/**
* @var non-empty-string
*/
private string $sourceFileName;
/**
* @var list<int>
*/
private array $sourceLines;
/**
* @param class-string $className
*
* @throws InvalidCodeUnitException
* @throws ReflectionException
*/
public static function forClass(string $className): ClassUnit
{
self::ensureUserDefinedClass($className);
$reflector = new ReflectionClass($className);
return new ClassUnit(
$className,
// @phpstan-ignore argument.type
$reflector->getFileName(),
range(
// @phpstan-ignore argument.type
$reflector->getStartLine(),
// @phpstan-ignore argument.type
$reflector->getEndLine(),
),
);
}
/**
* @param class-string $className
*
* @throws InvalidCodeUnitException
* @throws ReflectionException
*/
public static function forClassMethod(string $className, string $methodName): ClassMethodUnit
{
self::ensureUserDefinedClass($className);
$reflector = self::reflectorForClassMethod($className, $methodName);
return new ClassMethodUnit(
$className . '::' . $methodName,
// @phpstan-ignore argument.type
$reflector->getFileName(),
range(
// @phpstan-ignore argument.type
$reflector->getStartLine(),
// @phpstan-ignore argument.type
$reflector->getEndLine(),
),
);
}
/**
* @param non-empty-string $path
*
* @throws InvalidCodeUnitException
*/
public static function forFileWithAbsolutePath(string $path): FileUnit
{
self::ensureFileExistsAndIsReadable($path);
$lines = file($path);
assert($lines !== false);
return new FileUnit(
$path,
$path,
range(
1,
count($lines),
),
);
}
/**
* @param class-string $interfaceName
*
* @throws InvalidCodeUnitException
* @throws ReflectionException
*/
public static function forInterface(string $interfaceName): InterfaceUnit
{
self::ensureUserDefinedInterface($interfaceName);
$reflector = new ReflectionClass($interfaceName);
return new InterfaceUnit(
$interfaceName,
// @phpstan-ignore argument.type
$reflector->getFileName(),
range(
// @phpstan-ignore argument.type
$reflector->getStartLine(),
// @phpstan-ignore argument.type
$reflector->getEndLine(),
),
);
}
/**
* @param class-string $interfaceName
*
* @throws InvalidCodeUnitException
* @throws ReflectionException
*/
public static function forInterfaceMethod(string $interfaceName, string $methodName): InterfaceMethodUnit
{
self::ensureUserDefinedInterface($interfaceName);
$reflector = self::reflectorForClassMethod($interfaceName, $methodName);
return new InterfaceMethodUnit(
$interfaceName . '::' . $methodName,
// @phpstan-ignore argument.type
$reflector->getFileName(),
range(
// @phpstan-ignore argument.type
$reflector->getStartLine(),
// @phpstan-ignore argument.type
$reflector->getEndLine(),
),
);
}
/**
* @param class-string $traitName
*
* @throws InvalidCodeUnitException
* @throws ReflectionException
*/
public static function forTrait(string $traitName): TraitUnit
{
self::ensureUserDefinedTrait($traitName);
$reflector = new ReflectionClass($traitName);
return new TraitUnit(
$traitName,
// @phpstan-ignore argument.type
$reflector->getFileName(),
range(
// @phpstan-ignore argument.type
$reflector->getStartLine(),
// @phpstan-ignore argument.type
$reflector->getEndLine(),
),
);
}
/**
* @param class-string $traitName
*
* @throws InvalidCodeUnitException
* @throws ReflectionException
*/
public static function forTraitMethod(string $traitName, string $methodName): TraitMethodUnit
{
self::ensureUserDefinedTrait($traitName);
$reflector = self::reflectorForClassMethod($traitName, $methodName);
return new TraitMethodUnit(
$traitName . '::' . $methodName,
// @phpstan-ignore argument.type
$reflector->getFileName(),
range(
// @phpstan-ignore argument.type
$reflector->getStartLine(),
// @phpstan-ignore argument.type
$reflector->getEndLine(),
),
);
}
/**
* @param callable-string $functionName
*
* @throws InvalidCodeUnitException
* @throws ReflectionException
*/
public static function forFunction(string $functionName): FunctionUnit
{
$reflector = self::reflectorForFunction($functionName);
if (!$reflector->isUserDefined()) {
throw new InvalidCodeUnitException(
sprintf(
'"%s" is not a user-defined function',
$functionName,
),
);
}
return new FunctionUnit(
// @phpstan-ignore argument.type
$functionName,
// @phpstan-ignore argument.type
$reflector->getFileName(),
range(
// @phpstan-ignore argument.type
$reflector->getStartLine(),
// @phpstan-ignore argument.type
$reflector->getEndLine(),
),
);
}
/**
* @param non-empty-string $name
* @param non-empty-string $sourceFileName
* @param list<int> $sourceLines
*/
private function __construct(string $name, string $sourceFileName, array $sourceLines)
{
$this->name = $name;
$this->sourceFileName = $sourceFileName;
$this->sourceLines = $sourceLines;
}
/**
* @return non-empty-string
*/
public function name(): string
{
return $this->name;
}
/**
* @return non-empty-string
*/
public function sourceFileName(): string
{
return $this->sourceFileName;
}
/**
* @return list<int>
*/
public function sourceLines(): array
{
return $this->sourceLines;
}
/**
* @phpstan-assert-if-true ClassUnit $this
*/
public function isClass(): bool
{
return false;
}
/**
* @phpstan-assert-if-true ClassMethodUnit $this
*/
public function isClassMethod(): bool
{
return false;
}
/**
* @phpstan-assert-if-true InterfaceUnit $this
*/
public function isInterface(): bool
{
return false;
}
/**
* @phpstan-assert-if-true InterfaceMethodUnit $this
*/
public function isInterfaceMethod(): bool
{
return false;
}
/**
* @phpstan-assert-if-true TraitUnit $this
*/
public function isTrait(): bool
{
return false;
}
/**
* @phpstan-assert-if-true TraitMethodUnit $this
*/
public function isTraitMethod(): bool
{
return false;
}
/**
* @phpstan-assert-if-true FunctionUnit $this
*/
public function isFunction(): bool
{
return false;
}
/**
* @phpstan-assert-if-true FileUnit $this
*/
public function isFile(): bool
{
return false;
}
/**
* @param non-empty-string $path
*
* @throws InvalidCodeUnitException
*/
private static function ensureFileExistsAndIsReadable(string $path): void
{
if (!(file_exists($path) && is_readable($path))) {
throw new InvalidCodeUnitException(
sprintf(
'File "%s" does not exist or is not readable',
$path,
),
);
}
}
/**
* @param class-string $className
*
* @throws InvalidCodeUnitException
*/
private static function ensureUserDefinedClass(string $className): void
{
try {
$reflector = new ReflectionClass($className);
if ($reflector->isInterface()) {
throw new InvalidCodeUnitException(
sprintf(
'"%s" is an interface and not a class',
$className,
),
);
}
if ($reflector->isTrait()) {
throw new InvalidCodeUnitException(
sprintf(
'"%s" is a trait and not a class',
$className,
),
);
}
if (!$reflector->isUserDefined()) {
throw new InvalidCodeUnitException(
sprintf(
'"%s" is not a user-defined class',
$className,
),
);
}
// @codeCoverageIgnoreStart
} catch (\ReflectionException $e) {
throw new ReflectionException(
$e->getMessage(),
$e->getCode(),
$e,
);
}
// @codeCoverageIgnoreEnd
}
/**
* @param class-string $interfaceName
*
* @throws InvalidCodeUnitException
*/
private static function ensureUserDefinedInterface(string $interfaceName): void
{
try {
$reflector = new ReflectionClass($interfaceName);
if (!$reflector->isInterface()) {
throw new InvalidCodeUnitException(
sprintf(
'"%s" is not an interface',
$interfaceName,
),
);
}
if (!$reflector->isUserDefined()) {
throw new InvalidCodeUnitException(
sprintf(
'"%s" is not a user-defined interface',
$interfaceName,
),
);
}
// @codeCoverageIgnoreStart
} catch (\ReflectionException $e) {
throw new ReflectionException(
$e->getMessage(),
$e->getCode(),
$e,
);
}
// @codeCoverageIgnoreEnd
}
/**
* @param class-string $traitName
*
* @throws InvalidCodeUnitException
*/
private static function ensureUserDefinedTrait(string $traitName): void
{
try {
$reflector = new ReflectionClass($traitName);
if (!$reflector->isTrait()) {
throw new InvalidCodeUnitException(
sprintf(
'"%s" is not a trait',
$traitName,
),
);
}
// @codeCoverageIgnoreStart
if (!$reflector->isUserDefined()) {
throw new InvalidCodeUnitException(
sprintf(
'"%s" is not a user-defined trait',
$traitName,
),
);
}
} catch (\ReflectionException $e) {
throw new ReflectionException(
$e->getMessage(),
$e->getCode(),
$e,
);
}
// @codeCoverageIgnoreEnd
}
/**
* @param class-string $className
*
* @throws ReflectionException
*/
private static function reflectorForClassMethod(string $className, string $methodName): ReflectionMethod
{
try {
return new ReflectionMethod($className, $methodName);
// @codeCoverageIgnoreStart
} catch (\ReflectionException $e) {
throw new ReflectionException(
$e->getMessage(),
$e->getCode(),
$e,
);
}
// @codeCoverageIgnoreEnd
}
/**
* @param callable-string $functionName
*
* @throws ReflectionException
*/
private static function reflectorForFunction(string $functionName): ReflectionFunction
{
try {
return new ReflectionFunction($functionName);
// @codeCoverageIgnoreStart
} catch (\ReflectionException $e) {
throw new ReflectionException(
$e->getMessage(),
$e->getCode(),
$e,
);
}
// @codeCoverageIgnoreEnd
}
}

View File

@@ -0,0 +1,75 @@
<?php declare(strict_types=1);
/*
* This file is part of sebastian/code-unit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\CodeUnit;
use function array_merge;
use function count;
use Countable;
use IteratorAggregate;
/**
* @template-implements IteratorAggregate<int, CodeUnit>
*
* @immutable
*/
final readonly class CodeUnitCollection implements Countable, IteratorAggregate
{
/**
* @var list<CodeUnit>
*/
private array $codeUnits;
public static function fromList(CodeUnit ...$codeUnits): self
{
// @phpstan-ignore argument.type
return new self($codeUnits);
}
/**
* @param list<CodeUnit> $codeUnits
*/
private function __construct(array $codeUnits)
{
$this->codeUnits = $codeUnits;
}
/**
* @return list<CodeUnit>
*/
public function asArray(): array
{
return $this->codeUnits;
}
public function getIterator(): CodeUnitCollectionIterator
{
return new CodeUnitCollectionIterator($this);
}
public function count(): int
{
return count($this->codeUnits);
}
public function isEmpty(): bool
{
return empty($this->codeUnits);
}
public function mergeWith(self $other): self
{
return new self(
array_merge(
$this->asArray(),
$other->asArray(),
),
);
}
}

View File

@@ -0,0 +1,54 @@
<?php declare(strict_types=1);
/*
* This file is part of sebastian/code-unit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\CodeUnit;
use Iterator;
/**
* @template-implements Iterator<int, CodeUnit>
*/
final class CodeUnitCollectionIterator implements Iterator
{
/**
* @var list<CodeUnit>
*/
private array $codeUnits;
private int $position = 0;
public function __construct(CodeUnitCollection $collection)
{
$this->codeUnits = $collection->asArray();
}
public function rewind(): void
{
$this->position = 0;
}
public function valid(): bool
{
return isset($this->codeUnits[$this->position]);
}
public function key(): int
{
return $this->position;
}
public function current(): CodeUnit
{
return $this->codeUnits[$this->position];
}
public function next(): void
{
$this->position++;
}
}

View File

@@ -0,0 +1,21 @@
<?php declare(strict_types=1);
/*
* This file is part of sebastian/code-unit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\CodeUnit;
/**
* @immutable
*/
final readonly class FileUnit extends CodeUnit
{
public function isFile(): bool
{
return true;
}
}

View File

@@ -0,0 +1,21 @@
<?php declare(strict_types=1);
/*
* This file is part of sebastian/code-unit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\CodeUnit;
/**
* @immutable
*/
final readonly class FunctionUnit extends CodeUnit
{
public function isFunction(): bool
{
return true;
}
}

View File

@@ -0,0 +1,21 @@
<?php declare(strict_types=1);
/*
* This file is part of sebastian/code-unit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\CodeUnit;
/**
* @immutable
*/
final readonly class InterfaceMethodUnit extends CodeUnit
{
public function isInterfaceMethod(): bool
{
return true;
}
}

View File

@@ -0,0 +1,21 @@
<?php declare(strict_types=1);
/*
* This file is part of sebastian/code-unit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\CodeUnit;
/**
* @immutable
*/
final readonly class InterfaceUnit extends CodeUnit
{
public function isInterface(): bool
{
return true;
}
}

View File

@@ -0,0 +1,202 @@
<?php declare(strict_types=1);
/*
* This file is part of sebastian/code-unit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\CodeUnit;
use function array_keys;
use function array_merge;
use function array_unique;
use function array_values;
use function class_exists;
use function explode;
use function function_exists;
use function interface_exists;
use function ksort;
use function method_exists;
use function sort;
use function sprintf;
use function str_contains;
use function trait_exists;
use ReflectionClass;
use ReflectionFunction;
use ReflectionMethod;
final class Mapper
{
/**
* @return array<string,list<int>>
*/
public function codeUnitsToSourceLines(CodeUnitCollection $codeUnits): array
{
$result = [];
foreach ($codeUnits as $codeUnit) {
$sourceFileName = $codeUnit->sourceFileName();
if (!isset($result[$sourceFileName])) {
$result[$sourceFileName] = [];
}
$result[$sourceFileName] = array_merge($result[$sourceFileName], $codeUnit->sourceLines());
}
foreach (array_keys($result) as $sourceFileName) {
$result[$sourceFileName] = array_values(array_unique($result[$sourceFileName]));
sort($result[$sourceFileName]);
}
ksort($result);
return $result;
}
/**
* @throws InvalidCodeUnitException
* @throws ReflectionException
*/
public function stringToCodeUnits(string $unit): CodeUnitCollection
{
if (str_contains($unit, '::')) {
[$firstPart, $secondPart] = explode('::', $unit);
if ($this->isUserDefinedFunction($secondPart)) {
return CodeUnitCollection::fromList(CodeUnit::forFunction($secondPart));
}
if ($this->isUserDefinedMethod($firstPart, $secondPart)) {
return CodeUnitCollection::fromList(CodeUnit::forClassMethod($firstPart, $secondPart));
}
if ($this->isUserDefinedInterface($firstPart)) {
return CodeUnitCollection::fromList(CodeUnit::forInterfaceMethod($firstPart, $secondPart));
}
if ($this->isUserDefinedTrait($firstPart)) {
return CodeUnitCollection::fromList(CodeUnit::forTraitMethod($firstPart, $secondPart));
}
} else {
if ($this->isUserDefinedClass($unit)) {
return CodeUnitCollection::fromList(
...array_merge(
[CodeUnit::forClass($unit)],
$this->traits(new ReflectionClass($unit)),
),
);
}
if ($this->isUserDefinedInterface($unit)) {
return CodeUnitCollection::fromList(CodeUnit::forInterface($unit));
}
if ($this->isUserDefinedTrait($unit)) {
return CodeUnitCollection::fromList(CodeUnit::forTrait($unit));
}
if ($this->isUserDefinedFunction($unit)) {
return CodeUnitCollection::fromList(CodeUnit::forFunction($unit));
}
}
throw new InvalidCodeUnitException(
sprintf(
'"%s" is not a valid code unit',
$unit,
),
);
}
/**
* @phpstan-assert-if-true callable-string $functionName
*/
private function isUserDefinedFunction(string $functionName): bool
{
if (!function_exists($functionName)) {
return false;
}
return (new ReflectionFunction($functionName))->isUserDefined();
}
/**
* @phpstan-assert-if-true class-string $className
*/
private function isUserDefinedClass(string $className): bool
{
if (!class_exists($className)) {
return false;
}
return (new ReflectionClass($className))->isUserDefined();
}
/**
* @phpstan-assert-if-true interface-string $interfaceName
*/
private function isUserDefinedInterface(string $interfaceName): bool
{
if (!interface_exists($interfaceName)) {
return false;
}
return (new ReflectionClass($interfaceName))->isUserDefined();
}
/**
* @phpstan-assert-if-true trait-string $traitName
*/
private function isUserDefinedTrait(string $traitName): bool
{
if (!trait_exists($traitName)) {
return false;
}
return (new ReflectionClass($traitName))->isUserDefined();
}
/**
* @phpstan-assert-if-true class-string $className
*/
private function isUserDefinedMethod(string $className, string $methodName): bool
{
if (!class_exists($className)) {
return false;
}
if (!method_exists($className, $methodName)) {
return false;
}
return (new ReflectionMethod($className, $methodName))->isUserDefined();
}
/**
* @param ReflectionClass<object> $class
*
* @return list<TraitUnit>
*/
private function traits(ReflectionClass $class): array
{
$result = [];
foreach ($class->getTraits() as $trait) {
if (!$trait->isUserDefined()) {
// @codeCoverageIgnoreStart
continue;
// @codeCoverageIgnoreEnd
}
$result[] = CodeUnit::forTrait($trait->getName());
$result = array_merge($result, $this->traits($trait));
}
return $result;
}
}

View File

@@ -0,0 +1,21 @@
<?php declare(strict_types=1);
/*
* This file is part of sebastian/code-unit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\CodeUnit;
/**
* @immutable
*/
final readonly class TraitMethodUnit extends CodeUnit
{
public function isTraitMethod(): bool
{
return true;
}
}

View File

@@ -0,0 +1,21 @@
<?php declare(strict_types=1);
/*
* This file is part of sebastian/code-unit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\CodeUnit;
/**
* @immutable
*/
final readonly class TraitUnit extends CodeUnit
{
public function isTrait(): bool
{
return true;
}
}

View File

@@ -0,0 +1,16 @@
<?php declare(strict_types=1);
/*
* This file is part of sebastian/code-unit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\CodeUnit;
use Throwable;
interface Exception extends Throwable
{
}

View File

@@ -0,0 +1,16 @@
<?php declare(strict_types=1);
/*
* This file is part of sebastian/code-unit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\CodeUnit;
use RuntimeException;
final class InvalidCodeUnitException extends RuntimeException implements Exception
{
}

View File

@@ -0,0 +1,16 @@
<?php declare(strict_types=1);
/*
* This file is part of sebastian/code-unit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\CodeUnit;
use RuntimeException;
final class NoTraitException extends RuntimeException implements Exception
{
}

View File

@@ -0,0 +1,16 @@
<?php declare(strict_types=1);
/*
* This file is part of sebastian/code-unit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\CodeUnit;
use RuntimeException;
final class ReflectionException extends RuntimeException implements Exception
{
}

View File

@@ -2,12 +2,6 @@
All notable changes are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
## [7.0.0] - 2025-02-07
### Removed
* Removed support for PHP 8.2
## [6.3.0] - 2025-01-06
### Added
@@ -210,7 +204,6 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
* Added `SebastianBergmann\Comparator\Factory::reset()` to unregister all non-default comparators
* Added support for `phpunit/phpunit-mock-objects` version `^5.0`
[7.0.0]: https://github.com/sebastianbergmann/comparator/compare/6.3...main
[6.3.0]: https://github.com/sebastianbergmann/comparator/compare/6.2.1...6.3.0
[6.2.1]: https://github.com/sebastianbergmann/comparator/compare/6.2.0...6.2.1
[6.2.0]: https://github.com/sebastianbergmann/comparator/compare/6.1.1...6.2.0

View File

@@ -26,12 +26,11 @@
"issues": "https://github.com/sebastianbergmann/comparator/issues",
"security": "https://github.com/sebastianbergmann/comparator/security/policy"
},
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=8.3",
"sebastian/diff": "^7.0",
"sebastian/exporter": "^7.0",
"php": ">=8.2",
"sebastian/diff": "^6.0",
"sebastian/exporter": "^6.0",
"ext-dom": "*",
"ext-mbstring": "*"
},
@@ -39,11 +38,11 @@
"ext-bcmath": "For comparing BcMath\\Number objects"
},
"require-dev": {
"phpunit/phpunit": "^12.0-dev"
"phpunit/phpunit": "^11.4"
},
"config": {
"platform": {
"php": "8.3.0"
"php": "8.2.0"
},
"optimize-autoloader": true,
"sort-packages": true
@@ -60,7 +59,8 @@
},
"extra": {
"branch-alias": {
"dev-main": "7.0-dev"
"dev-main": "6.2-dev"
}
}
}

View File

@@ -25,8 +25,8 @@ use SebastianBergmann\Exporter\Exporter;
*/
class ScalarComparator extends Comparator
{
private const int OVERLONG_THRESHOLD = 40;
private const int KEEP_CONTEXT_CHARS = 25;
private const OVERLONG_THRESHOLD = 40;
private const KEEP_CONTEXT_CHARS = 25;
public function accepts(mixed $expected, mixed $actual): bool
{

View File

@@ -2,12 +2,6 @@
All notable changes are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
## [5.0.0] - 2025-02-07
### Removed
* This component is no longer supported on PHP 8.2
## [4.0.1] - 2024-07-03
### Changed
@@ -78,7 +72,6 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
* Initial release
[5.0.0]: https://github.com/sebastianbergmann/complexity/compare/4.0...main
[4.0.1]: https://github.com/sebastianbergmann/complexity/compare/4.0.0...4.0.1
[4.0.0]: https://github.com/sebastianbergmann/complexity/compare/3.2...4.0.0
[3.2.0]: https://github.com/sebastianbergmann/complexity/compare/3.1.0...3.2.0

View File

@@ -1,6 +1,6 @@
BSD 3-Clause License
Copyright (c) 2020-2025, Sebastian Bergmann
Copyright (c) 2020-2024, Sebastian Bergmann
All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
[![Latest Stable Version](https://poser.pugx.org/sebastian/complexity/v)](https://packagist.org/packages/sebastian/complexity)
[![Latest Stable Version](https://poser.pugx.org/sebastian/complexity/v/stable.png)](https://packagist.org/packages/sebastian/complexity)
[![CI Status](https://github.com/sebastianbergmann/complexity/workflows/CI/badge.svg)](https://github.com/sebastianbergmann/complexity/actions)
[![codecov](https://codecov.io/gh/sebastianbergmann/complexity/branch/main/graph/badge.svg)](https://codecov.io/gh/sebastianbergmann/complexity)

View File

@@ -15,18 +15,17 @@
"issues": "https://github.com/sebastianbergmann/complexity/issues",
"security": "https://github.com/sebastianbergmann/complexity/security/policy"
},
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=8.3",
"php": ">=8.2",
"nikic/php-parser": "^5.0"
},
"require-dev": {
"phpunit/phpunit": "^12.0-dev"
"phpunit/phpunit": "^11.0"
},
"config": {
"platform": {
"php": "8.3.0"
"php": "8.2.0"
},
"optimize-autoloader": true,
"sort-packages": true
@@ -38,7 +37,7 @@
},
"extra": {
"branch-alias": {
"dev-main": "5.0-dev"
"dev-main": "4.0-dev"
}
}
}

View File

@@ -51,6 +51,7 @@ final class Calculator
assert($nodes !== null);
return $this->calculateForAbstractSyntaxTree($nodes);
// @codeCoverageIgnoreStart
} catch (Error $error) {
throw new RuntimeException(

View File

@@ -32,7 +32,7 @@ final readonly class ComplexityCollection implements Countable, IteratorAggregat
public static function fromList(Complexity ...$items): self
{
return new self(array_values($items));
return new self($items);
}
/**

View File

@@ -13,6 +13,7 @@ use function assert;
use function is_array;
use PhpParser\Node;
use PhpParser\Node\Expr\New_;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
@@ -110,6 +111,7 @@ final class ComplexityCalculatingVisitor extends NodeVisitorAbstract
}
assert(isset($parent->namespacedName));
assert($parent->namespacedName instanceof Name);
return $parent->namespacedName->toString() . '::' . $node->name->toString();
}
@@ -120,7 +122,12 @@ final class ComplexityCalculatingVisitor extends NodeVisitorAbstract
private function functionName(Function_ $node): string
{
assert(isset($node->namespacedName));
assert($node->namespacedName instanceof Name);
return $node->namespacedName->toString();
$functionName = $node->namespacedName->toString();
assert($functionName !== '');
return $functionName;
}
}

View File

@@ -31,7 +31,7 @@ final class CyclomaticComplexityCalculatingVisitor extends NodeVisitorAbstract
*/
private int $cyclomaticComplexity = 1;
public function enterNode(Node $node): null
public function enterNode(Node $node): void
{
switch ($node::class) {
case BooleanAnd::class:
@@ -49,8 +49,6 @@ final class CyclomaticComplexityCalculatingVisitor extends NodeVisitorAbstract
case While_::class:
$this->cyclomaticComplexity++;
}
return null;
}
/**

View File

@@ -2,12 +2,6 @@
All notable changes are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
## [7.0.0] - 2025-02-07
### Removed
* This component is no longer supported on PHP 8.3
## [6.0.2] - 2024-07-03
### Changed
@@ -27,7 +21,7 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
* `SebastianBergmann\Diff\Chunk::getStart()`, `SebastianBergmann\Diff\Chunk::getStartRange()`, `SebastianBergmann\Diff\Chunk::getEnd()`, `SebastianBergmann\Diff\Chunk::getEndRange()`, and `SebastianBergmann\Diff\Chunk::getLines()`
* `SebastianBergmann\Diff\Diff::getFrom()`, `SebastianBergmann\Diff\Diff::getTo()`, and `SebastianBergmann\Diff\Diff::getChunks()`
* `SebastianBergmann\Diff\Line::getContent()` and `SebastianBergmann\Diff\Diff::getType()`
* This component is no longer supported on PHP 8.1
* Removed support for PHP 8.1
## [5.1.1] - 2024-03-02
@@ -81,7 +75,7 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
### Removed
* This component is no longer supported on PHP 7.3, PHP 7.4, and PHP 8.0
* Removed support for PHP 7.3, PHP 7.4, and PHP 8.0
## [4.0.4] - 2020-10-26
@@ -111,7 +105,7 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
### Removed
* This component is no longer supported on PHP 7.1 and PHP 7.2
* Removed support for PHP 7.1 and PHP 7.2
## [3.0.2] - 2019-02-04
@@ -135,7 +129,7 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
### Removed
* This component is no longer supported on PHP 7.0
* Removed support for PHP 7.0
### Fixed
@@ -157,7 +151,6 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
* This component is no longer supported on PHP 5.6
[7.0.0]: https://github.com/sebastianbergmann/diff/compare/6.0...main
[6.0.2]: https://github.com/sebastianbergmann/diff/compare/6.0.1...6.0.2
[6.0.1]: https://github.com/sebastianbergmann/diff/compare/6.0.0...6.0.1
[6.0.0]: https://github.com/sebastianbergmann/diff/compare/5.1...6.0.0

View File

@@ -1,6 +1,6 @@
BSD 3-Clause License
Copyright (c) 2002-2025, Sebastian Bergmann
Copyright (c) 2002-2024, Sebastian Bergmann
All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
[![Latest Stable Version](https://poser.pugx.org/sebastian/diff/v)](https://packagist.org/packages/sebastian/diff)
[![Latest Stable Version](https://poser.pugx.org/sebastian/diff/v/stable.png)](https://packagist.org/packages/sebastian/diff)
[![CI Status](https://github.com/sebastianbergmann/diff/workflows/CI/badge.svg)](https://github.com/sebastianbergmann/diff/actions)
[![codecov](https://codecov.io/gh/sebastianbergmann/diff/branch/main/graph/badge.svg)](https://codecov.io/gh/sebastianbergmann/diff)
@@ -27,17 +27,14 @@ composer require --dev sebastian/diff
The `Differ` class can be used to generate a textual representation of the difference between two strings:
```php
<?php declare(strict_types=1);
<?php
use SebastianBergmann\Diff\Differ;
use SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder;
$differ = new Differ(new UnifiedDiffOutputBuilder);
$differ = new Differ;
print $differ->diff('foo', 'bar');
```
The code above yields the output below:
```diff
--- Original
+++ New
@@ -46,16 +43,73 @@ The code above yields the output below:
+bar
```
The `UnifiedDiffOutputBuilder` used in the example above generates output in "unified diff"
format and is used by PHPUnit, for example.
There are three output builders available in this package:
The `StrictUnifiedDiffOutputBuilder` generates output in "strict unified diff" format with
hunks, similar to `diff -u` and compatible with `patch` or `git apply`.
#### UnifiedDiffOutputBuilder
The `DiffOnlyOutputBuilder` generates output that only contains the lines that differ.
This is default builder, which generates the output close to udiff and is used by PHPUnit.
If none of these three output builders match your use case then you can implement
`DiffOutputBuilderInterface` to generate custom output.
```php
<?php
use SebastianBergmann\Diff\Differ;
use SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder;
$builder = new UnifiedDiffOutputBuilder(
"--- Original\n+++ New\n", // custom header
false // do not add line numbers to the diff
);
$differ = new Differ($builder);
print $differ->diff('foo', 'bar');
```
#### StrictUnifiedDiffOutputBuilder
Generates (strict) Unified diff's (unidiffs) with hunks,
similar to `diff -u` and compatible with `patch` and `git apply`.
```php
<?php
use SebastianBergmann\Diff\Differ;
use SebastianBergmann\Diff\Output\StrictUnifiedDiffOutputBuilder;
$builder = new StrictUnifiedDiffOutputBuilder([
'collapseRanges' => true, // ranges of length one are rendered with the trailing `,1`
'commonLineThreshold' => 6, // number of same lines before ending a new hunk and creating a new one (if needed)
'contextLines' => 3, // like `diff: -u, -U NUM, --unified[=NUM]`, for patch/git apply compatibility best to keep at least @ 3
'fromFile' => '',
'fromFileDate' => null,
'toFile' => '',
'toFileDate' => null,
]);
$differ = new Differ($builder);
print $differ->diff('foo', 'bar');
```
#### DiffOnlyOutputBuilder
Output only the lines that differ.
```php
<?php
use SebastianBergmann\Diff\Differ;
use SebastianBergmann\Diff\Output\DiffOnlyOutputBuilder;
$builder = new DiffOnlyOutputBuilder(
"--- Original\n+++ New\n"
);
$differ = new Differ($builder);
print $differ->diff('foo', 'bar');
```
#### DiffOutputBuilderInterface
You can pass any output builder to the `Differ` class as longs as it implements the `DiffOutputBuilderInterface`.
#### Parsing diff

View File

@@ -18,20 +18,19 @@
"issues": "https://github.com/sebastianbergmann/diff/issues",
"security": "https://github.com/sebastianbergmann/diff/security/policy"
},
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"platform": {
"php": "8.3.0"
"php": "8.2.0"
},
"optimize-autoloader": true,
"sort-packages": true
},
"require": {
"php": ">=8.3"
"php": ">=8.2"
},
"require-dev": {
"phpunit/phpunit": "^12.0-dev",
"phpunit/phpunit": "^11.0",
"symfony/process": "^4.2 || ^5"
},
"autoload": {
@@ -46,7 +45,7 @@
},
"extra": {
"branch-alias": {
"dev-main": "7.0-dev"
"dev-main": "6.0-dev"
}
}
}

View File

@@ -73,6 +73,12 @@ final class Chunk implements IteratorAggregate
*/
public function setLines(array $lines): void
{
foreach ($lines as $line) {
if (!$line instanceof Line) {
throw new InvalidArgumentException;
}
}
$this->lines = $lines;
}

View File

@@ -30,11 +30,11 @@ use SebastianBergmann\Diff\Output\DiffOutputBuilderInterface;
final class Differ
{
public const int OLD = 0;
public const int ADDED = 1;
public const int REMOVED = 2;
public const int DIFF_LINE_END_WARNING = 3;
public const int NO_LINE_END_EOF_WARNING = 4;
public const OLD = 0;
public const ADDED = 1;
public const REMOVED = 2;
public const DIFF_LINE_END_WARNING = 3;
public const NO_LINE_END_EOF_WARNING = 4;
private DiffOutputBuilderInterface $outputBuilder;
public function __construct(DiffOutputBuilderInterface $outputBuilder)
@@ -84,11 +84,11 @@ final class Differ
reset($to);
foreach ($common as $token) {
while ((/* from-token */ reset($from)) !== $token) {
while (($fromToken = reset($from)) !== $token) {
$diff[] = [array_shift($from), self::REMOVED];
}
while ((/* to-token */ reset($to)) !== $token) {
while (($toToken = reset($to)) !== $token) {
$diff[] = [array_shift($to), self::ADDED];
}
@@ -137,7 +137,7 @@ final class Differ
return new TimeEfficientLongestCommonSubsequenceCalculator;
}
private function calculateEstimatedFootprint(array $from, array $to): int
private function calculateEstimatedFootprint(array $from, array $to): float|int
{
$itemSize = PHP_INT_SIZE === 4 ? 76 : 144;

View File

@@ -11,9 +11,9 @@ namespace SebastianBergmann\Diff;
final class Line
{
public const int ADDED = 1;
public const int REMOVED = 2;
public const int UNCHANGED = 3;
public const ADDED = 1;
public const REMOVED = 2;
public const UNCHANGED = 3;
private int $type;
private string $content;

View File

@@ -15,6 +15,7 @@ use function array_reverse;
use function array_slice;
use function count;
use function in_array;
use function max;
final class MemoryEfficientLongestCommonSubsequenceCalculator implements LongestCommonSubsequenceCalculator
{

View File

@@ -16,8 +16,6 @@ abstract class AbstractChunkOutputBuilder implements DiffOutputBuilderInterface
/**
* Takes input of the diff array and returns the common parts.
* Iterates through diff line by line.
*
* @return array<int, positive-int>
*/
protected function getCommonChunks(array $diff, int $lineThreshold = 5): array
{

View File

@@ -9,11 +9,9 @@
*/
namespace SebastianBergmann\Diff\Output;
use function assert;
use function fclose;
use function fopen;
use function fwrite;
use function is_resource;
use function str_ends_with;
use function stream_get_contents;
use function substr;
@@ -36,8 +34,6 @@ final class DiffOnlyOutputBuilder implements DiffOutputBuilderInterface
{
$buffer = fopen('php://memory', 'r+b');
assert(is_resource($buffer));
if ('' !== $this->header) {
fwrite($buffer, $this->header);

View File

@@ -11,14 +11,12 @@ namespace SebastianBergmann\Diff\Output;
use function array_merge;
use function array_splice;
use function assert;
use function count;
use function fclose;
use function fopen;
use function fwrite;
use function is_bool;
use function is_int;
use function is_resource;
use function is_string;
use function max;
use function min;
@@ -101,9 +99,6 @@ final class StrictUnifiedDiffOutputBuilder implements DiffOutputBuilderInterface
$this->changed = false;
$buffer = fopen('php://memory', 'r+b');
assert(is_resource($buffer));
fwrite($buffer, $this->header);
$this->writeDiffHunks($buffer, $diff);

View File

@@ -10,12 +10,10 @@
namespace SebastianBergmann\Diff\Output;
use function array_splice;
use function assert;
use function count;
use function fclose;
use function fopen;
use function fwrite;
use function is_resource;
use function max;
use function min;
use function str_ends_with;
@@ -48,8 +46,6 @@ final class UnifiedDiffOutputBuilder extends AbstractChunkOutputBuilder
{
$buffer = fopen('php://memory', 'r+b');
assert(is_resource($buffer));
if ('' !== $this->header) {
fwrite($buffer, $this->header);

View File

@@ -9,7 +9,6 @@
*/
namespace SebastianBergmann\Diff;
use const PREG_UNMATCHED_AS_NULL;
use function array_pop;
use function assert;
use function count;
@@ -72,9 +71,6 @@ final class Parser
return $diffs;
}
/**
* @param string[] $lines
*/
private function parseFileDiff(Diff $diff, array $lines): void
{
$chunks = [];

View File

@@ -11,6 +11,7 @@ namespace SebastianBergmann\Diff;
use function array_reverse;
use function count;
use function max;
use SplFixedArray;
final class TimeEfficientLongestCommonSubsequenceCalculator implements LongestCommonSubsequenceCalculator

View File

@@ -2,12 +2,6 @@
All notable changes in `sebastianbergmann/environment` are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
## [8.0.0] - 2025-02-07
### Removed
* This component is no longer supported on PHP 8.2
## [7.2.0] - 2024-07-03
### Changed
@@ -215,7 +209,6 @@ All notable changes in `sebastianbergmann/environment` are documented in this fi
* This component is no longer supported on PHP 5.6
[8.0.0]: https://github.com/sebastianbergmann/environment/compare/7.2...main
[7.2.0]: https://github.com/sebastianbergmann/environment/compare/7.1.0...7.2.0
[7.1.0]: https://github.com/sebastianbergmann/environment/compare/7.0.0...7.1.0
[7.0.0]: https://github.com/sebastianbergmann/environment/compare/6.1...7.0.0

View File

@@ -1,6 +1,6 @@
BSD 3-Clause License
Copyright (c) 2014-2025, Sebastian Bergmann
Copyright (c) 2014-2024, Sebastian Bergmann
All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
[![Latest Stable Version](https://poser.pugx.org/sebastian/environment/v)](https://packagist.org/packages/sebastian/environment)
[![Latest Stable Version](https://poser.pugx.org/sebastian/environment/v/stable.png)](https://packagist.org/packages/sebastian/environment)
[![CI Status](https://github.com/sebastianbergmann/environment/workflows/CI/badge.svg)](https://github.com/sebastianbergmann/environment/actions)
[![codecov](https://codecov.io/gh/sebastianbergmann/environment/branch/main/graph/badge.svg)](https://codecov.io/gh/sebastianbergmann/environment)

View File

@@ -16,18 +16,17 @@
},
"config": {
"platform": {
"php": "8.3.0"
"php": "8.2.0"
},
"optimize-autoloader": true,
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=8.3"
"php": ">=8.2"
},
"require-dev": {
"phpunit/phpunit": "^12.0-dev"
"phpunit/phpunit": "^11.0"
},
"suggest": {
"ext-posix": "*"
@@ -39,7 +38,7 @@
},
"extra": {
"branch-alias": {
"dev-main": "8.0-dev"
"dev-main": "7.2-dev"
}
}
}

View File

@@ -12,14 +12,12 @@ namespace SebastianBergmann\Environment;
use const DIRECTORY_SEPARATOR;
use const STDIN;
use const STDOUT;
use function assert;
use function defined;
use function fclose;
use function fstat;
use function function_exists;
use function getenv;
use function in_array;
use function is_array;
use function is_resource;
use function is_string;
use function posix_isatty;
@@ -38,17 +36,17 @@ final class Console
/**
* @var int
*/
public const int STDIN = 0;
public const STDIN = 0;
/**
* @var int
*/
public const int STDOUT = 1;
public const STDOUT = 1;
/**
* @var int
*/
public const int STDERR = 2;
public const STDERR = 2;
/**
* Returns true if STDOUT supports colorization.
@@ -184,10 +182,6 @@ final class Console
['suppress_errors' => true],
);
assert(is_array($pipes));
assert(isset($pipes[1]) && is_resource($pipes[1]));
assert(isset($pipes[2]) && is_resource($pipes[2]));
if (is_resource($process)) {
$info = stream_get_contents($pipes[1]);

View File

@@ -10,6 +10,7 @@
namespace SebastianBergmann\Environment;
use const PHP_BINARY;
use const PHP_MAJOR_VERSION;
use const PHP_SAPI;
use const PHP_VERSION;
use function array_map;
@@ -59,6 +60,10 @@ final class Runtime
*/
public function performsJustInTimeCompilation(): bool
{
if (PHP_MAJOR_VERSION < 8) {
return false;
}
if (!$this->isOpcacheActive()) {
return false;
}

View File

@@ -2,12 +2,6 @@
All notable changes are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
## [7.0.0] - 2025-02-07
### Removed
* This component is no longer supported on PHP 8.2
## [6.3.0] - 2024-12-05
### Added
@@ -184,7 +178,6 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
* Remove HHVM-specific code that is no longer needed
[7.0.0]: https://github.com/sebastianbergmann/exporter/compare/6.3...main
[6.3.0]: https://github.com/sebastianbergmann/exporter/compare/6.2.0...6.3.0
[6.2.0]: https://github.com/sebastianbergmann/exporter/compare/6.1.3...6.2.0
[6.1.3]: https://github.com/sebastianbergmann/exporter/compare/6.1.2...6.1.3

View File

@@ -1,6 +1,6 @@
BSD 3-Clause License
Copyright (c) 2002-2025, Sebastian Bergmann
Copyright (c) 2002-2024, Sebastian Bergmann
All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@@ -32,20 +32,19 @@
},
"config": {
"platform": {
"php": "8.3.0"
"php": "8.2.0"
},
"optimize-autoloader": true,
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=8.3",
"php": ">=8.2",
"ext-mbstring": "*",
"sebastian/recursion-context": "^7.0-dev"
"sebastian/recursion-context": "^6.0"
},
"require-dev": {
"phpunit/phpunit": "^12.0-dev"
"phpunit/phpunit": "^11.3"
},
"autoload": {
"classmap": [
@@ -59,7 +58,7 @@
},
"extra": {
"branch-alias": {
"dev-main": "7.0-dev"
"dev-main": "6.1-dev"
}
}
}

View File

@@ -2,12 +2,6 @@
All notable changes in `sebastian/global-state` are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
## [8.0.0] - 2025-02-07
### Removed
* This component is no longer supported on PHP 8.2
## [7.0.2] - 2024-07-03
### Changed
@@ -116,7 +110,6 @@ All notable changes in `sebastian/global-state` are documented in this file usin
* This component is no longer supported on PHP 7.0 and PHP 7.1
[8.0.0]: https://github.com/sebastianbergmann/global-state/compare/7.0...main
[7.0.2]: https://github.com/sebastianbergmann/global-state/compare/7.0.1...7.0.2
[7.0.1]: https://github.com/sebastianbergmann/global-state/compare/7.0.0...7.0.1
[7.0.0]: https://github.com/sebastianbergmann/global-state/compare/6.0...7.0.0

View File

@@ -1,6 +1,6 @@
BSD 3-Clause License
Copyright (c) 2001-2025, Sebastian Bergmann
Copyright (c) 2001-2024, Sebastian Bergmann
All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
[![Latest Stable Version](https://poser.pugx.org/sebastian/global-state/v)](https://packagist.org/packages/sebastian/global-state)
[![Latest Stable Version](https://poser.pugx.org/sebastian/global-state/v/stable.png)](https://packagist.org/packages/sebastian/global-state)
[![CI Status](https://github.com/sebastianbergmann/global-state/workflows/CI/badge.svg)](https://github.com/sebastianbergmann/global-state/actions)
[![codecov](https://codecov.io/gh/sebastianbergmann/global-state/branch/main/graph/badge.svg)](https://codecov.io/gh/sebastianbergmann/global-state)

View File

@@ -14,23 +14,22 @@
"issues": "https://github.com/sebastianbergmann/global-state/issues",
"security": "https://github.com/sebastianbergmann/global-state/security/policy"
},
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"platform": {
"php": "8.3.0"
"php": "8.2.0"
},
"optimize-autoloader": true,
"sort-packages": true
},
"require": {
"php": ">=8.3",
"sebastian/object-reflector": "^5.0",
"sebastian/recursion-context": "^7.0"
"php": ">=8.2",
"sebastian/object-reflector": "^4.0",
"sebastian/recursion-context": "^6.0"
},
"require-dev": {
"ext-dom": "*",
"phpunit/phpunit": "^12.0-dev"
"phpunit/phpunit": "^11.0"
},
"autoload": {
"classmap": [
@@ -47,7 +46,7 @@
},
"extra": {
"branch-alias": {
"dev-main": "8.0-dev"
"dev-main": "7.0-dev"
}
}
}

View File

@@ -13,7 +13,6 @@ use function array_diff;
use function array_key_exists;
use function array_keys;
use function array_merge;
use function assert;
use function in_array;
use function is_array;
use ReflectionClass;
@@ -96,8 +95,6 @@ final class Restorer
);
foreach ($keys as $key) {
assert(isset($GLOBALS[$superGlobalArray]) && is_array($GLOBALS[$superGlobalArray]));
if (isset($superGlobalVariables[$superGlobalArray][$key])) {
$GLOBALS[$superGlobalArray][$key] = $superGlobalVariables[$superGlobalArray][$key];
} else {

View File

@@ -128,7 +128,6 @@ final class Snapshot
assert($iniSettings !== false);
/* @phpstan-ignore assign.propertyType */
$this->iniSettings = $iniSettings;
}
@@ -293,7 +292,7 @@ final class Snapshot
!in_array($key, $superGlobalArrays, true) &&
$this->canBeSerialized($GLOBALS[$key]) &&
!$this->excludeList->isGlobalVariableExcluded($key)) {
/* @phpstan-ignore assign.propertyType */
/* @noinspection UnserializeExploitsInspection */
$this->globalVariables[$key] = unserialize(serialize($GLOBALS[$key]));
}
}
@@ -305,7 +304,7 @@ final class Snapshot
if (isset($GLOBALS[$superGlobalArray]) && is_array($GLOBALS[$superGlobalArray])) {
foreach ($GLOBALS[$superGlobalArray] as $key => $value) {
/* @phpstan-ignore assign.propertyType */
/* @noinspection UnserializeExploitsInspection */
$this->superGlobalVariables[$superGlobalArray][$key] = unserialize(serialize($value));
}
}
@@ -397,7 +396,6 @@ final class Snapshot
{
$result = [];
/* @phpstan-ignore argument.type */
if ($processed->contains($variable)) {
return $result;
}

View File

@@ -2,12 +2,6 @@
All notable changes are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
## [4.0.0] - 2025-02-07
### Removed
* This component is no longer supported on PHP 8.2
## [3.0.1] - 2024-07-03
### Changed
@@ -65,7 +59,6 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
* Initial release
[4.0.0]: https://github.com/sebastianbergmann/lines-of-code/compare/3.0...main
[3.0.1]: https://github.com/sebastianbergmann/lines-of-code/compare/3.0.0...3.0.1
[3.0.0]: https://github.com/sebastianbergmann/lines-of-code/compare/2.0...3.0.0
[2.0.2]: https://github.com/sebastianbergmann/lines-of-code/compare/2.0.1...2.0.2

View File

@@ -1,6 +1,6 @@
BSD 3-Clause License
Copyright (c) 2020-2025, Sebastian Bergmann
Copyright (c) 2020-2024, Sebastian Bergmann
All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
[![Latest Stable Version](https://poser.pugx.org/sebastian/lines-of-code/v)](https://packagist.org/packages/sebastian/lines-of-code)
[![Latest Stable Version](https://poser.pugx.org/sebastian/lines-of-code/v/stable.png)](https://packagist.org/packages/sebastian/lines-of-code)
[![CI Status](https://github.com/sebastianbergmann/lines-of-code/workflows/CI/badge.svg)](https://github.com/sebastianbergmann/lines-of-code/actions)
[![codecov](https://codecov.io/gh/sebastianbergmann/lines-of-code/branch/main/graph/badge.svg)](https://codecov.io/gh/sebastianbergmann/lines-of-code)

View File

@@ -15,18 +15,17 @@
"issues": "https://github.com/sebastianbergmann/lines-of-code/issues",
"security": "https://github.com/sebastianbergmann/lines-of-code/security/policy"
},
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=8.3",
"php": ">=8.2",
"nikic/php-parser": "^5.0"
},
"require-dev": {
"phpunit/phpunit": "^12.0-dev"
"phpunit/phpunit": "^11.0"
},
"config": {
"platform": {
"php": "8.3"
"php": "8.2"
},
"optimize-autoloader": true,
"sort-packages": true
@@ -38,7 +37,7 @@
},
"extra": {
"branch-alias": {
"dev-main": "4.0-dev"
"dev-main": "3.0-dev"
}
}
}

View File

@@ -48,6 +48,7 @@ final class Counter
assert($nodes !== null);
return $this->countInAbstractSyntaxTree($linesOfCode, $nodes);
// @codeCoverageIgnoreStart
} catch (Error $error) {
throw new RuntimeException(

View File

@@ -0,0 +1,16 @@
<?php declare(strict_types=1);
/*
* This file is part of sebastian/lines-of-code.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\LinesOfCode;
use InvalidArgumentException;
final class NegativeValueException extends InvalidArgumentException implements Exception
{
}

View File

@@ -43,17 +43,15 @@ final class LineCountingVisitor extends NodeVisitorAbstract
$this->linesOfCode = $linesOfCode;
}
public function enterNode(Node $node): null
public function enterNode(Node $node): void
{
$this->comments = array_merge($this->comments, $node->getComments());
if (!$node instanceof Expr) {
return null;
return;
}
$this->linesWithStatements[] = $node->getStartLine();
return null;
}
public function result(): LinesOfCode

View File

@@ -41,9 +41,30 @@ final readonly class LinesOfCode
* @param non-negative-int $logicalLinesOfCode
*
* @throws IllogicalValuesException
* @throws NegativeValueException
*/
public function __construct(int $linesOfCode, int $commentLinesOfCode, int $nonCommentLinesOfCode, int $logicalLinesOfCode)
{
/** @phpstan-ignore smaller.alwaysFalse */
if ($linesOfCode < 0) {
throw new NegativeValueException('$linesOfCode must not be negative');
}
/** @phpstan-ignore smaller.alwaysFalse */
if ($commentLinesOfCode < 0) {
throw new NegativeValueException('$commentLinesOfCode must not be negative');
}
/** @phpstan-ignore smaller.alwaysFalse */
if ($nonCommentLinesOfCode < 0) {
throw new NegativeValueException('$nonCommentLinesOfCode must not be negative');
}
/** @phpstan-ignore smaller.alwaysFalse */
if ($logicalLinesOfCode < 0) {
throw new NegativeValueException('$logicalLinesOfCode must not be negative');
}
if ($linesOfCode - $commentLinesOfCode !== $nonCommentLinesOfCode) {
throw new IllogicalValuesException('$linesOfCode !== $commentLinesOfCode + $nonCommentLinesOfCode');
}

View File

@@ -2,12 +2,6 @@
All notable changes to `sebastianbergmann/object-enumerator` are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
## [7.0.0] - 2025-02-07
### Removed
* This component is no longer supported on PHP 8.2
## [6.0.1] - 2024-07-03
### Changed
@@ -98,7 +92,6 @@ All notable changes to `sebastianbergmann/object-enumerator` are documented in t
* Initial release
[7.0.0]: https://github.com/sebastianbergmann/object-enumerator/compare/6.0...main
[6.0.1]: https://github.com/sebastianbergmann/object-enumerator/compare/6.0.0...6.0.1
[6.0.0]: https://github.com/sebastianbergmann/object-enumerator/compare/5.0...6.0.0
[5.0.0]: https://github.com/sebastianbergmann/object-enumerator/compare/4.0.4...5.0.0

View File

@@ -1,6 +1,6 @@
BSD 3-Clause License
Copyright (c) 2016-2025, Sebastian Bergmann
Copyright (c) 2016-2024, Sebastian Bergmann
All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
[![Latest Stable Version](https://poser.pugx.org/sebastian/object-enumerator/v)](https://packagist.org/packages/sebastian/object-enumerator)
[![Latest Stable Version](https://poser.pugx.org/sebastian/object-enumerator/v/stable.png)](https://packagist.org/packages/sebastian/object-enumerator)
[![CI Status](https://github.com/sebastianbergmann/object-enumerator/workflows/CI/badge.svg)](https://github.com/sebastianbergmann/object-enumerator/actions)
[![codecov](https://codecov.io/gh/sebastianbergmann/object-enumerator/branch/main/graph/badge.svg)](https://codecov.io/gh/sebastianbergmann/object-enumerator)

View File

@@ -13,22 +13,21 @@
"issues": "https://github.com/sebastianbergmann/object-enumerator/issues",
"security": "https://github.com/sebastianbergmann/object-enumerator/security/policy"
},
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"platform": {
"php": "8.3.0"
"php": "8.2.0"
},
"optimize-autoloader": true,
"sort-packages": true
},
"require": {
"php": ">=8.3",
"sebastian/object-reflector": "^5.0",
"sebastian/recursion-context": "^7.0"
"php": ">=8.2",
"sebastian/object-reflector": "^4.0",
"sebastian/recursion-context": "^6.0"
},
"require-dev": {
"phpunit/phpunit": "^12.0-dev"
"phpunit/phpunit": "^11.0"
},
"autoload": {
"classmap": [
@@ -42,7 +41,7 @@
},
"extra": {
"branch-alias": {
"dev-main": "7.0-dev"
"dev-main": "6.0-dev"
}
}
}

View File

@@ -2,12 +2,6 @@
All notable changes to `sebastianbergmann/object-reflector` are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
## [5.0.0] - 2025-02-07
### Removed
* This component is no longer supported on PHP 8.2
## [4.0.1] - 2024-07-03
### Changed
@@ -74,7 +68,6 @@ All notable changes to `sebastianbergmann/object-reflector` are documented in th
* Initial release
[5.0.0]: https://github.com/sebastianbergmann/object-reflector/compare/4.0...main
[4.0.1]: https://github.com/sebastianbergmann/object-reflector/compare/4.0.0...4.0.1
[4.0.0]: https://github.com/sebastianbergmann/object-reflector/compare/3.0...4.0.0
[3.0.0]: https://github.com/sebastianbergmann/object-reflector/compare/2.0.4...3.0.0

View File

@@ -1,6 +1,6 @@
BSD 3-Clause License
Copyright (c) 2017-2025, Sebastian Bergmann
Copyright (c) 2017-2024, Sebastian Bergmann
All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
[![Latest Stable Version](https://poser.pugx.org/sebastian/object-reflector/v)](https://packagist.org/packages/sebastian/object-reflector)
[![Latest Stable Version](https://poser.pugx.org/sebastian/object-reflector/v/stable.png)](https://packagist.org/packages/sebastian/object-reflector)
[![CI Status](https://github.com/sebastianbergmann/object-reflector/workflows/CI/badge.svg)](https://github.com/sebastianbergmann/object-reflector/actions)
[![codecov](https://codecov.io/gh/sebastianbergmann/object-reflector/branch/main/graph/badge.svg)](https://codecov.io/gh/sebastianbergmann/object-reflector)

View File

@@ -13,20 +13,19 @@
"issues": "https://github.com/sebastianbergmann/object-reflector/issues",
"security": "https://github.com/sebastianbergmann/object-reflector/security/policy"
},
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"platform": {
"php": "8.3.0"
"php": "8.2.0"
},
"optimize-autoloader": true,
"sort-packages": true
},
"require": {
"php": ">=8.3"
"php": ">=8.2"
},
"require-dev": {
"phpunit/phpunit": "^12.0-dev"
"phpunit/phpunit": "^11.0"
},
"autoload": {
"classmap": [
@@ -40,7 +39,7 @@
},
"extra": {
"branch-alias": {
"dev-main": "5.0-dev"
"dev-main": "4.0-dev"
}
}
}

View File

@@ -2,12 +2,6 @@
All notable changes are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
## [7.0.0] - 2025-02-07
### Removed
* This component is no longer supported on PHP 8.2
## [6.0.2] - 2024-07-03
### Changed
@@ -63,7 +57,6 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
* Tests etc. are now ignored for archive exports
[7.0.0]: https://github.com/sebastianbergmann/recursion-context/compare/6.0...main
[6.0.2]: https://github.com/sebastianbergmann/recursion-context/compare/6.0.1...6.0.2
[6.0.1]: https://github.com/sebastianbergmann/recursion-context/compare/6.0.0...6.0.1
[6.0.0]: https://github.com/sebastianbergmann/recursion-context/compare/5.0...6.0.0

View File

@@ -1,6 +1,6 @@
BSD 3-Clause License
Copyright (c) 2002-2025, Sebastian Bergmann
Copyright (c) 2002-2024, Sebastian Bergmann
All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
[![Latest Stable Version](https://poser.pugx.org/sebastian/recursion-context/v)](https://packagist.org/packages/sebastian/recursion-context)
[![Latest Stable Version](https://poser.pugx.org/sebastian/recursion-context/v/stable.png)](https://packagist.org/packages/sebastian/recursion-context)
[![CI Status](https://github.com/sebastianbergmann/recursion-context/workflows/CI/badge.svg)](https://github.com/sebastianbergmann/recursion-context/actions)
[![codecov](https://codecov.io/gh/sebastianbergmann/recursion-context/branch/main/graph/badge.svg)](https://codecov.io/gh/sebastianbergmann/recursion-context)

View File

@@ -21,20 +21,19 @@
"issues": "https://github.com/sebastianbergmann/recursion-context/issues",
"security": "https://github.com/sebastianbergmann/recursion-context/security/policy"
},
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"platform": {
"php": "8.3.0"
"php": "8.2.0"
},
"optimize-autoloader": true,
"sort-packages": true
},
"require": {
"php": ">=8.3"
"php": ">=8.2"
},
"require-dev": {
"phpunit/phpunit": "^12.0-dev"
"phpunit/phpunit": "^11.0"
},
"autoload": {
"classmap": [
@@ -43,7 +42,7 @@
},
"extra": {
"branch-alias": {
"dev-main": "7.0-dev"
"dev-main": "6.0-dev"
}
}
}

View File

@@ -16,7 +16,6 @@ use function array_pop;
use function array_slice;
use function count;
use function is_array;
use function is_int;
use function random_int;
use function spl_object_id;
use SplObjectStorage;
@@ -44,7 +43,6 @@ final class Context
public function __destruct()
{
foreach ($this->arrays as &$array) {
/* @phpstan-ignore function.alreadyNarrowedType */
if (is_array($array)) {
array_pop($array);
array_pop($array);
@@ -59,10 +57,9 @@ final class Context
*
* @param-out T $value
*/
public function add(array|object &$value): int
public function add(array|object &$value): false|int|string
{
if (is_array($value)) {
/* @phpstan-ignore paramOut.type */
return $this->addArray($value);
}
@@ -76,7 +73,7 @@ final class Context
*
* @param-out T $value
*/
public function contains(array|object &$value): false|int
public function contains(array|object &$value): false|int|string
{
if (is_array($value)) {
return $this->containsArray($value);
@@ -143,13 +140,7 @@ final class Context
{
$end = array_slice($array, -2);
if (isset($end[1]) &&
$end[1] === $this->objects &&
is_int($end[0])) {
return $end[0];
}
return false;
return isset($end[1]) && $end[1] === $this->objects ? $end[0] : false;
}
private function containsObject(object $value): false|int

View File

@@ -2,12 +2,6 @@
All notable changes are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
## [6.0.0] - 2025-02-07
### Removed
* This component is no longer supported on PHP 8.2
## [5.1.0] - 2024-09-17
### Added
@@ -177,7 +171,6 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
* Initial release based on [code contributed by Michel Hartmann to PHPUnit](https://github.com/sebastianbergmann/phpunit/pull/3673)
[6.0.0]: https://github.com/sebastianbergmann/type/compare/5.1...main
[5.1.0]: https://github.com/sebastianbergmann/type/compare/5.0.1...5.1.0
[5.0.1]: https://github.com/sebastianbergmann/type/compare/5.0.0...5.0.1
[5.0.0]: https://github.com/sebastianbergmann/type/compare/4.0...5.0.0

View File

@@ -1,6 +1,6 @@
BSD 3-Clause License
Copyright (c) 2019-2025, Sebastian Bergmann
Copyright (c) 2019-2024, Sebastian Bergmann
All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@@ -15,17 +15,16 @@
"issues": "https://github.com/sebastianbergmann/type/issues",
"security": "https://github.com/sebastianbergmann/type/security/policy"
},
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=8.3"
"php": ">=8.2"
},
"require-dev": {
"phpunit/phpunit": "^12.0-dev"
"phpunit/phpunit": "^11.3"
},
"config": {
"platform": {
"php": "8.3.0"
"php": "8.2.0"
},
"optimize-autoloader": true,
"sort-packages": true
@@ -46,7 +45,7 @@
},
"extra": {
"branch-alias": {
"dev-main": "6.0-dev"
"dev-main": "5.1-dev"
}
}
}

View File

@@ -33,6 +33,8 @@ final class ReflectionMapper
foreach ($reflector->getParameters() as $parameter) {
$name = $parameter->getName();
assert($name !== '');
if (!$parameter->hasType()) {
$parameters[] = new Parameter($name, new UnknownType);
@@ -88,7 +90,9 @@ final class ReflectionMapper
return $this->mapUnionType($returnType, $reflector);
}
return $this->mapIntersectionType($returnType, $reflector);
if ($returnType instanceof ReflectionIntersectionType) {
return $this->mapIntersectionType($returnType, $reflector);
}
}
public function fromPropertyType(ReflectionProperty $reflector): Type
@@ -109,47 +113,42 @@ final class ReflectionMapper
return $this->mapUnionType($propertyType, $reflector);
}
return $this->mapIntersectionType($propertyType, $reflector);
if ($propertyType instanceof ReflectionIntersectionType) {
return $this->mapIntersectionType($propertyType, $reflector);
}
}
private function mapNamedType(ReflectionNamedType $type, ReflectionFunction|ReflectionMethod|ReflectionProperty $reflector): Type
{
$classScope = !$reflector instanceof ReflectionFunction;
$typeName = $type->getName();
assert($typeName !== '');
if ($classScope && $typeName === 'self') {
if ($classScope && $type->getName() === 'self') {
return ObjectType::fromName(
$reflector->getDeclaringClass()->getName(),
$type->allowsNull(),
);
}
if ($classScope && $typeName === 'static') {
if ($classScope && $type->getName() === 'static') {
return new StaticType(
TypeName::fromReflection($reflector->getDeclaringClass()),
$type->allowsNull(),
);
}
if ($typeName === 'mixed') {
if ($type->getName() === 'mixed') {
return new MixedType;
}
if ($classScope && $typeName === 'parent') {
$parentClass = $reflector->getDeclaringClass()->getParentClass();
assert($parentClass !== false);
if ($classScope && $type->getName() === 'parent') {
return ObjectType::fromName(
$parentClass->getName(),
$reflector->getDeclaringClass()->getParentClass()->getName(),
$type->allowsNull(),
);
}
return Type::fromName(
$typeName,
$type->getName(),
$type->allowsNull(),
);
}

View File

@@ -48,17 +48,13 @@ final readonly class TypeName
}
/**
* @param ReflectionClass<object> $type
* @phpstan-ignore missingType.generics
*/
public static function fromReflection(ReflectionClass $type): self
{
$simpleName = $type->getShortName();
assert($simpleName !== '');
return new self(
$type->getNamespaceName(),
$simpleName,
$type->getShortName(),
);
}

View File

@@ -165,6 +165,12 @@ final class CallableType extends Type
[$className, $methodName] = $type->value();
}
/** @phpstan-ignore isset.variable */
assert(isset($className));
/** @phpstan-ignore isset.variable */
assert(isset($methodName));
if (!class_exists($className)) {
return false;
}

View File

@@ -9,6 +9,7 @@
*/
namespace SebastianBergmann\Type;
use function array_is_list;
use function assert;
use function count;
use function implode;
@@ -34,7 +35,7 @@ final class IntersectionType extends Type
$this->ensureOnlyValidTypes(...$types);
$this->ensureNoDuplicateTypes(...$types);
assert(!empty($types));
assert(array_is_list($types) && !empty($types));
$this->types = $types;
}

Some files were not shown because too many files have changed in this diff Show More