Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
83.33% covered (warning)
83.33%
10 / 12
84.62% covered (warning)
84.62%
11 / 13
70.00% covered (warning)
70.00%
7 / 10
66.67% covered (warning)
66.67%
4 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
Collection
83.33% covered (warning)
83.33%
10 / 12
84.62% covered (warning)
84.62%
11 / 13
70.00% covered (warning)
70.00%
7 / 10
66.67% covered (warning)
66.67%
4 / 6
11.19
0.00% covered (danger)
0.00%
0 / 1
 getIterator
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 __construct
80.00% covered (warning)
80.00%
4 / 5
83.33% covered (warning)
83.33%
5 / 6
50.00% covered (danger)
50.00%
2 / 4
0.00% covered (danger)
0.00%
0 / 1
4.12
 add
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 get
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 count
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 toArray
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace App\Shared\Domain\Model;
4
5use ArrayIterator;
6use Countable;
7use InvalidArgumentException;
8use IteratorAggregate;
9
10/**
11 * @author Wilhelm Zwertvaegher
12 * Generic collection
13 * @template T
14 * @implements IteratorAggregate<int, T>
15 */
16class Collection implements IteratorAggregate, Countable
17{
18
19    private string $className;
20
21    /** @var T[] */
22    private array $elements;
23
24    /**
25     * @return ArrayIterator<int, T>
26     */
27    public function getIterator(): ArrayIterator
28    {
29        return new ArrayIterator($this->elements);
30    }
31
32    /**
33     *
34     * @param class-string<T> $className
35     * @param T[] $elements
36     */
37    public function __construct(string $className, array $elements = [])
38    {
39        foreach ($elements as $element) {
40            if (!$element instanceof $className) {
41                throw new InvalidArgumentException(sprintf('All elements must be %s', $className));
42            }
43        }
44        $this->className = $className;
45        $this->elements = $elements;
46    }
47
48
49    /**
50     * @param T $element
51     * @return void
52     */
53    public function add($element): void
54    {
55        if (!$element instanceof $this->className) {
56            throw new InvalidArgumentException(sprintf('All elements must be %s', $this->className));
57        }
58        $this->elements[] = $element;
59    }
60
61    /**
62     * @return T|null
63     */
64    public function get(int $index)
65    {
66        return $this->elements[$index] ?? null;
67    }
68
69    public function count(): int
70    {
71        // TODO: Implement count() method.
72        return count($this->elements);
73    }
74
75    /**
76     * @return T[]
77     */
78    public function toArray(): array
79    {
80        return $this->elements;
81    }
82}

Paths

Below are the source code lines that represent each code path as identified by Xdebug. Please note a path is not necessarily coterminous with a line, a line may contain multiple paths and therefore show up more than once. Please also be aware that some paths may include implicit rather than explicit branches, e.g. an if statement always has an else as part of its logical flow even if you didn't write one.

Collection->__construct
37    public function __construct(string $className, array $elements = [])
38    {
39        foreach ($elements as $element) {
 
39        foreach ($elements as $element) {
 
40            if (!$element instanceof $className) {
 
41                throw new InvalidArgumentException(sprintf('All elements must be %s', $className));
37    public function __construct(string $className, array $elements = [])
38    {
39        foreach ($elements as $element) {
 
39        foreach ($elements as $element) {
 
40            if (!$element instanceof $className) {
 
39        foreach ($elements as $element) {
 
39        foreach ($elements as $element) {
 
39        foreach ($elements as $element) {
40            if (!$element instanceof $className) {
41                throw new InvalidArgumentException(sprintf('All elements must be %s', $className));
42            }
43        }
44        $this->className = $className;
45        $this->elements = $elements;
46    }
37    public function __construct(string $className, array $elements = [])
38    {
39        foreach ($elements as $element) {
 
39        foreach ($elements as $element) {
 
39        foreach ($elements as $element) {
40            if (!$element instanceof $className) {
41                throw new InvalidArgumentException(sprintf('All elements must be %s', $className));
42            }
43        }
44        $this->className = $className;
45        $this->elements = $elements;
46    }
37    public function __construct(string $className, array $elements = [])
38    {
39        foreach ($elements as $element) {
 
39        foreach ($elements as $element) {
40            if (!$element instanceof $className) {
41                throw new InvalidArgumentException(sprintf('All elements must be %s', $className));
42            }
43        }
44        $this->className = $className;
45        $this->elements = $elements;
46    }
Collection->add
53    public function add($element): void
54    {
55        if (!$element instanceof $this->className) {
 
56            throw new InvalidArgumentException(sprintf('All elements must be %s', $this->className));
53    public function add($element): void
54    {
55        if (!$element instanceof $this->className) {
 
58        $this->elements[] = $element;
59    }
Collection->count
72        return count($this->elements);
73    }
Collection->get
64    public function get(int $index)
65    {
66        return $this->elements[$index] ?? null;
67    }
Collection->getIterator
29        return new ArrayIterator($this->elements);
30    }
Collection->toArray
80        return $this->elements;
81    }
{main}
3namespace App\Shared\Domain\Model;
4
5use ArrayIterator;
6use Countable;
7use InvalidArgumentException;
8use IteratorAggregate;
9
10/**
11 * @author Wilhelm Zwertvaegher
12 * Generic collection
13 * @template T
14 * @implements IteratorAggregate<int, T>
15 */
16class Collection implements IteratorAggregate, Countable
17{
18
19    private string $className;
20
21    /** @var T[] */
22    private array $elements;
23
24    /**
25     * @return ArrayIterator<int, T>
26     */
27    public function getIterator(): ArrayIterator
28    {
29        return new ArrayIterator($this->elements);
30    }
31
32    /**
33     *
34     * @param class-string<T> $className
35     * @param T[] $elements
36     */
37    public function __construct(string $className, array $elements = [])
38    {
39        foreach ($elements as $element) {
40            if (!$element instanceof $className) {
41                throw new InvalidArgumentException(sprintf('All elements must be %s', $className));
42            }
43        }
44        $this->className = $className;
45        $this->elements = $elements;
46    }
47
48
49    /**
50     * @param T $element
51     * @return void
52     */
53    public function add($element): void
54    {
55        if (!$element instanceof $this->className) {
56            throw new InvalidArgumentException(sprintf('All elements must be %s', $this->className));
57        }
58        $this->elements[] = $element;
59    }
60
61    /**
62     * @return T|null
63     */
64    public function get(int $index)
65    {
66        return $this->elements[$index] ?? null;
67    }
68
69    public function count(): int
70    {
71        // TODO: Implement count() method.
72        return count($this->elements);
73    }
74
75    /**
76     * @return T[]
77     */
78    public function toArray(): array
79    {
80        return $this->elements;
81    }