Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
21 / 21
100.00% covered (success)
100.00%
11 / 11
CRAP
100.00% covered (success)
100.00%
1 / 1
PlainAttributes
100.00% covered (success)
100.00%
21 / 21
100.00% covered (success)
100.00%
11 / 11
16
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 merge
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
3
 offsetExists
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 offsetGet
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 offsetSet
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 offsetUnset
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getIterator
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getValues
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getObjects
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
3
 count
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 clone
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace Wikimedia\RemexHtml\Tokenizer;
4
5/**
6 * An Attributes implementation which is a simple array proxy.
7 */
8class PlainAttributes implements Attributes {
9    protected $data;
10    protected $attrObjects;
11
12    public function __construct( $data = [] ) {
13        $this->data = $data;
14    }
15
16    public function merge( Attributes $other ) {
17        foreach ( $other as $name => $value ) {
18            if ( !isset( $this[$name] ) ) {
19                $this[$name] = $value;
20            }
21        }
22    }
23
24    public function offsetExists( $key ): bool {
25        return isset( $this->data[$key] );
26    }
27
28    public function &offsetGet( $key ): string {
29        return $this->data[$key];
30    }
31
32    public function offsetSet( $key, $value ): void {
33        $this->data[$key] = $value;
34        if ( $this->attrObjects !== null ) {
35            $this->attrObjects[$key] = new Attribute( $key, null, null, $key, $value );
36        }
37    }
38
39    public function offsetUnset( $key ): void {
40        unset( $this->data[$key] );
41        unset( $this->attrObjects[$key] );
42    }
43
44    public function getIterator(): \ArrayIterator {
45        return new \ArrayIterator( $this->data );
46    }
47
48    public function getValues() {
49        return $this->data;
50    }
51
52    public function getObjects() {
53        if ( $this->attrObjects === null ) {
54            $result = [];
55            foreach ( $this->data as $name => $value ) {
56                $result[$name] = new Attribute( $name, null, null, $name, $value );
57            }
58            $this->attrObjects = $result;
59        }
60        return $this->attrObjects;
61    }
62
63    public function count() {
64        return count( $this->data );
65    }
66
67    public function clone() {
68        return $this;
69    }
70}