LogCalls::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
ccs 3
cts 3
cp 1
crap 1
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\PsrLogTestDoubles;
6
7
/**
8
 * Immutable and ordered collection of LogCall objects
9
 *
10
 * @since 2.0
11
 *
12
 * @licence GNU GPL v2+
13
 * @author Jeroen De Dauw < [email protected] >
14
 */
15
class LogCalls implements \IteratorAggregate, \Countable {
16
17
	private $calls;
18
19
	/**
20
	 * @param LogCall[] $calls
21
	 */
22 6
	public function __construct( LogCall... $calls ) {
23 6
		$this->calls = $calls;
24 6
	}
25
26 1
	public function getIterator() {
27 1
		return new \ArrayIterator( $this->calls );
28
	}
29
30
	/**
31
	 * @return string[]
32
	 */
33 2
	public function getMessages(): array {
34 2
		return array_map(
35 2
			function( LogCall $logCall ) {
36 1
				return $logCall->getMessage();
37 2
			},
38 2
			$this->calls
39
		);
40
	}
41
42 2
	public function getFirstCall(): ?LogCall {
43 2
		return empty( $this->calls ) ? null : $this->calls[0];
44
	}
45
46
	/**
47
	 * @since 2.1
48
	 * @return int
49
	 */
50 1
	public function count() {
51 1
		return count( $this->calls );
52
	}
53
54
}
55