Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
1 / 1
ActionSpecifier
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
6 / 6
8
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
3
 getAction
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getTitle
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getUser
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getIP
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getAccountName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace MediaWiki\Extension\AbuseFilter;
4
5use InvalidArgumentException;
6use MediaWiki\Linker\LinkTarget;
7use MediaWiki\User\UserIdentity;
8
9/**
10 * Plain value object that univocally represents an action being filtered
11 * @todo Add constants for possible actions?
12 * @todo Add the timestamp
13 */
14class ActionSpecifier {
15    /** @var string */
16    private $action;
17    /** @var LinkTarget */
18    private $title;
19    /** @var UserIdentity */
20    private $user;
21    /** @var string */
22    private $requestIP;
23    /** @var string|null */
24    private $accountName;
25
26    /**
27     * @param string $action Action being filtered (e.g. 'edit' or 'createaccount')
28     * @param LinkTarget $title Where the current action is executed. This is the user page
29     *   for account creations.
30     * @param UserIdentity $user
31     * @param string $requestIP
32     * @param string|null $accountName Required iff the action is an account creation
33     */
34    public function __construct(
35        string $action, LinkTarget $title, UserIdentity $user, string $requestIP, ?string $accountName
36    ) {
37        if ( $accountName === null && strpos( $action, 'createaccount' ) !== false ) {
38            throw new InvalidArgumentException( '$accountName required for account creations' );
39        }
40        $this->action = $action;
41        $this->title = $title;
42        $this->user = $user;
43        $this->requestIP = $requestIP;
44        $this->accountName = $accountName;
45    }
46
47    /**
48     * @return string
49     */
50    public function getAction(): string {
51        return $this->action;
52    }
53
54    /**
55     * @return LinkTarget
56     */
57    public function getTitle(): LinkTarget {
58        return $this->title;
59    }
60
61    /**
62     * @return UserIdentity
63     */
64    public function getUser(): UserIdentity {
65        return $this->user;
66    }
67
68    /**
69     * @return string
70     * @note It may be an empty string for less recent changes.
71     */
72    public function getIP(): string {
73        return $this->requestIP;
74    }
75
76    /**
77     * @return string|null
78     */
79    public function getAccountName(): ?string {
80        return $this->accountName;
81    }
82}