Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
74.07% covered (warning)
74.07%
20 / 27
75.00% covered (warning)
75.00%
3 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
Less_Tree_Url
74.07% covered (warning)
74.07%
20 / 27
75.00% covered (warning)
75.00%
3 / 4
17.42
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 accept
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 genCSS
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 compile
65.00% covered (warning)
65.00%
13 / 20
0.00% covered (danger)
0.00%
0 / 1
16.19
1<?php
2/**
3 * @private
4 */
5class Less_Tree_Url extends Less_Tree implements Less_Tree_HasValueProperty {
6
7    public $attrs;
8    public $value;
9    public $currentFileInfo;
10    public $isEvald;
11
12    /**
13     * @param Less_Tree_Variable|Less_Tree_Quoted|Less_Tree_Anonymous $value
14     * @param array|null $currentFileInfo
15     * @param bool|null $isEvald
16     */
17    public function __construct( Less_Tree $value, $currentFileInfo = null, $isEvald = null ) {
18        $this->value = $value;
19        $this->currentFileInfo = $currentFileInfo;
20        $this->isEvald = $isEvald;
21    }
22
23    public function accept( $visitor ) {
24        $this->value = $visitor->visitObj( $this->value );
25    }
26
27    /**
28     * @see Less_Tree::genCSS
29     */
30    public function genCSS( $output ) {
31        $output->add( 'url(' );
32        $this->value->genCSS( $output );
33        $output->add( ')' );
34    }
35
36    /**
37     * @param Less_Environment $env
38     */
39    public function compile( $env ) {
40        $val = $this->value->compile( $env );
41
42        if ( !$this->isEvald ) {
43            // Add the base path if the URL is relative
44            if ( Less_Parser::$options['relativeUrls']
45                && $this->currentFileInfo
46                && is_string( $val->value )
47                && Less_Environment::isPathRelative( $val->value )
48            ) {
49                $rootpath = $this->currentFileInfo['uri_root'];
50                if ( !$val->quote ) {
51                    $rootpath = preg_replace( '/[\(\)\'"\s]/', '\\$1', $rootpath );
52                }
53                $val->value = $rootpath . $val->value;
54            }
55
56            $val->value = Less_Environment::normalizePath( $val->value );
57        }
58
59        // Add cache buster if enabled
60        if ( Less_Parser::$options['urlArgs'] ) {
61            if ( !preg_match( '/^\s*data:/', $val->value ) ) {
62                $delimiter = strpos( $val->value, '?' ) === false ? '?' : '&';
63                $urlArgs = $delimiter . Less_Parser::$options['urlArgs'];
64                $hash_pos = strpos( $val->value, '#' );
65                if ( $hash_pos !== false ) {
66                    $val->value = substr_replace( $val->value, $urlArgs, $hash_pos, 0 );
67                } else {
68                    $val->value .= $urlArgs;
69                }
70            }
71        }
72
73        return new self( $val, $this->currentFileInfo, true );
74    }
75
76}