Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
Section
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 6
42
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
 setId
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setAboutId
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 addNode
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 addSection
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 hasNestedLevel
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2declare( strict_types = 1 );
3
4namespace Wikimedia\Parsoid\Wt2Html\DOM\Processors;
5
6use Wikimedia\Parsoid\Core\SectionMetadata;
7use Wikimedia\Parsoid\DOM\Document;
8use Wikimedia\Parsoid\DOM\Element;
9use Wikimedia\Parsoid\DOM\Node;
10
11class Section {
12    /** @var int */
13    private $level;
14
15    /**
16     * Useful during debugging, unrelated to data-mw-section-id
17     * @var int
18     */
19    private $debugId;
20
21    /** @var Element */
22    public $container;
23
24    /** @var SectionMetadata */
25    public $metadata;
26
27    public function __construct( int $level, int $debugId, Document $ownerDoc ) {
28        $this->level = $level;
29        $this->debugId = $debugId;
30        $this->container = $ownerDoc->createElement( 'section' );
31        // Use named arguments here in PHP 8.0+
32        $this->metadata = new SectionMetadata(
33            -1, /* tocLevel */
34            $level /* hLevel */
35        );
36    }
37
38    public function setId( int $id ): void {
39        $this->container->setAttribute( 'data-mw-section-id', (string)$id );
40        // $this->container->setAttribute( 'data-debug-id', (string)$this->debugId );
41    }
42
43    public function setAboutId( string $aboutId ): void {
44        $this->container->setAttribute( 'about', $aboutId );
45    }
46
47    public function addNode( Node $node ): void {
48        $this->container->appendChild( $node );
49    }
50
51    public function addSection( Section $section ): void {
52        // error_log( "Appending to " . $this->debugId . '\n' );
53        $this->container->appendChild( $section->container );
54    }
55
56    /**
57     * Does this section have a nesting level of $level?
58     * @param int $level
59     * @return bool
60     */
61    public function hasNestedLevel( int $level ): bool {
62        return $level > $this->level;
63    }
64}