EditInfo::__construct()   A
last analyzed

Complexity

Conditions 6
Paths 5

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 6.0163

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 12
cts 13
cp 0.9231
rs 9.0444
c 0
b 0
f 0
cc 6
nc 5
nop 4
crap 6.0163
1
<?php
2
3
namespace Mediawiki\DataModel;
4
5
use InvalidArgumentException;
6
7
/**
8
 * Represents flags that can be used when edits are made
9
 *
10
 * @author Addshore
11
 */
12
class EditInfo {
13
14
	// minor flags
15
	public const MINOR = true;
16
	public const NOTMINOR = false;
17
	// bot flags
18
	public const BOT = true;
19
	public const NOTBOT = false;
20
	// maxlag flags
21
	public const OFFLAG = null;
22
23
	/**
24
	 * @var EditInfo::MINOR|self::NOTMINOR
25
	 */
26
	protected $minor = false;
27
28
	/**
29
	 * @var EditInfo::BOT|self::NOTBOT
30
	 */
31
	protected $bot = false;
32
33
		/**
34
		 * @var int
35
		 */
36
	protected $maxlag = null;
37
38
	/**
39
	 * @var string
40
	 */
41
	protected $summary = null;
42
43
	/**
44
	 * @param string $summary
45
	 * @param bool $minor
46
	 * @param bool $bot
47
	 * @param int $maxlag
48
	 *
49
	 * @throws InvalidArgumentException
50 9
	 */
51 9
	public function __construct( $summary = '', $minor = self::NOTMINOR, $bot = self::NOTBOT, $maxlag = self::OFFLAG ) {
52 2
		if ( !is_string( $summary ) ) {
53
			throw new InvalidArgumentException( '$summary must be a string' );
54 7
		}
55 1
		if ( !is_bool( $minor ) ) {
56
			throw new InvalidArgumentException( '$minor must be a bool' );
57 6
		}
58 1
		if ( !is_bool( $bot ) ) {
59
			throw new InvalidArgumentException( '$bot must be a bool' );
60 5
		}
61
		if ( !is_int( $maxlag ) && $maxlag !== null ) {
62
			throw new InvalidArgumentException( '$maxlag must be an integer or null' );
63 5
		}
64 5
		$this->summary = $summary;
65 5
		$this->bot = $bot;
66 5
		$this->minor = $minor;
67 5
		$this->maxlag = $maxlag;
68
	}
69
70
	/**
71
	 * @return EditInfo::BOT|self::NOTBOT
0 ignored issues
show
Documentation introduced by
The doc-type EditInfo::BOT|self::NOTBOT could not be parsed: Unknown type name "EditInfo::BOT" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
72 5
	 */
73 5
	public function getBot() {
74
		return $this->bot;
75
	}
76
77
	/**
78
	 * @return EditInfo::MINOR|self::NOTMINOR
0 ignored issues
show
Documentation introduced by
The doc-type EditInfo::MINOR|self::NOTMINOR could not be parsed: Unknown type name "EditInfo::MINOR" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
79 5
	 */
80 5
	public function getMinor() {
81
		return $this->minor;
82
	}
83
84
		/**
85
		 * @return int|null
86
		 */
87
	public function getMaxlag() {
88
		return $this->maxlag;
89
	}
90
91
	/**
92
	 * @return string
93 5
	 */
94 5
	public function getSummary() {
95
		return $this->summary;
96
	}
97
98
}
99