summaryrefslogtreecommitdiff
blob: f92789954441c4fdfe8cd7ef9b9dab52aea5fd78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
/**
 * @file
 * @author Niklas Laxström
 * @license GPL-2.0-or-later
 */

namespace MediaWiki\Extension\Translate\Validation;

use ArrayIterator;
use Countable;
use IteratorAggregate;
use Traversable;

/**
 * Mutable collection for validation issues.
 *
 * @newable
 * @since 2020.06
 */
class ValidationIssues implements Countable, IteratorAggregate {
	/** @var ValidationIssue[] */
	private $issues = [];

	/** Add a new validation issue to the collection. */
	public function add( ValidationIssue $issue ) {
		$this->issues[] = $issue;
	}

	/** Merge another collection to this collection. */
	public function merge( ValidationIssues $issues ) {
		$this->issues = array_merge( $this->issues, $issues->issues );
	}

	/**
	 * Check whether this collection is not empty.
	 *
	 * @return bool False if empty, true otherwise
	 */
	public function hasIssues(): bool {
		return $this->issues !== [];
	}

	/** @return Traversable<ValidationIssue> */
	public function getIterator(): Traversable {
		return new ArrayIterator( $this->issues );
	}

	/** @inheritDoc */
	public function count(): int {
		return count( $this->issues );
	}
}

class_alias( ValidationIssues::class, '\MediaWiki\Extensions\Translate\ValidationIssues' );