Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
44.83% covered (danger)
44.83%
13 / 29
50.00% covered (danger)
50.00%
3 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
FauxGlobalHookArray
44.83% covered (danger)
44.83%
13 / 29
50.00% covered (danger)
50.00%
3 / 6
26.79
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 offsetExists
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 offsetGet
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
 offsetSet
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
20
 offsetUnset
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 getOriginalArray
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace MediaWiki\HookContainer;
4
5use InvalidArgumentException;
6
7/**
8 * @internal
9 */
10class FauxGlobalHookArray implements \ArrayAccess {
11
12    private HookContainer $hookContainer;
13
14    /**
15     * The original handler array.
16     * @var array
17     */
18    private array $originalArray;
19
20    /**
21     * @param HookContainer $hookContainer
22     * @param array $originalArray
23     */
24    public function __construct( HookContainer $hookContainer, array $originalArray = [] ) {
25        $this->hookContainer = $hookContainer;
26        $this->originalArray = $originalArray;
27    }
28
29    /**
30     * @inheritDoc
31     */
32    #[\ReturnTypeWillChange]
33    public function offsetExists( $key ) {
34        wfDeprecatedMsg(
35            'Accessing $wgHooks directly is deprecated, use HookContainer::isRegistered() instead.',
36            '1.40'
37        );
38        return $this->hookContainer->isRegistered( $key );
39    }
40
41    /**
42     * @inheritDoc
43     */
44    #[\ReturnTypeWillChange]
45    public function offsetGet( $key ) {
46        wfDeprecatedMsg(
47            'Accessing $wgHooks directly is deprecated, use HookContainer::getHandlers() ' .
48                'or HookContainer::register() instead.',
49            '1.40'
50        );
51
52        return new FauxHookHandlerArray( $this->hookContainer, $key );
53    }
54
55    /**
56     * @inheritDoc
57     */
58    #[\ReturnTypeWillChange]
59    public function offsetSet( $key, $value ) {
60        if ( !is_string( $key ) ) {
61            throw new InvalidArgumentException( '$key must be a string' );
62        }
63        if ( !is_array( $value ) ) {
64            throw new InvalidArgumentException( '$value must be an array' );
65        }
66
67        wfDeprecatedMsg(
68            'Manipulating $wgHooks is deprecated, use HookContainer::clear() and ' .
69                'HookContainer::register() instead.',
70            '1.40'
71        );
72
73        $this->hookContainer->clear( $key );
74
75        foreach ( $value as $handler ) {
76            $this->hookContainer->register( $key, $handler );
77        }
78    }
79
80    /**
81     * @inheritDoc
82     */
83    #[\ReturnTypeWillChange]
84    public function offsetUnset( $key ) {
85        wfDeprecatedMsg( 'Manipulating $wgHooks is deprecated, use HookContainer::clear() instead.', '1.40' );
86        if ( $this->hookContainer->isRegistered( $key ) ) {
87            $this->hookContainer->clear( $key );
88        }
89    }
90
91    public function getOriginalArray(): array {
92        return $this->originalArray;
93    }
94}