class ComplexityCollection
@psalm-immutable
Hierarchy
- class \SebastianBergmann\Complexity\ComplexityCollection implements \Countable, \IteratorAggregate
Expanded class hierarchy of ComplexityCollection
File
-
vendor/
sebastian/ complexity/ src/ Complexity/ ComplexityCollection.php, line 24
Namespace
SebastianBergmann\ComplexityView source
final class ComplexityCollection implements Countable, IteratorAggregate {
/**
* @psalm-var list<Complexity>
*/
private readonly array $items;
public static function fromList(Complexity ...$items) : self {
return new self($items);
}
/**
* @psalm-param list<Complexity> $items
*/
private function __construct(array $items) {
$this->items = $items;
}
/**
* @psalm-return list<Complexity>
*/
public function asArray() : array {
return $this->items;
}
public function getIterator() : ComplexityCollectionIterator {
return new ComplexityCollectionIterator($this);
}
/**
* @psalm-return non-negative-int
*/
public function count() : int {
return count($this->items);
}
public function isEmpty() : bool {
return empty($this->items);
}
/**
* @psalm-return non-negative-int
*/
public function cyclomaticComplexity() : int {
$cyclomaticComplexity = 0;
foreach ($this as $item) {
$cyclomaticComplexity += $item->cyclomaticComplexity();
}
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));
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
ComplexityCollection::$items | private | property | @psalm-var list<Complexity> |
ComplexityCollection::asArray | public | function | @psalm-return list<Complexity> |
ComplexityCollection::count | public | function | @psalm-return non-negative-int |
ComplexityCollection::cyclomaticComplexity | public | function | @psalm-return non-negative-int |
ComplexityCollection::fromList | public static | function | |
ComplexityCollection::getIterator | public | function | |
ComplexityCollection::isEmpty | public | function | |
ComplexityCollection::isFunction | public | function | |
ComplexityCollection::isMethod | public | function | |
ComplexityCollection::mergeWith | public | function | |
ComplexityCollection::sortByDescendingCyclomaticComplexity | public | function | |
ComplexityCollection::__construct | private | function | @psalm-param list<Complexity> $items |