Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
96.30% covered (success)
96.30%
26 / 27
80.00% covered (warning)
80.00%
4 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
Less_Tree_Extend
96.30% covered (success)
96.30%
26 / 27
80.00% covered (warning)
80.00%
4 / 5
11
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
1 / 1
3
 accept
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 compile
100.00% covered (success)
100.00%
3 / 3
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
 findSelfSelectors
85.71% covered (warning)
85.71%
6 / 7
0.00% covered (danger)
0.00%
0 / 1
5.07
1<?php
2declare( strict_types = 1 );
3
4/**
5 * @private
6 */
7class Less_Tree_Extend extends Less_Tree {
8
9    /** @var Less_Tree_Selector */
10    public $selector;
11    /** @var string */
12    public $option;
13    /** @var int */
14    public $index;
15    /** @var Less_Tree_Selector[] */
16    public $selfSelectors = [];
17    /** @var bool */
18    public $allowBefore;
19    /** @var bool */
20    public $allowAfter;
21    /** @var bool */
22    public $firstExtendOnThisSelectorPath;
23    /** @var Less_Tree_Ruleset|null */
24    public $ruleset;
25    /** @var string */
26    public $object_id;
27    /** @var array<string,true> */
28    public $parent_ids = [];
29
30    /**
31     * @param Less_Tree_Selector $selector
32     * @param string $option
33     * @param int $index
34     */
35    public function __construct( $selector, $option, $index ) {
36        static $i = 0;
37        $this->selector = $selector;
38        $this->option = $option;
39        $this->index = $index;
40
41        switch ( $option ) {
42            case "all":
43                $this->allowBefore = true;
44                $this->allowAfter = true;
45                break;
46            default:
47                $this->allowBefore = false;
48                $this->allowAfter = false;
49                break;
50        }
51
52        // This must use a string (instead of int) so that array_merge()
53        // preserves keys on arrays that use IDs in their keys.
54        $this->object_id = 'id_' . $i++;
55
56        $this->parent_ids = [
57            $this->object_id => true
58        ];
59    }
60
61    public function accept( $visitor ) {
62        $this->selector = $visitor->visitObj( $this->selector );
63    }
64
65    public function compile( $env ) {
66        Less_Parser::$has_extends = true;
67        $this->selector = $this->selector->compile( $env );
68        return $this;
69        // return new self( $this->selector->compile($env), $this->option, $this->index);
70    }
71
72    public function clone() {
73        return new self( $this->selector, $this->option, $this->index );
74    }
75
76    public function findSelfSelectors( $selectors ) {
77        $selfElements = [];
78
79        for ( $i = 0, $selectors_len = count( $selectors ); $i < $selectors_len; $i++ ) {
80            $selectorElements = $selectors[$i]->elements;
81            // duplicate the logic in genCSS function inside the selector node.
82            // future TODO - move both logics into the selector joiner visitor
83            if ( $i && $selectorElements && $selectorElements[0]->combinator === "" ) {
84                $selectorElements[0]->combinator = ' ';
85            }
86            $selfElements = array_merge( $selfElements, $selectors[$i]->elements );
87        }
88
89        $this->selfSelectors = [ new Less_Tree_Selector( $selfElements ) ];
90    }
91
92}