Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
VectorComponentMenu
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
3 / 3
4
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
 count
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
 getTemplateData
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2namespace MediaWiki\Skins\Vector\Components;
3
4use Countable;
5
6/**
7 * VectorComponentMenu component
8 */
9class VectorComponentMenu implements VectorComponent, Countable {
10    /** @var array */
11    private $data;
12
13    /**
14     * @param array $data
15     */
16    public function __construct( array $data ) {
17        $this->data = $data;
18    }
19
20    /**
21     * Counts how many items the menu has.
22     *
23     * @return int
24     */
25    public function count(): int {
26        $items = $this->data['array-list-items'] ?? null;
27        if ( $items ) {
28            return count( $items );
29        }
30        $htmlItems = $this->data['html-items'] ?? '';
31        return substr_count( $htmlItems, '<li' );
32    }
33
34    /**
35     * @inheritDoc
36     */
37    public function getTemplateData(): array {
38        return $this->data + [
39            'class' => '',
40            'label' => '',
41            'html-tooltip' => '',
42            'label-class' => '',
43            'html-before-portal' => '',
44            'html-items' => '',
45            'html-after-portal' => '',
46            'array-list-items' => null,
47        ];
48    }
49}