composer update

This commit is contained in:
2026-07-29 16:32:25 +02:00
parent 1ede9cc3af
commit 8ad8d279e6
1156 changed files with 22791 additions and 22591 deletions
+31
View File
@@ -2,6 +2,34 @@
All notable changes are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
## [3.2.0] - 2023-12-21
### Added
* `ComplexityCollection::sortByDescendingCyclomaticComplexity()`
### Changed
* This component is now compatible with `nikic/php-parser` 5.0
## [3.1.0] - 2023-09-28
### Added
* `Complexity::isFunction()` and `Complexity::isMethod()`
* `ComplexityCollection::isFunction()` and `ComplexityCollection::isMethod()`
* `ComplexityCollection::mergeWith()`
### Fixed
* Anonymous classes are not processed correctly
## [3.0.1] - 2023-08-31
### Fixed
* [#7](https://github.com/sebastianbergmann/complexity/pull/7): `ComplexityCalculatingVisitor` tries to process interface methods
## [3.0.0] - 2023-02-03
### Removed
@@ -30,6 +58,9 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
* Initial release
[3.2.0]: https://github.com/sebastianbergmann/complexity/compare/3.1.0...3.2.0
[3.1.0]: https://github.com/sebastianbergmann/complexity/compare/3.0.1...3.1.0
[3.0.1]: https://github.com/sebastianbergmann/complexity/compare/3.0.0...3.0.1
[3.0.0]: https://github.com/sebastianbergmann/complexity/compare/2.0.2...3.0.0
[2.0.2]: https://github.com/sebastianbergmann/complexity/compare/2.0.1...2.0.2
[2.0.1]: https://github.com/sebastianbergmann/complexity/compare/2.0.0...2.0.1
+25 -4
View File
@@ -1,9 +1,30 @@
# Security Policy
This library is intended to be used in development environments only. For instance, it is used by the testing framework PHPUnit. There is no reason why this library should be installed on a webserver.
If you believe you have found a security vulnerability in the library that is developed in this repository, please report it to us through coordinated disclosure.
**If you upload this library to a webserver then your deployment process is broken. On a more general note, if your `vendor` directory is publicly accessible on your webserver then your deployment process is also broken.**
**Please do not report security vulnerabilities through public GitHub issues, discussions, or pull requests.**
## Security Contact Information
Instead, please email `sebastian@phpunit.de`.
Please include as much of the information listed below as you can to help us better understand and resolve the issue:
* The type of issue
* Full paths of source file(s) related to the manifestation of the issue
* The location of the affected source code (tag/branch/commit or direct URL)
* Any special configuration required to reproduce the issue
* Step-by-step instructions to reproduce the issue
* Proof-of-concept or exploit code (if possible)
* Impact of the issue, including how an attacker might exploit the issue
This information will help us triage your report more quickly.
## Web Context
The library that is developed in this repository was either extracted from [PHPUnit](https://github.com/sebastianbergmann/phpunit) or developed specifically as a dependency for PHPUnit.
The library is developed with a focus on development environments and the command-line. No specific testing or hardening with regard to using the library in an HTTP or web context or with untrusted input data is performed. The library might also contain functionality that intentionally exposes internal application data for debugging purposes.
If the library is used in a web application, the application developer is responsible for filtering inputs or escaping outputs as necessary and for verifying that the used functionality is safe for use within the intended context.
Vulnerabilities specific to the use outside a development context will be fixed as applicable, provided that the fix does not have an averse effect on the primary use case for development purposes.
After the above, if you still would like to report a security vulnerability, please email `sebastian@phpunit.de`.
+4 -3
View File
@@ -12,12 +12,13 @@
}
],
"support": {
"issues": "https://github.com/sebastianbergmann/complexity/issues"
"issues": "https://github.com/sebastianbergmann/complexity/issues",
"security": "https://github.com/sebastianbergmann/complexity/security/policy"
},
"prefer-stable": true,
"require": {
"php": ">=8.1",
"nikic/php-parser": "^4.10"
"nikic/php-parser": "^4.18 || ^5.0"
},
"require-dev": {
"phpunit/phpunit": "^10.0"
@@ -36,7 +37,7 @@
},
"extra": {
"branch-alias": {
"dev-main": "3.0-dev"
"dev-main": "3.2-dev"
}
}
}
+3 -10
View File
@@ -12,12 +12,10 @@ namespace SebastianBergmann\Complexity;
use function assert;
use function file_get_contents;
use PhpParser\Error;
use PhpParser\Lexer;
use PhpParser\Node;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitor\NameResolver;
use PhpParser\NodeVisitor\ParentConnectingVisitor;
use PhpParser\Parser;
use PhpParser\ParserFactory;
final class Calculator
@@ -36,7 +34,7 @@ final class Calculator
public function calculateForSourceString(string $source): ComplexityCollection
{
try {
$nodes = $this->parser()->parse($source);
$nodes = (new ParserFactory)->createForHostVersion()->parse($source);
assert($nodes !== null);
@@ -47,7 +45,7 @@ final class Calculator
throw new RuntimeException(
$error->getMessage(),
$error->getCode(),
$error
$error,
);
}
// @codeCoverageIgnoreEnd
@@ -75,16 +73,11 @@ final class Calculator
throw new RuntimeException(
$error->getMessage(),
$error->getCode(),
$error
$error,
);
}
// @codeCoverageIgnoreEnd
return $complexityCalculatingVisitor->result();
}
private function parser(): Parser
{
return (new ParserFactory)->create(ParserFactory::PREFER_PHP7, new Lexer);
}
}
+30 -1
View File
@@ -9,27 +9,56 @@
*/
namespace SebastianBergmann\Complexity;
use function str_contains;
/**
* @psalm-immutable
*/
final class Complexity
{
private string $name;
/**
* @psalm-var non-empty-string
*/
private readonly string $name;
/**
* @psalm-var positive-int
*/
private int $cyclomaticComplexity;
/**
* @psalm-param non-empty-string $name
* @psalm-param positive-int $cyclomaticComplexity
*/
public function __construct(string $name, int $cyclomaticComplexity)
{
$this->name = $name;
$this->cyclomaticComplexity = $cyclomaticComplexity;
}
/**
* @psalm-return non-empty-string
*/
public function name(): string
{
return $this->name;
}
/**
* @psalm-return positive-int
*/
public function cyclomaticComplexity(): int
{
return $this->cyclomaticComplexity;
}
public function isFunction(): bool
{
return !$this->isMethod();
}
public function isMethod(): bool
{
return str_contains($this->name, '::');
}
}
@@ -9,7 +9,12 @@
*/
namespace SebastianBergmann\Complexity;
use function array_filter;
use function array_merge;
use function array_reverse;
use function array_values;
use function count;
use function usort;
use Countable;
use IteratorAggregate;
@@ -21,7 +26,7 @@ final class ComplexityCollection implements Countable, IteratorAggregate
/**
* @psalm-var list<Complexity>
*/
private array $items;
private readonly array $items;
public static function fromList(Complexity ...$items): self
{
@@ -49,6 +54,9 @@ final class ComplexityCollection implements Countable, IteratorAggregate
return new ComplexityCollectionIterator($this);
}
/**
* @psalm-return non-negative-int
*/
public function count(): int
{
return count($this->items);
@@ -59,6 +67,9 @@ final class ComplexityCollection implements Countable, IteratorAggregate
return empty($this->items);
}
/**
* @psalm-return non-negative-int
*/
public function cyclomaticComplexity(): int
{
$cyclomaticComplexity = 0;
@@ -69,4 +80,53 @@ final class ComplexityCollection implements Countable, IteratorAggregate
return $cyclomaticComplexity;
}
public function isFunction(): self
{
return new self(
array_values(
array_filter(
$this->items,
static fn (Complexity $complexity): bool => $complexity->isFunction(),
),
),
);
}
public function isMethod(): self
{
return new self(
array_values(
array_filter(
$this->items,
static fn (Complexity $complexity): bool => $complexity->isMethod(),
),
),
);
}
public function mergeWith(self $other): self
{
return new self(
array_merge(
$this->asArray(),
$other->asArray(),
),
);
}
public function sortByDescendingCyclomaticComplexity(): self
{
$items = $this->items;
usort(
$items,
static function (Complexity $a, Complexity $b): int
{
return $a->cyclomaticComplexity() <=> $b->cyclomaticComplexity();
},
);
return new self(array_reverse($items));
}
}
@@ -16,7 +16,7 @@ final class ComplexityCollectionIterator implements Iterator
/**
* @psalm-var list<Complexity>
*/
private array $items;
private readonly array $items;
private int $position = 0;
public function __construct(ComplexityCollection $items)
@@ -12,11 +12,13 @@ namespace SebastianBergmann\Complexity;
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;
use PhpParser\Node\Stmt\Function_;
use PhpParser\Node\Stmt\Interface_;
use PhpParser\Node\Stmt\Trait_;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitorAbstract;
@@ -41,6 +43,14 @@ final class ComplexityCalculatingVisitor extends NodeVisitorAbstract
}
if ($node instanceof ClassMethod) {
if ($node->getAttribute('parent') instanceof Interface_) {
return null;
}
if ($node->isAbstract()) {
return null;
}
$name = $this->classMethodName($node);
} else {
$name = $this->functionName($node);
@@ -52,7 +62,7 @@ final class ComplexityCalculatingVisitor extends NodeVisitorAbstract
$this->result[] = new Complexity(
$name,
$this->cyclomaticComplexity($statements)
$this->cyclomaticComplexity($statements),
);
if ($this->shortCircuitTraversal) {
@@ -69,6 +79,8 @@ final class ComplexityCalculatingVisitor extends NodeVisitorAbstract
/**
* @param Stmt[] $statements
*
* @psalm-return positive-int
*/
private function cyclomaticComplexity(array $statements): int
{
@@ -84,22 +96,37 @@ final class ComplexityCalculatingVisitor extends NodeVisitorAbstract
return $cyclomaticComplexityCalculatingVisitor->cyclomaticComplexity();
}
/**
* @psalm-return non-empty-string
*/
private function classMethodName(ClassMethod $node): string
{
$parent = $node->getAttribute('parent');
assert($parent instanceof Class_ || $parent instanceof Trait_);
if ($parent->getAttribute('parent') instanceof New_) {
return 'anonymous class';
}
assert(isset($parent->namespacedName));
assert($parent->namespacedName instanceof Name);
return $parent->namespacedName->toString() . '::' . $node->name->toString();
}
/**
* @psalm-return non-empty-string
*/
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;
}
}
@@ -26,6 +26,9 @@ use PhpParser\NodeVisitorAbstract;
final class CyclomaticComplexityCalculatingVisitor extends NodeVisitorAbstract
{
/**
* @psalm-var positive-int
*/
private int $cyclomaticComplexity = 1;
public function enterNode(Node $node): void
@@ -47,6 +50,9 @@ final class CyclomaticComplexityCalculatingVisitor extends NodeVisitorAbstract
}
}
/**
* @psalm-return positive-int
*/
public function cyclomaticComplexity(): int
{
return $this->cyclomaticComplexity;