Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
95.00% covered (success)
95.00%
19 / 20
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
Less_Visitor
95.00% covered (success)
95.00%
19 / 20
66.67% covered (warning)
66.67%
2 / 3
11
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
 visitObj
93.33% covered (success)
93.33%
14 / 15
0.00% covered (danger)
0.00%
0 / 1
8.02
 visitArray
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2/**
3 * @private
4 */
5class Less_Visitor {
6
7    protected $methods = [];
8    protected $_visitFnCache = [];
9
10    public function __construct() {
11        $this->_visitFnCache = get_class_methods( get_class( $this ) );
12        $this->_visitFnCache = array_flip( $this->_visitFnCache );
13    }
14
15    public function visitObj( $node ) {
16        if ( !$node || !is_object( $node ) ) {
17            return $node;
18        }
19        $funcName = 'visit' . str_replace( [ 'Less_Tree_', '_' ], '', get_class( $node ) );
20        if ( isset( $this->_visitFnCache[$funcName] ) ) {
21            $visitDeeper = true;
22            $newNode = $this->$funcName( $node, $visitDeeper );
23            if ( $this instanceof Less_VisitorReplacing ) {
24                $node = $newNode;
25            }
26
27            if ( $visitDeeper && is_object( $node ) ) {
28                $node->accept( $this );
29            }
30
31            $funcName .= 'Out';
32            if ( isset( $this->_visitFnCache[$funcName] ) ) {
33                $this->$funcName( $node );
34            }
35
36        } else {
37            $node->accept( $this );
38        }
39
40        return $node;
41    }
42
43    public function visitArray( &$nodes ) {
44        // NOTE: The use of by-ref in a normal (non-replacing) Visitor may be surprising,
45        // but upstream relies on this for Less_ImportVisitor, which modifies values of
46        // `$importParent->rules` yet is not a replacing visitor.
47        foreach ( $nodes as &$node ) {
48            $this->visitObj( $node );
49        }
50        return $nodes;
51    }
52}