Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of sebastian/complexity.
4
 *
5
 * (c) Sebastian Bergmann <sebastian@phpunit.de>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace SebastianBergmann\Complexity;
11
 
12
use function count;
13
use Countable;
14
use IteratorAggregate;
15
 
16
/**
17
 * @psalm-immutable
18
 */
19
final class ComplexityCollection implements Countable, IteratorAggregate
20
{
21
    /**
22
     * @psalm-var list<Complexity>
23
     */
24
    private $items = [];
25
 
26
    public static function fromList(Complexity ...$items): self
27
    {
28
        return new self($items);
29
    }
30
 
31
    /**
32
     * @psalm-param list<Complexity> $items
33
     */
34
    private function __construct(array $items)
35
    {
36
        $this->items = $items;
37
    }
38
 
39
    /**
40
     * @psalm-return list<Complexity>
41
     */
42
    public function asArray(): array
43
    {
44
        return $this->items;
45
    }
46
 
47
    public function getIterator(): ComplexityCollectionIterator
48
    {
49
        return new ComplexityCollectionIterator($this);
50
    }
51
 
52
    public function count(): int
53
    {
54
        return count($this->items);
55
    }
56
 
57
    public function isEmpty(): bool
58
    {
59
        return empty($this->items);
60
    }
61
 
62
    public function cyclomaticComplexity(): int
63
    {
64
        $cyclomaticComplexity = 0;
65
 
66
        foreach ($this as $item) {
67
            $cyclomaticComplexity += $item->cyclomaticComplexity();
68
        }
69
 
70
        return $cyclomaticComplexity;
71
    }
72
}