Completed
Push — master ( 2b6e28...3d0129 )
by
unknown
10:26
created

Contrib/less.php/Environment.php (5 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
4
/**
5
 * Environment
6
 *
7
 * @package Less
8
 * @subpackage environment
9
 */
10
class Less_Environment{
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
11
12
	//public $paths = array();				// option - unmodified - paths to search for imports on
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
13
	//public static $files = array();		// list of files that have been imported, used for import-once
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
14
	//public $rootpath;						// option - rootpath to append to URL's
15
	//public static $strictImports = null;	// option -
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
16
	//public $insecure;						// option - whether to allow imports from insecure ssl hosts
17
	//public $processImports;				// option - whether to process imports. if false then imports will not be imported
18
	//public $javascriptEnabled;			// option - whether JavaScript is enabled. if undefined, defaults to true
19
	//public $useFileCache;					// browser only - whether to use the per file session cache
20
	public $currentFileInfo;				// information about the current file - for error reporting and importing and making urls relative etc.
21
22
	public $importMultiple = false; 		// whether we are currently importing multiple copies
23
24
25
	/**
26
	 * @var array
27
	 */
28
	public $frames = array();
29
30
	/**
31
	 * @var array
32
	 */
33
	public $mediaBlocks = array();
34
35
	/**
36
	 * @var array
37
	 */
38
	public $mediaPath = array();
39
40
	public static $parensStack = 0;
41
42
	public static $tabLevel = 0;
43
44
	public static $lastRule = false;
45
46
	public static $_outputMap;
47
48
	public static $mixin_stack = 0;
49
50
	/**
51
	 * @var array
52
	 */
53
	public $functions = array();
54
55
56
	public function Init(){
57
58
		self::$parensStack = 0;
59
		self::$tabLevel = 0;
60
		self::$lastRule = false;
61
		self::$mixin_stack = 0;
62
63
		if( Less_Parser::$options['compress'] ){
64
65
			Less_Environment::$_outputMap = array(
66
				','	=> ',',
67
				': ' => ':',
68
				''  => '',
69
				' ' => ' ',
70
				':' => ' :',
71
				'+' => '+',
72
				'~' => '~',
73
				'>' => '>',
74
				'|' => '|',
75
		        '^' => '^',
76
		        '^^' => '^^'
77
			);
78
79
		}else{
80
81
			Less_Environment::$_outputMap = array(
82
				','	=> ', ',
83
				': ' => ': ',
84
				''  => '',
85
				' ' => ' ',
86
				':' => ' :',
87
				'+' => ' + ',
88
				'~' => ' ~ ',
89
				'>' => ' > ',
90
				'|' => '|',
91
		        '^' => ' ^ ',
92
		        '^^' => ' ^^ '
93
			);
94
95
		}
96
	}
97
98
99
	public function copyEvalEnv($frames = array() ){
100
		$new_env = new Less_Environment();
101
		$new_env->frames = $frames;
102
		return $new_env;
103
	}
104
105
106
	public static function isMathOn(){
107
		return !Less_Parser::$options['strictMath'] || Less_Environment::$parensStack;
108
	}
109
110
	public static function isPathRelative($path){
111
		return !preg_match('/^(?:[a-z-]+:|\/)/',$path);
112
	}
113
114
115
	/**
116
	 * Canonicalize a path by resolving references to '/./', '/../'
117
	 * Does not remove leading "../"
118
	 * @param string path or url
119
	 * @return string Canonicalized path
120
	 *
121
	 */
122
	public static function normalizePath($path){
123
124
		$segments = explode('/',$path);
125
		$segments = array_reverse($segments);
126
127
		$path = array();
128
		$path_len = 0;
129
130
		while( $segments ){
0 ignored issues
show
Bug Best Practice introduced by
The expression $segments of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
131
			$segment = array_pop($segments);
132
			switch( $segment ) {
133
134
				case '.':
135
				break;
136
137
				case '..':
138
					if( !$path_len || ( $path[$path_len-1] === '..') ){
139
						$path[] = $segment;
140
						$path_len++;
141
					}else{
142
						array_pop($path);
143
						$path_len--;
144
					}
145
				break;
146
147
				default:
148
					$path[] = $segment;
149
					$path_len++;
150
				break;
151
			}
152
		}
153
154
		return implode('/',$path);
155
	}
156
157
158
	public function unshiftFrame($frame){
159
		array_unshift($this->frames, $frame);
160
	}
161
162
	public function shiftFrame(){
163
		return array_shift($this->frames);
164
	}
165
166
}
167