Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
8 / 8
CRAP
100.00% covered (success)
100.00%
1 / 1
AutoBlockTarget
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
8 / 8
8
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 toString
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getType
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getLogPage
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getSpecificity
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 validateForCreation
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getLegacyUnion
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace MediaWiki\Block;
4
5use MediaWiki\DAO\WikiAwareEntity;
6use MediaWiki\Page\PageReference;
7use MediaWiki\Page\PageReferenceValue;
8use StatusValue;
9
10/**
11 * A block target of the form #1234 where the number is the block ID. For user
12 * input or display when the IP address needs to be hidden.
13 *
14 * @since 1.44
15 */
16class AutoBlockTarget extends BlockTarget {
17    private int $id;
18
19    /**
20     * @param int $id The block ID
21     * @param string|false $wikiId
22     */
23    public function __construct( int $id, string|false $wikiId = WikiAwareEntity::LOCAL ) {
24        parent::__construct( $wikiId );
25        $this->id = $id;
26    }
27
28    public function toString(): string {
29        return '#' . $this->id;
30    }
31
32    public function getType(): int {
33        return Block::TYPE_AUTO;
34    }
35
36    public function getLogPage(): PageReference {
37        return new PageReferenceValue( NS_USER, $this->toString(), $this->wikiId );
38    }
39
40    /** @inheritDoc */
41    public function getSpecificity() {
42        return 2;
43    }
44
45    public function validateForCreation(): StatusValue {
46        // Autoblocks are never valid for creation
47        return StatusValue::newFatal( 'badipaddress' );
48    }
49
50    /**
51     * Get the block ID
52     *
53     * @return int
54     */
55    public function getId(): int {
56        return $this->id;
57    }
58
59    /** @inheritDoc */
60    protected function getLegacyUnion() {
61        return (string)$this->id;
62    }
63}