Fix warning

This commit is contained in:
Laurent Destailleur 2023-05-01 12:43:28 +02:00
parent de4cabb334
commit cd9c7ca3d7
2 changed files with 138 additions and 39 deletions

View File

@ -8,6 +8,7 @@
* Copyright 2013, Leaf Corcoran <leafot@gmail.com> * Copyright 2013, Leaf Corcoran <leafot@gmail.com>
* Licensed under MIT or GPLv3, see LICENSE * Licensed under MIT or GPLv3, see LICENSE
*/ */
// phpcs:disable // phpcs:disable
/** /**
* The LESS compiler and parser. * The LESS compiler and parser.
@ -457,6 +458,7 @@ class Lessc
$parts = explode("$&$", $tag); $parts = explode("$&$", $tag);
$count = 0; $count = 0;
foreach ($parts as &$part) { foreach ($parts as &$part) {
$c = 0;
$part = str_replace($this->parentSelector, $replace, $part, $c); $part = str_replace($this->parentSelector, $replace, $part, $c);
$count += $c; $count += $c;
} }
@ -760,7 +762,6 @@ class Lessc
$orderedArgs = array(); $orderedArgs = array();
$keywordArgs = array(); $keywordArgs = array();
foreach ((array) $args as $arg) { foreach ((array) $args as $arg) {
$argval = null;
switch ($arg[0]) { switch ($arg[0]) {
case "arg": case "arg":
if (!isset($arg[2])) { if (!isset($arg[2])) {
@ -2152,6 +2153,7 @@ class Lessc
{ {
$this->pushEnv(); $this->pushEnv();
$parser = new lessc_parser($this, __METHOD__); $parser = new lessc_parser($this, __METHOD__);
$value = null;
foreach ($args as $name => $strValue) { foreach ($args as $name => $strValue) {
if ($name[0] !== '@') { if ($name[0] !== '@') {
$name = '@'.$name; $name = '@'.$name;
@ -2637,6 +2639,10 @@ class lessc_parser
// caches preg escaped literals // caches preg escaped literals
protected static $literalCache = array(); protected static $literalCache = array();
public $env;
public $count;
public function __construct($lessc, $sourceName = null) public function __construct($lessc, $sourceName = null)
{ {
$this->eatWhiteDefault = true; $this->eatWhiteDefault = true;
@ -2750,6 +2756,21 @@ class lessc_parser
return true; return true;
} }
$key = null;
$value = null;
$mediaQueries = null;
$dirName = null;
$dirValue = null;
$importValue = null;
$guards = null;
$tag = null;
$args = null;
$isVararg = null;
$argv = null;
$suffix = null;
$var = null;
$tags = null;
// setting a property // setting a property
if ($this->keyword($key) && $this->assign() && if ($this->keyword($key) && $this->assign() &&
$this->propertyValue($value, $key) && $this->end() $this->propertyValue($value, $key) && $this->end()
@ -2926,6 +2947,8 @@ class lessc_parser
// a list of expressions // a list of expressions
protected function expressionList(&$exps) protected function expressionList(&$exps)
{ {
$exp = null;
$values = array(); $values = array();
while ($this->expression($exp)) { while ($this->expression($exp)) {
@ -2946,6 +2969,9 @@ class lessc_parser
*/ */
protected function expression(&$out) protected function expression(&$out)
{ {
$lhs = null;
$rhs = null;
if ($this->value($lhs)) { if ($this->value($lhs)) {
$out = $this->expHelper($lhs, 0); $out = $this->expHelper($lhs, 0);
@ -2971,6 +2997,9 @@ class lessc_parser
*/ */
protected function expHelper($lhs, $minP) protected function expHelper($lhs, $minP)
{ {
$next = null;
$rhs = null;
$this->inExp = true; $this->inExp = true;
$ss = $this->seek(); $ss = $this->seek();
@ -2982,6 +3011,7 @@ class lessc_parser
// whitespace after the operator for it to be an expression // whitespace after the operator for it to be an expression
$needWhite = $whiteBefore && !$this->inParens; $needWhite = $whiteBefore && !$this->inParens;
$m = array();
if ($this->match(self::$operatorString.($needWhite ? '\s' : ''), $m) && self::$precedence[$m[1]] >= $minP) { if ($this->match(self::$operatorString.($needWhite ? '\s' : ''), $m) && self::$precedence[$m[1]] >= $minP) {
if (!$this->inParens && isset($this->env->currentProperty) && $m[1] == "/" && empty($this->env->supressedDivision)) { if (!$this->inParens && isset($this->env->currentProperty) && $m[1] == "/" && empty($this->env->supressedDivision)) {
foreach (self::$supressDivisionProps as $pattern) { foreach (self::$supressDivisionProps as $pattern) {
@ -3022,6 +3052,7 @@ class lessc_parser
// consume a list of values for a property // consume a list of values for a property
public function propertyValue(&$value, $keyName = null) public function propertyValue(&$value, $keyName = null)
{ {
$v = null;
$values = array(); $values = array();
if ($keyName !== null) { if ($keyName !== null) {
@ -3055,6 +3086,8 @@ class lessc_parser
protected function parenValue(&$out) protected function parenValue(&$out)
{ {
$exp = null;
$s = $this->seek(); $s = $this->seek();
// speed shortcut // speed shortcut
@ -3081,6 +3114,11 @@ class lessc_parser
// a single value // a single value
protected function value(&$value) protected function value(&$value)
{ {
$inner = null;
$word = null;
$str = null;
$var = null;
$s = $this->seek(); $s = $this->seek();
// speed shortcut // speed shortcut
@ -3134,6 +3172,7 @@ class lessc_parser
} }
// css hack: \0 // css hack: \0
$m = array();
if ($this->literal('\\') && $this->match('([0-9]+)', $m)) { if ($this->literal('\\') && $this->match('([0-9]+)', $m)) {
$value = array('keyword', '\\'.$m[1]); $value = array('keyword', '\\'.$m[1]);
return true; return true;
@ -3165,6 +3204,8 @@ class lessc_parser
protected function mediaQueryList(&$out) protected function mediaQueryList(&$out)
{ {
$list = null;
if ($this->genericList($list, "mediaQuery", ",", false)) { if ($this->genericList($list, "mediaQuery", ",", false)) {
$out = $list[2]; $out = $list[2];
return true; return true;
@ -3174,6 +3215,8 @@ class lessc_parser
protected function mediaQuery(&$out) protected function mediaQuery(&$out)
{ {
$mediaType = null;
$s = $this->seek(); $s = $this->seek();
$expressions = null; $expressions = null;
@ -3214,6 +3257,9 @@ class lessc_parser
protected function mediaExpression(&$out) protected function mediaExpression(&$out)
{ {
$feature = null;
$variable = null;
$s = $this->seek(); $s = $this->seek();
$value = null; $value = null;
if ($this->literal("(") && if ($this->literal("(") &&
@ -3238,6 +3284,9 @@ class lessc_parser
// an unbounded string stopped by $end // an unbounded string stopped by $end
protected function openString($end, &$out, $nestingOpen = null, $rejectStrs = null) protected function openString($end, &$out, $nestingOpen = null, $rejectStrs = null)
{ {
$str = null;
$inter = null;
$oldWhite = $this->eatWhiteDefault; $oldWhite = $this->eatWhiteDefault;
$this->eatWhiteDefault = false; $this->eatWhiteDefault = false;
@ -3254,6 +3303,7 @@ class lessc_parser
$nestingLevel = 0; $nestingLevel = 0;
$content = array(); $content = array();
$m = array();
while ($this->match($patt, $m, false)) { while ($this->match($patt, $m, false)) {
if (!empty($m[1])) { if (!empty($m[1])) {
$content[] = $m[1]; $content[] = $m[1];
@ -3308,6 +3358,8 @@ class lessc_parser
protected function string(&$out) protected function string(&$out)
{ {
$inter = null;
$s = $this->seek(); $s = $this->seek();
if ($this->literal('"', false)) { if ($this->literal('"', false)) {
$delim = '"'; $delim = '"';
@ -3326,6 +3378,7 @@ class lessc_parser
$oldWhite = $this->eatWhiteDefault; $oldWhite = $this->eatWhiteDefault;
$this->eatWhiteDefault = false; $this->eatWhiteDefault = false;
$m = array();
while ($this->match($patt, $m, false)) { while ($this->match($patt, $m, false)) {
$content[] = $m[1]; $content[] = $m[1];
if ($m[2] == "@{") { if ($m[2] == "@{") {
@ -3360,6 +3413,8 @@ class lessc_parser
protected function interpolation(&$out) protected function interpolation(&$out)
{ {
$interp = array();
$oldWhite = $this->eatWhiteDefault; $oldWhite = $this->eatWhiteDefault;
$this->eatWhiteDefault = true; $this->eatWhiteDefault = true;
@ -3383,6 +3438,8 @@ class lessc_parser
protected function unit(&$unit) protected function unit(&$unit)
{ {
$m = array();
// speed shortcut // speed shortcut
if (isset($this->buffer[$this->count])) { if (isset($this->buffer[$this->count])) {
$char = $this->buffer[$this->count]; $char = $this->buffer[$this->count];
@ -3401,6 +3458,8 @@ class lessc_parser
// a # color // a # color
protected function color(&$out) protected function color(&$out)
{ {
$m = array();
if ($this->match('(#(?:[0-9a-f]{8}|[0-9a-f]{6}|[0-9a-f]{3}))', $m)) { if ($this->match('(#(?:[0-9a-f]{8}|[0-9a-f]{6}|[0-9a-f]{3}))', $m)) {
if (strlen($m[1]) > 7) { if (strlen($m[1]) > 7) {
$out = array("string", "", array($m[1])); $out = array("string", "", array($m[1]));
@ -3420,6 +3479,9 @@ class lessc_parser
// delimiter. // delimiter.
protected function argumentDef(&$args, &$isVararg) protected function argumentDef(&$args, &$isVararg)
{ {
$value = array();
$rhs = null;
$s = $this->seek(); $s = $this->seek();
if (!$this->literal('(')) { if (!$this->literal('(')) {
return false; return false;
@ -3524,6 +3586,8 @@ class lessc_parser
// this accepts a hanging delimiter // this accepts a hanging delimiter
protected function tags(&$tags, $simple = false, $delim = ',') protected function tags(&$tags, $simple = false, $delim = ',')
{ {
$tt = array();
$tags = array(); $tags = array();
while ($this->tag($tt, $simple)) { while ($this->tag($tt, $simple)) {
$tags[] = $tt; $tags[] = $tt;
@ -3542,6 +3606,8 @@ class lessc_parser
// optionally separated by > (lazy, accepts extra >) // optionally separated by > (lazy, accepts extra >)
protected function mixinTags(&$tags) protected function mixinTags(&$tags)
{ {
$tt = array();
$tags = array(); $tags = array();
while ($this->tag($tt, true)) { while ($this->tag($tt, true)) {
$tags[] = $tt; $tags[] = $tt;
@ -3558,6 +3624,10 @@ class lessc_parser
// a bracketed value (contained within in a tag definition) // a bracketed value (contained within in a tag definition)
protected function tagBracket(&$parts, &$hasExpression) protected function tagBracket(&$parts, &$hasExpression)
{ {
$str = null;
$inter = null;
$word = null;
// speed shortcut // speed shortcut
if (isset($this->buffer[$this->count]) && $this->buffer[$this->count] != "[") { if (isset($this->buffer[$this->count]) && $this->buffer[$this->count] != "[") {
return false; return false;
@ -3576,6 +3646,7 @@ class lessc_parser
break; // get out early break; // get out early
} }
$m = array();
if ($this->match('\s+', $m)) { if ($this->match('\s+', $m)) {
$attrParts[] = " "; $attrParts[] = " ";
continue; continue;
@ -3629,6 +3700,9 @@ class lessc_parser
// a space separated list of selectors // a space separated list of selectors
protected function tag(&$tag, $simple = false) protected function tag(&$tag, $simple = false)
{ {
$interp = null;
$unit = null;
if ($simple) { if ($simple) {
$chars = '^@,:;{}\][>\(\) "\''; $chars = '^@,:;{}\][>\(\) "\'';
} else { } else {
@ -3644,6 +3718,7 @@ class lessc_parser
$this->eatWhiteDefault = false; $this->eatWhiteDefault = false;
while (true) { while (true) {
$m =array();
if ($this->match('(['.$chars.'0-9]['.$chars.']*)', $m)) { if ($this->match('(['.$chars.'0-9]['.$chars.']*)', $m)) {
$parts[] = $m[1]; $parts[] = $m[1];
if ($simple) { if ($simple) {
@ -3698,6 +3773,11 @@ class lessc_parser
{ {
$s = $this->seek(); $s = $this->seek();
$m = array();
$value = array();
$string = array();
$name = null;
if ($this->match('(%|[\w\-_][\w\-_:\.]+|[\w_])', $m) && $this->literal('(')) { if ($this->match('(%|[\w\-_][\w\-_:\.]+|[\w_])', $m) && $this->literal('(')) {
$fname = $m[1]; $fname = $m[1];
@ -3742,6 +3822,9 @@ class lessc_parser
// consume a less variable // consume a less variable
protected function variable(&$name) protected function variable(&$name)
{ {
$sub = null;
$name = null;
$s = $this->seek(); $s = $this->seek();
if ($this->literal($this->lessc->vPrefix, false) && if ($this->literal($this->lessc->vPrefix, false) &&
($this->variable($sub) || $this->keyword($name)) ($this->variable($sub) || $this->keyword($name))
@ -3774,6 +3857,7 @@ class lessc_parser
// consume a keyword // consume a keyword
protected function keyword(&$word) protected function keyword(&$word)
{ {
$m = array();
if ($this->match('([\w_\-\*!"][\w\-_"]*)', $m)) { if ($this->match('([\w_\-\*!"][\w\-_"]*)', $m)) {
$word = $m[1]; $word = $m[1];
return true; return true;
@ -3795,6 +3879,8 @@ class lessc_parser
protected function guards(&$guards) protected function guards(&$guards)
{ {
$g = null;
$s = $this->seek(); $s = $this->seek();
if (!$this->literal("when")) { if (!$this->literal("when")) {
@ -3824,6 +3910,8 @@ class lessc_parser
// TODO rename to guardGroup // TODO rename to guardGroup
protected function guardGroup(&$guardGroup) protected function guardGroup(&$guardGroup)
{ {
$guard = null;
$s = $this->seek(); $s = $this->seek();
$guardGroup = array(); $guardGroup = array();
while ($this->guard($guard)) { while ($this->guard($guard)) {
@ -3844,6 +3932,8 @@ class lessc_parser
protected function guard(&$guard) protected function guard(&$guard)
{ {
$exp = null;
$s = $this->seek(); $s = $this->seek();
$negate = $this->literal("not"); $negate = $this->literal("not");
@ -3884,11 +3974,14 @@ class lessc_parser
self::$literalCache[$what] = lessc::preg_quote($what); self::$literalCache[$what] = lessc::preg_quote($what);
} }
$m = array();
return $this->match(self::$literalCache[$what], $m, $eatWhitespace); return $this->match(self::$literalCache[$what], $m, $eatWhitespace);
} }
protected function genericList(&$out, $parseItem, $delim = "", $flatten = true) protected function genericList(&$out, $parseItem, $delim = "", $flatten = true)
{ {
$value = null;
$s = $this->seek(); $s = $this->seek();
$items = array(); $items = array();
while ($this->$parseItem($value)) { while ($this->$parseItem($value)) {
@ -3925,6 +4018,7 @@ class lessc_parser
} else { } else {
$validChars = $allowNewline ? "." : "[^\n]"; $validChars = $allowNewline ? "." : "[^\n]";
} }
$m = array();
if (!$this->match('('.$validChars.'*?)'.lessc::preg_quote($what), $m, !$until)) { if (!$this->match('('.$validChars.'*?)'.lessc::preg_quote($what), $m, !$until)) {
return false; return false;
} }
@ -3958,6 +4052,7 @@ class lessc_parser
{ {
if ($this->writeComments) { if ($this->writeComments) {
$gotWhite = false; $gotWhite = false;
$m = array();
while (preg_match(self::$whitePattern, $this->buffer, $m, null, $this->count)) { while (preg_match(self::$whitePattern, $this->buffer, $m, null, $this->count)) {
if (isset($m[1]) && empty($this->seenComments[$this->count])) { if (isset($m[1]) && empty($this->seenComments[$this->count])) {
$this->append(array("comment", $m[1])); $this->append(array("comment", $m[1]));
@ -4012,6 +4107,7 @@ class lessc_parser
} }
// TODO this depends on $this->count // TODO this depends on $this->count
$m = array();
if ($this->peek("(.*?)(\n|$)", $m, $count)) { if ($this->peek("(.*?)(\n|$)", $m, $count)) {
throw new exception("$msg: failed at `$m[1]` $loc"); throw new exception("$msg: failed at `$m[1]` $loc");
} else { } else {
@ -4090,6 +4186,7 @@ class lessc_parser
$newlines = 0; $newlines = 0;
switch ($min[0]) { switch ($min[0]) {
case 'url(': case 'url(':
$m = array();
if (preg_match('/url\(.*?\)/', $text, $m, 0, $count)) { if (preg_match('/url\(.*?\)/', $text, $m, 0, $count)) {
$count += strlen($m[0]) - strlen($min[0]); $count += strlen($m[0]) - strlen($min[0]);
} }
@ -4109,6 +4206,7 @@ class lessc_parser
} }
break; break;
case '/*': case '/*':
$m = array();
if (preg_match('/\/\*.*?\*\//s', $text, $m, 0, $count)) { if (preg_match('/\/\*.*?\*\//s', $text, $m, 0, $count)) {
$skip = strlen($m[0]); $skip = strlen($m[0]);
$newlines = substr_count($m[0], "\n"); $newlines = substr_count($m[0], "\n");

View File

@ -188,6 +188,7 @@ class LesscTest extends PHPUnit\Framework\TestCase
//var_dump($contentforlessc); exit; //var_dump($contentforlessc); exit;
} catch (exception $e) { } catch (exception $e) {
//echo "failed to compile lessc"; //echo "failed to compile lessc";
$result = 'Error';
dol_syslog("Failed to compile the CSS with lessc: ".$e->getMessage(), LOG_WARNING); dol_syslog("Failed to compile the CSS with lessc: ".$e->getMessage(), LOG_WARNING);
} }
@ -200,7 +201,7 @@ class LesscTest extends PHPUnit\Framework\TestCase
} }
"; ";
print __METHOD__." SeparatorDecimal=".$result."\n"; print __METHOD__." Result=".$result."\n";
$this->assertEquals(trim($result), trim($cssexpected)); $this->assertEquals(trim($result), trim($cssexpected));
return; return;