Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
ValidationIssues
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 5
30
0.00% covered (danger)
0.00%
0 / 1
 add
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 merge
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 hasIssues
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getIterator
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 count
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * @file
4 * @author Niklas Laxström
5 * @license GPL-2.0-or-later
6 */
7
8namespace MediaWiki\Extension\Translate\Validation;
9
10use ArrayIterator;
11use Countable;
12use IteratorAggregate;
13use Traversable;
14
15/**
16 * Mutable collection for validation issues.
17 *
18 * @newable
19 * @since 2020.06
20 */
21class ValidationIssues implements Countable, IteratorAggregate {
22    /** @var ValidationIssue[] */
23    private $issues = [];
24
25    /** Add a new validation issue to the collection. */
26    public function add( ValidationIssue $issue ) {
27        $this->issues[] = $issue;
28    }
29
30    /** Merge another collection to this collection. */
31    public function merge( ValidationIssues $issues ) {
32        $this->issues = array_merge( $this->issues, $issues->issues );
33    }
34
35    /**
36     * Check whether this collection is not empty.
37     *
38     * @return bool False if empty, true otherwise
39     */
40    public function hasIssues(): bool {
41        return $this->issues !== [];
42    }
43
44    /** @return Traversable<ValidationIssue> */
45    public function getIterator(): Traversable {
46        return new ArrayIterator( $this->issues );
47    }
48
49    /** @inheritDoc */
50    public function count(): int {
51        return count( $this->issues );
52    }
53}