From e8f652f365e6d475fa20325dc2347cd2ecea5eb1 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Tue, 16 Oct 2018 06:11:11 +0100 Subject: [PATCH] tests: Remove and resolve more PSR2 style overrides Inspired by https://github.com/MarcusSchwarz/lesserphp/pull/6. --- .phpcs.xml | 12 --- lessc.inc.php | 255 +++++++++++++++++++++++++++----------------- lessify.inc.php | 104 +++++++++--------- tests/InputTest.php | 11 +- tests/sort.php | 11 +- 5 files changed, 220 insertions(+), 173 deletions(-) diff --git a/.phpcs.xml b/.phpcs.xml index 8d0ffbd9..802e79c6 100644 --- a/.phpcs.xml +++ b/.phpcs.xml @@ -3,7 +3,6 @@ - @@ -12,36 +11,25 @@ - - - - - - - - - - - diff --git a/lessc.inc.php b/lessc.inc.php index f59e3f9b..37988952 100644 --- a/lessc.inc.php +++ b/lessc.inc.php @@ -81,12 +81,12 @@ protected function fileExists($name) { return is_file($name); } - static public function compressList($items, $delim) { + public static function compressList($items, $delim) { if (!isset($items[1]) && isset($items[0])) return $items[0]; else return array('list', $delim, $items); } - static public function preg_quote($what) { + public static function preg_quote($what) { return preg_quote($what, '/'); } @@ -294,7 +294,7 @@ protected function deduplicate($lines) { $unique = array(); $comments = array(); - foreach($lines as $line) { + foreach ($lines as $line) { if (strpos($line, '/*') === 0) { $comments[] = $line; continue; @@ -390,8 +390,8 @@ protected function compileMediaQuery($queries) { protected function multiplyMedia($env, $childQueries = null) { if (is_null($env) || - !empty($env->block->type) && $env->block->type != "media") - { + !empty($env->block->type) && $env->block->type != "media" + ) { return $childQueries; } @@ -634,7 +634,7 @@ protected function zipSetArgs($args, $orderedValues, $keywordValues) { $assignedValues = array(); $i = 0; - foreach ($args as $a) { + foreach ($args as $a) { if ($a[0] == "arg") { if (isset($keywordValues[$a[1]])) { // has keyword arg @@ -746,8 +746,8 @@ protected function compileProp($prop, $block, $out) { if ($suffix !== null && $subProp[0] == "assign" && is_string($subProp[1]) && - $subProp[1]{0} != $this->vPrefix) - { + $subProp[1]{0} != $this->vPrefix + ) { $subProp[2] = array( 'list', ' ', array($subProp[2], array('keyword', $suffix)) @@ -774,7 +774,7 @@ protected function compileProp($prop, $block, $out) { case "comment": $out->lines[] = $prop[1]; break; - case "import"; + case "import": list(, $importPath, $importId) = $prop; $importPath = $this->reduce($importPath); @@ -971,12 +971,16 @@ protected function lib_isrem($value) { protected function lib_rgbahex($color) { $color = $this->coerceColor($color); - if (is_null($color)) + if (is_null($color)) { $this->throwError("color expected for rgbahex"); + } return sprintf("#%02x%02x%02x%02x", - isset($color[4]) ? $color[4]*255 : 255, - $color[1],$color[2], $color[3]); + isset($color[4]) ? $color[4] * 255 : 255, + $color[1], + $color[2], + $color[3] + ); } protected function lib_argb($color){ @@ -995,20 +999,20 @@ protected function lib_data_uri($value) { $fullpath = $this->findImport($url); - if($fullpath && ($fsize = filesize($fullpath)) !== false) { + if ($fullpath && ($fsize = filesize($fullpath)) !== false) { // IE8 can't handle data uris larger than 32KB - if($fsize/1024 < 32) { - if(is_null($mime)) { - if(class_exists('finfo')) { // php 5.3+ + if ($fsize/1024 < 32) { + if (is_null($mime)) { + if (class_exists('finfo')) { // php 5.3+ $finfo = new finfo(FILEINFO_MIME); $mime = explode('; ', $finfo->file($fullpath)); $mime = $mime[0]; - } elseif(function_exists('mime_content_type')) { // PHP 5.2 + } elseif (function_exists('mime_content_type')) { // PHP 5.2 $mime = mime_content_type($fullpath); } } - if(!is_null($mime)) // fallback if the mime type is still unknown + if (!is_null($mime)) // fallback if the mime type is still unknown $url = sprintf('data:%s;base64,%s', $mime, base64_encode(file_get_contents($fullpath))); } } @@ -1074,7 +1078,7 @@ protected function lib_ceil($arg) { } protected function lib_round($arg) { - if($arg[0] != "list") { + if ($arg[0] != "list") { $value = $this->assertNumber($arg); return array("number", round($value), $arg[2]); } else { @@ -1147,7 +1151,9 @@ protected function lib_spin($args) { $hsl = $this->toHSL($color); $hsl[1] = $hsl[1] + $delta % 360; - if ($hsl[1] < 0) $hsl[1] += 360; + if ($hsl[1] < 0) { + $hsl[1] += 360; + } return $this->toRGB($hsl); } @@ -1365,7 +1371,9 @@ public function assertArgs($value, $expectedArgs, $name="") { } protected function toHSL($color) { - if ($color[0] == 'hsl') return $color; + if ($color[0] === 'hsl') { + return $color; + } $r = $color[1] / 255; $g = $color[2] / 255; @@ -1378,34 +1386,50 @@ protected function toHSL($color) { if ($min == $max) { $S = $H = 0; } else { - if ($L < 0.5) - $S = ($max - $min)/($max + $min); - else - $S = ($max - $min)/(2.0 - $max - $min); - - if ($r == $max) $H = ($g - $b)/($max - $min); - elseif ($g == $max) $H = 2.0 + ($b - $r)/($max - $min); - elseif ($b == $max) $H = 4.0 + ($r - $g)/($max - $min); + if ($L < 0.5) { + $S = ($max - $min) / ($max + $min); + } else { + $S = ($max - $min) / (2.0 - $max - $min); + } + if ($r == $max) { + $H = ($g - $b) / ($max - $min); + } elseif ($g == $max) { + $H = 2.0 + ($b - $r) / ($max - $min); + } elseif ($b == $max) { + $H = 4.0 + ($r - $g) / ($max - $min); + } } $out = array('hsl', ($H < 0 ? $H + 6 : $H)*60, - $S*100, - $L*100, + $S * 100, + $L * 100, ); - if (count($color) > 4) $out[] = $color[4]; // copy alpha + if (count($color) > 4) { + // copy alpha + $out[] = $color[4]; + } return $out; } protected function toRGB_helper($comp, $temp1, $temp2) { - if ($comp < 0) $comp += 1.0; - elseif ($comp > 1) $comp -= 1.0; + if ($comp < 0) { + $comp += 1.0; + } elseif ($comp > 1) { + $comp -= 1.0; + } - if (6 * $comp < 1) return $temp1 + ($temp2 - $temp1) * 6 * $comp; - if (2 * $comp < 1) return $temp2; - if (3 * $comp < 2) return $temp1 + ($temp2 - $temp1)*((2/3) - $comp) * 6; + if (6 * $comp < 1) { + return $temp1 + ($temp2 - $temp1) * 6 * $comp; + } + if (2 * $comp < 1) { + return $temp2; + } + if (3 * $comp < 2) { + return $temp1 + ($temp2 - $temp1)*((2/3) - $comp) * 6; + } return $temp1; } @@ -1415,7 +1439,9 @@ protected function toRGB_helper($comp, $temp1, $temp2) { * Expects H to be in range of 0 to 360, S and L in 0 to 100 */ protected function toRGB($color) { - if ($color[0] == 'color') return $color; + if ($color[0] === 'color') { + return $color; + } $H = $color[1] / 360; $S = $color[2] / 100; @@ -1425,7 +1451,7 @@ protected function toRGB($color) { $r = $g = $b = $L; } else { $temp2 = $L < 0.5 ? - $L*(1.0 + $S) : + $L * (1.0 + $S) : $L + $S - $L * $S; $temp1 = 2.0 * $L - $temp2; @@ -1437,7 +1463,10 @@ protected function toRGB($color) { // $out = array('color', round($r*255), round($g*255), round($b*255)); $out = array('color', $r*255, $g*255, $b*255); - if (count($color) > 4) $out[] = $color[4]; // copy alpha + if (count($color) > 4) { + // copy alpha + $out[] = $color[4]; + } return $out; } @@ -1451,7 +1480,10 @@ protected function clamp($v, $max = 1, $min = 0) { */ protected function funcToColor($func) { $fname = $func[1]; - if ($func[2][0] != 'list') return false; // need a list of arguments + if ($func[2][0] != 'list') { + // need a list of arguments + return false; + } $rawComponents = $func[2][2]; if ($fname == 'hsl' || $fname == 'hsla') { @@ -1461,15 +1493,21 @@ protected function funcToColor($func) { $val = $this->reduce($c); $val = isset($val[1]) ? floatval($val[1]) : 0; - if ($i == 0) $clamp = 360; - elseif ($i < 3) $clamp = 100; - else $clamp = 1; + if ($i == 0) { + $clamp = 360; + } elseif ($i < 3) { + $clamp = 100; + } else { + $clamp = 1; + } $hsl[] = $this->clamp($val, $clamp); $i++; } - while (count($hsl) < 4) $hsl[] = 0; + while (count($hsl) < 4) { + $hsl[] = 0; + } return $this->toRGB($hsl); } elseif ($fname == 'rgb' || $fname == 'rgba') { @@ -1493,7 +1531,9 @@ protected function funcToColor($func) { $i++; } - while (count($components) < 3) $components[] = 0; + while (count($components) < 3) { + $components[] = 0; + } array_unshift($components, 'color'); return $this->fixColor($components); } @@ -1574,8 +1614,11 @@ protected function reduce($value, $forExpression = false) { } // convert to a typed value if the result is a php primitive - if (is_numeric($ret)) $ret = array('number', $ret, ""); - elseif (!is_array($ret)) $ret = array('keyword', $ret); + if (is_numeric($ret)) { + $ret = array('number', $ret, ""); + } elseif (!is_array($ret)) { + $ret = array('keyword', $ret); + } return $ret; } @@ -1617,7 +1660,7 @@ protected function reduce($value, $forExpression = false) { // coerce a value for use in color operation protected function coerceColor($value) { - switch($value[0]) { + switch ($value[0]) { case 'color': return $value; case 'raw_color': $c = array("color", 0, 0, 0); @@ -1638,9 +1681,9 @@ protected function coerceColor($value) { if (isset(self::$cssColors[$name])) { $rgba = explode(',', self::$cssColors[$name]); - if(isset($rgba[3])) + if (isset($rgba[3])) { return array('color', $rgba[0], $rgba[1], $rgba[2], $rgba[3]); - + } return array('color', $rgba[0], $rgba[1], $rgba[2]); } return null; @@ -1667,8 +1710,7 @@ protected function flattenList($value) { } public function toBool($a) { - if ($a) return self::$TRUE; - else return self::$FALSE; + return $a ? self::$TRUE : self::$FALSE; } // evaluate an expression @@ -1711,8 +1753,12 @@ protected function evaluate($exp) { // make the expression look it did before being parsed $paddedOp = $op; - if ($whiteBefore) $paddedOp = " " . $paddedOp; - if ($whiteAfter) $paddedOp .= " "; + if ($whiteBefore) { + $paddedOp = " " . $paddedOp; + } + if ($whiteAfter) { + $paddedOp .= " "; + } return array("string", "", array($left, $paddedOp, $right)); } @@ -1776,7 +1822,9 @@ protected function op_color_color($op, $left, $right) { $out[] = $lval % $rval; break; case '/': - if ($rval == 0) $this->throwError("evaluate error: can't divide by zero"); + if ($rval == 0) { + $this->throwError("evaluate error: can't divide by zero"); + } $out[] = $lval / $rval; break; default: @@ -1786,7 +1834,7 @@ protected function op_color_color($op, $left, $right) { return $this->fixColor($out); } - function lib_red($color){ + public function lib_red($color){ $color = $this->coerceColor($color); if (is_null($color)) { $this->throwError('color expected for red()'); @@ -1795,7 +1843,7 @@ function lib_red($color){ return $color[1]; } - function lib_green($color){ + public function lib_green($color){ $color = $this->coerceColor($color); if (is_null($color)) { $this->throwError('color expected for green()'); @@ -1804,7 +1852,7 @@ function lib_green($color){ return $color[2]; } - function lib_blue($color){ + public function lib_blue($color){ $color = $this->coerceColor($color); if (is_null($color)) { $this->throwError('color expected for blue()'); @@ -1898,12 +1946,13 @@ protected function get($name) { return array('list', ' ', $current->arguments); } - if (isset($current->store[$name])) + if (isset($current->store[$name])) { return $current->store[$name]; - else { - $current = isset($current->storeParent) ? - $current->storeParent : $current->parent; } + + $current = isset($current->storeParent) ? + $current->storeParent : + $current->parent; } $this->throwError("variable $name is undefined"); @@ -1914,7 +1963,9 @@ protected function injectVariables($args) { $this->pushEnv(); $parser = new lessc_parser($this, __METHOD__); foreach ($args as $name => $strValue) { - if ($name{0} != '@') $name = '@'.$name; + if ($name{0} !== '@') { + $name = '@' . $name; + } $parser->count = 0; $parser->buffer = (string)$strValue; if (!$parser->propertyValue($value)) { @@ -2022,15 +2073,15 @@ public function cachedCompile($in, $force = false) { if (is_string($in)) { $root = $in; - } elseif (is_array($in) and isset($in['root'])) { - if ($force or ! isset($in['files'])) { + } elseif (is_array($in) && isset($in['root'])) { + if ($force || !isset($in['files'])) { // If we are forcing a recompile or if for some reason the // structure does not contain any file information we should // specify the root to trigger a rebuild. $root = $in['root']; - } elseif (isset($in['files']) and is_array($in['files'])) { - foreach ($in['files'] as $fname => $ftime ) { - if (!file_exists($fname) or filemtime($fname) > $ftime) { + } elseif (isset($in['files']) && is_array($in['files'])) { + foreach ($in['files'] as $fname => $ftime) { + if (!file_exists($fname) || filemtime($fname) > $ftime) { // One of the files we knew about previously has changed // so we should look at our incoming root again. $root = $in['root']; @@ -2473,8 +2524,8 @@ protected function parseChunk() { // setting a property if ($this->keyword($key) && $this->assign() && - $this->propertyValue($value, $key) && $this->end()) - { + $this->propertyValue($value, $key) && $this->end() + ) { $this->append(array('assign', $key, $value), $s); return true; } else { @@ -2489,8 +2540,8 @@ protected function parseChunk() { // media if ($this->literal('@media')) { if (($this->mediaQueryList($mediaQueries) || true) - && $this->literal('{')) - { + && $this->literal('{') + ) { $media = $this->pushSpecialBlock("media"); $media->queries = is_null($mediaQueries) ? array() : $mediaQueries; return true; @@ -2503,8 +2554,8 @@ protected function parseChunk() { if ($this->literal("@", false) && $this->keyword($dirName)) { if ($this->isDirective($dirName, $this->blockDirectives)) { if (($this->openString("{", $dirValue, null, array(";")) || true) && - $this->literal("{")) - { + $this->literal("{") + ) { $dir = $this->pushSpecialBlock("directive"); $dir->name = $dirName; if (isset($dirValue)) $dir->value = $dirValue; @@ -2523,8 +2574,8 @@ protected function parseChunk() { // setting a variable if ($this->variable($var) && $this->assign() && - $this->propertyValue($value) && $this->end()) - { + $this->propertyValue($value) && $this->end() + ) { $this->append(array('assign', $var, $value), $s); return true; } else { @@ -2539,8 +2590,8 @@ protected function parseChunk() { // opening parametric mixin if ($this->tag($tag, true) && $this->argumentDef($args, $isVararg) && ($this->guards($guards) || true) && - $this->literal('{')) - { + $this->literal('{') + ) { $block = $this->pushBlock($this->fixTags(array($tag))); $block->args = $args; $block->isVararg = $isVararg; @@ -2600,8 +2651,8 @@ protected function parseChunk() { // mixin if ($this->mixinTags($tags) && ($this->argumentDef($argv, $isVararg) || true) && - ($this->keyword($suffix) || true) && $this->end()) - { + ($this->keyword($suffix) || true) && $this->end() + ) { $tags = $this->fixTags($tags); $this->append(array('mixin', $tags, $argv, $suffix), $s); return true; @@ -2756,8 +2807,8 @@ protected function parenValue(&$out) { $inParens = $this->inParens; if ($this->literal("(") && ($this->inParens = true) && $this->expression($exp) && - $this->literal(")")) - { + $this->literal(")") + ) { $out = $exp; $this->inParens = $inParens; return true; @@ -2779,8 +2830,8 @@ protected function value(&$value) { if ($this->literal("-", false) && (($this->variable($inner) && $inner = array("variable", $inner)) || $this->unit($inner) || - $this->parenValue($inner))) - { + $this->parenValue($inner)) + ) { $value = array("unary", "-", $inner); return true; } else { @@ -2885,8 +2936,8 @@ protected function mediaExpression(&$out) { if ($this->literal("(") && $this->keyword($feature) && ($this->literal(":") && $this->expression($value) || true) && - $this->literal(")")) - { + $this->literal(")") + ) { $out = array("mediaExp", $feature); if ($value) $out[] = $value; return true; @@ -3025,8 +3076,8 @@ protected function interpolation(&$out) { $s = $this->seek(); if ($this->literal("@{") && $this->openString("}", $interp, null, array("'", '"', ";")) && - $this->literal("}", false)) - { + $this->literal("}", false) + ) { $out = array("interpolate", $interp); $this->eatWhiteDefault = $oldWhite; if ($this->eatWhiteDefault) $this->whitespace(); @@ -3073,7 +3124,9 @@ protected function color(&$out) { // delimiter. protected function argumentDef(&$args, &$isVararg) { $s = $this->seek(); - if (!$this->literal('(')) return false; + if (!$this->literal('(')) { + return false; + } $values = array(); $delim = ","; @@ -3102,7 +3155,9 @@ protected function argumentDef(&$args, &$isVararg) { } $values[] = $arg; - if ($isVararg) break; + if ($isVararg) { + break; + } continue; } else { $values[] = array("lit", $value); @@ -3120,7 +3175,7 @@ protected function argumentDef(&$args, &$isVararg) { if (isset($values[1])) { // 2 items $newList = array(); foreach ($values as $i => $arg) { - switch($arg[0]) { + switch ($arg[0]) { case "arg": if ($i) { $this->throwError("Cannot mix ; and , as delimiter types"); @@ -3191,7 +3246,9 @@ protected function mixinTags(&$tags) { $this->literal(">"); } - if (count($tags) == 0) return false; + if (!$tags) { + return false; + } return true; } @@ -3268,11 +3325,11 @@ protected function tagBracket(&$parts, &$hasExpression) { // a space separated list of selectors protected function tag(&$tag, $simple = false) { - if ($simple) + if ($simple) { $chars = '^@,:;{}\][>\(\) "\''; - else + } else { $chars = '^@,;{}["\''; - + } $s = $this->seek(); $hasExpression = false; @@ -3377,8 +3434,8 @@ protected function func(&$func) { protected function variable(&$name) { $s = $this->seek(); if ($this->literal($this->lessc->vPrefix, false) && - ($this->variable($sub) || $this->keyword($name))) - { + ($this->variable($sub) || $this->keyword($name)) + ) { if (!empty($sub)) { $name = array('variable', $sub); } else { @@ -3821,5 +3878,3 @@ class lessc_formatter_lessjs extends lessc_formatter_classic { public $assignSeparator = ": "; public $selectorSeparator = ","; } - - diff --git a/lessify.inc.php b/lessify.inc.php index 9b7baa12..c47301ad 100644 --- a/lessify.inc.php +++ b/lessify.inc.php @@ -21,25 +21,27 @@ // class easyparse { - var $buffer; - var $count; + public $buffer; + public $count; - function __construct($str) { + public function __construct($str) { $this->count = 0; $this->buffer = trim($str); } - function seek($where = null) { - if ($where === null) return $this->count; - else $this->count = $where; + public function seek($where = null) { + if ($where === null) { + return $this->count; + } + $this->count = $where; return true; } - function preg_quote($what) { + public function preg_quote($what) { return preg_quote($what, '/'); } - function match($regex, &$out, $eatWhitespace = true) { + public function match($regex, &$out, $eatWhitespace = true) { $r = '/'.$regex.($eatWhitespace ? '\s*' : '').'/Ais'; if (preg_match($r, $this->buffer, $out, null, $this->count)) { $this->count += strlen($out[0]); @@ -48,17 +50,17 @@ function match($regex, &$out, $eatWhitespace = true) { return false; } - function literal($what, $eatWhitespace = true) { + public function literal($what, $eatWhitespace = true) { // this is here mainly prevent notice from { } string accessor if ($this->count >= strlen($this->buffer)) return false; // shortcut on single letter - if (!$eatWhitespace and strlen($what) == 1) { + if (!$eatWhitespace and strlen($what) === 1) { if ($this->buffer{$this->count} == $what) { $this->count++; return true; } - else return false; + return false; } return $this->match($this->preg_quote($what), $m, $eatWhitespace); @@ -70,55 +72,57 @@ class tagparse extends easyparse { static private $combinators = null; static private $match_opts = null; - function parse() { + public function parse() { if (empty(self::$combinators)) { - self::$combinators = '('.implode('|', array_map(array($this, 'preg_quote'), + self::$combinators = '(' . implode('|', array_map(array($this, 'preg_quote'), array('+', '>', '~'))).')'; - self::$match_opts = '('.implode('|', array_map(array($this, 'preg_quote'), - array('=', '~=', '|=', '$=', '*='))).')'; + self::$match_opts = '(' . implode('|', array_map(array($this, 'preg_quote'), + array('=', '~=', '|=', '$=', '*='))) . ')'; } // crush whitespace - $this->buffer = preg_replace('/\s+/', ' ', $this->buffer).' '; + $this->buffer = preg_replace('/\s+/', ' ', $this->buffer) . ' '; $tags = array(); - while ($this->tag($t)) $tags[] = $t; + while ($this->tag($t)) { + $tags[] = $t; + } return $tags; } - static function compileString($string) { + public static function compileString($string) { list(, $delim, $str) = $string; - $str = str_replace($delim, "\\".$delim, $str); + $str = str_replace($delim, "\\" . $delim, $str); $str = str_replace("\n", "\\\n", $str); - return $delim.$str.$delim; + return $delim . $str . $delim; } - static function compilePaths($paths) { + public static function compilePaths($paths) { return implode(', ', array_map(array('self', 'compilePath'), $paths)); } // array of tags - static function compilePath($path) { + public static function compilePath($path) { return implode(' ', array_map(array('self', 'compileTag'), $path)); } - static function compileTag($tag) { + public static function compileTag($tag) { ob_start(); - if (isset($tag['comb'])) echo $tag['comb']." "; + if (isset($tag['comb'])) echo $tag['comb'] . " "; if (isset($tag['front'])) echo $tag['front']; if (isset($tag['attr'])) { - echo '['.$tag['attr']; + echo '[' . $tag['attr']; if (isset($tag['op'])) { - echo $tag['op'].$tag['op_value']; + echo $tag['op'] . $tag['op_value']; } echo ']'; } return ob_get_clean(); } - function string(&$out) { + public function string(&$out) { $s = $this->seek(); if ($this->literal('"')) { @@ -179,7 +183,7 @@ function string(&$out) { return false; } - function tag(&$out) { + public function tag(&$out) { $s = $this->seek(); $tag = array(); if ($this->combinator($op)) $tag['comb'] = $op; @@ -219,7 +223,7 @@ function tag(&$out) { return false; } - function ident(&$out) { + public function ident(&$out) { // [-]?{nmstart}{nmchar}* // nmstart: [_a-z]|{nonascii}|{escape} // nmchar: [_a-z0-9-]|{nonascii}|{escape} @@ -230,7 +234,7 @@ function ident(&$out) { return false; } - function value(&$out) { + public function value(&$out) { if ($this->string($str)) { $out = $this->compileString($str); return true; @@ -242,7 +246,7 @@ function value(&$out) { } - function combinator(&$op) { + public function combinator(&$op) { if ($this->match(self::$combinators, $m)) { $op = $m[1]; return true; @@ -252,42 +256,42 @@ function combinator(&$op) { } class nodecounter { - var $count = 0; - var $children = array(); + public $count = 0; + public $children = array(); - var $name; - var $child_blocks; - var $the_block; + public $name; + public $child_blocks; + public $the_block; - function __construct($name) { + public function __construct($name) { $this->name = $name; } - function dump($stack = null) { + public function dump($stack = null) { if (is_null($stack)) $stack = array(); $stack[] = $this->getName(); - echo implode(' -> ', $stack)." ($this->count)\n"; + echo implode(' -> ', $stack) . " ($this->count)\n"; foreach ($this->children as $child) { $child->dump($stack); } } - static function compileProperties($c, $block) { - foreach($block as $name => $value) { + public static function compileProperties($c, $block) { + foreach ($block as $name => $value) { if ($c->isProperty($name, $value)) { - echo $c->compileProperty($name, $value)."\n"; + echo $c->compileProperty($name, $value) . "\n"; } } } - function compile($c, $path = null) { + public function compile($c, $path = null) { if (is_null($path)) $path = array(); $path[] = $this->name; $isVisible = !is_null($this->the_block) || !is_null($this->child_blocks); if ($isVisible) { - echo $c->indent(implode(' ', $path).' {'); + echo $c->indent(implode(' ', $path) . ' {'); $c->indentLevel++; $path = array(); @@ -307,7 +311,7 @@ function compile($c, $path = null) { } // compile child nodes - foreach($this->children as $node) { + foreach ($this->children as $node) { $node->compile($c, $path); } @@ -318,12 +322,12 @@ function compile($c, $path = null) { } - function getName() { + public function getName() { if (is_null($this->name)) return "[root]"; else return $this->name; } - function getNode($name) { + public function getNode($name) { if (!isset($this->children[$name])) { $this->children[$name] = new nodecounter($name); } @@ -331,7 +335,7 @@ function getNode($name) { return $this->children[$name]; } - function findNode($path) { + public function findNode($path) { $current = $this; for ($i = 0; $i < count($path); $i++) { $t = tagparse::compileTag($path[$i]); @@ -341,7 +345,7 @@ function findNode($path) { return $current; } - function addBlock($path, $block) { + public function addBlock($path, $block) { $node = $this->findNode($path); if (!is_null($node->the_block)) throw new exception("can this happen?"); @@ -349,7 +353,7 @@ function addBlock($path, $block) { $node->the_block = $block; } - function addToNode($path, $block) { + public function addToNode($path, $block) { $node = $this->findNode($path); $node->child_blocks[] = $block; } diff --git a/tests/InputTest.php b/tests/InputTest.php index ae8c494a..bac19917 100644 --- a/tests/InputTest.php +++ b/tests/InputTest.php @@ -49,8 +49,10 @@ public function testInputFile($inFname) { } public function fileNameProvider() { - return array_map(function($a) { return array($a); }, - self::findInputNames()); + return array_map( + function($a) { return array($a); }, + self::findInputNames() + ); } // only run when env is set @@ -59,7 +61,7 @@ public function buildInput($inFname) { file_put_contents(self::outputNameFor($inFname), $css); } - static public function findInputNames($pattern="*.less") { + public static function findInputNames($pattern="*.less") { $files = array(); foreach (self::$testDirs as $inputDir => $outputDir) { $files = array_merge($files, glob(__DIR__ . "/" . $inputDir . "/" . $pattern)); @@ -68,7 +70,7 @@ static public function findInputNames($pattern="*.less") { return array_filter($files, "is_file"); } - static public function outputNameFor($input) { + public static function outputNameFor($input) { $front = _quote(__DIR__ . "/"); $out = preg_replace("/^$front/", "", $input); @@ -86,4 +88,3 @@ static public function outputNameFor($input) { return __DIR__ . "/" . $out; } } - diff --git a/tests/sort.php b/tests/sort.php index ab88604f..8987a90e 100644 --- a/tests/sort.php +++ b/tests/sort.php @@ -1,7 +1,7 @@ coerceColor($value); } @@ -24,7 +24,7 @@ public function compileValue($value) { } class SortingFormatter extends lessc_formatter_lessjs { - function sortKey($block) { + public function sortKey($block) { if (!isset($block->sortKey)) { sort($block->selectors, SORT_STRING); $block->sortKey = implode(",", $block->selectors); @@ -33,7 +33,7 @@ function sortKey($block) { return $block->sortKey; } - function sortBlock($block) { + public function sortBlock($block) { usort($block->children, function($a, $b) { $sort = strcmp($this->sortKey($a), $this->sortKey($b)); if ($sort == 0) { @@ -44,7 +44,7 @@ function sortBlock($block) { } - function block($block) { + public function block($block) { $this->sortBlock($block); return parent::block($block); } @@ -54,4 +54,3 @@ function block($block) { $less = new lesscNormalized(); $less->setFormatter(new SortingFormatter); echo $less->parse(file_get_contents($fname)); -