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