diff --git a/CHANGELOG.md b/CHANGELOG.md index fff5a80..cec593d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). * Indonesian localization * Basque localization +### Changed + +* Update dependencies + ## 2.0.0 - 2022-06-07 ### Added @@ -24,7 +28,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). * Output generated QR code with `data:` URI * Change the QR code generation library * Use less.php instead of lesserphp -* Use the prefers-color-scheme CSS feature to let the client choose its prefered theme (dark/light) +* Use the prefers-color-scheme CSS feature to let the client choose its preferred theme (dark/light) ### Removed diff --git a/README.md b/README.md index c52e4bd..758c9df 100755 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ A LibreQR instance is available at . ### Generic -Just place this source code in a Web server with PHP7.4+, extensions `gd`, `mbstring` and `iconv`, and writing rights on the `css/` directory. +Just place this source code in a Web server with PHP8.0+, extensions `gd`, `mbstring` and `iconv`, and writing rights on the `css/` directory. #### Security hardening diff --git a/vendor/autoload.php b/vendor/autoload.php index 79bfa69..52e3daf 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -3,10 +3,23 @@ // autoload.php @generated by Composer if (PHP_VERSION_ID < 50600) { - echo 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL; - exit(1); + if (!headers_sent()) { + header('HTTP/1.1 500 Internal Server Error'); + } + $err = 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL; + if (!ini_get('display_errors')) { + if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') { + fwrite(STDERR, $err); + } elseif (!headers_sent()) { + echo $err; + } + } + trigger_error( + $err, + E_USER_ERROR + ); } require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInit6bb82695b2f28e8ee61f74ae2d5c5202::getLoader(); +return ComposerAutoloaderInitd4957e04ba4dff37d0ecbf0a4b59e14a::getLoader(); diff --git a/vendor/bacon/bacon-qr-code/composer.json b/vendor/bacon/bacon-qr-code/composer.json index 1440cc3..7f193da 100644 --- a/vendor/bacon/bacon-qr-code/composer.json +++ b/vendor/bacon/bacon-qr-code/composer.json @@ -34,5 +34,11 @@ "allow-plugins": { "ocramius/package-versions": true } + }, + "archive": { + "exclude": [ + "/test", + "/phpunit.xml.dist" + ] } } diff --git a/vendor/bacon/bacon-qr-code/phpunit.xml.dist b/vendor/bacon/bacon-qr-code/phpunit.xml.dist new file mode 100644 index 0000000..d9e4d57 --- /dev/null +++ b/vendor/bacon/bacon-qr-code/phpunit.xml.dist @@ -0,0 +1,13 @@ + + + + + src + + + + + ./test + + + diff --git a/vendor/bacon/bacon-qr-code/src/Common/CharacterSetEci.php b/vendor/bacon/bacon-qr-code/src/Common/CharacterSetEci.php index 6dfff17..9049ccb 100644 --- a/vendor/bacon/bacon-qr-code/src/Common/CharacterSetEci.php +++ b/vendor/bacon/bacon-qr-code/src/Common/CharacterSetEci.php @@ -89,6 +89,9 @@ final class CharacterSetEci extends AbstractEnum */ private static $nameToEci; + /** + * @param int[] $values + */ public function __construct(array $values, string ...$otherEncodingNames) { $this->values = $values; diff --git a/vendor/bacon/bacon-qr-code/src/Common/FormatInformation.php b/vendor/bacon/bacon-qr-code/src/Common/FormatInformation.php index 53e3541..38295fc 100644 --- a/vendor/bacon/bacon-qr-code/src/Common/FormatInformation.php +++ b/vendor/bacon/bacon-qr-code/src/Common/FormatInformation.php @@ -62,7 +62,7 @@ class FormatInformation /** * Offset i holds the number of 1 bits in the binary representation of i. * - * @var array + * @var int[] */ private const BITS_SET_IN_HALF_BYTE = [0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4]; diff --git a/vendor/bacon/bacon-qr-code/src/Common/Mode.php b/vendor/bacon/bacon-qr-code/src/Common/Mode.php index 51e6c9a..af5a113 100644 --- a/vendor/bacon/bacon-qr-code/src/Common/Mode.php +++ b/vendor/bacon/bacon-qr-code/src/Common/Mode.php @@ -42,6 +42,9 @@ final class Mode extends AbstractEnum */ private $bits; + /** + * @param int[] $characterCountBitsForVersions + */ protected function __construct(array $characterCountBitsForVersions, int $bits) { $this->characterCountBitsForVersions = $characterCountBitsForVersions; diff --git a/vendor/bacon/bacon-qr-code/src/Encoder/Encoder.php b/vendor/bacon/bacon-qr-code/src/Encoder/Encoder.php index cf4fde0..3208460 100644 --- a/vendor/bacon/bacon-qr-code/src/Encoder/Encoder.php +++ b/vendor/bacon/bacon-qr-code/src/Encoder/Encoder.php @@ -37,7 +37,7 @@ final class Encoder /** * Codec cache. * - * @var array + * @var array */ private static $codecs = []; diff --git a/vendor/bacon/bacon-qr-code/src/Renderer/Image/SvgImageBackEnd.php b/vendor/bacon/bacon-qr-code/src/Renderer/Image/SvgImageBackEnd.php index 714da6e..cb37a9f 100644 --- a/vendor/bacon/bacon-qr-code/src/Renderer/Image/SvgImageBackEnd.php +++ b/vendor/bacon/bacon-qr-code/src/Renderer/Image/SvgImageBackEnd.php @@ -334,7 +334,7 @@ final class SvgImageBackEnd implements ImageBackEndInterface $this->xmlWriter->writeAttribute('stop-color', $this->getColorString($startColor)); if ($startColor instanceof Alpha) { - $this->xmlWriter->writeAttribute('stop-opacity', $startColor->getAlpha()); + $this->xmlWriter->writeAttribute('stop-opacity', (string) $startColor->getAlpha()); } $this->xmlWriter->endElement(); @@ -344,7 +344,7 @@ final class SvgImageBackEnd implements ImageBackEndInterface $this->xmlWriter->writeAttribute('stop-color', $this->getColorString($endColor)); if ($endColor instanceof Alpha) { - $this->xmlWriter->writeAttribute('stop-opacity', $endColor->getAlpha()); + $this->xmlWriter->writeAttribute('stop-opacity', (string) $endColor->getAlpha()); } $this->xmlWriter->endElement(); diff --git a/vendor/bacon/bacon-qr-code/src/Renderer/Module/EdgeIterator/EdgeIterator.php b/vendor/bacon/bacon-qr-code/src/Renderer/Module/EdgeIterator/EdgeIterator.php index af52d52..eb29dc6 100644 --- a/vendor/bacon/bacon-qr-code/src/Renderer/Module/EdgeIterator/EdgeIterator.php +++ b/vendor/bacon/bacon-qr-code/src/Renderer/Module/EdgeIterator/EdgeIterator.php @@ -41,7 +41,7 @@ final class EdgeIterator implements IteratorAggregate } /** - * @return Edge[] + * @return Traversable */ public function getIterator() : Traversable { diff --git a/vendor/bacon/bacon-qr-code/src/Renderer/Path/EllipticArc.php b/vendor/bacon/bacon-qr-code/src/Renderer/Path/EllipticArc.php index eff7deb..9f2385a 100644 --- a/vendor/bacon/bacon-qr-code/src/Renderer/Path/EllipticArc.php +++ b/vendor/bacon/bacon-qr-code/src/Renderer/Path/EllipticArc.php @@ -136,7 +136,7 @@ final class EllipticArc implements OperationInterface /** * @return Curve[] */ - private function createCurves(float $fromX, $fromY) : array + private function createCurves(float $fromX, float $fromY) : array { $xAngle = deg2rad($this->xAxisAngle); list($centerX, $centerY, $radiusX, $radiusY, $startAngle, $deltaAngle) = diff --git a/vendor/bacon/bacon-qr-code/test/Integration/ImagickRenderingTest.php b/vendor/bacon/bacon-qr-code/test/Integration/ImagickRenderingTest.php index 39e44bf..3df8687 100644 --- a/vendor/bacon/bacon-qr-code/test/Integration/ImagickRenderingTest.php +++ b/vendor/bacon/bacon-qr-code/test/Integration/ImagickRenderingTest.php @@ -17,10 +17,16 @@ use BaconQrCode\Writer; use PHPUnit\Framework\TestCase; use Spatie\Snapshots\MatchesSnapshots; +/** + * @group integration + */ final class ImagickRenderingTest extends TestCase { use MatchesSnapshots; + /** + * @requires extension imagick + */ public function testGenericQrCode() : void { $renderer = new ImageRenderer( @@ -35,6 +41,9 @@ final class ImagickRenderingTest extends TestCase unlink($tempName); } + /** + * @requires extension imagick + */ public function testIssue79() : void { $eye = SquareEye::instance(); diff --git a/vendor/bin/lessc b/vendor/bin/lessc index 7ae7f57..d2c6c96 100644 --- a/vendor/bin/lessc +++ b/vendor/bin/lessc @@ -108,10 +108,12 @@ if (PHP_VERSION_ID < 80000) { } } - if (function_exists('stream_wrapper_register') && stream_wrapper_register('phpvfscomposer', 'Composer\BinProxyWrapper')) { - include("phpvfscomposer://" . __DIR__ . '/..'.'/wikimedia/less.php/bin/lessc'); - exit(0); + if ( + (function_exists('stream_get_wrappers') && in_array('phpvfscomposer', stream_get_wrappers(), true)) + || (function_exists('stream_wrapper_register') && stream_wrapper_register('phpvfscomposer', 'Composer\BinProxyWrapper')) + ) { + return include("phpvfscomposer://" . __DIR__ . '/..'.'/wikimedia/less.php/bin/lessc'); } } -include __DIR__ . '/..'.'/wikimedia/less.php/bin/lessc'; +return include __DIR__ . '/..'.'/wikimedia/less.php/bin/lessc'; diff --git a/vendor/composer/ClassLoader.php b/vendor/composer/ClassLoader.php index afef3fa..7824d8f 100644 --- a/vendor/composer/ClassLoader.php +++ b/vendor/composer/ClassLoader.php @@ -42,35 +42,37 @@ namespace Composer\Autoload; */ class ClassLoader { - /** @var ?string */ + /** @var \Closure(string):void */ + private static $includeFile; + + /** @var string|null */ private $vendorDir; // PSR-4 /** - * @var array[] - * @psalm-var array> + * @var array> */ private $prefixLengthsPsr4 = array(); /** - * @var array[] - * @psalm-var array> + * @var array> */ private $prefixDirsPsr4 = array(); /** - * @var array[] - * @psalm-var array + * @var list */ private $fallbackDirsPsr4 = array(); // PSR-0 /** - * @var array[] - * @psalm-var array> + * List of PSR-0 prefixes + * + * Structured as array('F (first letter)' => array('Foo\Bar (full prefix)' => array('path', 'path2'))) + * + * @var array>> */ private $prefixesPsr0 = array(); /** - * @var array[] - * @psalm-var array + * @var list */ private $fallbackDirsPsr0 = array(); @@ -78,8 +80,7 @@ class ClassLoader private $useIncludePath = false; /** - * @var string[] - * @psalm-var array + * @var array */ private $classMap = array(); @@ -87,29 +88,29 @@ class ClassLoader private $classMapAuthoritative = false; /** - * @var bool[] - * @psalm-var array + * @var array */ private $missingClasses = array(); - /** @var ?string */ + /** @var string|null */ private $apcuPrefix; /** - * @var self[] + * @var array */ private static $registeredLoaders = array(); /** - * @param ?string $vendorDir + * @param string|null $vendorDir */ public function __construct($vendorDir = null) { $this->vendorDir = $vendorDir; + self::initializeIncludeClosure(); } /** - * @return string[] + * @return array> */ public function getPrefixes() { @@ -121,8 +122,7 @@ class ClassLoader } /** - * @return array[] - * @psalm-return array> + * @return array> */ public function getPrefixesPsr4() { @@ -130,8 +130,7 @@ class ClassLoader } /** - * @return array[] - * @psalm-return array + * @return list */ public function getFallbackDirs() { @@ -139,8 +138,7 @@ class ClassLoader } /** - * @return array[] - * @psalm-return array + * @return list */ public function getFallbackDirsPsr4() { @@ -148,8 +146,7 @@ class ClassLoader } /** - * @return string[] Array of classname => path - * @psalm-return array + * @return array Array of classname => path */ public function getClassMap() { @@ -157,8 +154,7 @@ class ClassLoader } /** - * @param string[] $classMap Class to filename map - * @psalm-param array $classMap + * @param array $classMap Class to filename map * * @return void */ @@ -175,24 +171,25 @@ class ClassLoader * Registers a set of PSR-0 directories for a given prefix, either * appending or prepending to the ones previously set for this prefix. * - * @param string $prefix The prefix - * @param string[]|string $paths The PSR-0 root directories - * @param bool $prepend Whether to prepend the directories + * @param string $prefix The prefix + * @param list|string $paths The PSR-0 root directories + * @param bool $prepend Whether to prepend the directories * * @return void */ public function add($prefix, $paths, $prepend = false) { + $paths = (array) $paths; if (!$prefix) { if ($prepend) { $this->fallbackDirsPsr0 = array_merge( - (array) $paths, + $paths, $this->fallbackDirsPsr0 ); } else { $this->fallbackDirsPsr0 = array_merge( $this->fallbackDirsPsr0, - (array) $paths + $paths ); } @@ -201,19 +198,19 @@ class ClassLoader $first = $prefix[0]; if (!isset($this->prefixesPsr0[$first][$prefix])) { - $this->prefixesPsr0[$first][$prefix] = (array) $paths; + $this->prefixesPsr0[$first][$prefix] = $paths; return; } if ($prepend) { $this->prefixesPsr0[$first][$prefix] = array_merge( - (array) $paths, + $paths, $this->prefixesPsr0[$first][$prefix] ); } else { $this->prefixesPsr0[$first][$prefix] = array_merge( $this->prefixesPsr0[$first][$prefix], - (array) $paths + $paths ); } } @@ -222,9 +219,9 @@ class ClassLoader * Registers a set of PSR-4 directories for a given namespace, either * appending or prepending to the ones previously set for this namespace. * - * @param string $prefix The prefix/namespace, with trailing '\\' - * @param string[]|string $paths The PSR-4 base directories - * @param bool $prepend Whether to prepend the directories + * @param string $prefix The prefix/namespace, with trailing '\\' + * @param list|string $paths The PSR-4 base directories + * @param bool $prepend Whether to prepend the directories * * @throws \InvalidArgumentException * @@ -232,17 +229,18 @@ class ClassLoader */ public function addPsr4($prefix, $paths, $prepend = false) { + $paths = (array) $paths; if (!$prefix) { // Register directories for the root namespace. if ($prepend) { $this->fallbackDirsPsr4 = array_merge( - (array) $paths, + $paths, $this->fallbackDirsPsr4 ); } else { $this->fallbackDirsPsr4 = array_merge( $this->fallbackDirsPsr4, - (array) $paths + $paths ); } } elseif (!isset($this->prefixDirsPsr4[$prefix])) { @@ -252,18 +250,18 @@ class ClassLoader throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); } $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; - $this->prefixDirsPsr4[$prefix] = (array) $paths; + $this->prefixDirsPsr4[$prefix] = $paths; } elseif ($prepend) { // Prepend directories for an already registered namespace. $this->prefixDirsPsr4[$prefix] = array_merge( - (array) $paths, + $paths, $this->prefixDirsPsr4[$prefix] ); } else { // Append directories for an already registered namespace. $this->prefixDirsPsr4[$prefix] = array_merge( $this->prefixDirsPsr4[$prefix], - (array) $paths + $paths ); } } @@ -272,8 +270,8 @@ class ClassLoader * Registers a set of PSR-0 directories for a given prefix, * replacing any others previously set for this prefix. * - * @param string $prefix The prefix - * @param string[]|string $paths The PSR-0 base directories + * @param string $prefix The prefix + * @param list|string $paths The PSR-0 base directories * * @return void */ @@ -290,8 +288,8 @@ class ClassLoader * Registers a set of PSR-4 directories for a given namespace, * replacing any others previously set for this namespace. * - * @param string $prefix The prefix/namespace, with trailing '\\' - * @param string[]|string $paths The PSR-4 base directories + * @param string $prefix The prefix/namespace, with trailing '\\' + * @param list|string $paths The PSR-4 base directories * * @throws \InvalidArgumentException * @@ -425,7 +423,8 @@ class ClassLoader public function loadClass($class) { if ($file = $this->findFile($class)) { - includeFile($file); + $includeFile = self::$includeFile; + $includeFile($file); return true; } @@ -476,9 +475,9 @@ class ClassLoader } /** - * Returns the currently registered loaders indexed by their corresponding vendor directories. + * Returns the currently registered loaders keyed by their corresponding vendor directories. * - * @return self[] + * @return array */ public static function getRegisteredLoaders() { @@ -555,18 +554,26 @@ class ClassLoader return false; } -} -/** - * Scope isolated include. - * - * Prevents access to $this/self from included files. - * - * @param string $file - * @return void - * @private - */ -function includeFile($file) -{ - include $file; + /** + * @return void + */ + private static function initializeIncludeClosure() + { + if (self::$includeFile !== null) { + return; + } + + /** + * Scope isolated include. + * + * Prevents access to $this/self from included files. + * + * @param string $file + * @return void + */ + self::$includeFile = \Closure::bind(static function($file) { + include $file; + }, null, null); + } } diff --git a/vendor/composer/InstalledVersions.php b/vendor/composer/InstalledVersions.php index c6b54af..51e734a 100644 --- a/vendor/composer/InstalledVersions.php +++ b/vendor/composer/InstalledVersions.php @@ -98,7 +98,7 @@ class InstalledVersions { foreach (self::getInstalled() as $installed) { if (isset($installed['versions'][$packageName])) { - return $includeDevRequirements || empty($installed['versions'][$packageName]['dev_requirement']); + return $includeDevRequirements || !isset($installed['versions'][$packageName]['dev_requirement']) || $installed['versions'][$packageName]['dev_requirement'] === false; } } @@ -119,7 +119,7 @@ class InstalledVersions */ public static function satisfies(VersionParser $parser, $packageName, $constraint) { - $constraint = $parser->parseConstraints($constraint); + $constraint = $parser->parseConstraints((string) $constraint); $provided = $parser->parseConstraints(self::getVersionRanges($packageName)); return $provided->matches($constraint); @@ -328,7 +328,9 @@ class InstalledVersions if (isset(self::$installedByVendor[$vendorDir])) { $installed[] = self::$installedByVendor[$vendorDir]; } elseif (is_file($vendorDir.'/composer/installed.php')) { - $installed[] = self::$installedByVendor[$vendorDir] = require $vendorDir.'/composer/installed.php'; + /** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array} $required */ + $required = require $vendorDir.'/composer/installed.php'; + $installed[] = self::$installedByVendor[$vendorDir] = $required; if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) { self::$installed = $installed[count($installed) - 1]; } @@ -340,12 +342,17 @@ class InstalledVersions // only require the installed.php file if this file is loaded from its dumped location, // and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937 if (substr(__DIR__, -8, 1) !== 'C') { - self::$installed = require __DIR__ . '/installed.php'; + /** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array} $required */ + $required = require __DIR__ . '/installed.php'; + self::$installed = $required; } else { self::$installed = array(); } } - $installed[] = self::$installed; + + if (self::$installed !== array()) { + $installed[] = self::$installed; + } return $installed; } diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index a81e37d..a767034 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInit6bb82695b2f28e8ee61f74ae2d5c5202 +class ComposerAutoloaderInitd4957e04ba4dff37d0ecbf0a4b59e14a { private static $loader; @@ -24,12 +24,12 @@ class ComposerAutoloaderInit6bb82695b2f28e8ee61f74ae2d5c5202 require __DIR__ . '/platform_check.php'; - spl_autoload_register(array('ComposerAutoloaderInit6bb82695b2f28e8ee61f74ae2d5c5202', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInitd4957e04ba4dff37d0ecbf0a4b59e14a', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__)); - spl_autoload_unregister(array('ComposerAutoloaderInit6bb82695b2f28e8ee61f74ae2d5c5202', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInitd4957e04ba4dff37d0ecbf0a4b59e14a', 'loadClassLoader')); require __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInit6bb82695b2f28e8ee61f74ae2d5c5202::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInitd4957e04ba4dff37d0ecbf0a4b59e14a::getInitializer($loader)); $loader->register(true); diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index c6b0153..b2e269c 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInit6bb82695b2f28e8ee61f74ae2d5c5202 +class ComposerStaticInitd4957e04ba4dff37d0ecbf0a4b59e14a { public static $prefixLengthsPsr4 = array ( 'E' => @@ -54,10 +54,10 @@ class ComposerStaticInit6bb82695b2f28e8ee61f74ae2d5c5202 public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInit6bb82695b2f28e8ee61f74ae2d5c5202::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInit6bb82695b2f28e8ee61f74ae2d5c5202::$prefixDirsPsr4; - $loader->prefixesPsr0 = ComposerStaticInit6bb82695b2f28e8ee61f74ae2d5c5202::$prefixesPsr0; - $loader->classMap = ComposerStaticInit6bb82695b2f28e8ee61f74ae2d5c5202::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInitd4957e04ba4dff37d0ecbf0a4b59e14a::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInitd4957e04ba4dff37d0ecbf0a4b59e14a::$prefixDirsPsr4; + $loader->prefixesPsr0 = ComposerStaticInitd4957e04ba4dff37d0ecbf0a4b59e14a::$prefixesPsr0; + $loader->classMap = ComposerStaticInitd4957e04ba4dff37d0ecbf0a4b59e14a::$classMap; }, null, ClassLoader::class); } diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index d43d4f1..dec70d7 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -2,17 +2,17 @@ "packages": [ { "name": "bacon/bacon-qr-code", - "version": "2.0.7", - "version_normalized": "2.0.7.0", + "version": "2.0.8", + "version_normalized": "2.0.8.0", "source": { "type": "git", "url": "https://github.com/Bacon/BaconQrCode.git", - "reference": "d70c840f68657ce49094b8d91f9ee0cc07fbf66c" + "reference": "8674e51bb65af933a5ffaf1c308a660387c35c22" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Bacon/BaconQrCode/zipball/d70c840f68657ce49094b8d91f9ee0cc07fbf66c", - "reference": "d70c840f68657ce49094b8d91f9ee0cc07fbf66c", + "url": "https://api.github.com/repos/Bacon/BaconQrCode/zipball/8674e51bb65af933a5ffaf1c308a660387c35c22", + "reference": "8674e51bb65af933a5ffaf1c308a660387c35c22", "shasum": "" }, "require": { @@ -29,7 +29,7 @@ "suggest": { "ext-imagick": "to generate QR code images" }, - "time": "2022-03-14T02:02:36+00:00", + "time": "2022-12-07T17:46:57+00:00", "type": "library", "installation-source": "dist", "autoload": { @@ -53,30 +53,33 @@ "homepage": "https://github.com/Bacon/BaconQrCode", "support": { "issues": "https://github.com/Bacon/BaconQrCode/issues", - "source": "https://github.com/Bacon/BaconQrCode/tree/2.0.7" + "source": "https://github.com/Bacon/BaconQrCode/tree/2.0.8" }, "install-path": "../bacon/bacon-qr-code" }, { "name": "dasprid/enum", - "version": "1.0.3", - "version_normalized": "1.0.3.0", + "version": "1.0.4", + "version_normalized": "1.0.4.0", "source": { "type": "git", "url": "https://github.com/DASPRiD/Enum.git", - "reference": "5abf82f213618696dda8e3bf6f64dd042d8542b2" + "reference": "8e6b6ea76eabbf19ea2bf5b67b98e1860474012f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/DASPRiD/Enum/zipball/5abf82f213618696dda8e3bf6f64dd042d8542b2", - "reference": "5abf82f213618696dda8e3bf6f64dd042d8542b2", + "url": "https://api.github.com/repos/DASPRiD/Enum/zipball/8e6b6ea76eabbf19ea2bf5b67b98e1860474012f", + "reference": "8e6b6ea76eabbf19ea2bf5b67b98e1860474012f", "shasum": "" }, + "require": { + "php": ">=7.1 <9.0" + }, "require-dev": { "phpunit/phpunit": "^7 | ^8 | ^9", - "squizlabs/php_codesniffer": "^3.4" + "squizlabs/php_codesniffer": "*" }, - "time": "2020-10-02T16:03:48+00:00", + "time": "2023-03-01T18:44:03+00:00", "type": "library", "installation-source": "dist", "autoload": { @@ -103,33 +106,36 @@ ], "support": { "issues": "https://github.com/DASPRiD/Enum/issues", - "source": "https://github.com/DASPRiD/Enum/tree/1.0.3" + "source": "https://github.com/DASPRiD/Enum/tree/1.0.4" }, "install-path": "../dasprid/enum" }, { "name": "endroid/qr-code", - "version": "4.4.9", - "version_normalized": "4.4.9.0", + "version": "4.8.2", + "version_normalized": "4.8.2.0", "source": { "type": "git", "url": "https://github.com/endroid/qr-code.git", - "reference": "bf087fa1e93a1b7310e2d94d187e26ae51db199d" + "reference": "2436c2333a3931c95e2b96eb82f16f53143d6bba" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/endroid/qr-code/zipball/bf087fa1e93a1b7310e2d94d187e26ae51db199d", - "reference": "bf087fa1e93a1b7310e2d94d187e26ae51db199d", + "url": "https://api.github.com/repos/endroid/qr-code/zipball/2436c2333a3931c95e2b96eb82f16f53143d6bba", + "reference": "2436c2333a3931c95e2b96eb82f16f53143d6bba", "shasum": "" }, "require": { "bacon/bacon-qr-code": "^2.0.5", - "php": "^7.4||^8.0" + "php": "^8.0" + }, + "conflict": { + "khanamiryan/qrcode-detector-decoder": "^1.0.6" }, "require-dev": { "endroid/quality": "dev-master", "ext-gd": "*", - "khanamiryan/qrcode-detector-decoder": "^1.0.4", + "khanamiryan/qrcode-detector-decoder": "^1.0.4||^2.0.2", "setasign/fpdf": "^1.8.2" }, "suggest": { @@ -138,7 +144,7 @@ "roave/security-advisories": "Makes sure package versions with known security issues are not installed", "setasign/fpdf": "Enables you to use the PDF writer" }, - "time": "2022-05-10T07:25:08+00:00", + "time": "2023-03-30T18:46:02+00:00", "type": "library", "extra": { "branch-alias": { @@ -172,7 +178,7 @@ ], "support": { "issues": "https://github.com/endroid/qr-code/issues", - "source": "https://github.com/endroid/qr-code/tree/4.4.9" + "source": "https://github.com/endroid/qr-code/tree/4.8.2" }, "funding": [ { @@ -184,30 +190,31 @@ }, { "name": "wikimedia/less.php", - "version": "v3.1.0", - "version_normalized": "3.1.0.0", + "version": "v3.2.1", + "version_normalized": "3.2.1.0", "source": { "type": "git", "url": "https://github.com/wikimedia/less.php.git", - "reference": "a486d78b9bd16b72f237fc6093aa56d69ce8bd13" + "reference": "0d5b30ba792bdbf8991a646fc9c30561b38a5559" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/wikimedia/less.php/zipball/a486d78b9bd16b72f237fc6093aa56d69ce8bd13", - "reference": "a486d78b9bd16b72f237fc6093aa56d69ce8bd13", + "url": "https://api.github.com/repos/wikimedia/less.php/zipball/0d5b30ba792bdbf8991a646fc9c30561b38a5559", + "reference": "0d5b30ba792bdbf8991a646fc9c30561b38a5559", "shasum": "" }, "require": { "php": ">=7.2.9" }, "require-dev": { - "mediawiki/mediawiki-codesniffer": "34.0.0", - "mediawiki/minus-x": "1.0.0", - "php-parallel-lint/php-console-highlighter": "0.5.0", - "php-parallel-lint/php-parallel-lint": "1.2.0", + "mediawiki/mediawiki-codesniffer": "40.0.1", + "mediawiki/mediawiki-phan-config": "0.12.0", + "mediawiki/minus-x": "1.1.1", + "php-parallel-lint/php-console-highlighter": "1.0.0", + "php-parallel-lint/php-parallel-lint": "1.3.2", "phpunit/phpunit": "^8.5" }, - "time": "2020-12-11T19:33:31+00:00", + "time": "2023-02-03T06:43:41+00:00", "bin": [ "bin/lessc" ], @@ -226,6 +233,10 @@ "Apache-2.0" ], "authors": [ + { + "name": "Timo Tijhof", + "homepage": "https://timotijhof.net" + }, { "name": "Josh Schmidt", "homepage": "https://github.com/oyejorge" @@ -239,7 +250,8 @@ "homepage": "https://github.com/Mordred" } ], - "description": "PHP port of the Javascript version of LESS http://lesscss.org (Originally maintained by Josh Schmidt)", + "description": "PHP port of the LESS processor", + "homepage": "https://gerrit.wikimedia.org/g/mediawiki/libs/less.php", "keywords": [ "css", "less", @@ -250,7 +262,7 @@ ], "support": { "issues": "https://github.com/wikimedia/less.php/issues", - "source": "https://github.com/wikimedia/less.php/tree/v3.1.0" + "source": "https://github.com/wikimedia/less.php/tree/v3.2.1" }, "install-path": "../wikimedia/less.php" } diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index 7c8fcd4..2c32d24 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -3,7 +3,7 @@ 'name' => '__root__', 'pretty_version' => 'dev-main', 'version' => 'dev-main', - 'reference' => '5e455c1499d4fba2d9bb825e4db8b58a3a6a595e', + 'reference' => 'b4ef98673f4ec96aac0c1ff7bda444f72101c479', 'type' => 'library', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), @@ -13,43 +13,43 @@ '__root__' => array( 'pretty_version' => 'dev-main', 'version' => 'dev-main', - 'reference' => '5e455c1499d4fba2d9bb825e4db8b58a3a6a595e', + 'reference' => 'b4ef98673f4ec96aac0c1ff7bda444f72101c479', 'type' => 'library', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), 'dev_requirement' => false, ), 'bacon/bacon-qr-code' => array( - 'pretty_version' => '2.0.7', - 'version' => '2.0.7.0', - 'reference' => 'd70c840f68657ce49094b8d91f9ee0cc07fbf66c', + 'pretty_version' => '2.0.8', + 'version' => '2.0.8.0', + 'reference' => '8674e51bb65af933a5ffaf1c308a660387c35c22', 'type' => 'library', 'install_path' => __DIR__ . '/../bacon/bacon-qr-code', 'aliases' => array(), 'dev_requirement' => false, ), 'dasprid/enum' => array( - 'pretty_version' => '1.0.3', - 'version' => '1.0.3.0', - 'reference' => '5abf82f213618696dda8e3bf6f64dd042d8542b2', + 'pretty_version' => '1.0.4', + 'version' => '1.0.4.0', + 'reference' => '8e6b6ea76eabbf19ea2bf5b67b98e1860474012f', 'type' => 'library', 'install_path' => __DIR__ . '/../dasprid/enum', 'aliases' => array(), 'dev_requirement' => false, ), 'endroid/qr-code' => array( - 'pretty_version' => '4.4.9', - 'version' => '4.4.9.0', - 'reference' => 'bf087fa1e93a1b7310e2d94d187e26ae51db199d', + 'pretty_version' => '4.8.2', + 'version' => '4.8.2.0', + 'reference' => '2436c2333a3931c95e2b96eb82f16f53143d6bba', 'type' => 'library', 'install_path' => __DIR__ . '/../endroid/qr-code', 'aliases' => array(), 'dev_requirement' => false, ), 'wikimedia/less.php' => array( - 'pretty_version' => 'v3.1.0', - 'version' => '3.1.0.0', - 'reference' => 'a486d78b9bd16b72f237fc6093aa56d69ce8bd13', + 'pretty_version' => 'v3.2.1', + 'version' => '3.2.1.0', + 'reference' => '0d5b30ba792bdbf8991a646fc9c30561b38a5559', 'type' => 'library', 'install_path' => __DIR__ . '/../wikimedia/less.php', 'aliases' => array(), diff --git a/vendor/composer/platform_check.php b/vendor/composer/platform_check.php index 580fa96..adfb472 100644 --- a/vendor/composer/platform_check.php +++ b/vendor/composer/platform_check.php @@ -4,8 +4,8 @@ $issues = array(); -if (!(PHP_VERSION_ID >= 70400)) { - $issues[] = 'Your Composer dependencies require a PHP version ">= 7.4.0". You are running ' . PHP_VERSION . '.'; +if (!(PHP_VERSION_ID >= 80000)) { + $issues[] = 'Your Composer dependencies require a PHP version ">= 8.0.0". You are running ' . PHP_VERSION . '.'; } if ($issues) { diff --git a/vendor/dasprid/enum/.github/workflows/tests.yml b/vendor/dasprid/enum/.github/workflows/tests.yml new file mode 100644 index 0000000..94b2562 --- /dev/null +++ b/vendor/dasprid/enum/.github/workflows/tests.yml @@ -0,0 +1,47 @@ +name: Tests + +on: [push, pull_request] + +jobs: + php-tests: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: true + matrix: + php: [8.2, 8.1, 8.0, 7.4, 7.3, 7.2, 7.1] + dependency-version: [prefer-stable] + os: [ubuntu-latest, windows-latest] + + name: ${{ matrix.os }} - PHP${{ matrix.php }} - ${{ matrix.dependency-version }} + + steps: + - name: Set git to use LF + run: | + git config --global core.autocrlf false + git config --global core.eol lf + + - name: Checkout code + uses: actions/checkout@v3 + + - name: Cache dependencies + uses: actions/cache@v3 + with: + path: ~/.composer/cache/files + key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + coverage: none + + - name: Install dependencies + run: | + composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction + + - name: Execute tests + run: vendor/bin/phpunit + + - name: Code Sniffer + run: vendor/bin/phpcs + diff --git a/vendor/dasprid/enum/README.md b/vendor/dasprid/enum/README.md index 9e9ca12..da37045 100644 --- a/vendor/dasprid/enum/README.md +++ b/vendor/dasprid/enum/README.md @@ -1,6 +1,6 @@ # PHP 7.1 enums -[![Build Status](https://travis-ci.org/DASPRiD/Enum.svg?branch=master)](https://travis-ci.org/DASPRiD/Enum) +[![Build Status](https://github.com/DASPRiD/Enum/actions/workflows/tests.yml/badge.svg)](https://github.com/DASPRiD/Enum/actions?query=workflow%3Atests) [![Coverage Status](https://coveralls.io/repos/github/DASPRiD/Enum/badge.svg?branch=master)](https://coveralls.io/github/DASPRiD/Enum?branch=master) [![Latest Stable Version](https://poser.pugx.org/dasprid/enum/v/stable)](https://packagist.org/packages/dasprid/enum) [![Total Downloads](https://poser.pugx.org/dasprid/enum/downloads)](https://packagist.org/packages/dasprid/enum) @@ -41,7 +41,7 @@ final class WeekDay extends AbstractEnum protected const SATURDAY = null; protected const SUNDAY = null; } -``` +``` If you need to provide constants for either internal use or public use, you can mark them as either private or public, in which case they will be ignored by the enum, which only considers protected constants as valid values. As you can @@ -56,16 +56,16 @@ function tellItLikeItIs(WeekDay $weekDay) case WeekDay::MONDAY(): echo 'Mondays are bad.'; break; - + case WeekDay::FRIDAY(): echo 'Fridays are better.'; break; - + case WeekDay::SATURDAY(): case WeekDay::SUNDAY(): echo 'Weekends are best.'; break; - + default: echo 'Midweek days are so-so.'; } @@ -107,14 +107,14 @@ final class Planet extends AbstractEnum protected const SATURN = [5.688e+26, 6.0268e7]; protected const URANUS = [8.686e+25, 2.5559e7]; protected const NEPTUNE = [1.024e+26, 2.4746e7]; - + /** * Universal gravitational constant. * * @var float */ private const G = 6.67300E-11; - + /** * Mass in kilograms. * @@ -124,32 +124,32 @@ final class Planet extends AbstractEnum /** * Radius in meters. - * + * * @var float - */ + */ private $radius; - + protected function __construct(float $mass, float $radius) { $this->mass = $mass; $this->radius = $radius; } - + public function mass() : float { return $this->mass; } - + public function radius() : float { - return $this->radius; + return $this->radius; } - + public function surfaceGravity() : float { return self::G * $this->mass / ($this->radius * $this->radius); } - + public function surfaceWeight(float $otherMass) : float { return $otherMass * $this->surfaceGravity(); diff --git a/vendor/dasprid/enum/composer.json b/vendor/dasprid/enum/composer.json index b3d745a..133e279 100644 --- a/vendor/dasprid/enum/composer.json +++ b/vendor/dasprid/enum/composer.json @@ -14,9 +14,12 @@ "enum", "map" ], + "require": { + "php": ">=7.1 <9.0" + }, "require-dev": { "phpunit/phpunit": "^7 | ^8 | ^9", - "squizlabs/php_codesniffer": "^3.4" + "squizlabs/php_codesniffer": "*" }, "autoload": { "psr-4": { diff --git a/vendor/dasprid/enum/src/EnumMap.php b/vendor/dasprid/enum/src/EnumMap.php index 77c5f35..95b8856 100644 --- a/vendor/dasprid/enum/src/EnumMap.php +++ b/vendor/dasprid/enum/src/EnumMap.php @@ -88,6 +88,31 @@ final class EnumMap implements Serializable, IteratorAggregate $this->values = array_fill(0, count($this->keyUniverse), null); } + public function __serialize(): array + { + $values = []; + + foreach ($this->values as $ordinal => $value) { + if (null === $value) { + continue; + } + + $values[$ordinal] = $this->unmaskNull($value); + } + + return [ + 'keyType' => $this->keyType, + 'valueType' => $this->valueType, + 'allowNullValues' => $this->allowNullValues, + 'values' => $values, + ]; + } + + public function __unserialize(array $data): void + { + $this->unserialize(serialize($data)); + } + /** * Checks whether the map types match the supplied ones. * @@ -261,22 +286,7 @@ final class EnumMap implements Serializable, IteratorAggregate public function serialize() : string { - $values = []; - - foreach ($this->values as $ordinal => $value) { - if (null === $value) { - continue; - } - - $values[$ordinal] = $this->unmaskNull($value); - } - - return serialize([ - 'keyType' => $this->keyType, - 'valueType' => $this->valueType, - 'allowNullValues' => $this->allowNullValues, - 'values' => $values, - ]); + return serialize($this->__serialize()); } public function unserialize($serialized) : void diff --git a/vendor/endroid/qr-code/LICENSE b/vendor/endroid/qr-code/LICENSE index 6d36c02..546d814 100644 --- a/vendor/endroid/qr-code/LICENSE +++ b/vendor/endroid/qr-code/LICENSE @@ -1,4 +1,4 @@ -Copyright 2020 (c) Jeroen van den Enden +Copyright 2022 (c) Jeroen van den Enden Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/vendor/endroid/qr-code/README.md b/vendor/endroid/qr-code/README.md index 1d78681..35cbac3 100644 --- a/vendor/endroid/qr-code/README.md +++ b/vendor/endroid/qr-code/README.md @@ -14,13 +14,17 @@ for validating generated QR codes. Further extended with Twig extensions, genera Symfony bundle for easy installation and configuration. Different writers are provided to generate the QR code as PNG, SVG, EPS or in binary format. +## Sponsored by + +[![Blackfire.io](assets/blackfire.png)](https://www.blackfire.io) + ## Installation Use [Composer](https://getcomposer.org/) to install the library. Also make sure you have enabled and configured the [GD extension](https://www.php.net/manual/en/book.image.php) if you want to generate images. ``` bash -$ composer require endroid/qr-code + composer require endroid/qr-code ``` ## Usage: using the builder @@ -47,6 +51,7 @@ $result = Builder::create() ->labelText('This is the label') ->labelFont(new NotoSans(20)) ->labelAlignment(new LabelAlignmentCenter()) + ->validateResult(false) ->build(); ``` @@ -61,11 +66,12 @@ use Endroid\QrCode\Label\Label; use Endroid\QrCode\Logo\Logo; use Endroid\QrCode\RoundBlockSizeMode\RoundBlockSizeModeMargin; use Endroid\QrCode\Writer\PngWriter; +use Endroid\QrCode\Writer\ValidationException; $writer = new PngWriter(); // Create QR code -$qrCode = QrCode::create('Data') +$qrCode = QrCode::create('Life is too short to be generating QR codes') ->setEncoding(new Encoding('UTF-8')) ->setErrorCorrectionLevel(new ErrorCorrectionLevelLow()) ->setSize(300) @@ -83,6 +89,9 @@ $label = Label::create('Label') ->setTextColor(new Color(255, 0, 0)); $result = $writer->write($qrCode, $logo, $label); + +// Validate the result +$writer->validateResult($result, 'Life is too short to be generating QR codes'); ``` ## Usage: working with results @@ -104,10 +113,32 @@ $dataUri = $result->getDataUri(); ### Writer options +Some writers provide writer options. Each available writer option is can be +found as a constant prefixed with WRITER_OPTION_ in the writer class. + +* `PdfWriter` + * `unit`: unit of measurement (default: mm) + * `fpdf`: PDF to place the image in (default: new PDF) + * `x`: image offset (default: 0) + * `y`: image offset (default: 0) +* `PngWriter` + * `compression_level`: compression level (0-9, default: -1 = zlib default) +* `SvgWriter` + * `block_id`: id of the block element for external reference (default: block) + * `exclude_xml_declaration`: exclude XML declaration (default: false) + * `exclude_svg_width_and_height`: exclude width and height (default: false) + * `force_xlink_href`: forces xlink namespace in case of compatibility issues (default: false) +* `WebPWriter` + * `quality`: image quality (0-100, default: 80) + +You can provide any writer options like this. + ```php use Endroid\QrCode\Writer\SvgWriter; -$builder->setWriterOptions([SvgWriter::WRITER_OPTION_EXCLUDE_XML_DECLARATION => true]); +$builder->setWriterOptions([ + SvgWriter::WRITER_OPTION_EXCLUDE_XML_DECLARATION => true +]); ``` ### Encoding @@ -145,13 +176,14 @@ size can result in additional padding to compensate for the rounding difference. And finally the encoding (default UTF-8 to support large character sets) can be set to `ISO-8859-1` if possible to improve readability. -## Built-in validation reader +## Validating the generated QR code -You can enable the built-in validation reader (disabled by default) by calling -setValidateResult(true). This validation reader does not guarantee that the QR -code will be readable by all readers but it helps you provide a minimum level -of quality. Take note that the validator can consume quite amount of additional -resources and it should be installed separately only if you use it. +If you need to be extra sure the QR code you generated is readable and contains +the exact data you requested you can enable the validation reader, which is +disabled by default. You can do this either via the builder or directly on any +writer that supports validation. See the examples above. + +Please note that validation affects performance so only use it in case of problems. ## Symfony integration diff --git a/vendor/endroid/qr-code/assets/blackfire.png b/vendor/endroid/qr-code/assets/blackfire.png new file mode 100644 index 0000000..bc378fd Binary files /dev/null and b/vendor/endroid/qr-code/assets/blackfire.png differ diff --git a/vendor/endroid/qr-code/composer.json b/vendor/endroid/qr-code/composer.json index 9fd62c0..2a43347 100644 --- a/vendor/endroid/qr-code/composer.json +++ b/vendor/endroid/qr-code/composer.json @@ -12,15 +12,18 @@ } ], "require": { - "php": "^7.4||^8.0", + "php": "^8.0", "bacon/bacon-qr-code": "^2.0.5" }, "require-dev": { "ext-gd": "*", "endroid/quality": "dev-master", - "khanamiryan/qrcode-detector-decoder": "^1.0.4", + "khanamiryan/qrcode-detector-decoder": "^1.0.4||^2.0.2", "setasign/fpdf": "^1.8.2" }, + "conflict": { + "khanamiryan/qrcode-detector-decoder": "^1.0.6" + }, "suggest": { "ext-gd": "Enables you to write PNG images", "khanamiryan/qrcode-detector-decoder": "Enables you to use the image validator", @@ -41,6 +44,9 @@ "sort-packages": true, "preferred-install": { "endroid/*": "source" + }, + "allow-plugins": { + "endroid/installer": true } }, "extra": { diff --git a/vendor/endroid/qr-code/src/Builder/Builder.php b/vendor/endroid/qr-code/src/Builder/Builder.php index c00be13..914ec94 100644 --- a/vendor/endroid/qr-code/src/Builder/Builder.php +++ b/vendor/endroid/qr-code/src/Builder/Builder.php @@ -7,6 +7,7 @@ namespace Endroid\QrCode\Builder; use Endroid\QrCode\Color\ColorInterface; use Endroid\QrCode\Encoding\EncodingInterface; use Endroid\QrCode\ErrorCorrectionLevel\ErrorCorrectionLevelInterface; +use Endroid\QrCode\Exception\ValidationException; use Endroid\QrCode\Label\Alignment\LabelAlignmentInterface; use Endroid\QrCode\Label\Font\FontInterface; use Endroid\QrCode\Label\Label; @@ -24,7 +25,7 @@ use Endroid\QrCode\Writer\WriterInterface; class Builder implements BuilderInterface { /** - * @var array{ + * @var array{ * data: string, * writer: WriterInterface, * writerOptions: array, @@ -77,7 +78,7 @@ class Builder implements BuilderInterface return $this; } - /** @param array $writerOptions */ + /** @param array $writerOptions */ public function writerOptions(array $writerOptions): BuilderInterface { $this->options['writerOptions'] = $writerOptions; @@ -216,7 +217,7 @@ class Builder implements BuilderInterface $writer = $this->options['writer']; if ($this->options['validateResult'] && !$writer instanceof ValidatingWriterInterface) { - throw new \Exception('Unable to validate result with '.get_class($writer)); + throw ValidationException::createForUnsupportedWriter(strval(get_class($writer))); } /** @var QrCode $qrCode */ @@ -242,7 +243,7 @@ class Builder implements BuilderInterface * * @return mixed */ - private function buildObject(string $class, string $optionsPrefix = null) + private function buildObject(string $class, string|null $optionsPrefix = null) { /** @var \ReflectionClass $reflectionClass */ $reflectionClass = new \ReflectionClass($class); diff --git a/vendor/endroid/qr-code/src/Builder/BuilderInterface.php b/vendor/endroid/qr-code/src/Builder/BuilderInterface.php index 5e69bc2..c173e5a 100644 --- a/vendor/endroid/qr-code/src/Builder/BuilderInterface.php +++ b/vendor/endroid/qr-code/src/Builder/BuilderInterface.php @@ -20,7 +20,7 @@ interface BuilderInterface public function writer(WriterInterface $writer): BuilderInterface; - /** @param array $writerOptions */ + /** @param array $writerOptions */ public function writerOptions(array $writerOptions): BuilderInterface; public function data(string $data): BuilderInterface; diff --git a/vendor/endroid/qr-code/src/Color/Color.php b/vendor/endroid/qr-code/src/Color/Color.php index 26d9c4a..2fb716d 100644 --- a/vendor/endroid/qr-code/src/Color/Color.php +++ b/vendor/endroid/qr-code/src/Color/Color.php @@ -6,17 +6,12 @@ namespace Endroid\QrCode\Color; final class Color implements ColorInterface { - private int $red; - private int $green; - private int $blue; - private int $alpha; - - public function __construct(int $red, int $green, int $blue, int $alpha = 0) - { - $this->red = $red; - $this->green = $green; - $this->blue = $blue; - $this->alpha = $alpha; + public function __construct( + private int $red, + private int $green, + private int $blue, + private int $alpha = 0 + ) { } public function getRed(): int @@ -44,6 +39,11 @@ final class Color implements ColorInterface return 1 - $this->alpha / 127; } + public function getHex(): string + { + return sprintf('#%02x%02x%02x', $this->red, $this->green, $this->blue); + } + public function toArray(): array { return [ diff --git a/vendor/endroid/qr-code/src/Color/ColorInterface.php b/vendor/endroid/qr-code/src/Color/ColorInterface.php index 91d3818..398be26 100644 --- a/vendor/endroid/qr-code/src/Color/ColorInterface.php +++ b/vendor/endroid/qr-code/src/Color/ColorInterface.php @@ -16,6 +16,8 @@ interface ColorInterface public function getOpacity(): float; + public function getHex(): string; + /** @return array */ public function toArray(): array; } diff --git a/vendor/endroid/qr-code/src/Encoding/Encoding.php b/vendor/endroid/qr-code/src/Encoding/Encoding.php index 2126d1e..54e6375 100644 --- a/vendor/endroid/qr-code/src/Encoding/Encoding.php +++ b/vendor/endroid/qr-code/src/Encoding/Encoding.php @@ -6,15 +6,12 @@ namespace Endroid\QrCode\Encoding; final class Encoding implements EncodingInterface { - private string $value; - - public function __construct(string $value) - { + public function __construct( + private string $value + ) { if (!in_array($value, mb_list_encodings())) { throw new \Exception(sprintf('Invalid encoding "%s"', $value)); } - - $this->value = $value; } public function __toString(): string diff --git a/vendor/endroid/qr-code/src/Exception/ValidationException.php b/vendor/endroid/qr-code/src/Exception/ValidationException.php new file mode 100644 index 0000000..f64c4bb --- /dev/null +++ b/vendor/endroid/qr-code/src/Exception/ValidationException.php @@ -0,0 +1,23 @@ +width = $width; - $this->height = $height; + private function __construct( + private int $width, + private int $height + ) { } public static function createForLabel(LabelInterface $label): self diff --git a/vendor/endroid/qr-code/src/ImageData/LogoImageData.php b/vendor/endroid/qr-code/src/ImageData/LogoImageData.php index 75b4078..d823cce 100644 --- a/vendor/endroid/qr-code/src/ImageData/LogoImageData.php +++ b/vendor/endroid/qr-code/src/ImageData/LogoImageData.php @@ -8,31 +8,14 @@ use Endroid\QrCode\Logo\LogoInterface; class LogoImageData { - private string $data; - - /** @var mixed */ - private $image; - - private string $mimeType; - private int $width; - private int $height; - private bool $punchoutBackground; - - /** @param mixed $image */ private function __construct( - string $data, - $image, - string $mimeType, - int $width, - int $height, - bool $punchoutBackground + private string $data, + private \GdImage|null $image, + private string $mimeType, + private int $width, + private int $height, + private bool $punchoutBackground ) { - $this->data = $data; - $this->image = $image; - $this->mimeType = $mimeType; - $this->width = $width; - $this->height = $height; - $this->punchoutBackground = $punchoutBackground; } public static function createForLogo(LogoInterface $logo): self @@ -89,10 +72,9 @@ class LogoImageData return $this->data; } - /** @return mixed */ - public function getImage() + public function getImage(): \GdImage { - if (null === $this->image) { + if (!$this->image instanceof \GdImage) { throw new \Exception('SVG Images have no image resource'); } @@ -126,10 +108,7 @@ class LogoImageData private static function detectMimeTypeFromUrl(string $url): string { - /** @var mixed $format */ - $format = PHP_VERSION_ID >= 80000 ? true : 1; - - $headers = get_headers($url, $format); + $headers = get_headers($url, true); if (!is_array($headers) || !isset($headers['Content-Type'])) { throw new \Exception(sprintf('Content type could not be determined for logo URL "%s"', $url)); diff --git a/vendor/endroid/qr-code/src/Label/Font/Font.php b/vendor/endroid/qr-code/src/Label/Font/Font.php index 8026772..116e091 100644 --- a/vendor/endroid/qr-code/src/Label/Font/Font.php +++ b/vendor/endroid/qr-code/src/Label/Font/Font.php @@ -6,18 +6,14 @@ namespace Endroid\QrCode\Label\Font; final class Font implements FontInterface { - private string $path; - private int $size; - - public function __construct(string $path, int $size = 16) - { - $this->validatePath($path); - - $this->path = $path; - $this->size = $size; + public function __construct( + private string $path, + private int $size = 16 + ) { + $this->assertValidPath($path); } - private function validatePath(string $path): void + private function assertValidPath(string $path): void { if (!file_exists($path)) { throw new \Exception(sprintf('Invalid font path "%s"', $path)); diff --git a/vendor/endroid/qr-code/src/Label/Font/NotoSans.php b/vendor/endroid/qr-code/src/Label/Font/NotoSans.php index c72b244..9934c1d 100644 --- a/vendor/endroid/qr-code/src/Label/Font/NotoSans.php +++ b/vendor/endroid/qr-code/src/Label/Font/NotoSans.php @@ -6,11 +6,9 @@ namespace Endroid\QrCode\Label\Font; final class NotoSans implements FontInterface { - private int $size; - - public function __construct(int $size = 16) - { - $this->size = $size; + public function __construct( + private int $size = 16 + ) { } public function getPath(): string diff --git a/vendor/endroid/qr-code/src/Label/Font/OpenSans.php b/vendor/endroid/qr-code/src/Label/Font/OpenSans.php index 4daab73..d1adece 100644 --- a/vendor/endroid/qr-code/src/Label/Font/OpenSans.php +++ b/vendor/endroid/qr-code/src/Label/Font/OpenSans.php @@ -6,11 +6,9 @@ namespace Endroid\QrCode\Label\Font; final class OpenSans implements FontInterface { - private int $size; - - public function __construct(int $size = 16) - { - $this->size = $size; + public function __construct( + private int $size = 16 + ) { } public function getPath(): string diff --git a/vendor/endroid/qr-code/src/Label/Label.php b/vendor/endroid/qr-code/src/Label/Label.php index 5d5d013..131cc57 100644 --- a/vendor/endroid/qr-code/src/Label/Label.php +++ b/vendor/endroid/qr-code/src/Label/Label.php @@ -15,24 +15,22 @@ use Endroid\QrCode\Label\Margin\MarginInterface; final class Label implements LabelInterface { - private string $text; private FontInterface $font; private LabelAlignmentInterface $alignment; private MarginInterface $margin; private ColorInterface $textColor; public function __construct( - string $text, - FontInterface $font = null, - LabelAlignmentInterface $alignment = null, - MarginInterface $margin = null, - ColorInterface $textColor = null + private string $text, + FontInterface|null $font = null, + LabelAlignmentInterface|null $alignment = null, + MarginInterface|null $margin = null, + ColorInterface|null $textColor = null ) { - $this->text = $text; - $this->font = isset($font) ? $font : new Font(__DIR__.'/../../assets/noto_sans.otf', 16); - $this->alignment = isset($alignment) ? $alignment : new LabelAlignmentCenter(); - $this->margin = isset($margin) ? $margin : new Margin(0, 10, 10, 10); - $this->textColor = isset($textColor) ? $textColor : new Color(0, 0, 0); + $this->font = $font ?? new Font(__DIR__.'/../../assets/noto_sans.otf', 16); + $this->alignment = $alignment ?? new LabelAlignmentCenter(); + $this->margin = $margin ?? new Margin(0, 10, 10, 10); + $this->textColor = $textColor ?? new Color(0, 0, 0); } public static function create(string $text): self diff --git a/vendor/endroid/qr-code/src/Label/Margin/Margin.php b/vendor/endroid/qr-code/src/Label/Margin/Margin.php index 3a5aeef..b1f7175 100644 --- a/vendor/endroid/qr-code/src/Label/Margin/Margin.php +++ b/vendor/endroid/qr-code/src/Label/Margin/Margin.php @@ -6,17 +6,12 @@ namespace Endroid\QrCode\Label\Margin; final class Margin implements MarginInterface { - private int $top; - private int $right; - private int $bottom; - private int $left; - - public function __construct(int $top, int $right, int $bottom, int $left) - { - $this->top = $top; - $this->right = $right; - $this->bottom = $bottom; - $this->left = $left; + public function __construct( + private int $top, + private int $right, + private int $bottom, + private int $left + ) { } public function getTop(): int diff --git a/vendor/endroid/qr-code/src/Logo/Logo.php b/vendor/endroid/qr-code/src/Logo/Logo.php index b50d743..7b28a2a 100644 --- a/vendor/endroid/qr-code/src/Logo/Logo.php +++ b/vendor/endroid/qr-code/src/Logo/Logo.php @@ -6,17 +6,12 @@ namespace Endroid\QrCode\Logo; final class Logo implements LogoInterface { - private string $path; - private ?int $resizeToWidth; - private ?int $resizeToHeight; - private bool $punchoutBackground; - - public function __construct(string $path, ?int $resizeToWidth = null, ?int $resizeToHeight = null, bool $punchoutBackground = false) - { - $this->path = $path; - $this->resizeToWidth = $resizeToWidth; - $this->resizeToHeight = $resizeToHeight; - $this->punchoutBackground = $punchoutBackground; + public function __construct( + private string $path, + private int|null $resizeToWidth = null, + private int|null $resizeToHeight = null, + private bool $punchoutBackground = false + ) { } public static function create(string $path): self @@ -36,24 +31,24 @@ final class Logo implements LogoInterface return $this; } - public function getResizeToWidth(): ?int + public function getResizeToWidth(): int|null { return $this->resizeToWidth; } - public function setResizeToWidth(?int $resizeToWidth): self + public function setResizeToWidth(int|null $resizeToWidth): self { $this->resizeToWidth = $resizeToWidth; return $this; } - public function getResizeToHeight(): ?int + public function getResizeToHeight(): int|null { return $this->resizeToHeight; } - public function setResizeToHeight(?int $resizeToHeight): self + public function setResizeToHeight(int|null $resizeToHeight): self { $this->resizeToHeight = $resizeToHeight; diff --git a/vendor/endroid/qr-code/src/Logo/LogoInterface.php b/vendor/endroid/qr-code/src/Logo/LogoInterface.php index 13d940c..12036e3 100644 --- a/vendor/endroid/qr-code/src/Logo/LogoInterface.php +++ b/vendor/endroid/qr-code/src/Logo/LogoInterface.php @@ -8,9 +8,9 @@ interface LogoInterface { public function getPath(): string; - public function getResizeToWidth(): ?int; + public function getResizeToWidth(): int|null; - public function getResizeToHeight(): ?int; + public function getResizeToHeight(): int|null; public function getPunchoutBackground(): bool; } diff --git a/vendor/endroid/qr-code/src/Matrix/Matrix.php b/vendor/endroid/qr-code/src/Matrix/Matrix.php index b0dd63e..48e22c7 100644 --- a/vendor/endroid/qr-code/src/Matrix/Matrix.php +++ b/vendor/endroid/qr-code/src/Matrix/Matrix.php @@ -11,9 +11,6 @@ use Endroid\QrCode\RoundBlockSizeMode\RoundBlockSizeModeShrink; final class Matrix implements MatrixInterface { - /** @var array> */ - private array $blockValues = []; - private float $blockSize; private int $innerSize; private int $outerSize; @@ -21,10 +18,12 @@ final class Matrix implements MatrixInterface private int $marginRight; /** @param array> $blockValues */ - public function __construct(array $blockValues, int $size, int $margin, RoundBlockSizeModeInterface $roundBlockSizeMode) - { - $this->blockValues = $blockValues; - + public function __construct( + private array $blockValues, + int $size, + int $margin, + RoundBlockSizeModeInterface $roundBlockSizeMode + ) { $this->blockSize = $size / $this->getBlockCount(); $this->innerSize = $size; $this->outerSize = $size + 2 * $margin; diff --git a/vendor/endroid/qr-code/src/QrCode.php b/vendor/endroid/qr-code/src/QrCode.php index 1dcd7d7..08c7dab 100644 --- a/vendor/endroid/qr-code/src/QrCode.php +++ b/vendor/endroid/qr-code/src/QrCode.php @@ -15,30 +15,24 @@ use Endroid\QrCode\RoundBlockSizeMode\RoundBlockSizeModeMargin; final class QrCode implements QrCodeInterface { - private string $data; private EncodingInterface $encoding; private ErrorCorrectionLevelInterface $errorCorrectionLevel; - private int $size; - private int $margin; private RoundBlockSizeModeInterface $roundBlockSizeMode; private ColorInterface $foregroundColor; private ColorInterface $backgroundColor; public function __construct( - string $data, - EncodingInterface $encoding = null, - ErrorCorrectionLevelInterface $errorCorrectionLevel = null, - int $size = 300, - int $margin = 10, - RoundBlockSizeModeInterface $roundBlockSizeMode = null, - ColorInterface $foregroundColor = null, - ColorInterface $backgroundColor = null + private string $data, + EncodingInterface|null $encoding = null, + ErrorCorrectionLevelInterface|null $errorCorrectionLevel = null, + private int $size = 300, + private int $margin = 10, + RoundBlockSizeModeInterface|null $roundBlockSizeMode = null, + ColorInterface|null $foregroundColor = null, + ColorInterface|null $backgroundColor = null ) { - $this->data = $data; $this->encoding = $encoding ?? new Encoding('UTF-8'); $this->errorCorrectionLevel = $errorCorrectionLevel ?? new ErrorCorrectionLevelLow(); - $this->size = $size; - $this->margin = $margin; $this->roundBlockSizeMode = $roundBlockSizeMode ?? new RoundBlockSizeModeMargin(); $this->foregroundColor = $foregroundColor ?? new Color(0, 0, 0); $this->backgroundColor = $backgroundColor ?? new Color(255, 255, 255); diff --git a/vendor/endroid/qr-code/src/WritableInterface.php b/vendor/endroid/qr-code/src/WritableInterface.php deleted file mode 100644 index a465ced..0000000 --- a/vendor/endroid/qr-code/src/WritableInterface.php +++ /dev/null @@ -1,7 +0,0 @@ -create($qrCode); + + $baseBlockSize = $qrCode->getRoundBlockSizeMode() instanceof RoundBlockSizeModeNone ? 10 : intval($matrix->getBlockSize()); + $baseImage = imagecreatetruecolor($matrix->getBlockCount() * $baseBlockSize, $matrix->getBlockCount() * $baseBlockSize); + + if (!$baseImage) { + throw new \Exception('Unable to generate image: please check if the GD extension is enabled and configured correctly'); + } + + /** @var int $foregroundColor */ + $foregroundColor = imagecolorallocatealpha( + $baseImage, + $qrCode->getForegroundColor()->getRed(), + $qrCode->getForegroundColor()->getGreen(), + $qrCode->getForegroundColor()->getBlue(), + $qrCode->getForegroundColor()->getAlpha() + ); + + /** @var int $transparentColor */ + $transparentColor = imagecolorallocatealpha($baseImage, 255, 255, 255, 127); + + imagefill($baseImage, 0, 0, $transparentColor); + + for ($rowIndex = 0; $rowIndex < $matrix->getBlockCount(); ++$rowIndex) { + for ($columnIndex = 0; $columnIndex < $matrix->getBlockCount(); ++$columnIndex) { + if (1 === $matrix->getBlockValue($rowIndex, $columnIndex)) { + imagefilledrectangle( + $baseImage, + $columnIndex * $baseBlockSize, + $rowIndex * $baseBlockSize, + ($columnIndex + 1) * $baseBlockSize - 1, + ($rowIndex + 1) * $baseBlockSize - 1, + $foregroundColor + ); + } + } + } + + $targetWidth = $matrix->getOuterSize(); + $targetHeight = $matrix->getOuterSize(); + + if ($label instanceof LabelInterface) { + $labelImageData = LabelImageData::createForLabel($label); + $targetHeight += $labelImageData->getHeight() + $label->getMargin()->getTop() + $label->getMargin()->getBottom(); + } + + $targetImage = imagecreatetruecolor($targetWidth, $targetHeight); + + if (!$targetImage) { + throw new \Exception('Unable to generate image: please check if the GD extension is enabled and configured correctly'); + } + + /** @var int $backgroundColor */ + $backgroundColor = imagecolorallocatealpha( + $targetImage, + $qrCode->getBackgroundColor()->getRed(), + $qrCode->getBackgroundColor()->getGreen(), + $qrCode->getBackgroundColor()->getBlue(), + $qrCode->getBackgroundColor()->getAlpha() + ); + + imagefill($targetImage, 0, 0, $backgroundColor); + + imagecopyresampled( + $targetImage, + $baseImage, + $matrix->getMarginLeft(), + $matrix->getMarginLeft(), + 0, + 0, + $matrix->getInnerSize(), + $matrix->getInnerSize(), + imagesx($baseImage), + imagesy($baseImage) + ); + + if ($qrCode->getBackgroundColor()->getAlpha() > 0) { + imagesavealpha($targetImage, true); + } + + $result = new GdResult($matrix, $targetImage); + + if ($logo instanceof LogoInterface) { + $result = $this->addLogo($logo, $result); + } + + if ($label instanceof LabelInterface) { + $result = $this->addLabel($label, $result); + } + + return $result; + } + + private function addLogo(LogoInterface $logo, GdResult $result): GdResult + { + $logoImageData = LogoImageData::createForLogo($logo); + + if ('image/svg+xml' === $logoImageData->getMimeType()) { + throw new \Exception('PNG Writer does not support SVG logo'); + } + + $targetImage = $result->getImage(); + $matrix = $result->getMatrix(); + + if ($logoImageData->getPunchoutBackground()) { + /** @var int $transparent */ + $transparent = imagecolorallocatealpha($targetImage, 255, 255, 255, 127); + imagealphablending($targetImage, false); + $xOffsetStart = intval($matrix->getOuterSize() / 2 - $logoImageData->getWidth() / 2); + $yOffsetStart = intval($matrix->getOuterSize() / 2 - $logoImageData->getHeight() / 2); + for ($xOffset = $xOffsetStart; $xOffset < $xOffsetStart + $logoImageData->getWidth(); ++$xOffset) { + for ($yOffset = $yOffsetStart; $yOffset < $yOffsetStart + $logoImageData->getHeight(); ++$yOffset) { + imagesetpixel($targetImage, $xOffset, $yOffset, $transparent); + } + } + } + + imagecopyresampled( + $targetImage, + $logoImageData->getImage(), + intval($matrix->getOuterSize() / 2 - $logoImageData->getWidth() / 2), + intval($matrix->getOuterSize() / 2 - $logoImageData->getHeight() / 2), + 0, + 0, + $logoImageData->getWidth(), + $logoImageData->getHeight(), + imagesx($logoImageData->getImage()), + imagesy($logoImageData->getImage()) + ); + + return new GdResult($matrix, $targetImage); + } + + private function addLabel(LabelInterface $label, GdResult $result): GdResult + { + $targetImage = $result->getImage(); + + $labelImageData = LabelImageData::createForLabel($label); + + /** @var int $textColor */ + $textColor = imagecolorallocatealpha( + $targetImage, + $label->getTextColor()->getRed(), + $label->getTextColor()->getGreen(), + $label->getTextColor()->getBlue(), + $label->getTextColor()->getAlpha() + ); + + $x = intval(imagesx($targetImage) / 2 - $labelImageData->getWidth() / 2); + $y = imagesy($targetImage) - $label->getMargin()->getBottom(); + + if ($label->getAlignment() instanceof LabelAlignmentLeft) { + $x = $label->getMargin()->getLeft(); + } elseif ($label->getAlignment() instanceof LabelAlignmentRight) { + $x = imagesx($targetImage) - $labelImageData->getWidth() - $label->getMargin()->getRight(); + } + + imagettftext($targetImage, $label->getFont()->getSize(), 0, $x, $y, $textColor, $label->getFont()->getPath(), $label->getText()); + + return new GdResult($result->getMatrix(), $targetImage); + } + + public function validateResult(ResultInterface $result, string $expectedData): void + { + $string = $result->getString(); + + if (!class_exists(QrReader::class)) { + throw ValidationException::createForMissingPackage('khanamiryan/qrcode-detector-decoder'); + } + + $reader = new QrReader($string, QrReader::SOURCE_TYPE_BLOB); + if ($reader->text() !== $expectedData) { + throw ValidationException::createForInvalidData($expectedData, strval($reader->text())); + } + } +} diff --git a/vendor/endroid/qr-code/src/Writer/BinaryWriter.php b/vendor/endroid/qr-code/src/Writer/BinaryWriter.php index a18230c..c8aff4d 100644 --- a/vendor/endroid/qr-code/src/Writer/BinaryWriter.php +++ b/vendor/endroid/qr-code/src/Writer/BinaryWriter.php @@ -13,7 +13,7 @@ use Endroid\QrCode\Writer\Result\ResultInterface; final class BinaryWriter implements WriterInterface { - public function write(QrCodeInterface $qrCode, LogoInterface $logo = null, LabelInterface $label = null, array $options = []): ResultInterface + public function write(QrCodeInterface $qrCode, LogoInterface|null $logo = null, LabelInterface|null $label = null, array $options = []): ResultInterface { $matrixFactory = new MatrixFactory(); $matrix = $matrixFactory->create($qrCode); diff --git a/vendor/endroid/qr-code/src/Writer/ConsoleWriter.php b/vendor/endroid/qr-code/src/Writer/ConsoleWriter.php new file mode 100644 index 0000000..cd8604a --- /dev/null +++ b/vendor/endroid/qr-code/src/Writer/ConsoleWriter.php @@ -0,0 +1,23 @@ +create($qrCode); + + return new ConsoleResult($matrix, $qrCode->getForegroundColor(), $qrCode->getBackgroundColor()); + } +} diff --git a/vendor/endroid/qr-code/src/Writer/DebugWriter.php b/vendor/endroid/qr-code/src/Writer/DebugWriter.php index 3e89515..6dd7738 100644 --- a/vendor/endroid/qr-code/src/Writer/DebugWriter.php +++ b/vendor/endroid/qr-code/src/Writer/DebugWriter.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace Endroid\QrCode\Writer; +use Endroid\QrCode\Bacon\MatrixFactory; use Endroid\QrCode\Label\LabelInterface; use Endroid\QrCode\Logo\LogoInterface; use Endroid\QrCode\QrCodeInterface; @@ -12,9 +13,12 @@ use Endroid\QrCode\Writer\Result\ResultInterface; final class DebugWriter implements WriterInterface, ValidatingWriterInterface { - public function write(QrCodeInterface $qrCode, LogoInterface $logo = null, LabelInterface $label = null, array $options = []): ResultInterface + public function write(QrCodeInterface $qrCode, LogoInterface|null $logo = null, LabelInterface|null $label = null, array $options = []): ResultInterface { - return new DebugResult($qrCode, $logo, $label, $options); + $matrixFactory = new MatrixFactory(); + $matrix = $matrixFactory->create($qrCode); + + return new DebugResult($matrix, $qrCode, $logo, $label, $options); } public function validateResult(ResultInterface $result, string $expectedData): void diff --git a/vendor/endroid/qr-code/src/Writer/EpsWriter.php b/vendor/endroid/qr-code/src/Writer/EpsWriter.php index 2ffd219..092ccf3 100644 --- a/vendor/endroid/qr-code/src/Writer/EpsWriter.php +++ b/vendor/endroid/qr-code/src/Writer/EpsWriter.php @@ -15,7 +15,7 @@ final class EpsWriter implements WriterInterface { public const DECIMAL_PRECISION = 10; - public function write(QrCodeInterface $qrCode, LogoInterface $logo = null, LabelInterface $label = null, array $options = []): ResultInterface + public function write(QrCodeInterface $qrCode, LogoInterface|null $logo = null, LabelInterface|null $label = null, array $options = []): ResultInterface { $matrixFactory = new MatrixFactory(); $matrix = $matrixFactory->create($qrCode); @@ -39,6 +39,6 @@ final class EpsWriter implements WriterInterface } } - return new EpsResult($lines); + return new EpsResult($matrix, $lines); } } diff --git a/vendor/endroid/qr-code/src/Writer/GifWriter.php b/vendor/endroid/qr-code/src/Writer/GifWriter.php new file mode 100644 index 0000000..ed684d7 --- /dev/null +++ b/vendor/endroid/qr-code/src/Writer/GifWriter.php @@ -0,0 +1,23 @@ +getMatrix(), $gdResult->getImage()); + } +} diff --git a/vendor/endroid/qr-code/src/Writer/PdfWriter.php b/vendor/endroid/qr-code/src/Writer/PdfWriter.php index 78f0603..de26240 100644 --- a/vendor/endroid/qr-code/src/Writer/PdfWriter.php +++ b/vendor/endroid/qr-code/src/Writer/PdfWriter.php @@ -17,8 +17,9 @@ final class PdfWriter implements WriterInterface public const WRITER_OPTION_PDF = 'fpdf'; public const WRITER_OPTION_X = 'x'; public const WRITER_OPTION_Y = 'y'; + public const WRITER_OPTION_LINK = 'link'; - public function write(QrCodeInterface $qrCode, LogoInterface $logo = null, LabelInterface $label = null, array $options = []): ResultInterface + public function write(QrCodeInterface $qrCode, LogoInterface|null $logo = null, LabelInterface|null $label = null, array $options = []): ResultInterface { $matrixFactory = new MatrixFactory(); $matrix = $matrixFactory->create($qrCode); @@ -99,7 +100,12 @@ final class PdfWriter implements WriterInterface $fpdf->Cell($matrix->getOuterSize(), 0, $label->getText(), 0, 0, 'C'); } - return new PdfResult($fpdf); + if (isset($options[self::WRITER_OPTION_LINK])) { + $link = $options[self::WRITER_OPTION_LINK]; + $fpdf->Link($x, $y, $x + $matrix->getOuterSize(), $y + $matrix->getOuterSize(), $link); + } + + return new PdfResult($matrix, $fpdf); } private function addLogo(LogoInterface $logo, \FPDF $fpdf, float $x, float $y, float $size): void diff --git a/vendor/endroid/qr-code/src/Writer/PngWriter.php b/vendor/endroid/qr-code/src/Writer/PngWriter.php index e944d84..ce28cfe 100644 --- a/vendor/endroid/qr-code/src/Writer/PngWriter.php +++ b/vendor/endroid/qr-code/src/Writer/PngWriter.php @@ -4,224 +4,26 @@ declare(strict_types=1); namespace Endroid\QrCode\Writer; -use Endroid\QrCode\Bacon\MatrixFactory; -use Endroid\QrCode\ImageData\LabelImageData; -use Endroid\QrCode\ImageData\LogoImageData; -use Endroid\QrCode\Label\Alignment\LabelAlignmentLeft; -use Endroid\QrCode\Label\Alignment\LabelAlignmentRight; use Endroid\QrCode\Label\LabelInterface; use Endroid\QrCode\Logo\LogoInterface; use Endroid\QrCode\QrCodeInterface; -use Endroid\QrCode\RoundBlockSizeMode\RoundBlockSizeModeNone; +use Endroid\QrCode\Writer\Result\GdResult; use Endroid\QrCode\Writer\Result\PngResult; use Endroid\QrCode\Writer\Result\ResultInterface; -use Zxing\QrReader; -final class PngWriter implements WriterInterface, ValidatingWriterInterface +final class PngWriter extends AbstractGdWriter { - public function write(QrCodeInterface $qrCode, LogoInterface $logo = null, LabelInterface $label = null, array $options = []): ResultInterface + public const WRITER_OPTION_COMPRESSION_LEVEL = 'compression_level'; + + public function write(QrCodeInterface $qrCode, LogoInterface|null $logo = null, LabelInterface|null $label = null, array $options = []): ResultInterface { - if (!extension_loaded('gd')) { - throw new \Exception('Unable to generate image: please check if the GD extension is enabled and configured correctly'); + if (!isset($options[self::WRITER_OPTION_COMPRESSION_LEVEL])) { + $options[self::WRITER_OPTION_COMPRESSION_LEVEL] = -1; } - $matrixFactory = new MatrixFactory(); - $matrix = $matrixFactory->create($qrCode); + /** @var GdResult $gdResult */ + $gdResult = parent::write($qrCode, $logo, $label, $options); - $baseBlockSize = $qrCode->getRoundBlockSizeMode() instanceof RoundBlockSizeModeNone ? 10 : intval($matrix->getBlockSize()); - $baseImage = imagecreatetruecolor($matrix->getBlockCount() * $baseBlockSize, $matrix->getBlockCount() * $baseBlockSize); - - if (!$baseImage) { - throw new \Exception('Unable to generate image: please check if the GD extension is enabled and configured correctly'); - } - - /** @var int $foregroundColor */ - $foregroundColor = imagecolorallocatealpha( - $baseImage, - $qrCode->getForegroundColor()->getRed(), - $qrCode->getForegroundColor()->getGreen(), - $qrCode->getForegroundColor()->getBlue(), - $qrCode->getForegroundColor()->getAlpha() - ); - - /** @var int $transparentColor */ - $transparentColor = imagecolorallocatealpha($baseImage, 255, 255, 255, 127); - - imagefill($baseImage, 0, 0, $transparentColor); - - for ($rowIndex = 0; $rowIndex < $matrix->getBlockCount(); ++$rowIndex) { - for ($columnIndex = 0; $columnIndex < $matrix->getBlockCount(); ++$columnIndex) { - if (1 === $matrix->getBlockValue($rowIndex, $columnIndex)) { - imagefilledrectangle( - $baseImage, - $columnIndex * $baseBlockSize, - $rowIndex * $baseBlockSize, - ($columnIndex + 1) * $baseBlockSize - 1, - ($rowIndex + 1) * $baseBlockSize - 1, - $foregroundColor - ); - } - } - } - - $targetWidth = $matrix->getOuterSize(); - $targetHeight = $matrix->getOuterSize(); - - if ($label instanceof LabelInterface) { - $labelImageData = LabelImageData::createForLabel($label); - $targetHeight += $labelImageData->getHeight() + $label->getMargin()->getTop() + $label->getMargin()->getBottom(); - } - - $targetImage = imagecreatetruecolor($targetWidth, $targetHeight); - - if (!$targetImage) { - throw new \Exception('Unable to generate image: please check if the GD extension is enabled and configured correctly'); - } - - /** @var int $backgroundColor */ - $backgroundColor = imagecolorallocatealpha( - $targetImage, - $qrCode->getBackgroundColor()->getRed(), - $qrCode->getBackgroundColor()->getGreen(), - $qrCode->getBackgroundColor()->getBlue(), - $qrCode->getBackgroundColor()->getAlpha() - ); - - imagefill($targetImage, 0, 0, $backgroundColor); - - imagecopyresampled( - $targetImage, - $baseImage, - $matrix->getMarginLeft(), - $matrix->getMarginLeft(), - 0, - 0, - $matrix->getInnerSize(), - $matrix->getInnerSize(), - imagesx($baseImage), - imagesy($baseImage) - ); - - if (PHP_VERSION_ID < 80000) { - imagedestroy($baseImage); - } - - if ($qrCode->getBackgroundColor()->getAlpha() > 0) { - imagesavealpha($targetImage, true); - } - - $result = new PngResult($targetImage); - - if ($logo instanceof LogoInterface) { - $result = $this->addLogo($logo, $result); - } - - if ($label instanceof LabelInterface) { - $result = $this->addLabel($label, $result); - } - - return $result; - } - - private function addLogo(LogoInterface $logo, PngResult $result): PngResult - { - $logoImageData = LogoImageData::createForLogo($logo); - - if ('image/svg+xml' === $logoImageData->getMimeType()) { - throw new \Exception('PNG Writer does not support SVG logo'); - } - - $targetImage = $result->getImage(); - - if ($logoImageData->getPunchoutBackground()) { - /** @var int $transparent */ - $transparent = imagecolorallocatealpha($targetImage, 255, 255, 255, 127); - imagealphablending($targetImage, false); - for ( - $x_offset = intval(imagesx($targetImage) / 2 - $logoImageData->getWidth() / 2); - $x_offset < intval(imagesx($targetImage) / 2 - $logoImageData->getWidth() / 2) + $logoImageData->getWidth(); - ++$x_offset - ) { - for ( - $y_offset = intval(imagesy($targetImage) / 2 - $logoImageData->getHeight() / 2); - $y_offset < intval(imagesy($targetImage) / 2 - $logoImageData->getHeight() / 2) + $logoImageData->getHeight(); - ++$y_offset - ) { - imagesetpixel( - $targetImage, - $x_offset, - $y_offset, - $transparent - ); - } - } - } - - imagecopyresampled( - $targetImage, - $logoImageData->getImage(), - intval(imagesx($targetImage) / 2 - $logoImageData->getWidth() / 2), - intval(imagesx($targetImage) / 2 - $logoImageData->getHeight() / 2), - 0, - 0, - $logoImageData->getWidth(), - $logoImageData->getHeight(), - imagesx($logoImageData->getImage()), - imagesy($logoImageData->getImage()) - ); - - if (PHP_VERSION_ID < 80000) { - imagedestroy($logoImageData->getImage()); - } - - return new PngResult($targetImage); - } - - private function addLabel(LabelInterface $label, PngResult $result): PngResult - { - $targetImage = $result->getImage(); - - $labelImageData = LabelImageData::createForLabel($label); - - /** @var int $textColor */ - $textColor = imagecolorallocatealpha( - $targetImage, - $label->getTextColor()->getRed(), - $label->getTextColor()->getGreen(), - $label->getTextColor()->getBlue(), - $label->getTextColor()->getAlpha() - ); - - $x = intval(imagesx($targetImage) / 2 - $labelImageData->getWidth() / 2); - $y = imagesy($targetImage) - $label->getMargin()->getBottom(); - - if ($label->getAlignment() instanceof LabelAlignmentLeft) { - $x = $label->getMargin()->getLeft(); - } elseif ($label->getAlignment() instanceof LabelAlignmentRight) { - $x = imagesx($targetImage) - $labelImageData->getWidth() - $label->getMargin()->getRight(); - } - - imagettftext($targetImage, $label->getFont()->getSize(), 0, $x, $y, $textColor, $label->getFont()->getPath(), $label->getText()); - - return new PngResult($targetImage); - } - - public function validateResult(ResultInterface $result, string $expectedData): void - { - $string = $result->getString(); - - if (!class_exists(QrReader::class)) { - throw new \Exception('Please install khanamiryan/qrcode-detector-decoder or disable image validation'); - } - - if (PHP_VERSION_ID >= 80000) { - throw new \Exception('The validator is not compatible with PHP 8 yet, see https://github.com/khanamiryan/php-qrcode-detector-decoder/pull/103'); - } - - $reader = new QrReader($string, QrReader::SOURCE_TYPE_BLOB); - if ($reader->text() !== $expectedData) { - throw new \Exception('Built-in validation reader read "'.$reader->text().'" instead of "'.$expectedData.'". - Adjust your parameters to increase readability or disable built-in validation.'); - } + return new PngResult($gdResult->getMatrix(), $gdResult->getImage(), $options[self::WRITER_OPTION_COMPRESSION_LEVEL]); } } diff --git a/vendor/endroid/qr-code/src/Writer/Result/AbstractResult.php b/vendor/endroid/qr-code/src/Writer/Result/AbstractResult.php index 43b680b..fc8f30b 100644 --- a/vendor/endroid/qr-code/src/Writer/Result/AbstractResult.php +++ b/vendor/endroid/qr-code/src/Writer/Result/AbstractResult.php @@ -4,8 +4,20 @@ declare(strict_types=1); namespace Endroid\QrCode\Writer\Result; +use Endroid\QrCode\Matrix\MatrixInterface; + abstract class AbstractResult implements ResultInterface { + public function __construct( + private MatrixInterface $matrix + ) { + } + + public function getMatrix(): MatrixInterface + { + return $this->matrix; + } + public function getDataUri(): string { return 'data:'.$this->getMimeType().';base64,'.base64_encode($this->getString()); diff --git a/vendor/endroid/qr-code/src/Writer/Result/BinaryResult.php b/vendor/endroid/qr-code/src/Writer/Result/BinaryResult.php index 0618940..386fb6a 100644 --- a/vendor/endroid/qr-code/src/Writer/Result/BinaryResult.php +++ b/vendor/endroid/qr-code/src/Writer/Result/BinaryResult.php @@ -8,19 +8,19 @@ use Endroid\QrCode\Matrix\MatrixInterface; final class BinaryResult extends AbstractResult { - private MatrixInterface $matrix; - public function __construct(MatrixInterface $matrix) { - $this->matrix = $matrix; + parent::__construct($matrix); } public function getString(): string { + $matrix = $this->getMatrix(); + $binaryString = ''; - for ($rowIndex = 0; $rowIndex < $this->matrix->getBlockCount(); ++$rowIndex) { - for ($columnIndex = 0; $columnIndex < $this->matrix->getBlockCount(); ++$columnIndex) { - $binaryString .= $this->matrix->getBlockValue($rowIndex, $columnIndex); + for ($rowIndex = 0; $rowIndex < $matrix->getBlockCount(); ++$rowIndex) { + for ($columnIndex = 0; $columnIndex < $matrix->getBlockCount(); ++$columnIndex) { + $binaryString .= $matrix->getBlockValue($rowIndex, $columnIndex); } $binaryString .= "\n"; } diff --git a/vendor/endroid/qr-code/src/Writer/Result/ConsoleResult.php b/vendor/endroid/qr-code/src/Writer/Result/ConsoleResult.php new file mode 100644 index 0000000..1da8984 --- /dev/null +++ b/vendor/endroid/qr-code/src/Writer/Result/ConsoleResult.php @@ -0,0 +1,69 @@ + ' ', + 1 => "\xe2\x96\x80", + 2 => "\xe2\x96\x84", + 3 => "\xe2\x96\x88", + ]; + + private string $colorEscapeCode; + + public function __construct( + MatrixInterface $matrix, + ColorInterface $foreground, + ColorInterface $background + ) { + parent::__construct($matrix); + + $this->colorEscapeCode = sprintf( + "\e[38;2;%d;%d;%dm\e[48;2;%d;%d;%dm", + $foreground->getRed(), + $foreground->getGreen(), + $foreground->getBlue(), + $background->getRed(), + $background->getGreen(), + $background->getBlue() + ); + } + + public function getMimeType(): string + { + return 'text/plain'; + } + + public function getString(): string + { + $matrix = $this->getMatrix(); + + $side = $matrix->getBlockCount(); + $marginLeft = $this->colorEscapeCode.self::TWO_BLOCKS[0].self::TWO_BLOCKS[0]; + $marginRight = self::TWO_BLOCKS[0].self::TWO_BLOCKS[0]."\e[0m".PHP_EOL; + $marginVertical = $marginLeft.str_repeat(self::TWO_BLOCKS[0], $side).$marginRight; + + $qrCodeString = $marginVertical; + for ($rowIndex = 0; $rowIndex < $side; $rowIndex += 2) { + $qrCodeString .= $marginLeft; + for ($columnIndex = 0; $columnIndex < $side; ++$columnIndex) { + $combined = $matrix->getBlockValue($rowIndex, $columnIndex); + if ($rowIndex + 1 < $side) { + $combined |= $matrix->getBlockValue($rowIndex + 1, $columnIndex) << 1; + } + $qrCodeString .= self::TWO_BLOCKS[$combined]; + } + $qrCodeString .= $marginRight; + } + $qrCodeString .= $marginVertical; + + return $qrCodeString; + } +} diff --git a/vendor/endroid/qr-code/src/Writer/Result/DebugResult.php b/vendor/endroid/qr-code/src/Writer/Result/DebugResult.php index c3cbff0..167c177 100644 --- a/vendor/endroid/qr-code/src/Writer/Result/DebugResult.php +++ b/vendor/endroid/qr-code/src/Writer/Result/DebugResult.php @@ -6,26 +6,22 @@ namespace Endroid\QrCode\Writer\Result; use Endroid\QrCode\Label\LabelInterface; use Endroid\QrCode\Logo\LogoInterface; +use Endroid\QrCode\Matrix\MatrixInterface; use Endroid\QrCode\QrCodeInterface; final class DebugResult extends AbstractResult { - private QrCodeInterface $qrCode; - private ?LogoInterface $logo; - private ?LabelInterface $label; - - /** @var array */ - private array $options; - private bool $validateResult = false; - /** @param array $options */ - public function __construct(QrCodeInterface $qrCode, LogoInterface $logo = null, LabelInterface $label = null, array $options = []) - { - $this->qrCode = $qrCode; - $this->logo = $logo; - $this->label = $label; - $this->options = $options; + public function __construct( + MatrixInterface $matrix, + private QrCodeInterface $qrCode, + private LogoInterface|null $logo = null, + private LabelInterface|null $label = null, + /** @var array $options */ + private array $options = [] + ) { + parent::__construct($matrix); } public function setValidateResult(bool $validateResult): void diff --git a/vendor/endroid/qr-code/src/Writer/Result/EpsResult.php b/vendor/endroid/qr-code/src/Writer/Result/EpsResult.php index 0e55991..361551f 100644 --- a/vendor/endroid/qr-code/src/Writer/Result/EpsResult.php +++ b/vendor/endroid/qr-code/src/Writer/Result/EpsResult.php @@ -4,15 +4,16 @@ declare(strict_types=1); namespace Endroid\QrCode\Writer\Result; +use Endroid\QrCode\Matrix\MatrixInterface; + final class EpsResult extends AbstractResult { - /** @var array */ - private array $lines; - - /** @param array $lines */ - public function __construct(array $lines) - { - $this->lines = $lines; + public function __construct( + MatrixInterface $matrix, + /** @var array $lines */ + private array $lines + ) { + parent::__construct($matrix); } public function getString(): string diff --git a/vendor/endroid/qr-code/src/Writer/Result/GdResult.php b/vendor/endroid/qr-code/src/Writer/Result/GdResult.php new file mode 100644 index 0000000..237884a --- /dev/null +++ b/vendor/endroid/qr-code/src/Writer/Result/GdResult.php @@ -0,0 +1,32 @@ +image; + } + + public function getString(): string + { + throw new \Exception('You can only use this method in a concrete implementation'); + } + + public function getMimeType(): string + { + throw new \Exception('You can only use this method in a concrete implementation'); + } +} diff --git a/vendor/endroid/qr-code/src/Writer/Result/GifResult.php b/vendor/endroid/qr-code/src/Writer/Result/GifResult.php new file mode 100644 index 0000000..84b2497 --- /dev/null +++ b/vendor/endroid/qr-code/src/Writer/Result/GifResult.php @@ -0,0 +1,21 @@ +image); + + return strval(ob_get_clean()); + } + + public function getMimeType(): string + { + return 'image/gif'; + } +} diff --git a/vendor/endroid/qr-code/src/Writer/Result/PdfResult.php b/vendor/endroid/qr-code/src/Writer/Result/PdfResult.php index b4c644f..2b74a2a 100644 --- a/vendor/endroid/qr-code/src/Writer/Result/PdfResult.php +++ b/vendor/endroid/qr-code/src/Writer/Result/PdfResult.php @@ -4,13 +4,15 @@ declare(strict_types=1); namespace Endroid\QrCode\Writer\Result; +use Endroid\QrCode\Matrix\MatrixInterface; + final class PdfResult extends AbstractResult { - private \FPDF $fpdf; - - public function __construct(\FPDF $fpdf) - { - $this->fpdf = $fpdf; + public function __construct( + MatrixInterface $matrix, + private \FPDF $fpdf + ) { + parent::__construct($matrix); } public function getPdf(): \FPDF diff --git a/vendor/endroid/qr-code/src/Writer/Result/PngResult.php b/vendor/endroid/qr-code/src/Writer/Result/PngResult.php index efa26c5..73aa5ba 100644 --- a/vendor/endroid/qr-code/src/Writer/Result/PngResult.php +++ b/vendor/endroid/qr-code/src/Writer/Result/PngResult.php @@ -4,27 +4,22 @@ declare(strict_types=1); namespace Endroid\QrCode\Writer\Result; -final class PngResult extends AbstractResult +use Endroid\QrCode\Matrix\MatrixInterface; + +final class PngResult extends GdResult { - /** @var mixed */ - private $image; + private int $quality; - /** @param mixed $image */ - public function __construct($image) + public function __construct(MatrixInterface $matrix, \GdImage $image, int $quality = -1) { - $this->image = $image; - } - - /** @return mixed */ - public function getImage() - { - return $this->image; + parent::__construct($matrix, $image); + $this->quality = $quality; } public function getString(): string { ob_start(); - imagepng($this->image); + imagepng($this->image, quality: $this->quality); return strval(ob_get_clean()); } diff --git a/vendor/endroid/qr-code/src/Writer/Result/ResultInterface.php b/vendor/endroid/qr-code/src/Writer/Result/ResultInterface.php index a255605..2cd387e 100644 --- a/vendor/endroid/qr-code/src/Writer/Result/ResultInterface.php +++ b/vendor/endroid/qr-code/src/Writer/Result/ResultInterface.php @@ -4,8 +4,12 @@ declare(strict_types=1); namespace Endroid\QrCode\Writer\Result; +use Endroid\QrCode\Matrix\MatrixInterface; + interface ResultInterface { + public function getMatrix(): MatrixInterface; + public function getString(): string; public function getDataUri(): string; diff --git a/vendor/endroid/qr-code/src/Writer/Result/SvgResult.php b/vendor/endroid/qr-code/src/Writer/Result/SvgResult.php index 295202c..31a637f 100644 --- a/vendor/endroid/qr-code/src/Writer/Result/SvgResult.php +++ b/vendor/endroid/qr-code/src/Writer/Result/SvgResult.php @@ -4,15 +4,16 @@ declare(strict_types=1); namespace Endroid\QrCode\Writer\Result; +use Endroid\QrCode\Matrix\MatrixInterface; + final class SvgResult extends AbstractResult { - private \SimpleXMLElement $xml; - private bool $excludeXmlDeclaration; - - public function __construct(\SimpleXMLElement $xml, bool $excludeXmlDeclaration = false) - { - $this->xml = $xml; - $this->excludeXmlDeclaration = $excludeXmlDeclaration; + public function __construct( + MatrixInterface $matrix, + private \SimpleXMLElement $xml, + private bool $excludeXmlDeclaration = false + ) { + parent::__construct($matrix); } public function getXml(): \SimpleXMLElement diff --git a/vendor/endroid/qr-code/src/Writer/Result/WebPResult.php b/vendor/endroid/qr-code/src/Writer/Result/WebPResult.php new file mode 100644 index 0000000..b5141d1 --- /dev/null +++ b/vendor/endroid/qr-code/src/Writer/Result/WebPResult.php @@ -0,0 +1,35 @@ +quality = $quality; + } + + public function getString(): string + { + if (!function_exists('imagewebp')) { + throw new \Exception('WebP support is not available in your GD installation'); + } + + ob_start(); + imagewebp($this->image, quality: $this->quality); + + return strval(ob_get_clean()); + } + + public function getMimeType(): string + { + return 'image/webp'; + } +} diff --git a/vendor/endroid/qr-code/src/Writer/SvgWriter.php b/vendor/endroid/qr-code/src/Writer/SvgWriter.php index 233c903..713d19a 100644 --- a/vendor/endroid/qr-code/src/Writer/SvgWriter.php +++ b/vendor/endroid/qr-code/src/Writer/SvgWriter.php @@ -17,9 +17,10 @@ final class SvgWriter implements WriterInterface public const DECIMAL_PRECISION = 10; public const WRITER_OPTION_BLOCK_ID = 'block_id'; public const WRITER_OPTION_EXCLUDE_XML_DECLARATION = 'exclude_xml_declaration'; + public const WRITER_OPTION_EXCLUDE_SVG_WIDTH_AND_HEIGHT = 'exclude_svg_width_and_height'; public const WRITER_OPTION_FORCE_XLINK_HREF = 'force_xlink_href'; - public function write(QrCodeInterface $qrCode, LogoInterface $logo = null, LabelInterface $label = null, array $options = []): ResultInterface + public function write(QrCodeInterface $qrCode, LogoInterface|null $logo = null, LabelInterface|null $label = null, array $options = []): ResultInterface { if (!isset($options[self::WRITER_OPTION_BLOCK_ID])) { $options[self::WRITER_OPTION_BLOCK_ID] = 'block'; @@ -29,13 +30,19 @@ final class SvgWriter implements WriterInterface $options[self::WRITER_OPTION_EXCLUDE_XML_DECLARATION] = false; } + if (!isset($options[self::WRITER_OPTION_EXCLUDE_SVG_WIDTH_AND_HEIGHT])) { + $options[self::WRITER_OPTION_EXCLUDE_SVG_WIDTH_AND_HEIGHT] = false; + } + $matrixFactory = new MatrixFactory(); $matrix = $matrixFactory->create($qrCode); $xml = new \SimpleXMLElement(''); $xml->addAttribute('version', '1.1'); - $xml->addAttribute('width', $matrix->getOuterSize().'px'); - $xml->addAttribute('height', $matrix->getOuterSize().'px'); + if (!$options[self::WRITER_OPTION_EXCLUDE_SVG_WIDTH_AND_HEIGHT]) { + $xml->addAttribute('width', $matrix->getOuterSize().'px'); + $xml->addAttribute('height', $matrix->getOuterSize().'px'); + } $xml->addAttribute('viewBox', '0 0 '.$matrix->getOuterSize().' '.$matrix->getOuterSize()); $xml->addChild('defs'); @@ -65,7 +72,7 @@ final class SvgWriter implements WriterInterface } } - $result = new SvgResult($xml, boolval($options[self::WRITER_OPTION_EXCLUDE_XML_DECLARATION])); + $result = new SvgResult($matrix, $xml, boolval($options[self::WRITER_OPTION_EXCLUDE_XML_DECLARATION])); if ($logo instanceof LogoInterface) { $this->addLogo($logo, $result, $options); @@ -74,7 +81,7 @@ final class SvgWriter implements WriterInterface return $result; } - /** @param array $options */ + /** @param array $options */ private function addLogo(LogoInterface $logo, SvgResult $result, array $options): void { $logoImageData = LogoImageData::createForLogo($logo); diff --git a/vendor/endroid/qr-code/src/Writer/WebPWriter.php b/vendor/endroid/qr-code/src/Writer/WebPWriter.php new file mode 100644 index 0000000..afd1e2b --- /dev/null +++ b/vendor/endroid/qr-code/src/Writer/WebPWriter.php @@ -0,0 +1,29 @@ +getMatrix(), $gdResult->getImage(), $options[self::WRITER_OPTION_QUALITY]); + } +} diff --git a/vendor/endroid/qr-code/src/Writer/WriterInterface.php b/vendor/endroid/qr-code/src/Writer/WriterInterface.php index 4370f1b..16bba17 100644 --- a/vendor/endroid/qr-code/src/Writer/WriterInterface.php +++ b/vendor/endroid/qr-code/src/Writer/WriterInterface.php @@ -11,6 +11,6 @@ use Endroid\QrCode\Writer\Result\ResultInterface; interface WriterInterface { - /** @param array $options */ - public function write(QrCodeInterface $qrCode, LogoInterface $logo = null, LabelInterface $label = null, array $options = []): ResultInterface; + /** @param array $options */ + public function write(QrCodeInterface $qrCode, LogoInterface|null $logo = null, LabelInterface|null $label = null, array $options = []): ResultInterface; } diff --git a/vendor/wikimedia/less.php/API.md b/vendor/wikimedia/less.php/API.md new file mode 100644 index 0000000..010c90f --- /dev/null +++ b/vendor/wikimedia/less.php/API.md @@ -0,0 +1,197 @@ +Less.php API +======== + +## Basic use + +#### Parse strings + +```php +$parser = new Less_Parser(); +$parser->parse( '@color: #36c; .link { color: @color; } a { color: @color; }' ); +$css = $parser->getCss(); +``` + +#### Parse files + +The `parseFile()` function takes two parameters: + +* The absolute path to a `.less` file. +* The base URL for any relative image or CSS references in the `.less` file, + typically the same directory that contains the `.less` file or a public equivalent. + +```php +$parser = new Less_Parser(); +$parser->parseFile( '/var/www/mysite/bootstrap.less', 'https://example.org/mysite/' ); +$css = $parser->getCss(); +``` + +#### Handle invalid syntax + +An exception will be thrown if the compiler encounters invalid LESS. + +```php +try{ + $parser = new Less_Parser(); + $parser->parseFile( '/var/www/mysite/bootstrap.less', 'https://example.org/mysite/' ); + $css = $parser->getCss(); +} catch (Exception $e) { + echo $e->getMessage(); +} +``` + +#### Parse multiple inputs + +Less.php can parse multiple input sources (e.g. files and/or strings) and generate a single CSS output. + +```php +$parser = new Less_Parser(); +$parser->parseFile( '/var/www/mysite/bootstrap.less', '/mysite/' ); +$parser->parse( '@color: #36c; .link { color: @color; } a { color: @color; }' ); +$css = $parser->getCss(); +``` + +#### Metadata + +Less.php keeps track of which `.less` files have been parsed, i.e. the input +file(s) and any direct and indirect imports. + +```php +$parser = new Less_Parser(); +$parser->parseFile( '/var/www/mysite/bootstrap.less', '/mysite/' ); +$css = $parser->getCss(); +$files = $parser->AllParsedFiles(); +``` + +#### Compress output + +You can tell Less.php to remove comments and whitespace to generate minified CSS. + +```php +$options = [ 'compress' => true ]; +$parser = new Less_Parser( $options ); +$parser->parseFile( '/var/www/mysite/bootstrap.less', '/mysite/' ); +$css = $parser->getCss(); +``` + +#### Get variables + +You can use the `getVariables()` method to get an all variables defined and +their value in an associative array. Note that the input must be compiled first +by calling `getCss()`. + +```php +$parser = new Less_Parser; +$parser->parseFile( '/var/www/mysite/bootstrap.less'); +$css = $parser->getCss(); +$variables = $parser->getVariables(); + +``` + +#### Set variables + +Use the `ModifyVars()` method to inject additional variables, i.e. custom values +computed or accessed from your PHP code. + +```php +$parser = new Less_Parser(); +$parser->parseFile( '/var/www/mysite/bootstrap.less', '/mysite/' ); +$parser->ModifyVars( [ 'font-size-base' => '16px' ] ); +$css = $parser->getCss(); +``` + +#### Import directories + +By default, Less.php will look for imported files in the directory of the file passed to `parseFile()`. + +If you use `parse()`, or if need to enable additional import directories, you can specify these by +calling `SetImportDirs()`. + +```php +$directories = [ '/var/www/mysite/bootstrap/' => '/mysite/bootstrap/' ]; +$parser = new Less_Parser(); +$parser->SetImportDirs( $directories ); +$parser->parseFile( '/var/www/mysite/theme.less', '/mysite/' ); +$css = $parser->getCss(); +``` + +## Caching + +Compiling LESS code into CSS can be a time-consuming process. It is recommended to cache your results. + +#### Basic cache + +Use the `Less_Cache` class to save and reuse the results of compiling LESS files. +This class will check the modified time and size of each LESS file (including imported files) and +either re-use or re-generate the CSS output accordingly. + +The cache files are determinstically named, based on the full list of referenced LESS files and the metadata (file path, file mtime, file size) of each file. This means that each time a change is made, a different cache filename is used. + +```php +$lessFiles = [ '/var/www/mysite/bootstrap.less' => '/mysite/' ]; +$options = [ 'cache_dir' => '/var/www/writable_folder' ]; +$cssOutputFile = Less_Cache::Get( $lessFiles, $options ); +$css = file_get_contents( '/var/www/writable_folder/' . $cssOutputFile ); +``` + +#### Caching with variables + +Passing custom variables to `Less_Cache::Get()`: + +```php +$lessFiles = [ '/var/www/mysite/bootstrap.less' => '/mysite/' ]; +$options = [ 'cache_dir' => '/var/www/writable_folder' ]; +$variables = [ 'width' => '100px' ]; +$cssOutputFile = Less_Cache::Get( $lessFiles, $options, $variables ); +$css = file_get_contents( '/var/www/writable_folder/' . $cssOutputFile ); +``` + +#### Incremental caching + +In addition to the whole-output caching described above, Less.php also has the ability to keep an internal cache which allows re-parses to be faster by effectively only re-compiling portions that have changed. + +## Source maps + +Less.php supports v3 sourcemaps. + +#### Inline + +The sourcemap will be appended to the generated CSS file. + +```php +$options = [ 'sourceMap' => true ]; +$parser = new Less_Parser($options); +$parser->parseFile( '/var/www/mysite/bootstrap.less', '/mysite/' ); +$css = $parser->getCss(); +``` + +#### Saving to map file + +```php +$options = [ + 'sourceMap' => true, + 'sourceMapWriteTo' => '/var/www/mysite/writable_folder/filename.map', + 'sourceMapURL' => '/mysite/writable_folder/filename.map', +]; +$parser = new Less_Parser($options); +$parser->parseFile( '/var/www/mysite/bootstrap.less', '/mysite/' ); +$css = $parser->getCss(); +``` + +## Command line + +An additional script has been included to use the Less.php compiler from the command line. +In its simplest invocation, you specify an input file and the compiled CSS is written to standard out: + +``` +$ lessc input.less > output.css +``` + +By using the `-w` flag you can watch a specified input file and have it compile as needed to the output file: + +``` +$ lessc -w input.less output.css +``` + +Errors from watch mode are written to standard out. + +For more information, run `lessc --help` diff --git a/vendor/wikimedia/less.php/CHANGES.md b/vendor/wikimedia/less.php/CHANGES.md index 92f82f8..3334aeb 100644 --- a/vendor/wikimedia/less.php/CHANGES.md +++ b/vendor/wikimedia/less.php/CHANGES.md @@ -1,70 +1,91 @@ -# 3.1.0 -- [All Changes](https://github.com/wikimedia/less.php/compare/v3.0.0...v3.1.0) -* PHP 8.0 support: Drop use of curly braces for sub-string eval (James D. Forrester) +# Changelog + +## 3.2.1 + +* [All changes](https://gerrit.wikimedia.org/g/mediawiki/libs/less.php/+log/v3.2.1) +* Tree_Ruleset: Fix support for nested parent selectors (Timo Tijhof) [T204816](https://phabricator.wikimedia.org/T204816) +* Fix ParseError when interpolating variable after colon in selector (Timo Tijhof) [T327163](https://phabricator.wikimedia.org/T327163) +* Functions: Fix "Undefined property" warning on bad minmax arg +* Tree_Call: Include previous exception when catching functions (Robert Frunzke) + +## 3.2.0 + +* [All changes](https://github.com/wikimedia/less.php/compare/v3.1.0...v3.2.0) +* Fix "Implicit conversion" PHP 8.1 warnings (Ayokunle Odusan) +* Fix "Creation of dynamic property" PHP 8.2 warnings (Bas Couwenberg) +* Fix "Creation of dynamic property" PHP 8.2 warnings (Rajesh Kumar) +* Tree_Url: Add support for "Url" type to `Parser::getVariables()` (ciroarcadio) [#51](https://github.com/wikimedia/less.php/pull/51) +* Tree_Import: Add support for importing URLs without file extension (Timo Tijhof) [#27](https://github.com/wikimedia/less.php/issues/27) + +## 3.1.0 + +* [All changes](https://github.com/wikimedia/less.php/compare/v3.0.0...v3.1.0) +* Add PHP 8.0 support: Drop use of curly braces for sub-string eval (James D. Forrester) * Make `Directive::__construct` $rules arg optional (fix PHP 7.4 warning) (Sam Reed) * ProcessExtends: Improve performance by using a map for selectors and parents (Andrey Legayev) -* build: Run CI tests on PHP 8.0 too (James D. Forrester) -* code: Fix PSR12.Properties.ConstantVisibility.NotFound (Sam Reed) -# 3.0.0 -- [All Changes](https://github.com/wikimedia/less.php/compare/v2.0.0...v3.0.0) -- Raise PHP requirement from 7.1 to 7.2.9 (James Forrester) -- build: Upgrade phpunit to ^8.5 and make pass (James Forrester) -- build: Install php-parallel-lint (James Forrester) -- build: Install minus-x and make pass (James Forrester) +## 3.0.0 -# 2.0.0 -- [All Changes](https://github.com/wikimedia/less.php/compare/1.8.2...v2.0.0) -- Relax PHP requirement down to 7.1, from 7.2.9 (Franz Liedke) -- Reflect recent breaking changes properly with the semantic versioning (James Forrester) +* [All changes](https://github.com/wikimedia/less.php/compare/v2.0.0...v3.0.0) +* Raise PHP requirement from 7.1 to 7.2.9 (James Forrester) -# 1.8.2 -- [All Changes](https://github.com/wikimedia/less.php/compare/1.8.1...1.8.2) -- Require PHP 7.2.9+, up from 5.3+ (James Forrester) -- Release: Update Version.php with the current release ID (COBadger) -- Fix access array offset on value of type null (Michele Locati) -- Fixed test suite on PHP 7.4 (Sergei Morozov) -- docs: Fix 1.8.1 "All changes" link (Timo Tijhof) +## 2.0.0 -# 1.8.1 -- [All Changes](https://github.com/wikimedia/less.php/compare/v1.8.0...1.8.1) -- Another PHP 7.3 compatibility tweak +* [All changes](https://github.com/wikimedia/less.php/compare/v1.8.2...v2.0.0) +* Relax PHP requirement down to 7.1, from 7.2.9 (Franz Liedke) +* Reflect recent breaking changes properly with the semantic versioning (James Forrester) -# 1.8.0 -- [All Changes](https://github.com/Asenar/less.php/compare/v1.7.0.13...v1.8.0) -- Wikimedia fork -- Supports up to PHP 7.3 -- No longer tested against PHP 5, though it's still remains allowed in `composer.json` for HHVM compatibility -- Switched to [semantic versioning](https://semver.org/), hence version numbers now use 3 digits +## 1.8.2 -# 1.7.0.13 - - [All Changes](https://github.com/Asenar/less.php/compare/v1.7.0.12...v1.7.0.13) - - Fix composer.json (PSR-4 was invalid) +* [All changes](https://github.com/wikimedia/less.php/compare/v1.8.1...v1.8.2) +* Require PHP 7.2.9+, up from 5.3+ (James Forrester) +* release: Update Version.php with the current release ID (COBadger) +* Fix access array offset on value of type null (Michele Locati) +* Fix test suite on PHP 7.4 (Sergei Morozov) -# 1.7.0.12 - - [All Changes](https://github.com/Asenar/less.php/compare/v1.7.0.11...v1.7.0.12) - - set bin/lessc bit executable - - Add 'gettingVariables' method in Less_Parser +## 1.8.1 -# 1.7.0.11 - - [All Changes](https://github.com/Asenar/less.php/compare/v1.7.0.10...v1.7.0.11) - - Fix realpath issue (windows) - - Set Less_Tree_Call property back to public ( Fix 258 266 267 issues from oyejorge/less.php) +* [All changes](https://github.com/wikimedia/less.php/compare/v1.8.0...v1.8.1) +* Another PHP 7.3 compatibility tweak -# 1.7.0.10 +## 1.8.0 - - [All Changes](https://github.com/oyejorge/less.php/compare/v1.7.0.9...v1.7.10) - - Add indentation option - - Add 'optional' modifier for @import - - fix $color in Exception messages - - don't use set_time_limit when running cli - - take relative-url into account when building the cache filename - - urlArgs should be string no array() - - add bug-report fixtures [#6dc898f](https://github.com/oyejorge/less.php/commit/6dc898f5d75b447464906bdf19d79c2e19d95e33) - - fix #269, missing on NameValue type [#a8dac63](https://github.com/oyejorge/less.php/commit/a8dac63d93fb941c54fb78b12588abf635747c1b) +Library forked by Wikimedia, from [oyejorge/less.php](https://github.com/oyejorge/less.php). -# 1.7.0.9 +* [All changes](https://github.com/wikimedia/less.php/compare/v1.7.0.13...v1.8.0) +* Supports up to PHP 7.3 +* No longer tested against PHP 5, though it's still remains allowed in `composer.json` for HHVM compatibility +* Switched to [semantic versioning](https://semver.org/), hence version numbers now use 3 digits - - [All Changes](https://github.com/oyejorge/less.php/compare/v1.7.0.8...v1.7.0.9) - - Remove space at beginning of Version.php - - Revert require() paths in test interface +## 1.7.0.13 + +* [All changes](https://github.com/wikimedia/less.php/compare/v1.7.0.12...v1.7.0.13) +* Fix composer.json (PSR-4 was invalid) + +## 1.7.0.12 + +* [All changes](https://github.com/wikimedia/less.php/compare/v1.7.0.11...v1.7.0.12) +* set bin/lessc bit executable +* Add `gettingVariables` method to `Less_Parser` + +## 1.7.0.11 + +* [All changes](https://github.com/wikimedia/less.php/compare/v1.7.0.10...v1.7.0.11) +* Fix realpath issue (windows) +* Set Less_Tree_Call property back to public ( Fix 258 266 267 issues from oyejorge/less.php) + +## 1.7.0.10 + +* [All changes](https://github.com/wikimedia/less.php/compare/v1.7.0.9...v1.7.10) +* Add indentation option +* Add `optional` modifier for `@import` +* Fix $color in Exception messages +* take relative-url into account when building the cache filename +* urlArgs should be string no array() +* fix missing on NameValue type [#269](https://github.com/oyejorge/less.php/issues/269) + +## 1.7.0.9 + +* [All changes](https://github.com/wikimedia/less.php/compare/v1.7.0.8...v1.7.0.9) +* Remove space at beginning of Version.php +* Revert require() paths in test interface diff --git a/vendor/wikimedia/less.php/CODE_OF_CONDUCT.md b/vendor/wikimedia/less.php/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..498acf7 --- /dev/null +++ b/vendor/wikimedia/less.php/CODE_OF_CONDUCT.md @@ -0,0 +1 @@ +The development of this software is covered by a [Code of Conduct](https://www.mediawiki.org/wiki/Special:MyLanguage/Code_of_Conduct). diff --git a/vendor/wikimedia/less.php/LICENSE b/vendor/wikimedia/less.php/LICENSE index 82216a5..d645695 100644 --- a/vendor/wikimedia/less.php/LICENSE +++ b/vendor/wikimedia/less.php/LICENSE @@ -1,178 +1,202 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION -1. Definitions. + 1. Definitions. - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. -2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. -3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. -4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. -5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. -6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. -7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. -8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. -9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. -END OF TERMS AND CONDITIONS + END OF TERMS AND CONDITIONS + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/vendor/wikimedia/less.php/NOTICE.txt b/vendor/wikimedia/less.php/NOTICE.txt new file mode 100644 index 0000000..099293c --- /dev/null +++ b/vendor/wikimedia/less.php/NOTICE.txt @@ -0,0 +1,18 @@ +wikimedia/less.php. https://gerrit.wikimedia.org/g/mediawiki/libs/less.php + +Copyright Matt Agar +Copyright Martin Jantošovič +Copyright Josh Schmidt +Copyright Timo Tijhof + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/vendor/wikimedia/less.php/README.md b/vendor/wikimedia/less.php/README.md index d10177c..a89ea6c 100644 --- a/vendor/wikimedia/less.php/README.md +++ b/vendor/wikimedia/less.php/README.md @@ -1,315 +1,77 @@ -[![Continuous Integration](https://github.com/wikimedia/less.php/workflows/PHP%20Test/badge.svg)](https://github.com/wikimedia/less.php/actions) +[![Packagist](https://img.shields.io/packagist/v/wikimedia/less.php.svg?style=flat)](https://packagist.org/packages/wikimedia/less.php) -[Less.php](http://lessphp.typesettercms.com) +Less.php ======== -This is the Wikimedia fork of a PHP port of the official LESS processor . +This is a PHP port of the [official LESS processor](https://lesscss.org). -* [About](#about) -* [Installation](#installation) -* [Basic Use](#basic-use) -* [Caching](#caching) -* [Source Maps](#source-maps) -* [Command Line](#command-line) -* [Integration with other projects](#integration-with-other-projects) -* [Transitioning from Leafo/lessphp](#transitioning-from-leafolessphp) -* [Credits](#credits) +## About +The code structure of Less.php mirrors that of upstream Less.js to ensure compatibility and help reduce maintenance. The port is currently compatible with Less.js 2.5.3. Please note that "inline JavaScript expressions" (via eval or backticks) are not supported. +* [API § Caching](./API.md#caching), Less.php includes a file-based cache. +* [API § Source maps](./API.md#source-maps), Less.php supports v3 sourcemaps. +* [API § Command line](./API.md#command-line), the `lessc` command includes a watch mode. -About ---- -The code structure of less.php mirrors that of the official processor which helps us ensure compatibility and allows for easy maintenance. +## Installation -Please note, there are a few unsupported LESS features: +You can install the library with Composer or standalone. -- Evaluation of JavaScript expressions within back-ticks (for obvious reasons). -- Definition of custom functions. +If you have [Composer](https://getcomposer.org/download/) installed: +1. Run `composer require wikimedia/less.php` +2. Use `Less_Parser` in your code. -Installation ---- +Or standalone: -You can install the library with Composer or manually. +1. [Download Less.php](https://gerrit.wikimedia.org/g/mediawiki/libs/less.php/+archive/HEAD.tar.gz) and upload the PHP files to your server. +2. Include the library: + ```php + require_once '[path to]/less.php/lib/Less/Autoloader.php'; + Less_Autoloader::register(); + ``` +3. Use `Less_Parser` in your code. -#### Composer +## Security -1. [Install Composer](https://getcomposer.org/download/) -2. Run `composer require wikimedia/less.php` +The LESS processor language is powerful and includes features that may read or embed arbitrary files that the web server has access to, and features that may be computationally exensive if misused. -#### Manually From Release +In general you should treat LESS files as being in the same trust domain as other server-side executables, such as PHP code. In particular, it is not recommended to allow people that use your web service to provide arbitrary LESS code for server-side processing. -Step 1. [Download a release](https://github.com/wikimedia/less.php/releases) and upload the PHP files to your server. +_See also [SECURITY](./SECURITY.md)._ -Step 2. Include the library: +## Who uses Less.php? -```php -require_once '[path to less.php]/lib/Less/Autoloader.php'; -Less_Autoloader::register(); -``` +* **[Wikipedia](https://en.wikipedia.org/wiki/MediaWiki)** and the MediaWiki platform ([docs](https://www.mediawiki.org/wiki/ResourceLoader/Architecture#Resource:_Styles)). +* **[Matomo](https://en.wikipedia.org/wiki/Matomo_(software))** ([docs](https://devdocs.magento.com/guides/v2.4/frontend-dev-guide/css-topics/custom_preprocess.html)). +* **[Magento](https://en.wikipedia.org/wiki/Magento)** as part of Adobe Commerce ([docs](https://developer.matomo.org/guides/asset-pipeline#vanilla-javascript-css-and-less-files)). +* **[Icinga](https://en.wikipedia.org/wiki/Icinga)** in Icinga Web ([docs](https://github.com/Icinga/icingaweb2)). +* **[Shopware](https://de.wikipedia.org/wiki/Shopware)** ([docs](https://developers.shopware.com/designers-guide/less/)). -Basic Use ---- +## Integrations -#### Parsing Strings +Less.php has been integrated with various other projects. -```php -$parser = new Less_Parser(); -$parser->parse( '@color: #4D926F; #header { color: @color; } h2 { color: @color; }' ); -$css = $parser->getCss(); -``` +#### Transitioning from Leafo/lessphp +If you're looking to transition from the [Leafo/lessphp](https://github.com/leafo/lessphp) library, use the `lessc.inc.php` adapter file that comes with Less.php. -#### Parsing LESS Files -The parseFile() function takes two arguments: +This allows Less.php to be a drop-in replacement for Leafo/lessphp. -1. The absolute path of the .less file to be parsed -2. The url root to prepend to any relative image or @import urls in the .less file. +[Download Less.php](https://gerrit.wikimedia.org/g/mediawiki/libs/less.php/+archive/HEAD.tar.gz), unzip the files into your project, and include its `lessc.inc.php` instead. -```php -$parser = new Less_Parser(); -$parser->parseFile( '/var/www/mysite/bootstrap.less', 'http://example.com/mysite/' ); -$css = $parser->getCss(); -``` +Note: The `setPreserveComments` option is ignored. Less.php already preserves CSS block comments by default, and removes LESS inline comments. +#### Drupal -#### Handling Invalid LESS -An exception will be thrown if the compiler encounters invalid LESS. - -```php -try{ - $parser = new Less_Parser(); - $parser->parseFile( '/var/www/mysite/bootstrap.less', 'http://example.com/mysite/' ); - $css = $parser->getCss(); -}catch(Exception $e){ - $error_message = $e->getMessage(); -} -``` - - -#### Parsing Multiple Sources -less.php can parse multiple sources to generate a single CSS file. - -```php -$parser = new Less_Parser(); -$parser->parseFile( '/var/www/mysite/bootstrap.less', '/mysite/' ); -$parser->parse( '@color: #4D926F; #header { color: @color; } h2 { color: @color; }' ); -$css = $parser->getCss(); -``` - -#### Getting Info About The Parsed Files -less.php can tell you which .less files were imported and parsed. - -```php -$parser = new Less_Parser(); -$parser->parseFile( '/var/www/mysite/bootstrap.less', '/mysite/' ); -$css = $parser->getCss(); -$imported_files = $parser->allParsedFiles(); -``` - - -#### Compressing Output -You can tell less.php to remove comments and whitespace to generate minimized CSS files. - -```php -$options = array( 'compress'=>true ); -$parser = new Less_Parser( $options ); -$parser->parseFile( '/var/www/mysite/bootstrap.less', '/mysite/' ); -$css = $parser->getCss(); -``` - -#### Getting Variables -You can use the getVariables() method to get an all variables defined and -their value in a php associative array. Note that LESS has to be previously -compiled. -```php -$parser = new Less_Parser; -$parser->parseFile( '/var/www/mysite/bootstrap.less'); -$css = $parser->getCss(); -$variables = $parser->getVariables(); - -``` - - - -#### Setting Variables -You can use the ModifyVars() method to customize your CSS if you have variables stored in PHP associative arrays. - -```php -$parser = new Less_Parser(); -$parser->parseFile( '/var/www/mysite/bootstrap.less', '/mysite/' ); -$parser->ModifyVars( array('font-size-base'=>'16px') ); -$css = $parser->getCss(); -``` - - -#### Import Directories -By default, less.php will look for @imports in the directory of the file passed to parseFile(). -If you're using parse() or if @imports reside in different directories, you can tell less.php where to look. - -```php -$directories = array( '/var/www/mysite/bootstrap/' => '/mysite/bootstrap/' ); -$parser = new Less_Parser(); -$parser->SetImportDirs( $directories ); -$parser->parseFile( '/var/www/mysite/theme.less', '/mysite/' ); -$css = $parser->getCss(); -``` - - -Caching ---- -Compiling LESS code into CSS is a time consuming process, caching your results is highly recommended. - - -#### Caching CSS -Use the Less_Cache class to save and reuse the results of compiled LESS files. -This method will check the modified time and size of each LESS file (including imported files) and regenerate a new CSS file when changes are found. -Note: When changes are found, this method will return a different file name for the new cached content. - -```php -$less_files = array( '/var/www/mysite/bootstrap.less' => '/mysite/' ); -$options = array( 'cache_dir' => '/var/www/writable_folder' ); -$css_file_name = Less_Cache::Get( $less_files, $options ); -$compiled = file_get_contents( '/var/www/writable_folder/'.$css_file_name ); -``` - -#### Caching CSS With Variables -Passing options to Less_Cache::Get() - -```php -$less_files = array( '/var/www/mysite/bootstrap.less' => '/mysite/' ); -$options = array( 'cache_dir' => '/var/www/writable_folder' ); -$variables = array( 'width' => '100px' ); -$css_file_name = Less_Cache::Get( $less_files, $options, $variables ); -$compiled = file_get_contents( '/var/www/writable_folder/'.$css_file_name ); -``` - - -#### Parser Caching -less.php will save serialized parser data for each .less file if a writable folder is passed to the SetCacheDir() method. -Note: This feature only caches intermediate parsing results to improve the performance of repeated CSS generation. -Your application should cache any CSS generated by less.php. - -```php -$options = array('cache_dir'=>'/var/www/writable_folder'); -$parser = new Less_Parser( $options ); -$parser->parseFile( '/var/www/mysite/bootstrap.less', '/mysite/' ); -$css = $parser->getCss(); -``` - -You can specify the caching technique used by changing the ```cache_method``` option. Supported methods are: -* ```php```: Creates valid PHP files which can be included without any changes (default method). -* ```var_export```: Like "php", but using PHP's ```var_export()``` function without any optimizations. - It's recommended to use "php" instead. -* ```serialize```: Faster, but pretty memory-intense. -* ```callback```: Use custom callback functions to implement your own caching method. Give the "cache_callback_get" and - "cache_callback_set" options with callables (see PHP's ```call_user_func()``` and ```is_callable()``` functions). less.php - will pass the parser object (class ```Less_Parser```), the path to the parsed .less file ("/some/path/to/file.less") and - an identifier that will change every time the .less file is modified. The ```get``` callback must return the ruleset - (an array with ```Less_Tree``` objects) provided as fourth parameter of the ```set``` callback. If something goes wrong, - return ```NULL``` (cache doesn't exist) or ```FALSE```. - - - -Source Maps ---- -Less.php supports v3 sourcemaps - -#### Inline -The sourcemap will be appended to the generated CSS file. - -```php -$options = array( 'sourceMap' => true ); -$parser = new Less_Parser($options); -$parser->parseFile( '/var/www/mysite/bootstrap.less', '/mysite/' ); -$css = $parser->getCss(); -``` - -#### Saving to Map File - -```php -$options = array( - 'sourceMap' => true, - 'sourceMapWriteTo' => '/var/www/mysite/writable_folder/filename.map', - 'sourceMapURL' => '/mysite/writable_folder/filename.map', - ); -$parser = new Less_Parser($options); -$parser->parseFile( '/var/www/mysite/bootstrap.less', '/mysite/' ); -$css = $parser->getCss(); -``` - - -Command line ---- -An additional script has been included to use the compiler from the command line. -In the simplest invocation, you specify an input file and the compiled CSS is written to standard out: - -``` -$ lessc input.less > output.css -``` - -By using the -w flag you can watch a specified input file and have it compile as needed to the output file: - -``` -$ lessc -w input.less output.css -``` - -Errors from watch mode are written to standard out. - -For more help, run `lessc --help` - - -Integration with other projects ---- - -#### Drupal 7 - -This library can be used as drop-in replacement of lessphp to work with [Drupal 7 less module](https://drupal.org/project/less). - -How to install: - -1. [Download the less.php source code](https://github.com/wikimedia/less.php/archive/master.zip) and unzip it so that 'lessc.inc.php' is located at 'sites/all/libraries/lessphp/lessc.inc.php'. -2. Download and install [Drupal 7 less module](https://drupal.org/project/less) as usual. -3. That's it :) - -#### JBST WordPress theme - -JBST has a built-in LESS compiler based on lessphp. Customize your WordPress theme with LESS. - -How to use / install: - -1. [Download the latest release](https://github.com/bassjobsen/jamedo-bootstrap-start-theme) copy the files to your {wordpress/}wp-content/themes folder and activate it. -2. Find the compiler under Appearance > LESS Compiler in your WordPress dashboard -3. Enter your LESS code in the text area and press (re)compile - -Use the built-in compiler to: -- set any [Bootstrap](http://getbootstrap.com/customize/) variable or use Bootstrap's mixins: - -`@navbar-default-color: blue;` - - create a custom button: `.btn-custom { - .button-variant(white; red; blue); -}` -- set any built-in LESS variable: for example `@footer_bg_color: black;` sets the background color of the footer to black -- use built-in mixins: - add a custom font: `.include-custom-font(@family: arial,@font-path, @path: @custom-font-dir, @weight: normal, @style: normal);` - -The compiler can also be downloaded as [plugin](http://wordpress.org/plugins/wp-less-to-css/) +Less.php can be used with [Drupal's less module](https://drupal.org/project/less) via the `lessc.inc.php` adapter. [Download Less.php](https://gerrit.wikimedia.org/g/mediawiki/libs/less.php/+archive/HEAD.tar.gz) and unzip it so that `lessc.inc.php` is located at `sites/all/libraries/lessphp/lessc.inc.php`, then install the Drupal less module as usual. #### WordPress -This simple plugin will simply make the library available to other plugins and themes and can be used as a dependency using the [TGM Library](http://tgmpluginactivation.com/) +* [wp_enqueue_less](https://github.com/Ed-ITSolutions/wp_enqueue_less) is a Composer package for use in WordPress themes and plugins. It provides a `wp_enqueue_less()` function to automatically manage caching and compilation on-demand, and loads the compressed CSS on the page. +* [JBST framework](https://github.com/bassjobsen/jamedo-bootstrap-start-theme) bundles a copy of Less.php. +* The [lessphp plugin](https://wordpress.org/plugins/lessphp/) bundles a copy of Less.php for use in other plugins or themes. This dependency can also be combined with the [TGM Library](http://tgmpluginactivation.com/). -How to install: - -1. Install the plugin from your WordPress Dashboard: http://wordpress.org/plugins/lessphp/ -2. That's it :) - - -Transitioning from Leafo/lessphp ---- -Projects looking for an easy transition from leafo/lessphp can use the lessc.inc.php adapter. To use, [Download the less.php source code](https://github.com/wikimedia/less.php/archive/master.zip) and unzip the files into your project so that the new 'lessc.inc.php' replaces the existing 'lessc.inc.php'. - -Note, the 'setPreserveComments' will no longer have any effect on the compiled LESS. - -Credits ---- -less.php was originally ported to PHP by [Matt Agar](https://github.com/agar) and then updated by [Martin Jantošovič](https://github.com/Mordred). This Wikimedia-maintained fork was split off from [Josh Schmidt's version](https://github.com/oyejorge/less.php). +## Credits +Less.php was originally ported to PHP in 2011 by [Matt Agar](https://github.com/agar) and then updated by [Martin Jantošovič](https://github.com/Mordred) in 2012. From 2013 to 2017, [Josh Schmidt](https://github.com/oyejorge) lead development of the library. Since 2019, the library is maintained by Wikimedia Foundation. diff --git a/vendor/wikimedia/less.php/SECURITY.md b/vendor/wikimedia/less.php/SECURITY.md new file mode 100644 index 0000000..687c735 --- /dev/null +++ b/vendor/wikimedia/less.php/SECURITY.md @@ -0,0 +1,5 @@ +# Security policy + +Wikimedia takes security seriously. If you believe you have found a +security issue, see +for information on how to responsibly report it. diff --git a/vendor/wikimedia/less.php/bin/lessc b/vendor/wikimedia/less.php/bin/lessc index fa1fb95..7e3d128 100644 --- a/vendor/wikimedia/less.php/bin/lessc +++ b/vendor/wikimedia/less.php/bin/lessc @@ -1,7 +1,7 @@ #!/usr/bin/env php =7.2.9" - }, - "require-dev": { - "mediawiki/mediawiki-codesniffer": "34.0.0", - "mediawiki/minus-x": "1.0.0", - "php-parallel-lint/php-console-highlighter": "0.5.0", - "php-parallel-lint/php-parallel-lint": "1.2.0", - "phpunit/phpunit": "^8.5" - }, - "scripts": { - "test": [ - "parallel-lint . --exclude vendor", - "phpcs -sp", - "phpunit", - "minus-x check ." - ], - "fix": [ - "minus-x fix .", - "phpcbf" - ] - }, - "autoload": { - "psr-0": { "Less": "lib/" }, - "classmap": ["lessc.inc.php"] - }, - "bin": [ - "bin/lessc" - ] -} diff --git a/vendor/wikimedia/less.php/lessc.inc.php b/vendor/wikimedia/less.php/lessc.inc.php index 284445f..a3c66dd 100644 --- a/vendor/wikimedia/less.php/lessc.inc.php +++ b/vendor/wikimedia/less.php/lessc.inc.php @@ -14,14 +14,14 @@ if ( !class_exists( 'Less_Parser' ) ) { class lessc { - static public $VERSION = Less_Version::less_version; + public static $VERSION = Less_Version::less_version; public $importDir = ''; - protected $allParsedFiles = array(); - protected $libFunctions = array(); - protected $registeredVars = array(); + protected $allParsedFiles = []; + protected $libFunctions = []; + protected $registeredVars = []; private $formatterName; - private $options = array(); + private $options = []; public function __construct( $lessc = null, $sourceName = null ) { } @@ -74,7 +74,7 @@ class lessc { $this->options[$name] = $value; } - public function parse( $buffer, $presets = array() ) { + public function parse( $buffer, $presets = [] ) { $this->setVariables( $presets ); $parser = new Less_Parser( $this->getOptions() ); @@ -91,7 +91,7 @@ class lessc { } protected function getOptions() { - $options = array( 'relativeUrls' => false ); + $options = [ 'relativeUrls' => false ]; switch ( $this->formatterName ) { case 'compressed': $options['compress'] = true; @@ -105,7 +105,7 @@ class lessc { protected function getImportDirs() { $dirs_ = (array)$this->importDir; - $dirs = array(); + $dirs = []; foreach ( $dirs_ as $dir ) { $dirs[$dir] = ''; } @@ -116,7 +116,7 @@ class lessc { $oldImport = $this->importDir; $this->importDir = (array)$this->importDir; - $this->allParsedFiles = array(); + $this->allParsedFiles = []; $parser = new Less_Parser( $this->getOptions() ); $parser->SetImportDirs( $this->getImportDirs() ); @@ -141,7 +141,7 @@ class lessc { public function compileFile( $fname, $outFname = null ) { if ( !is_readable( $fname ) ) { - throw new Exception( 'load error: failed to find '.$fname ); + throw new Exception( 'load error: failed to find ' . $fname ); } $pi = pathinfo( $fname ); @@ -149,9 +149,9 @@ class lessc { $oldImport = $this->importDir; $this->importDir = (array)$this->importDir; - $this->importDir[] = Less_Parser::AbsPath( $pi['dirname'] ).'/'; + $this->importDir[] = Less_Parser::AbsPath( $pi['dirname'] ) . '/'; - $this->allParsedFiles = array(); + $this->allParsedFiles = []; $this->addParsedFile( $fname ); $parser = new Less_Parser( $this->getOptions() ); @@ -237,7 +237,7 @@ class lessc { if ( $root !== null ) { // If we have a root value which means we should rebuild. - $out = array(); + $out = []; $out['root'] = $root; $out['compiled'] = $this->compileFile( $root ); $out['files'] = $this->allParsedFiles(); diff --git a/vendor/wikimedia/less.php/lib/Less/Autoloader.php b/vendor/wikimedia/less.php/lib/Less/Autoloader.php index 00116f7..a4f7a4a 100644 --- a/vendor/wikimedia/less.php/lib/Less/Autoloader.php +++ b/vendor/wikimedia/less.php/lib/Less/Autoloader.php @@ -2,28 +2,14 @@ /** * Autoloader - * - * @package Less - * @subpackage autoload */ class Less_Autoloader { - /** - * Registered flag - * - * @var boolean - */ + /** @var bool */ protected static $registered = false; /** - * Library directory - * - * @var string - */ - protected static $libDir; - - /** - * Register the autoloader in the spl autoloader + * Register the autoloader in the SPL autoloader * * @return void * @throws Exception If there was an error in registration @@ -33,9 +19,7 @@ class Less_Autoloader { return; } - self::$libDir = dirname( __FILE__ ); - - if ( false === spl_autoload_register( array( 'Less_Autoloader', 'loadClass' ) ) ) { + if ( !spl_autoload_register( [ 'Less_Autoloader', 'loadClass' ] ) ) { throw new Exception( 'Unable to register Less_Autoloader::loadClass as an autoloading method.' ); } @@ -43,17 +27,17 @@ class Less_Autoloader { } /** - * Unregisters the autoloader + * Unregister the autoloader * * @return void */ public static function unregister() { - spl_autoload_unregister( array( 'Less_Autoloader', 'loadClass' ) ); + spl_autoload_unregister( [ 'Less_Autoloader', 'loadClass' ] ); self::$registered = false; } /** - * Loads the class + * Load the class * * @param string $className The class to load */ @@ -64,14 +48,10 @@ class Less_Autoloader { } $className = substr( $className, 5 ); - $fileName = self::$libDir . DIRECTORY_SEPARATOR . str_replace( '_', DIRECTORY_SEPARATOR, $className ) . '.php'; + $fileName = __DIR__ . DIRECTORY_SEPARATOR . str_replace( '_', DIRECTORY_SEPARATOR, $className ) . '.php'; - if ( file_exists( $fileName ) ) { - require $fileName; - return true; - } else { - throw new Exception( 'file not loadable '.$fileName ); - } + require $fileName; + return true; } } diff --git a/vendor/wikimedia/less.php/lib/Less/Cache.php b/vendor/wikimedia/less.php/lib/Less/Cache.php index 7b6df23..c8c4b44 100644 --- a/vendor/wikimedia/less.php/lib/Less/Cache.php +++ b/vendor/wikimedia/less.php/lib/Less/Cache.php @@ -1,27 +1,21 @@ '/' ); + $less_files += [ $vars_file => '/' ]; } // generate name for compiled css file $hash = md5( json_encode( $less_files ) ); - $list_file = Less_Cache::$cache_dir . Less_Cache::$prefix . $hash . '.list'; + $list_file = self::$cache_dir . self::$prefix . $hash . '.list'; // check cached content if ( !isset( $parser_options['use_cache'] ) || $parser_options['use_cache'] === true ) { @@ -129,19 +123,13 @@ class Less_Cache { * @param array $modify_vars Array of variables * @return string Name of the css file */ - public static function Regen( $less_files, $parser_options = array(), $modify_vars = array() ) { + public static function Regen( $less_files, $parser_options = [], $modify_vars = [] ) { $parser_options['use_cache'] = false; return self::Get( $less_files, $parser_options, $modify_vars ); } - public static function Cache( &$less_files, $parser_options = array() ) { - // get less.php if it exists - $file = dirname( __FILE__ ) . '/Less.php'; - if ( file_exists( $file ) && !class_exists( 'Less_Parser' ) ) { - require_once $file; - } - - $parser_options['cache_dir'] = Less_Cache::$cache_dir; + public static function Cache( &$less_files, $parser_options = [] ) { + $parser_options['cache_dir'] = self::$cache_dir; $parser = new Less_Parser( $parser_options ); // combine files @@ -172,54 +160,52 @@ class Less_Cache { return $parser_options['output']; } - return Less_Cache::$cache_dir.$parser_options['output']; + return self::$cache_dir . $parser_options['output']; } - return Less_Cache::$cache_dir.$compiled_name; + return self::$cache_dir . $compiled_name; } private static function CompiledName( $files, $extrahash ) { // save the file list - $temp = array( Less_Version::cache_version ); + $temp = [ Less_Version::cache_version ]; foreach ( $files as $file ) { - $temp[] = filemtime( $file )."\t".filesize( $file )."\t".$file; + $temp[] = filemtime( $file ) . "\t" . filesize( $file ) . "\t" . $file; } - return Less_Cache::$prefix.sha1( json_encode( $temp ).$extrahash ).'.css'; + return self::$prefix . sha1( json_encode( $temp ) . $extrahash ) . '.css'; } public static function SetCacheDir( $dir ) { - Less_Cache::$cache_dir = $dir; + self::$cache_dir = $dir; self::CheckCacheDir(); } public static function CheckCacheDir() { - Less_Cache::$cache_dir = str_replace( '\\', '/', Less_Cache::$cache_dir ); - Less_Cache::$cache_dir = rtrim( Less_Cache::$cache_dir, '/' ).'/'; + self::$cache_dir = str_replace( '\\', '/', self::$cache_dir ); + self::$cache_dir = rtrim( self::$cache_dir, '/' ) . '/'; - if ( !file_exists( Less_Cache::$cache_dir ) ) { - if ( !mkdir( Less_Cache::$cache_dir ) ) { - throw new Less_Exception_Parser( 'Less.php cache directory couldn\'t be created: '.Less_Cache::$cache_dir ); + if ( !file_exists( self::$cache_dir ) ) { + if ( !mkdir( self::$cache_dir ) ) { + throw new Less_Exception_Parser( 'Less.php cache directory couldn\'t be created: ' . self::$cache_dir ); } - } elseif ( !is_dir( Less_Cache::$cache_dir ) ) { - throw new Less_Exception_Parser( 'Less.php cache directory doesn\'t exist: '.Less_Cache::$cache_dir ); + } elseif ( !is_dir( self::$cache_dir ) ) { + throw new Less_Exception_Parser( 'Less.php cache directory doesn\'t exist: ' . self::$cache_dir ); - } elseif ( !is_writable( Less_Cache::$cache_dir ) ) { - throw new Less_Exception_Parser( 'Less.php cache directory isn\'t writable: '.Less_Cache::$cache_dir ); + } elseif ( !is_writable( self::$cache_dir ) ) { + throw new Less_Exception_Parser( 'Less.php cache directory isn\'t writable: ' . self::$cache_dir ); } - } /** * Delete unused less.php files - * */ public static function CleanCache() { static $clean = false; - if ( $clean || empty( Less_Cache::$cache_dir ) ) { + if ( $clean || empty( self::$cache_dir ) ) { return; } @@ -227,9 +213,9 @@ class Less_Cache { // only remove files with extensions created by less.php // css files removed based on the list files - $remove_types = array( 'lesscache' => 1,'list' => 1,'less' => 1,'map' => 1 ); + $remove_types = [ 'lesscache' => 1,'list' => 1,'less' => 1,'map' => 1 ]; - $files = scandir( Less_Cache::$cache_dir ); + $files = scandir( self::$cache_dir ); if ( !$files ) { return; } @@ -238,7 +224,7 @@ class Less_Cache { foreach ( $files as $file ) { // don't delete if the file wasn't created with less.php - if ( strpos( $file, Less_Cache::$prefix ) !== 0 ) { + if ( strpos( $file, self::$prefix ) !== 0 ) { continue; } @@ -249,7 +235,7 @@ class Less_Cache { continue; } - $full_path = Less_Cache::$cache_dir . $file; + $full_path = self::$cache_dir . $file; $mtime = filemtime( $full_path ); // don't delete if it's a relatively new file @@ -261,7 +247,7 @@ class Less_Cache { if ( $type === 'list' ) { self::ListFiles( $full_path, $list, $css_file_name ); if ( $css_file_name ) { - $css_file = Less_Cache::$cache_dir . $css_file_name; + $css_file = self::$cache_dir . $css_file_name; if ( file_exists( $css_file ) ) { unlink( $css_file ); } @@ -270,12 +256,10 @@ class Less_Cache { unlink( $full_path ); } - } /** * Get the list of less files and generated css file from a list file - * */ static function ListFiles( $list_file, &$list, &$css_file_name ) { $list = explode( "\n", file_get_contents( $list_file ) ); @@ -283,11 +267,10 @@ class Less_Cache { // pop the cached name that should match $compiled_name $css_file_name = array_pop( $list ); - if ( !preg_match( '/^' . Less_Cache::$prefix . '[a-f0-9]+\.css$/', $css_file_name ) ) { + if ( !preg_match( '/^' . self::$prefix . '[a-f0-9]+\.css$/', $css_file_name ) ) { $list[] = $css_file_name; $css_file_name = false; } - } } diff --git a/vendor/wikimedia/less.php/lib/Less/Colors.php b/vendor/wikimedia/less.php/lib/Less/Colors.php index 9be76cb..2f715c2 100644 --- a/vendor/wikimedia/less.php/lib/Less/Colors.php +++ b/vendor/wikimedia/less.php/lib/Less/Colors.php @@ -1,169 +1,176 @@ '#f0f8ff', - 'antiquewhite' => '#faebd7', - 'aqua' => '#00ffff', - 'aquamarine' => '#7fffd4', - 'azure' => '#f0ffff', - 'beige' => '#f5f5dc', - 'bisque' => '#ffe4c4', - 'black' => '#000000', - 'blanchedalmond' => '#ffebcd', - 'blue' => '#0000ff', - 'blueviolet' => '#8a2be2', - 'brown' => '#a52a2a', - 'burlywood' => '#deb887', - 'cadetblue' => '#5f9ea0', - 'chartreuse' => '#7fff00', - 'chocolate' => '#d2691e', - 'coral' => '#ff7f50', - 'cornflowerblue' => '#6495ed', - 'cornsilk' => '#fff8dc', - 'crimson' => '#dc143c', - 'cyan' => '#00ffff', - 'darkblue' => '#00008b', - 'darkcyan' => '#008b8b', - 'darkgoldenrod' => '#b8860b', - 'darkgray' => '#a9a9a9', - 'darkgrey' => '#a9a9a9', - 'darkgreen' => '#006400', - 'darkkhaki' => '#bdb76b', - 'darkmagenta' => '#8b008b', - 'darkolivegreen' => '#556b2f', - 'darkorange' => '#ff8c00', - 'darkorchid' => '#9932cc', - 'darkred' => '#8b0000', - 'darksalmon' => '#e9967a', - 'darkseagreen' => '#8fbc8f', - 'darkslateblue' => '#483d8b', - 'darkslategray' => '#2f4f4f', - 'darkslategrey' => '#2f4f4f', - 'darkturquoise' => '#00ced1', - 'darkviolet' => '#9400d3', - 'deeppink' => '#ff1493', - 'deepskyblue' => '#00bfff', - 'dimgray' => '#696969', - 'dimgrey' => '#696969', - 'dodgerblue' => '#1e90ff', - 'firebrick' => '#b22222', - 'floralwhite' => '#fffaf0', - 'forestgreen' => '#228b22', - 'fuchsia' => '#ff00ff', - 'gainsboro' => '#dcdcdc', - 'ghostwhite' => '#f8f8ff', - 'gold' => '#ffd700', - 'goldenrod' => '#daa520', - 'gray' => '#808080', - 'grey' => '#808080', - 'green' => '#008000', - 'greenyellow' => '#adff2f', - 'honeydew' => '#f0fff0', - 'hotpink' => '#ff69b4', - 'indianred' => '#cd5c5c', - 'indigo' => '#4b0082', - 'ivory' => '#fffff0', - 'khaki' => '#f0e68c', - 'lavender' => '#e6e6fa', - 'lavenderblush' => '#fff0f5', - 'lawngreen' => '#7cfc00', - 'lemonchiffon' => '#fffacd', - 'lightblue' => '#add8e6', - 'lightcoral' => '#f08080', - 'lightcyan' => '#e0ffff', - 'lightgoldenrodyellow' => '#fafad2', - 'lightgray' => '#d3d3d3', - 'lightgrey' => '#d3d3d3', - 'lightgreen' => '#90ee90', - 'lightpink' => '#ffb6c1', - 'lightsalmon' => '#ffa07a', - 'lightseagreen' => '#20b2aa', - 'lightskyblue' => '#87cefa', - 'lightslategray' => '#778899', - 'lightslategrey' => '#778899', - 'lightsteelblue' => '#b0c4de', - 'lightyellow' => '#ffffe0', - 'lime' => '#00ff00', - 'limegreen' => '#32cd32', - 'linen' => '#faf0e6', - 'magenta' => '#ff00ff', - 'maroon' => '#800000', - 'mediumaquamarine' => '#66cdaa', - 'mediumblue' => '#0000cd', - 'mediumorchid' => '#ba55d3', - 'mediumpurple' => '#9370d8', - 'mediumseagreen' => '#3cb371', - 'mediumslateblue' => '#7b68ee', - 'mediumspringgreen' => '#00fa9a', - 'mediumturquoise' => '#48d1cc', - 'mediumvioletred' => '#c71585', - 'midnightblue' => '#191970', - 'mintcream' => '#f5fffa', - 'mistyrose' => '#ffe4e1', - 'moccasin' => '#ffe4b5', - 'navajowhite' => '#ffdead', - 'navy' => '#000080', - 'oldlace' => '#fdf5e6', - 'olive' => '#808000', - 'olivedrab' => '#6b8e23', - 'orange' => '#ffa500', - 'orangered' => '#ff4500', - 'orchid' => '#da70d6', - 'palegoldenrod' => '#eee8aa', - 'palegreen' => '#98fb98', - 'paleturquoise' => '#afeeee', - 'palevioletred' => '#d87093', - 'papayawhip' => '#ffefd5', - 'peachpuff' => '#ffdab9', - 'peru' => '#cd853f', - 'pink' => '#ffc0cb', - 'plum' => '#dda0dd', - 'powderblue' => '#b0e0e6', - 'purple' => '#800080', - 'red' => '#ff0000', - 'rosybrown' => '#bc8f8f', - 'royalblue' => '#4169e1', - 'saddlebrown' => '#8b4513', - 'salmon' => '#fa8072', - 'sandybrown' => '#f4a460', - 'seagreen' => '#2e8b57', - 'seashell' => '#fff5ee', - 'sienna' => '#a0522d', - 'silver' => '#c0c0c0', - 'skyblue' => '#87ceeb', - 'slateblue' => '#6a5acd', - 'slategray' => '#708090', - 'slategrey' => '#708090', - 'snow' => '#fffafa', - 'springgreen' => '#00ff7f', - 'steelblue' => '#4682b4', - 'tan' => '#d2b48c', - 'teal' => '#008080', - 'thistle' => '#d8bfd8', - 'tomato' => '#ff6347', - 'turquoise' => '#40e0d0', - 'violet' => '#ee82ee', - 'wheat' => '#f5deb3', - 'white' => '#ffffff', - 'whitesmoke' => '#f5f5f5', - 'yellow' => '#ffff00', - 'yellowgreen' => '#9acd32' - ); + private const COLORS = [ + 'aliceblue' => '#f0f8ff', + 'antiquewhite' => '#faebd7', + 'aqua' => '#00ffff', + 'aquamarine' => '#7fffd4', + 'azure' => '#f0ffff', + 'beige' => '#f5f5dc', + 'bisque' => '#ffe4c4', + 'black' => '#000000', + 'blanchedalmond' => '#ffebcd', + 'blue' => '#0000ff', + 'blueviolet' => '#8a2be2', + 'brown' => '#a52a2a', + 'burlywood' => '#deb887', + 'cadetblue' => '#5f9ea0', + 'chartreuse' => '#7fff00', + 'chocolate' => '#d2691e', + 'coral' => '#ff7f50', + 'cornflowerblue' => '#6495ed', + 'cornsilk' => '#fff8dc', + 'crimson' => '#dc143c', + 'cyan' => '#00ffff', + 'darkblue' => '#00008b', + 'darkcyan' => '#008b8b', + 'darkgoldenrod' => '#b8860b', + 'darkgray' => '#a9a9a9', + 'darkgrey' => '#a9a9a9', + 'darkgreen' => '#006400', + 'darkkhaki' => '#bdb76b', + 'darkmagenta' => '#8b008b', + 'darkolivegreen' => '#556b2f', + 'darkorange' => '#ff8c00', + 'darkorchid' => '#9932cc', + 'darkred' => '#8b0000', + 'darksalmon' => '#e9967a', + 'darkseagreen' => '#8fbc8f', + 'darkslateblue' => '#483d8b', + 'darkslategray' => '#2f4f4f', + 'darkslategrey' => '#2f4f4f', + 'darkturquoise' => '#00ced1', + 'darkviolet' => '#9400d3', + 'deeppink' => '#ff1493', + 'deepskyblue' => '#00bfff', + 'dimgray' => '#696969', + 'dimgrey' => '#696969', + 'dodgerblue' => '#1e90ff', + 'firebrick' => '#b22222', + 'floralwhite' => '#fffaf0', + 'forestgreen' => '#228b22', + 'fuchsia' => '#ff00ff', + 'gainsboro' => '#dcdcdc', + 'ghostwhite' => '#f8f8ff', + 'gold' => '#ffd700', + 'goldenrod' => '#daa520', + 'gray' => '#808080', + 'grey' => '#808080', + 'green' => '#008000', + 'greenyellow' => '#adff2f', + 'honeydew' => '#f0fff0', + 'hotpink' => '#ff69b4', + 'indianred' => '#cd5c5c', + 'indigo' => '#4b0082', + 'ivory' => '#fffff0', + 'khaki' => '#f0e68c', + 'lavender' => '#e6e6fa', + 'lavenderblush' => '#fff0f5', + 'lawngreen' => '#7cfc00', + 'lemonchiffon' => '#fffacd', + 'lightblue' => '#add8e6', + 'lightcoral' => '#f08080', + 'lightcyan' => '#e0ffff', + 'lightgoldenrodyellow' => '#fafad2', + 'lightgray' => '#d3d3d3', + 'lightgrey' => '#d3d3d3', + 'lightgreen' => '#90ee90', + 'lightpink' => '#ffb6c1', + 'lightsalmon' => '#ffa07a', + 'lightseagreen' => '#20b2aa', + 'lightskyblue' => '#87cefa', + 'lightslategray' => '#778899', + 'lightslategrey' => '#778899', + 'lightsteelblue' => '#b0c4de', + 'lightyellow' => '#ffffe0', + 'lime' => '#00ff00', + 'limegreen' => '#32cd32', + 'linen' => '#faf0e6', + 'magenta' => '#ff00ff', + 'maroon' => '#800000', + 'mediumaquamarine' => '#66cdaa', + 'mediumblue' => '#0000cd', + 'mediumorchid' => '#ba55d3', + 'mediumpurple' => '#9370d8', + 'mediumseagreen' => '#3cb371', + 'mediumslateblue' => '#7b68ee', + 'mediumspringgreen' => '#00fa9a', + 'mediumturquoise' => '#48d1cc', + 'mediumvioletred' => '#c71585', + 'midnightblue' => '#191970', + 'mintcream' => '#f5fffa', + 'mistyrose' => '#ffe4e1', + 'moccasin' => '#ffe4b5', + 'navajowhite' => '#ffdead', + 'navy' => '#000080', + 'oldlace' => '#fdf5e6', + 'olive' => '#808000', + 'olivedrab' => '#6b8e23', + 'orange' => '#ffa500', + 'orangered' => '#ff4500', + 'orchid' => '#da70d6', + 'palegoldenrod' => '#eee8aa', + 'palegreen' => '#98fb98', + 'paleturquoise' => '#afeeee', + 'palevioletred' => '#d87093', + 'papayawhip' => '#ffefd5', + 'peachpuff' => '#ffdab9', + 'peru' => '#cd853f', + 'pink' => '#ffc0cb', + 'plum' => '#dda0dd', + 'powderblue' => '#b0e0e6', + 'purple' => '#800080', + 'red' => '#ff0000', + 'rosybrown' => '#bc8f8f', + 'royalblue' => '#4169e1', + 'saddlebrown' => '#8b4513', + 'salmon' => '#fa8072', + 'sandybrown' => '#f4a460', + 'seagreen' => '#2e8b57', + 'seashell' => '#fff5ee', + 'sienna' => '#a0522d', + 'silver' => '#c0c0c0', + 'skyblue' => '#87ceeb', + 'slateblue' => '#6a5acd', + 'slategray' => '#708090', + 'slategrey' => '#708090', + 'snow' => '#fffafa', + 'springgreen' => '#00ff7f', + 'steelblue' => '#4682b4', + 'tan' => '#d2b48c', + 'teal' => '#008080', + 'thistle' => '#d8bfd8', + 'tomato' => '#ff6347', + 'turquoise' => '#40e0d0', + 'violet' => '#ee82ee', + 'wheat' => '#f5deb3', + 'white' => '#ffffff', + 'whitesmoke' => '#f5f5f5', + 'yellow' => '#ffff00', + 'yellowgreen' => '#9acd32', + ]; - public static function hasOwnProperty( $color ) { - return isset( self::$colors[$color] ); + /** + * @param string $color + * @return bool + */ + public static function hasOwnProperty( string $color ): bool { + return isset( self::COLORS[$color] ); } - public static function color( $color ) { - return self::$colors[$color]; + /** + * @param string $color Should be an existing color name, + * checked via hasOwnProperty() + * @return string the corresponding hexadecimal representation + */ + public static function color( string $color ): string { + return self::COLORS[$color]; } } diff --git a/vendor/wikimedia/less.php/lib/Less/Configurable.php b/vendor/wikimedia/less.php/lib/Less/Configurable.php index 7f1348b..ec16d80 100644 --- a/vendor/wikimedia/less.php/lib/Less/Configurable.php +++ b/vendor/wikimedia/less.php/lib/Less/Configurable.php @@ -1,10 +1,6 @@ defaultOptions ); diff --git a/vendor/wikimedia/less.php/lib/Less/Environment.php b/vendor/wikimedia/less.php/lib/Less/Environment.php index 2555d03..bfc3825 100644 --- a/vendor/wikimedia/less.php/lib/Less/Environment.php +++ b/vendor/wikimedia/less.php/lib/Less/Environment.php @@ -1,39 +1,35 @@ ',', ': ' => ':', '' => '', @@ -70,11 +66,11 @@ class Less_Environment { '|' => '|', '^' => '^', '^^' => '^^' - ); + ]; } else { - Less_Environment::$_outputMap = array( + self::$_outputMap = [ ',' => ', ', ': ' => ': ', '' => '', @@ -86,19 +82,19 @@ class Less_Environment { '|' => '|', '^' => ' ^ ', '^^' => ' ^^ ' - ); + ]; } } - public function copyEvalEnv( $frames = array() ) { + public function copyEvalEnv( $frames = [] ) { $new_env = new Less_Environment(); $new_env->frames = $frames; return $new_env; } public static function isMathOn() { - return !Less_Parser::$options['strictMath'] || Less_Environment::$parensStack; + return !Less_Parser::$options['strictMath'] || self::$parensStack; } public static function isPathRelative( $path ) { @@ -108,15 +104,14 @@ class Less_Environment { /** * Canonicalize a path by resolving references to '/./', '/../' * Does not remove leading "../" - * @param string path or url + * @param string $path or url * @return string Canonicalized path - * */ public static function normalizePath( $path ) { $segments = explode( '/', $path ); $segments = array_reverse( $segments ); - $path = array(); + $path = []; $path_len = 0; while ( $segments ) { @@ -124,9 +119,10 @@ class Less_Environment { switch ( $segment ) { case '.': - break; + break; case '..': + // @phan-suppress-next-line PhanTypeInvalidDimOffset False positive if ( !$path_len || ( $path[$path_len - 1] === '..' ) ) { $path[] = $segment; $path_len++; @@ -134,12 +130,12 @@ class Less_Environment { array_pop( $path ); $path_len--; } - break; + break; default: $path[] = $segment; $path_len++; - break; + break; } } diff --git a/vendor/wikimedia/less.php/lib/Less/Exception/Chunk.php b/vendor/wikimedia/less.php/lib/Less/Exception/Chunk.php index 1f1dddb..8071eb8 100644 --- a/vendor/wikimedia/less.php/lib/Less/Exception/Chunk.php +++ b/vendor/wikimedia/less.php/lib/Less/Exception/Chunk.php @@ -1,10 +1,6 @@ message = 'ParseError: Unexpected input'; // default message @@ -40,7 +34,6 @@ class Less_Exception_Chunk extends Less_Exception_Parser { /** * See less.js chunks() * We don't actually need the chunks - * */ protected function Chunks() { $level = 0; @@ -95,7 +88,9 @@ class Less_Exception_Chunk extends Less_Exception_Parser { break; // \ case 92: - if ( $this->parserCurrentIndex < $this->input_len - 1 ) { $this->parserCurrentIndex++; break; + if ( $this->parserCurrentIndex < $this->input_len - 1 ) { + $this->parserCurrentIndex++; + break; } return $this->fail( "unescaped `\\`" ); @@ -105,11 +100,12 @@ class Less_Exception_Chunk extends Less_Exception_Parser { case 96: $matched = 0; $currentChunkStartIndex = $this->parserCurrentIndex; - for ( $this->parserCurrentIndex = $this->parserCurrentIndex + 1; $this->parserCurrentIndex < $this->input_len; $this->parserCurrentIndex++ ) { + for ( $this->parserCurrentIndex += 1; $this->parserCurrentIndex < $this->input_len; $this->parserCurrentIndex++ ) { $cc2 = $this->CharCode( $this->parserCurrentIndex ); if ( $cc2 > 96 ) { continue; } - if ( $cc2 == $cc ) { $matched = 1; break; + if ( $cc2 == $cc ) { $matched = 1; +break; } if ( $cc2 == 92 ) { // \ if ( $this->parserCurrentIndex == $this->input_len - 1 ) { @@ -129,15 +125,15 @@ class Less_Exception_Chunk extends Less_Exception_Parser { $cc2 = $this->CharCode( $this->parserCurrentIndex + 1 ); if ( $cc2 == 47 ) { // //, find lnfeed - for ( $this->parserCurrentIndex = $this->parserCurrentIndex + 2; $this->parserCurrentIndex < $this->input_len; $this->parserCurrentIndex++ ) { + for ( $this->parserCurrentIndex += 2; $this->parserCurrentIndex < $this->input_len; $this->parserCurrentIndex++ ) { $cc2 = $this->CharCode( $this->parserCurrentIndex ); if ( ( $cc2 <= 13 ) && ( ( $cc2 == 10 ) || ( $cc2 == 13 ) ) ) { break; } } - } else if ( $cc2 == 42 ) { + } elseif ( $cc2 == 42 ) { // /*, find */ $lastMultiComment = $currentChunkStartIndex = $this->parserCurrentIndex; - for ( $this->parserCurrentIndex = $this->parserCurrentIndex + 2; $this->parserCurrentIndex < $this->input_len - 1; $this->parserCurrentIndex++ ) { + for ( $this->parserCurrentIndex += 2; $this->parserCurrentIndex < $this->input_len - 1; $this->parserCurrentIndex++ ) { $cc2 = $this->CharCode( $this->parserCurrentIndex ); if ( $cc2 == 125 ) { $lastMultiCommentEndBrace = $this->parserCurrentIndex; } @@ -167,7 +163,7 @@ class Less_Exception_Chunk extends Less_Exception_Parser { } else { return $this->fail( "missing closing `}`", $lastOpening ); } - } else if ( $parenLevel !== 0 ) { + } elseif ( $parenLevel !== 0 ) { return $this->fail( "missing closing `)`", $lastParen ); } @@ -186,7 +182,7 @@ class Less_Exception_Chunk extends Less_Exception_Parser { } else { $this->index = $index; } - $this->message = 'ParseError: '.$msg; + $this->message = 'ParseError: ' . $msg; } /* diff --git a/vendor/wikimedia/less.php/lib/Less/Exception/Compiler.php b/vendor/wikimedia/less.php/lib/Less/Exception/Compiler.php index 1c3727a..e963b69 100644 --- a/vendor/wikimedia/less.php/lib/Less/Exception/Compiler.php +++ b/vendor/wikimedia/less.php/lib/Less/Exception/Compiler.php @@ -2,9 +2,6 @@ /** * Compiler Exception - * - * @package Less - * @subpackage exception */ class Less_Exception_Compiler extends Less_Exception_Parser { diff --git a/vendor/wikimedia/less.php/lib/Less/Exception/Parser.php b/vendor/wikimedia/less.php/lib/Less/Exception/Parser.php index 8bbf25f..22d9d19 100644 --- a/vendor/wikimedia/less.php/lib/Less/Exception/Parser.php +++ b/vendor/wikimedia/less.php/lib/Less/Exception/Parser.php @@ -2,46 +2,36 @@ /** * Parser Exception - * - * @package Less - * @subpackage exception */ class Less_Exception_Parser extends Exception { /** * The current file * - * @var Less_ImportedFile + * @var array */ public $currentFile; /** * The current parser index * - * @var integer + * @var int */ public $index; protected $input; - protected $details = array(); + protected $details = []; /** - * Constructor - * - * @param string $message - * @param Exception $previous Previous exception - * @param integer $index The current parser index - * @param Less_FileInfo|string $currentFile The file - * @param integer $code The exception code + * @param string|null $message + * @param Exception|null $previous Previous exception + * @param int|null $index The current parser index + * @param array|null $currentFile The file + * @param int $code The exception code */ public function __construct( $message = null, Exception $previous = null, $index = null, $currentFile = null, $code = 0 ) { - if ( PHP_VERSION_ID < 50300 ) { - $this->previous = $previous; - parent::__construct( $message, $code ); - } else { - parent::__construct( $message, $code, $previous ); - } + parent::__construct( $message, $code, $previous ); $this->currentFile = $currentFile; $this->index = $index; @@ -56,20 +46,18 @@ class Less_Exception_Parser extends Exception { } /** - * Converts the exception to string - * - * @return string + * Set a message based on the exception info */ public function genMessage() { if ( $this->currentFile && $this->currentFile['filename'] ) { - $this->message .= ' in '.basename( $this->currentFile['filename'] ); + $this->message .= ' in ' . basename( $this->currentFile['filename'] ); } if ( $this->index !== null ) { $this->getInput(); if ( $this->input ) { $line = self::getLineNumber(); - $this->message .= ' on line '.$line.', column '.self::getColumn(); + $this->message .= ' on line ' . $line . ', column ' . self::getColumn(); $lines = explode( "\n", $this->input ); @@ -78,17 +66,16 @@ class Less_Exception_Parser extends Exception { $last_line = min( $count, $start_line + 6 ); $num_len = strlen( $last_line ); for ( $i = $start_line; $i < $last_line; $i++ ) { - $this->message .= "\n".str_pad( $i + 1, $num_len, '0', STR_PAD_LEFT ).'| '.$lines[$i]; + $this->message .= "\n" . str_pad( (string)( $i + 1 ), $num_len, '0', STR_PAD_LEFT ) . '| ' . $lines[$i]; } } } - } /** * Returns the line number the error was encountered * - * @return integer + * @return int */ public function getLineNumber() { if ( $this->index ) { @@ -105,7 +92,7 @@ class Less_Exception_Parser extends Exception { /** * Returns the column the error was encountered * - * @return integer + * @return int */ public function getColumn() { $part = substr( $this->input, 0, $this->index ); diff --git a/vendor/wikimedia/less.php/lib/Less/Functions.php b/vendor/wikimedia/less.php/lib/Less/Functions.php index c9e97bd..43a964c 100644 --- a/vendor/wikimedia/less.php/lib/Less/Functions.php +++ b/vendor/wikimedia/less.php/lib/Less/Functions.php @@ -2,34 +2,33 @@ /** * Builtin functions - * - * @package Less - * @subpackage function - * @see http://lesscss.org/functions/ + * @see https://lesscss.org/functions/ */ class Less_Functions { public $env; public $currentFileInfo; - function __construct( $env, $currentFileInfo = null ) { + function __construct( $env, array $currentFileInfo = null ) { $this->env = $env; $this->currentFileInfo = $currentFileInfo; } /** * @param string $op + * @param float $a + * @param float $b */ public static function operate( $op, $a, $b ) { switch ( $op ) { case '+': -return $a + $b; + return $a + $b; case '-': -return $a - $b; + return $a - $b; case '*': -return $a * $b; + return $a * $b; case '/': -return $a / $b; + return $a / $b; } } @@ -52,7 +51,7 @@ return $a / $b; public static function number( $n ) { if ( $n instanceof Less_Tree_Dimension ) { return floatval( $n->unit->is( '%' ) ? $n->value / 100 : $n->value ); - } else if ( is_numeric( $n ) ) { + } elseif ( is_numeric( $n ) ) { return $n; } else { throw new Less_Exception_Compiler( "color functions take numbers as parameters" ); @@ -63,20 +62,20 @@ return $a / $b; if ( $n instanceof Less_Tree_Dimension && $n->unit->is( '%' ) ) { return (float)$n->value * $size / 100; } else { - return Less_Functions::number( $n ); + return self::number( $n ); } } public function rgb( $r = null, $g = null, $b = null ) { - if ( is_null( $r ) || is_null( $g ) || is_null( $b ) ) { + if ( $r === null || $g === null || $b === null ) { throw new Less_Exception_Compiler( "rgb expects three parameters" ); } return $this->rgba( $r, $g, $b, 1.0 ); } public function rgba( $r = null, $g = null, $b = null, $a = null ) { - $rgb = array( $r, $g, $b ); - $rgb = array_map( array( 'Less_Functions','scaled' ), $rgb ); + $rgb = [ $r, $g, $b ]; + $rgb = array_map( [ 'Less_Functions','scaled' ], $rgb ); $a = self::number( $a ); return new Less_Tree_Color( $rgb, $a ); @@ -96,18 +95,30 @@ return $a / $b; $m1 = $l * 2 - $m2; - return $this->rgba( self::hsla_hue( $h + 1 / 3, $m1, $m2 ) * 255, - self::hsla_hue( $h, $m1, $m2 ) * 255, - self::hsla_hue( $h - 1 / 3, $m1, $m2 ) * 255, - $a ); + return $this->rgba( + self::hsla_hue( $h + 1 / 3, $m1, $m2 ) * 255, + self::hsla_hue( $h, $m1, $m2 ) * 255, + self::hsla_hue( $h - 1 / 3, $m1, $m2 ) * 255, + $a + ); } /** - * @param double $h + * @param float $h + * @param float $m1 + * @param float $m2 */ public function hsla_hue( $h, $m1, $m2 ) { $h = $h < 0 ? $h + 1 : ( $h > 1 ? $h - 1 : $h ); - if ( $h * 6 < 1 ) return $m1 + ( $m2 - $m1 ) * $h * 6; else if ( $h * 2 < 1 ) return $m2; else if ( $h * 3 < 2 ) return $m1 + ( $m2 - $m1 ) * ( 2 / 3 - $h ) * 6; else return $m1; + if ( $h * 6 < 1 ) { + return $m1 + ( $m2 - $m1 ) * $h * 6; + } elseif ( $h * 2 < 1 ) { + return $m2; + } elseif ( $h * 3 < 2 ) { + return $m1 + ( $m2 - $m1 ) * ( 2 / 3 - $h ) * 6; + } else { + return $m1; + } } public function hsv( $h, $s, $v ) { @@ -115,33 +126,42 @@ return $a / $b; } /** - * @param double $a + * @param Less_Tree|float $h + * @param Less_Tree|float $s + * @param Less_Tree|float $v + * @param float $a */ public function hsva( $h, $s, $v, $a ) { - $h = ( ( Less_Functions::number( $h ) % 360 ) / 360 ) * 360; - $s = Less_Functions::number( $s ); - $v = Less_Functions::number( $v ); - $a = Less_Functions::number( $a ); + $h = ( ( self::number( $h ) % 360 ) / 360 ) * 360; + $s = self::number( $s ); + $v = self::number( $v ); + $a = self::number( $a ); - $i = floor( ( $h / 60 ) % 6 ); + $i = floor( (int)( $h / 60 ) % 6 ); $f = ( $h / 60 ) - $i; - $vs = array( $v, - $v * ( 1 - $s ), - $v * ( 1 - $f * $s ), - $v * ( 1 - ( 1 - $f ) * $s ) ); + $vs = [ + $v, + $v * ( 1 - $s ), + $v * ( 1 - $f * $s ), + $v * ( 1 - ( 1 - $f ) * $s ) + ]; - $perm = array( array( 0, 3, 1 ), - array( 2, 0, 1 ), - array( 1, 0, 3 ), - array( 1, 2, 0 ), - array( 3, 1, 0 ), - array( 0, 1, 2 ) ); + $perm = [ + [ 0, 3, 1 ], + [ 2, 0, 1 ], + [ 1, 0, 3 ], + [ 1, 2, 0 ], + [ 3, 1, 0 ], + [ 0, 1, 2 ] + ]; - return $this->rgba( $vs[$perm[$i][0]] * 255, - $vs[$perm[$i][1]] * 255, - $vs[$perm[$i][2]] * 255, - $a ); + return $this->rgba( + $vs[$perm[$i][0]] * 255, + $vs[$perm[$i][1]] * 255, + $vs[$perm[$i][2]] * 255, + $a + ); } public function hue( $color = null ) { @@ -275,7 +295,8 @@ return $a / $b; } /** - * @param Less_Tree_Dimension $amount + * @param Less_Tree_Color|null $color + * @param Less_Tree_Dimension|null $amount */ public function desaturate( $color = null, $amount = null ) { if ( !$color instanceof Less_Tree_Color ) { @@ -286,7 +307,6 @@ return $a / $b; } $hsl = $color->toHSL(); - $hsl['s'] -= $amount->value / 100; $hsl['s'] = self::clamp( $hsl['s'] ); @@ -385,11 +405,13 @@ return $a / $b; // // Copyright (c) 2006-2009 Hampton Catlin, Nathan Weizenbaum, and Chris Eppstein - // http://sass-lang.com + // https://sass-lang.com/ // /** - * @param Less_Tree_Color $color1 + * @param Less_Tree|null $color1 + * @param Less_Tree|null $color2 + * @param Less_Tree|null $weight */ public function mix( $color1 = null, $color2 = null, $weight = null ) { if ( !$color1 instanceof Less_Tree_Color ) { @@ -414,9 +436,11 @@ return $a / $b; $w1 = ( ( ( ( $w * $a ) == -1 ) ? $w : ( $w + $a ) / ( 1 + $w * $a ) ) + 1 ) / 2; $w2 = 1 - $w1; - $rgb = array( $color1->rgb[0] * $w1 + $color2->rgb[0] * $w2, - $color1->rgb[1] * $w1 + $color2->rgb[1] * $w2, - $color1->rgb[2] * $w1 + $color2->rgb[2] * $w2 ); + $rgb = [ + $color1->rgb[0] * $w1 + $color2->rgb[0] * $w2, + $color1->rgb[1] * $w1 + $color2->rgb[1] * $w2, + $color1->rgb[2] * $w1 + $color2->rgb[2] * $w2 + ]; $alpha = $color1->alpha * $p + $color2->alpha * ( 1 - $p ); @@ -456,7 +480,7 @@ return $a / $b; if ( !$threshold ) { $threshold = 0.43; } else { - $threshold = Less_Functions::number( $threshold ); + $threshold = self::number( $threshold ); } if ( $color->luma() < $threshold ) { @@ -474,7 +498,7 @@ return $a / $b; } public function escape( $str ) { - $revert = array( '%21' => '!', '%2A' => '*', '%27' => "'",'%3F' => '?','%26' => '&','%2C' => ',','%2F' => '/','%40' => '@','%2B' => '+','%24' => '$' ); + $revert = [ '%21' => '!', '%2A' => '*', '%27' => "'",'%3F' => '?','%26' => '&','%2C' => ',','%2F' => '/','%40' => '@','%2B' => '+','%24' => '$' ]; return new Less_Tree_Anonymous( strtr( rawurlencode( $str->value ), $revert ) ); } @@ -486,7 +510,7 @@ return $a / $b; public function replace( $string, $pattern, $replacement, $flags = null ) { $result = $string->value; - $expr = '/'.str_replace( '/', '\\/', $pattern->value ).'/'; + $expr = '/' . str_replace( '/', '\\/', $pattern->value ) . '/'; if ( $flags && $flags->value ) { $expr .= self::replace_flags( $flags->value ); } @@ -507,11 +531,11 @@ return $a / $b; switch ( $flag ) { case 'e': case 'g': - break; + break; default: $new_flags .= $flag; - break; + break; } } @@ -642,7 +666,7 @@ return $a / $b; } $args[0] = (float)$args[0]->value; return new Less_Tree_Dimension( call_user_func_array( $fn, $args ), $unit ); - } else if ( is_numeric( $args[0] ) ) { + } elseif ( is_numeric( $args[0] ) ) { return call_user_func_array( $fn, $args ); } else { throw new Less_Exception_Compiler( "math functions take numbers as parameters" ); @@ -650,7 +674,8 @@ return $a / $b; } /** - * @param boolean $isMin + * @param bool $isMin + * @param array $args */ private function _minmax( $isMin, $args ) { $arg_count = count( $args ); @@ -663,18 +688,24 @@ return $a / $b; $unitClone = null; $unitStatic = null; - $order = array(); // elems only contains original argument values. - $values = array(); // key is the unit.toString() for unified tree.Dimension values, - // value is the index into the order array. + // elems only contains original argument values. + $order = []; + // key is the unit.toString() for unified tree.Dimension values, + // value is the index into the order array. + $values = []; for ( $i = 0; $i < $arg_count; $i++ ) { $current = $args[$i]; if ( !( $current instanceof Less_Tree_Dimension ) ) { - if ( is_array( $args[$i]->value ) ) { + // @phan-suppress-next-line PhanUndeclaredProperty Checked Less_Tree->value + if ( property_exists( $args[$i], 'value' ) && is_array( $args[$i]->value ) ) { + // @phan-suppress-next-line PhanUndeclaredProperty Checked Less_Tree->value $args[] = $args[$i]->value; } continue; } + // PhanTypeInvalidDimOffset -- False positive, safe after continue or non-first iterations + '@phan-var non-empty-list $order'; if ( $current->unit->toString() === '' && !$unitClone ) { $temp = new Less_Tree_Dimension( $current->value, $unitClone ); @@ -725,11 +756,11 @@ return $a / $b; if ( count( $order ) == 1 ) { return $order[0]; } - $args = array(); + $args = []; foreach ( $order as $a ) { - $args[] = $a->toCSS( $this->env ); + $args[] = $a->toCSS(); } - return new Less_Tree_Anonymous( ( $isMin ? 'min(' : 'max(' ) . implode( Less_Environment::$_outputMap[','], $args ).')' ); + return new Less_Tree_Anonymous( ( $isMin ? 'min(' : 'max(' ) . implode( Less_Environment::$_outputMap[','], $args ) . ')' ); } public function min() { @@ -807,10 +838,12 @@ return $a / $b; } /** - * @param string $unit + * @param Less_Tree $n + * @param Less_Tree|string $unit */ public function isunit( $n, $unit ) { if ( is_object( $unit ) && property_exists( $unit, 'value' ) ) { + // @phan-suppress-next-line PhanUndeclaredProperty Checked Less_Tree->value $unit = $unit->value; } @@ -818,6 +851,7 @@ return $a / $b; } /** + * @param Less_Tree $n * @param string $type */ private function _isa( $n, $type ) { @@ -866,15 +900,16 @@ return $a / $b; $filePath = str_replace( '\\', '/', $filePath ); if ( Less_Environment::isPathRelative( $filePath ) ) { - + $currentFileInfo = $this->currentFileInfo; + '@phan-var array $currentFileInfo'; if ( Less_Parser::$options['relativeUrls'] ) { - $temp = $this->currentFileInfo['currentDirectory']; + $temp = $currentFileInfo['currentDirectory']; } else { - $temp = $this->currentFileInfo['entryPath']; + $temp = $currentFileInfo['entryPath']; } if ( !empty( $temp ) ) { - $filePath = Less_Environment::normalizePath( rtrim( $temp, '/' ).'/'.$filePath ); + $filePath = Less_Environment::normalizePath( rtrim( $temp, '/' ) . '/' . $filePath ); } } @@ -895,7 +930,7 @@ return $a / $b; $mimetype = Less_Mime::lookup( $filePath ); $charset = Less_Mime::charsets_lookup( $mimetype ); - $useBase64 = !in_array( $charset, array( 'US-ASCII', 'UTF-8' ) ); + $useBase64 = !in_array( $charset, [ 'US-ASCII', 'UTF-8' ] ); if ( $useBase64 ) { $mimetype .= ';base64'; } @@ -914,8 +949,8 @@ return $a / $b; $DATA_URI_MAX_KB = 32; $fileSizeInKB = round( strlen( $buf ) / 1024 ); if ( $fileSizeInKB >= $DATA_URI_MAX_KB ) { - $url = new Less_Tree_Url( ( $filePathNode ? $filePathNode : $mimetypeNode ), $this->currentFileInfo ); - return $url->compile( $this ); + $url = new Less_Tree_Url( ( $filePathNode ?: $mimetypeNode ), $this->currentFileInfo ); + return $url->compile( $this->env ); } if ( $buf ) { @@ -994,9 +1029,9 @@ return $a / $b; $returner .= ''; if ( $useBase64 ) { - $returner = "'data:image/svg+xml;base64,".base64_encode( $returner )."'"; + $returner = "'data:image/svg+xml;base64," . base64_encode( $returner ) . "'"; } else { - $returner = "'data:image/svg+xml,".$returner."'"; + $returner = "'data:image/svg+xml," . $returner . "'"; } return new Less_Tree_URL( new Less_Tree_Anonymous( $returner ) ); @@ -1009,17 +1044,18 @@ return $a / $b; * @return string The encoded string */ public static function encodeURIComponent( $string ) { - $revert = array( '%21' => '!', '%2A' => '*', '%27' => "'", '%28' => '(', '%29' => ')' ); + $revert = [ '%21' => '!', '%2A' => '*', '%27' => "'", '%28' => '(', '%29' => ')' ]; return strtr( rawurlencode( $string ), $revert ); } // Color Blending - // ref: http://www.w3.org/TR/compositing-1 - + // ref: https://www.w3.org/TR/compositing-1/ public function colorBlend( $mode, $color1, $color2 ) { - $ab = $color1->alpha; // backdrop - $as = $color2->alpha; // source - $r = array(); // result + // backdrop + $ab = $color1->alpha; + // source + $as = $color2->alpha; + $result = []; $ar = $as + $ab * ( 1 - $as ); for ( $i = 0; $i < 3; $i++ ) { @@ -1029,10 +1065,10 @@ return $a / $b; if ( $ar ) { $cr = ( $as * $cs + $ab * ( $cb - $as * ( $cb + $cs - $cr ) ) ) / $ar; } - $r[$i] = $cr * 255; + $result[$i] = $cr * 255; } - return new Less_Tree_Color( $r, $ar ); + return new Less_Tree_Color( $result, $ar ); } public function multiply( $color1 = null, $color2 = null ) { @@ -1043,7 +1079,7 @@ return $a / $b; throw new Less_Exception_Compiler( 'The second argument to multiply must be a color' . ( $color2 instanceof Less_Tree_Expression ? ' (did you forgot commas?)' : '' ) ); } - return $this->colorBlend( array( $this,'colorBlendMultiply' ), $color1, $color2 ); + return $this->colorBlend( [ $this,'colorBlendMultiply' ], $color1, $color2 ); } private function colorBlendMultiply( $cb, $cs ) { @@ -1058,7 +1094,7 @@ return $a / $b; throw new Less_Exception_Compiler( 'The second argument to screen must be a color' . ( $color2 instanceof Less_Tree_Expression ? ' (did you forgot commas?)' : '' ) ); } - return $this->colorBlend( array( $this,'colorBlendScreen' ), $color1, $color2 ); + return $this->colorBlend( [ $this,'colorBlendScreen' ], $color1, $color2 ); } private function colorBlendScreen( $cb, $cs ) { @@ -1073,7 +1109,7 @@ return $a / $b; throw new Less_Exception_Compiler( 'The second argument to overlay must be a color' . ( $color2 instanceof Less_Tree_Expression ? ' (did you forgot commas?)' : '' ) ); } - return $this->colorBlend( array( $this,'colorBlendOverlay' ), $color1, $color2 ); + return $this->colorBlend( [ $this,'colorBlendOverlay' ], $color1, $color2 ); } private function colorBlendOverlay( $cb, $cs ) { @@ -1091,7 +1127,7 @@ return $a / $b; throw new Less_Exception_Compiler( 'The second argument to softlight must be a color' . ( $color2 instanceof Less_Tree_Expression ? ' (did you forgot commas?)' : '' ) ); } - return $this->colorBlend( array( $this,'colorBlendSoftlight' ), $color1, $color2 ); + return $this->colorBlend( [ $this,'colorBlendSoftlight' ], $color1, $color2 ); } private function colorBlendSoftlight( $cb, $cs ) { @@ -1113,7 +1149,7 @@ return $a / $b; throw new Less_Exception_Compiler( 'The second argument to hardlight must be a color' . ( $color2 instanceof Less_Tree_Expression ? ' (did you forgot commas?)' : '' ) ); } - return $this->colorBlend( array( $this,'colorBlendHardlight' ), $color1, $color2 ); + return $this->colorBlend( [ $this,'colorBlendHardlight' ], $color1, $color2 ); } private function colorBlendHardlight( $cb, $cs ) { @@ -1128,7 +1164,7 @@ return $a / $b; throw new Less_Exception_Compiler( 'The second argument to difference must be a color' . ( $color2 instanceof Less_Tree_Expression ? ' (did you forgot commas?)' : '' ) ); } - return $this->colorBlend( array( $this,'colorBlendDifference' ), $color1, $color2 ); + return $this->colorBlend( [ $this,'colorBlendDifference' ], $color1, $color2 ); } private function colorBlendDifference( $cb, $cs ) { @@ -1143,7 +1179,7 @@ return $a / $b; throw new Less_Exception_Compiler( 'The second argument to exclusion must be a color' . ( $color2 instanceof Less_Tree_Expression ? ' (did you forgot commas?)' : '' ) ); } - return $this->colorBlend( array( $this,'colorBlendExclusion' ), $color1, $color2 ); + return $this->colorBlend( [ $this,'colorBlendExclusion' ], $color1, $color2 ); } private function colorBlendExclusion( $cb, $cs ) { @@ -1158,7 +1194,7 @@ return $a / $b; throw new Less_Exception_Compiler( 'The second argument to average must be a color' . ( $color2 instanceof Less_Tree_Expression ? ' (did you forgot commas?)' : '' ) ); } - return $this->colorBlend( array( $this,'colorBlendAverage' ), $color1, $color2 ); + return $this->colorBlend( [ $this,'colorBlendAverage' ], $color1, $color2 ); } // non-w3c functions: @@ -1174,7 +1210,7 @@ return $a / $b; throw new Less_Exception_Compiler( 'The second argument to negation must be a color' . ( $color2 instanceof Less_Tree_Expression ? ' (did you forgot commas?)' : '' ) ); } - return $this->colorBlend( array( $this,'colorBlendNegation' ), $color1, $color2 ); + return $this->colorBlend( [ $this,'colorBlendNegation' ], $color1, $color2 ); } public function colorBlendNegation( $cb, $cs ) { diff --git a/vendor/wikimedia/less.php/lib/Less/Mime.php b/vendor/wikimedia/less.php/lib/Less/Mime.php index b4723f9..45a7bf3 100644 --- a/vendor/wikimedia/less.php/lib/Less/Mime.php +++ b/vendor/wikimedia/less.php/lib/Less/Mime.php @@ -1,37 +1,32 @@ 'text/html', - '.html' => 'text/html', - '.gif' => 'image/gif', - '.jpg' => 'image/jpeg', - '.jpeg' => 'image/jpeg', - '.png' => 'image/png', - '.ttf' => 'application/x-font-ttf', - '.otf' => 'application/x-font-otf', - '.eot' => 'application/vnd.ms-fontobject', - '.woff' => 'application/x-font-woff', - '.svg' => 'image/svg+xml', - ); + private static $types = [ + '.htm' => 'text/html', + '.html' => 'text/html', + '.gif' => 'image/gif', + '.jpg' => 'image/jpeg', + '.jpeg' => 'image/jpeg', + '.png' => 'image/png', + '.ttf' => 'application/x-font-ttf', + '.otf' => 'application/x-font-otf', + '.eot' => 'application/vnd.ms-fontobject', + '.woff' => 'application/x-font-woff', + '.svg' => 'image/svg+xml', + ]; public static function lookup( $filepath ) { $parts = explode( '.', $filepath ); - $ext = '.'.strtolower( array_pop( $parts ) ); + $ext = '.' . strtolower( array_pop( $parts ) ); - if ( !isset( self::$_types[$ext] ) ) { - return null; - } - return self::$_types[$ext]; + return self::$types[$ext] ?? null; } public static function charsets_lookup( $type = null ) { diff --git a/vendor/wikimedia/less.php/lib/Less/Output.php b/vendor/wikimedia/less.php/lib/Less/Output.php index 8f7dd61..be6c160 100644 --- a/vendor/wikimedia/less.php/lib/Less/Output.php +++ b/vendor/wikimedia/less.php/lib/Less/Output.php @@ -1,26 +1,24 @@ strs ) === 0; diff --git a/vendor/wikimedia/less.php/lib/Less/Output/Mapped.php b/vendor/wikimedia/less.php/lib/Less/Output/Mapped.php index e486c98..ece5172 100644 --- a/vendor/wikimedia/less.php/lib/Less/Output/Mapped.php +++ b/vendor/wikimedia/less.php/lib/Less/Output/Mapped.php @@ -1,10 +1,8 @@ false, // option - whether to compress 'strictUnits' => false, // whether units need to evaluate correctly 'strictMath' => false, // whether math has to be within parenthesis @@ -22,7 +16,7 @@ class Less_Parser { 'urlArgs' => '', // whether to add args into url tokens 'numPrecision' => 8, - 'import_dirs' => array(), + 'import_dirs' => [], 'import_callback' => null, 'cache_dir' => null, 'cache_method' => 'php', // false, 'serialize', 'php', 'var_export', 'callback'; @@ -36,16 +30,17 @@ class Less_Parser { 'indentation' => ' ', - 'plugins' => array(), + 'plugins' => [], - ); + ]; - public static $options = array(); + /** @var array{compress:bool,strictUnits:bool,strictMath:bool,numPrecision:int,import_dirs:array,import_callback:null|callable,indentation:string} */ + public static $options = []; private $input; // Less input string private $input_len; // input string length private $pos; // current index in `input` - private $saveStack = array(); // holds state for backtracking + private $saveStack = []; // holds state for backtracking private $furthest; private $mb_internal_encoding = ''; // for remember exists value of mbstring.internal_encoding @@ -54,9 +49,9 @@ class Less_Parser { */ private $env; - protected $rules = array(); + protected $rules = []; - private static $imports = array(); + private static $imports = []; public static $has_extends = false; @@ -67,7 +62,7 @@ class Less_Parser { * * @var array */ - public static $contentsMap = array(); + public static $contentsMap = []; /** * @param Less_Environment|array|null $env @@ -78,7 +73,7 @@ class Less_Parser { if ( $env instanceof Less_Environment ) { $this->env = $env; } else { - $this->SetOptions( Less_Parser::$default_options ); + $this->SetOptions( self::$default_options ); $this->Reset( $env ); } @@ -89,25 +84,23 @@ class Less_Parser { $this->mb_internal_encoding = ini_get( 'mbstring.internal_encoding' ); @ini_set( 'mbstring.internal_encoding', 'ascii' ); } - } /** * Reset the parser state completely - * */ public function Reset( $options = null ) { - $this->rules = array(); - self::$imports = array(); + $this->rules = []; + self::$imports = []; self::$has_extends = false; - self::$imports = array(); - self::$contentsMap = array(); + self::$imports = []; + self::$contentsMap = []; - $this->env = new Less_Environment( $options ); + $this->env = new Less_Environment(); // set new options if ( is_array( $options ) ) { - $this->SetOptions( Less_Parser::$default_options ); + $this->SetOptions( self::$default_options ); $this->SetOptions( $options ); } @@ -117,7 +110,6 @@ class Less_Parser { /** * Set one or more compiler options * options: import_dirs, cache_dir, cache_method - * */ public function SetOptions( $options ) { foreach ( $options as $option => $value ) { @@ -127,24 +119,23 @@ class Less_Parser { /** * Set one compiler option - * */ public function SetOption( $option, $value ) { switch ( $option ) { case 'import_dirs': $this->SetImportDirs( $value ); - return; + return; case 'cache_dir': if ( is_string( $value ) ) { Less_Cache::SetCacheDir( $value ); Less_Cache::CheckCacheDir(); } - return; + return; } - Less_Parser::$options[$option] = $value; + self::$options[$option] = $value; } /** @@ -163,8 +154,9 @@ class Less_Parser { * @param string $name function name */ public function unregisterFunction( $name ) { - if ( isset( $this->env->functions[$name] ) ) + if ( isset( $this->env->functions[$name] ) ) { unset( $this->env->functions[$name] ); + } } /** @@ -174,13 +166,12 @@ class Less_Parser { */ public function getCss() { $precision = ini_get( 'precision' ); - @ini_set( 'precision', 16 ); + @ini_set( 'precision', '16' ); $locale = setlocale( LC_NUMERIC, 0 ); setlocale( LC_NUMERIC, "C" ); try { - - $root = new Less_Tree_Ruleset( array(), $this->rules ); + $root = new Less_Tree_Ruleset( null, $this->rules ); $root->root = true; $root->firstRoot = true; @@ -191,8 +182,8 @@ class Less_Parser { $this->PostVisitors( $evaldRoot ); - if ( Less_Parser::$options['sourceMap'] ) { - $generator = new Less_SourceMap_Generator( $evaldRoot, Less_Parser::$contentsMap, Less_Parser::$options ); + if ( self::$options['sourceMap'] ) { + $generator = new Less_SourceMap_Generator( $evaldRoot, self::$contentsMap, self::$options ); // will also save file // FIXME: should happen somewhere else? $css = $generator->generateCSS(); @@ -200,7 +191,7 @@ class Less_Parser { $css = $evaldRoot->toCSS(); } - if ( Less_Parser::$options['compress'] ) { + if ( self::$options['compress'] ) { $css = preg_replace( '/(^(\s)+)|((\s)+$)/', '', $css ); } @@ -237,21 +228,21 @@ class Less_Parser { } /** - * - * this function gets the private rules variable and returns an array of the found variables - * it uses a helper method getVariableValue() that contains the logic ot fetch the value from the rule object + * Gets the private rules variable and returns an array of the found variables + * it uses a helper method getVariableValue() that contains the logic ot fetch the value + * from the rule object * * @return array */ public function getVariables() { - $variables = array(); + $variables = []; - $not_variable_type = array( + $not_variable_type = [ 'Comment', // this include less comments ( // ) and css comments (/* */) 'Import', // do not search variables in included files @import 'Ruleset', // selectors (.someclass, #someid, …) 'Operation', // - ); + ]; // @TODO run compilation if not runned yet foreach ( $this->rules as $key => $rule ) { @@ -283,85 +274,82 @@ class Less_Parser { } /** - * * This method gets the value of the less variable from the rules object. * Since the objects vary here we add the logic for extracting the css/less value. * - * @param $var - * - * @return bool|string + * @param Less_Tree $var + * @return string */ - private function getVariableValue( $var ) { - if ( !is_a( $var, 'Less_Tree' ) ) { - throw new Exception( 'var is not a Less_Tree object' ); - } - - switch ( $var->type ) { - case 'Color': + private function getVariableValue( Less_Tree $var ) { + switch ( get_class( $var ) ) { + case Less_Tree_Color::class: return $this->rgb2html( $var->rgb ); - case 'Unit': - return $var->value. $var->unit->numerator[0]; - case 'Variable': + case Less_Tree_Variable::class: return $this->findVarByName( $var->name ); - case 'Keyword': + case Less_Tree_Keyword::class: return $var->value; - case 'Rule': + case Less_Tree_Url::class: + // Based on Less_Tree_Url::genCSS() + // Recurse to serialize the Less_Tree_Quoted value + return 'url(' . $this->getVariableValue( $var->value ) . ')'; + case Less_Tree_Rule::class: return $this->getVariableValue( $var->value ); - case 'Value': + case Less_Tree_Value::class: $value = ''; foreach ( $var->value as $sub_value ) { - $value .= $this->getVariableValue( $sub_value ).' '; + $value .= $this->getVariableValue( $sub_value ) . ' '; } return $value; - case 'Quoted': - return $var->quote.$var->value.$var->quote; - case 'Dimension': + case Less_Tree_Quoted::class: + return $var->quote . $var->value . $var->quote; + case Less_Tree_Dimension::class: $value = $var->value; if ( $var->unit && $var->unit->numerator ) { $value .= $var->unit->numerator[0]; } return $value; - case 'Expression': - $value = ""; + case Less_Tree_Expression::class: + $value = ''; foreach ( $var->value as $item ) { - $value .= $this->getVariableValue( $item )." "; + $value .= $this->getVariableValue( $item ) . " "; } return $value; - case 'Operation': + case Less_Tree_Operation::class: throw new Exception( 'getVariables() require Less to be compiled. please use $parser->getCss() before calling getVariables()' ); - case 'Comment': - case 'Import': - case 'Ruleset': + case Less_Tree_Unit::class: + case Less_Tree_Comment::class: + case Less_Tree_Import::class: + case Less_Tree_Ruleset::class: default: - throw new Exception( "type missing in switch/case getVariableValue for ".$var->type ); + throw new Exception( "type missing in switch/case getVariableValue for " . $var->type ); } - return false; } private function rgb2html( $r, $g = -1, $b = -1 ) { - if ( is_array( $r ) && sizeof( $r ) == 3 ) + if ( is_array( $r ) && count( $r ) == 3 ) { list( $r, $g, $b ) = $r; + } - $r = intval( $r ); $g = intval( $g ); + $r = intval( $r ); +$g = intval( $g ); $b = intval( $b ); $r = dechex( $r < 0 ? 0 : ( $r > 255 ? 255 : $r ) ); $g = dechex( $g < 0 ? 0 : ( $g > 255 ? 255 : $g ) ); $b = dechex( $b < 0 ? 0 : ( $b > 255 ? 255 : $b ) ); - $color = ( strlen( $r ) < 2 ? '0' : '' ).$r; - $color .= ( strlen( $g ) < 2 ? '0' : '' ).$g; - $color .= ( strlen( $b ) < 2 ? '0' : '' ).$b; - return '#'.$color; + $color = ( strlen( $r ) < 2 ? '0' : '' ) . $r; + $color .= ( strlen( $g ) < 2 ? '0' : '' ) . $g; + $color .= ( strlen( $b ) < 2 ? '0' : '' ) . $b; + return '#' . $color; } /** * Run pre-compile visitors - * */ private function PreVisitors( $root ) { - if ( Less_Parser::$options['plugins'] ) { - foreach ( Less_Parser::$options['plugins'] as $plugin ) { + if ( self::$options['plugins'] ) { + foreach ( self::$options['plugins'] as $plugin ) { if ( !empty( $plugin->isPreEvalVisitor ) ) { $plugin->run( $root ); } @@ -371,18 +359,17 @@ class Less_Parser { /** * Run post-compile visitors - * */ private function PostVisitors( $evaldRoot ) { - $visitors = array(); + $visitors = []; $visitors[] = new Less_Visitor_joinSelector(); if ( self::$has_extends ) { $visitors[] = new Less_Visitor_processExtends(); } $visitors[] = new Less_Visitor_toCSS(); - if ( Less_Parser::$options['plugins'] ) { - foreach ( Less_Parser::$options['plugins'] as $plugin ) { + if ( self::$options['plugins'] ) { + foreach ( self::$options['plugins'] as $plugin ) { if ( property_exists( $plugin, 'isPreEvalVisitor' ) && $plugin->isPreEvalVisitor ) { continue; } @@ -398,20 +385,20 @@ class Less_Parser { for ( $i = 0; $i < count( $visitors ); $i++ ) { $visitors[$i]->run( $evaldRoot ); } - } /** - * Parse a Less string into css + * Parse a Less string * + * @throws Less_Exception_Parser If the compiler encounters invalid syntax * @param string $str The string to convert - * @param string $uri_root The url of the file - * @return Less_Tree_Ruleset|Less_Parser + * @param string|null $file_uri The url of the file + * @return Less_Parser */ public function parse( $str, $file_uri = null ) { if ( !$file_uri ) { $uri_root = ''; - $filename = 'anonymous-file-'.Less_Parser::$next_id++.'.less'; + $filename = 'anonymous-file-' . self::$next_id++ . '.less'; } else { $file_uri = self::WinPath( $file_uri ); $filename = $file_uri; @@ -435,7 +422,7 @@ class Less_Parser { /** * Parse a Less string from a given file * - * @throws Less_Exception_Parser + * @throws Less_Exception_Parser If the compiler encounters invalid syntax * @param string $filename The file to parse * @param string $uri_root The url of the file * @param bool $returnRoot Indicates whether the return value should be a css string a root node @@ -465,7 +452,7 @@ class Less_Parser { if ( $returnRoot ) { $rules = $this->GetRules( $filename ); - $return = new Less_Tree_Ruleset( array(), $rules ); + $return = new Less_Tree_Ruleset( null, $rules ); } else { $this->_parse( $filename ); $return = $this; @@ -484,7 +471,7 @@ class Less_Parser { * @return Less_Parser */ public function ModifyVars( $vars ) { - $this->input = Less_Parser::serializeVars( $vars ); + $this->input = self::serializeVars( $vars ); $this->_parse(); return $this; @@ -492,16 +479,17 @@ class Less_Parser { /** * @param string $filename + * @param string $uri_root */ public function SetFileInfo( $filename, $uri_root = '' ) { $filename = Less_Environment::normalizePath( $filename ); $dirname = preg_replace( '/[^\/\\\\]*$/', '', $filename ); if ( !empty( $uri_root ) ) { - $uri_root = rtrim( $uri_root, '/' ).'/'; + $uri_root = rtrim( $uri_root, '/' ) . '/'; } - $currentFileInfo = array(); + $currentFileInfo = []; // entry info if ( isset( $this->env->currentFileInfo ) ) { @@ -516,7 +504,7 @@ class Less_Parser { } $currentFileInfo['currentDirectory'] = $dirname; - $currentFileInfo['currentUri'] = $uri_root.basename( $filename ); + $currentFileInfo['currentUri'] = $uri_root . basename( $filename ); $currentFileInfo['filename'] = $filename; $currentFileInfo['uri_root'] = $uri_root; @@ -530,24 +518,23 @@ class Less_Parser { /** * @deprecated 1.5.1.2 - * */ public function SetCacheDir( $dir ) { if ( !file_exists( $dir ) ) { if ( mkdir( $dir ) ) { return true; } - throw new Less_Exception_Parser( 'Less.php cache directory couldn\'t be created: '.$dir ); + throw new Less_Exception_Parser( 'Less.php cache directory couldn\'t be created: ' . $dir ); } elseif ( !is_dir( $dir ) ) { - throw new Less_Exception_Parser( 'Less.php cache directory doesn\'t exist: '.$dir ); + throw new Less_Exception_Parser( 'Less.php cache directory doesn\'t exist: ' . $dir ); } elseif ( !is_writable( $dir ) ) { - throw new Less_Exception_Parser( 'Less.php cache directory isn\'t writable: '.$dir ); + throw new Less_Exception_Parser( 'Less.php cache directory isn\'t writable: ' . $dir ); } else { $dir = self::WinPath( $dir ); - Less_Cache::$cache_dir = rtrim( $dir, '/' ).'/'; + Less_Cache::$cache_dir = rtrim( $dir, '/' ) . '/'; return true; } } @@ -558,28 +545,28 @@ class Less_Parser { * @param array $dirs */ public function SetImportDirs( $dirs ) { - Less_Parser::$options['import_dirs'] = array(); + self::$options['import_dirs'] = []; foreach ( $dirs as $path => $uri_root ) { $path = self::WinPath( $path ); if ( !empty( $path ) ) { - $path = rtrim( $path, '/' ).'/'; + $path = rtrim( $path, '/' ) . '/'; } if ( !is_callable( $uri_root ) ) { $uri_root = self::WinPath( $uri_root ); if ( !empty( $uri_root ) ) { - $uri_root = rtrim( $uri_root, '/' ).'/'; + $uri_root = rtrim( $uri_root, '/' ) . '/'; } } - Less_Parser::$options['import_dirs'][$path] = $uri_root; + self::$options['import_dirs'][$path] = $uri_root; } } /** - * @param string $file_path + * @param string|null $file_path */ private function _parse( $file_path = null ) { $this->rules = array_merge( $this->rules, $this->GetRules( $file_path ) ); @@ -596,11 +583,11 @@ class Less_Parser { $cache_file = $this->CacheFile( $file_path ); if ( $cache_file ) { - if ( Less_Parser::$options['cache_method'] == 'callback' ) { - if ( is_callable( Less_Parser::$options['cache_callback_get'] ) ) { + if ( self::$options['cache_method'] == 'callback' ) { + if ( is_callable( self::$options['cache_callback_get'] ) ) { $cache = call_user_func_array( - Less_Parser::$options['cache_callback_get'], - array( $this, $file_path, $cache_file ) + self::$options['cache_callback_get'], + [ $this, $file_path, $cache_file ] ); if ( $cache ) { @@ -610,7 +597,7 @@ class Less_Parser { } } elseif ( file_exists( $cache_file ) ) { - switch ( Less_Parser::$options['cache_method'] ) { + switch ( self::$options['cache_method'] ) { // Using serialize // Faster but uses more memory @@ -642,26 +629,26 @@ class Less_Parser { // save the cache if ( $cache_file ) { - if ( Less_Parser::$options['cache_method'] == 'callback' ) { - if ( is_callable( Less_Parser::$options['cache_callback_set'] ) ) { + if ( self::$options['cache_method'] == 'callback' ) { + if ( is_callable( self::$options['cache_callback_set'] ) ) { call_user_func_array( - Less_Parser::$options['cache_callback_set'], - array( $this, $file_path, $cache_file, $rules ) + self::$options['cache_callback_set'], + [ $this, $file_path, $cache_file, $rules ] ); } } else { - // msg('write cache file'); - switch ( Less_Parser::$options['cache_method'] ) { + switch ( self::$options['cache_method'] ) { case 'serialize': file_put_contents( $cache_file, serialize( $rules ) ); break; case 'php': - file_put_contents( $cache_file, '' ); + // Mask PHP open tag to avoid breaking Doxygen + file_put_contents( $cache_file, '<' . '?php return ' . self::ArgString( $rules ) . '; ?>' ); break; case 'var_export': // Requires __set_state() - file_put_contents( $cache_file, '' ); + file_put_contents( $cache_file, '<' . '?php return ' . var_export( $rules, true ) . '; ?>' ); break; } @@ -674,7 +661,6 @@ class Less_Parser { /** * Set up the input buffer - * */ public function SetInput( $file_path ) { if ( $file_path ) { @@ -687,20 +673,18 @@ class Less_Parser { $this->input = preg_replace( '/\\G\xEF\xBB\xBF/', '', $this->input ); $this->input_len = strlen( $this->input ); - if ( Less_Parser::$options['sourceMap'] && $this->env->currentFileInfo ) { + if ( self::$options['sourceMap'] && $this->env->currentFileInfo ) { $uri = $this->env->currentFileInfo['currentUri']; - Less_Parser::$contentsMap[$uri] = $this->input; + self::$contentsMap[$uri] = $this->input; } - } /** * Free up some memory - * */ public function UnsetInput() { - unset( $this->input, $this->pos, $this->input_len, $this->furthest ); - $this->saveStack = array(); + $this->input = $this->pos = $this->input_len = $this->furthest = null; + $this->saveStack = []; } public function CacheFile( $file_path ) { @@ -709,13 +693,13 @@ class Less_Parser { $env = get_object_vars( $this->env ); unset( $env['frames'] ); - $parts = array(); + $parts = []; $parts[] = $file_path; $parts[] = filesize( $file_path ); $parts[] = filemtime( $file_path ); $parts[] = $env; $parts[] = Less_Version::cache_version; - $parts[] = Less_Parser::$options['cache_method']; + $parts[] = self::$options['cache_method']; return Less_Cache::$cache_dir . Less_Cache::$prefix . base_convert( sha1( json_encode( $parts ) ), 16, 36 ) . '.lesscache'; } } @@ -740,6 +724,9 @@ class Less_Parser { } private function restore() { + if ( $this->pos > $this->furthest ) { + $this->furthest = $this->pos; + } $this->pos = array_pop( $this->saveStack ); } @@ -751,10 +738,10 @@ class Less_Parser { * Determine if the character at the specified offset from the current position is a white space. * * @param int $offset - * * @return bool */ private function isWhitespace( $offset = 0 ) { + // @phan-suppress-next-line PhanParamSuspiciousOrder False positive return strpos( " \t\n\r\v\f", $this->input[$this->pos + $offset] ) !== false; } @@ -762,9 +749,9 @@ class Less_Parser { * Parse from a token, regexp or string, and move forward if match * * @param array $toks - * @return array + * @return null|string|array|Less_Tree */ - private function match( $toks ) { + private function matcher( $toks ) { // The match is confirmed, add the match length to `this::pos`, // and consume any extra white-space characters (' ' || '\n') // which come after that. The reason for this is that LeSS's @@ -799,8 +786,7 @@ class Less_Parser { /** * @param string[] $toks - * - * @return string + * @return null|string|array|Less_Tree */ private function MatchFuncs( $toks ) { if ( $this->pos < $this->input_len ) { @@ -811,10 +797,14 @@ class Less_Parser { } } } - } - // Match a single character in the input, + /** + * Match a single character in the input. + * + * @param string $tok + * @see less-2.5.3.js#parserInput.$char + */ private function MatchChar( $tok ) { if ( ( $this->pos < $this->input_len ) && ( $this->input[$this->pos] === $tok ) ) { $this->skipWhitespace( 1 ); @@ -822,7 +812,11 @@ class Less_Parser { } } - // Match a regexp from the current start point + /** + * Match a regexp from the current start point + * + * @return array|null + */ private function MatchReg( $tok ) { if ( preg_match( $tok, $this->input, $match, 0, $this->pos ) ) { $this->skipWhitespace( strlen( $match[0] ) ); @@ -835,7 +829,7 @@ class Less_Parser { * just return the match. * * @param string $tok - * @return integer + * @return int|false */ public function PeekReg( $tok ) { return preg_match( $tok, $this->input, $match, 0, $this->pos ); @@ -845,12 +839,12 @@ class Less_Parser { * @param string $tok */ public function PeekChar( $tok ) { - // return ($this->input[$this->pos] === $tok ); return ( $this->pos < $this->input_len ) && ( $this->input[$this->pos] === $tok ); } /** - * @param integer $length + * @param int $length + * @see less-2.5.3.js#skipWhitespace */ public function skipWhitespace( $length ) { $this->pos += $length; @@ -868,8 +862,8 @@ class Less_Parser { * @param string $tok * @param string|null $msg */ - public function expect( $tok, $msg = NULL ) { - $result = $this->match( array( $tok ) ); + public function expect( $tok, $msg = null ) { + $result = $this->matcher( [ $tok ] ); if ( !$result ) { $this->Error( $msg ? "Expected '" . $tok . "' got '" . $this->input[$this->pos] . "'" : $msg ); } else { @@ -879,11 +873,12 @@ class Less_Parser { /** * @param string $tok + * @param string|null $msg */ public function expectChar( $tok, $msg = null ) { $result = $this->MatchChar( $tok ); if ( !$result ) { - $msg = $msg ? $msg : "Expected '" . $tok . "' got '" . $this->input[$this->pos] . "'"; + $msg = $msg ?: "Expected '" . $tok . "' got '" . $this->input[$this->pos] . "'"; $this->Error( $msg ); } else { return $result; @@ -935,8 +930,9 @@ class Less_Parser { // Only at one point is the primary rule not called from the // block rule: at the root level. // + // @see less-2.5.3.js#parsers.primary private function parsePrimary() { - $root = array(); + $root = []; while ( true ) { @@ -950,8 +946,16 @@ class Less_Parser { continue; } - // $node = $this->MatchFuncs( array( 'parseMixinDefinition', 'parseRule', 'parseRuleset', 'parseMixinCall', 'parseComment', 'parseDirective')); - $node = $this->MatchFuncs( array( 'parseMixinDefinition', 'parseNameValue', 'parseRule', 'parseRuleset', 'parseMixinCall', 'parseComment', 'parseRulesetCall', 'parseDirective' ) ); + $node = $this->MatchFuncs( [ + 'parseMixinDefinition', + 'parseNameValue', + 'parseRule', + 'parseRuleset', + 'parseMixinCall', + 'parseComment', + 'parseRulesetCall', + 'parseDirective' + ] ); if ( $node ) { $root[] = $node; @@ -977,18 +981,18 @@ class Less_Parser { if ( $this->input[$this->pos + 1] === '/' ) { $match = $this->MatchReg( '/\\G\/\/.*/' ); - return $this->NewObj4( 'Less_Tree_Comment', array( $match[0], true, $this->pos, $this->env->currentFileInfo ) ); + return $this->NewObj( 'Less_Tree_Comment', [ $match[0], true, $this->pos, $this->env->currentFileInfo ] ); } // $comment = $this->MatchReg('/\\G\/\*(?:[^*]|\*+[^\/*])*\*+\/\n?/'); $comment = $this->MatchReg( '/\\G\/\*(?s).*?\*+\/\n?/' );// not the same as less.js to prevent fatal errors if ( $comment ) { - return $this->NewObj4( 'Less_Tree_Comment', array( $comment[0], false, $this->pos, $this->env->currentFileInfo ) ); + return $this->NewObj( 'Less_Tree_Comment', [ $comment[0], false, $this->pos, $this->env->currentFileInfo ] ); } } private function parseComments() { - $comments = array(); + $comments = []; while ( $this->pos < $this->input_len ) { $comment = $this->parseComment(); @@ -1002,11 +1006,13 @@ class Less_Parser { return $comments; } - // - // A string, which supports escaping " and ' - // - // "milky way" 'he\'s the one!' - // + /** + * A string, which supports escaping " and ' + * + * "milky way" 'he\'s the one!' + * + * @return Less_Tree_Quoted|null + */ private function parseEntitiesQuoted() { $j = $this->pos; $e = false; @@ -1031,8 +1037,8 @@ class Less_Parser { return; } - $quoted = $char.$matched.$char; - return $this->NewObj5( 'Less_Tree_Quoted', array( $quoted, $matched, $e, $index, $this->env->currentFileInfo ) ); + $quoted = $char . $matched . $char; + return $this->NewObj( 'Less_Tree_Quoted', [ $quoted, $matched, $e, $index, $this->env->currentFileInfo ] ); } /** @@ -1071,11 +1077,13 @@ class Less_Parser { return false; } - // - // A catch-all word, such as: - // - // black border-collapse - // + /** + * A catch-all word, such as: + * + * black border-collapse + * + * @return Less_Tree_Keyword|Less_Tree_Color|null + */ private function parseEntitiesKeyword() { // $k = $this->MatchReg('/\\G[_A-Za-z-][_A-Za-z0-9-]*/'); $k = $this->MatchReg( '/\\G%|\\G[_A-Za-z-][_A-Za-z0-9-]*/' ); @@ -1085,7 +1093,7 @@ class Less_Parser { if ( $color ) { return $color; } - return $this->NewObj1( 'Less_Tree_Keyword', $k ); + return $this->NewObj( 'Less_Tree_Keyword', [ $k ] ); } } @@ -1095,11 +1103,11 @@ class Less_Parser { if ( Less_Colors::hasOwnProperty( $keyword ) ) { // detect named color - return $this->NewObj1( 'Less_Tree_Color', substr( Less_Colors::color( $keyword ), 1 ) ); + return $this->NewObj( 'Less_Tree_Color', [ substr( Less_Colors::color( $keyword ), 1 ) ] ); } if ( $keyword === 'transparent' ) { - return $this->NewObj3( 'Less_Tree_Color', array( array( 0, 0, 0 ), 0, true ) ); + return $this->NewObj( 'Less_Tree_Color', [ [ 0, 0, 0 ], 0, true ] ); } } @@ -1144,19 +1152,19 @@ class Less_Parser { } if ( $name ) { - return $this->NewObj4( 'Less_Tree_Call', array( $name, $args, $index, $this->env->currentFileInfo ) ); + return $this->NewObj( 'Less_Tree_Call', [ $name, $args, $index, $this->env->currentFileInfo ] ); } } /** * Parse a list of arguments * - * @return array + * @return array */ private function parseEntitiesArguments() { - $args = array(); + $args = []; while ( true ) { - $arg = $this->MatchFuncs( array( 'parseEntitiesAssignment','parseExpression' ) ); + $arg = $this->MatchFuncs( [ 'parseEntitiesAssignment', 'parseExpression' ] ); if ( !$arg ) { break; } @@ -1169,15 +1177,20 @@ class Less_Parser { return $args; } + /** @return Less_Tree_Dimension|Less_Tree_Color|Less_Tree_Quoted|Less_Tree_UnicodeDescriptor|null */ private function parseEntitiesLiteral() { - return $this->MatchFuncs( array( 'parseEntitiesDimension','parseEntitiesColor','parseEntitiesQuoted','parseUnicodeDescriptor' ) ); + return $this->MatchFuncs( [ 'parseEntitiesDimension','parseEntitiesColor','parseEntitiesQuoted','parseUnicodeDescriptor' ] ); } - // Assignments are argument entities for calls. - // They are present in ie filter properties as shown below. - // - // filter: progid:DXImageTransform.Microsoft.Alpha( *opacity=50* ) - // + /** + * Assignments are argument entities for calls. + * + * They are present in IE filter properties as shown below. + * + * filter: progid:DXImageTransform.Microsoft.Alpha( *opacity=50* ) + * + * @return Less_Tree_Assignment|null + */ private function parseEntitiesAssignment() { $key = $this->MatchReg( '/\\G\w+(?=\s?=)/' ); if ( !$key ) { @@ -1190,7 +1203,7 @@ class Less_Parser { $value = $this->parseEntity(); if ( $value ) { - return $this->NewObj2( 'Less_Tree_Assignment', array( $key[0], $value ) ); + return $this->NewObj( 'Less_Tree_Assignment', [ $key[0], $value ] ); } } @@ -1206,62 +1219,73 @@ class Less_Parser { return; } - $value = $this->match( array( 'parseEntitiesQuoted','parseEntitiesVariable','/\\Gdata\:.*?[^\)]+/','/\\G(?:(?:\\\\[\(\)\'"])|[^\(\)\'"])+/' ) ); + $value = $this->matcher( [ 'parseEntitiesQuoted','parseEntitiesVariable','/\\Gdata\:.*?[^\)]+/','/\\G(?:(?:\\\\[\(\)\'"])|[^\(\)\'"])+/' ] ); if ( !$value ) { $value = ''; } $this->expectChar( ')' ); + // @phan-suppress-next-line PhanUndeclaredProperty if ( isset( $value->value ) || $value instanceof Less_Tree_Variable ) { - return $this->NewObj2( 'Less_Tree_Url', array( $value, $this->env->currentFileInfo ) ); + return $this->NewObj( 'Less_Tree_Url', [ $value, $this->env->currentFileInfo ] ); } - return $this->NewObj2( 'Less_Tree_Url', array( $this->NewObj1( 'Less_Tree_Anonymous', $value ), $this->env->currentFileInfo ) ); + return $this->NewObj( 'Less_Tree_Url', [ $this->NewObj( 'Less_Tree_Anonymous', [ $value ] ), $this->env->currentFileInfo ] ); } - // - // A Variable entity, such as `@fink`, in - // - // width: @fink + 2px - // - // We use a different parser for variable definitions, - // see `parsers.variable`. - // + /** + * A Variable entity, such as `@fink`, in + * + * width: @fink + 2px + * + * We use a different parser for variable definitions, + * see `parsers.variable`. + * + * @return Less_Tree_Variable|null + */ private function parseEntitiesVariable() { $index = $this->pos; if ( $this->PeekChar( '@' ) && ( $name = $this->MatchReg( '/\\G@@?[\w-]+/' ) ) ) { - return $this->NewObj3( 'Less_Tree_Variable', array( $name[0], $index, $this->env->currentFileInfo ) ); + return $this->NewObj( 'Less_Tree_Variable', [ $name[0], $index, $this->env->currentFileInfo ] ); } } - // A variable entity using the protective {} e.g. @{var} + /** + * A variable entity using the protective `{}` e.g. `@{var}`. + * + * @return Less_Tree_Variable|null + */ private function parseEntitiesVariableCurly() { $index = $this->pos; if ( $this->input_len > ( $this->pos + 1 ) && $this->input[$this->pos] === '@' && ( $curly = $this->MatchReg( '/\\G@\{([\w-]+)\}/' ) ) ) { - return $this->NewObj3( 'Less_Tree_Variable', array( '@'.$curly[1], $index, $this->env->currentFileInfo ) ); + return $this->NewObj( 'Less_Tree_Variable', [ '@' . $curly[1], $index, $this->env->currentFileInfo ] ); } } - // - // A Hexadecimal color - // - // #4F3C2F - // - // `rgb` and `hsl` colors are parsed through the `entities.call` parser. - // + /** + * A Hexadecimal color + * + * #4F3C2F + * + * `rgb` and `hsl` colors are parsed through the `entities.call` parser. + * + * @return Less_Tree_Color|null + */ private function parseEntitiesColor() { if ( $this->PeekChar( '#' ) && ( $rgb = $this->MatchReg( '/\\G#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})/' ) ) ) { - return $this->NewObj1( 'Less_Tree_Color', $rgb[1] ); + return $this->NewObj( 'Less_Tree_Color', [ $rgb[1] ] ); } } - // - // A Dimension, that is, a number and a unit - // - // 0.5em 95% - // + /** + * A Dimension, that is, a number and a unit + * + * 0.5em 95% + * + * @return Less_Tree_Dimension|null + */ private function parseEntitiesDimension() { $c = @ord( $this->input[$this->pos] ); @@ -1272,23 +1296,24 @@ class Less_Parser { $value = $this->MatchReg( '/\\G([+-]?\d*\.?\d+)(%|[a-z]+)?/' ); if ( $value ) { - if ( isset( $value[2] ) ) { - return $this->NewObj2( 'Less_Tree_Dimension', array( $value[1],$value[2] ) ); + return $this->NewObj( 'Less_Tree_Dimension', [ $value[1],$value[2] ] ); } - return $this->NewObj1( 'Less_Tree_Dimension', $value[1] ); + return $this->NewObj( 'Less_Tree_Dimension', [ $value[1] ] ); } } - // - // A unicode descriptor, as is used in unicode-range - // - // U+0?? or U+00A1-00A9 - // + /** + * A unicode descriptor, as is used in unicode-range + * + * U+0?? or U+00A1-00A9 + * + * @return Less_Tree_UnicodeDescriptor|null + */ function parseUnicodeDescriptor() { $ud = $this->MatchReg( '/\\G(U\+[0-9a-fA-F?]+)(\-[0-9a-fA-F?]+)?/' ); if ( $ud ) { - return $this->NewObj1( 'Less_Tree_UnicodeDescriptor', $ud[0] ); + return $this->NewObj( 'Less_Tree_UnicodeDescriptor', [ $ud[0] ] ); } } @@ -1312,7 +1337,7 @@ class Less_Parser { } $str = $this->MatchReg( '/\\G`([^`]*)`/' ); if ( $str ) { - return $this->NewObj3( 'Less_Tree_Javascript', array( $str[1], $this->pos, $e ) ); + return $this->NewObj( 'Less_Tree_Javascript', [ $str[1], $this->pos, $e ] ); } } @@ -1334,7 +1359,7 @@ class Less_Parser { // private function parseRulesetCall() { if ( $this->input[$this->pos] === '@' && ( $name = $this->MatchReg( '/\\G(@[\w-]+)\s*\(\s*\)\s*;/' ) ) ) { - return $this->NewObj1( 'Less_Tree_RulesetCall', $name[1] ); + return $this->NewObj( 'Less_Tree_RulesetCall', [ $name[1] ] ); } } @@ -1343,20 +1368,22 @@ class Less_Parser { // function parseExtend( $isRule = false ) { $index = $this->pos; - $extendList = array(); + $extendList = []; - if ( !$this->MatchReg( $isRule ? '/\\G&:extend\(/' : '/\\G:extend\(/' ) ) { return; + if ( !$this->MatchReg( $isRule ? '/\\G&:extend\(/' : '/\\G:extend\(/' ) ) { + return; } - do{ + do { $option = null; - $elements = array(); + $elements = []; while ( true ) { $option = $this->MatchReg( '/\\G(all)(?=\s*(\)|,))/' ); if ( $option ) { break; } $e = $this->parseElement(); - if ( !$e ) { break; + if ( !$e ) { + break; } $elements[] = $e; } @@ -1365,9 +1392,9 @@ class Less_Parser { $option = $option[1]; } - $extendList[] = $this->NewObj3( 'Less_Tree_Extend', array( $this->NewObj1( 'Less_Tree_Selector', $elements ), $option, $index ) ); + $extendList[] = $this->NewObj( 'Less_Tree_Extend', [ $this->NewObj( 'Less_Tree_Selector', [ $elements ] ), $option, $index ] ); - }while ( $this->MatchChar( "," ) ); + } while ( $this->MatchChar( "," ) ); $this->expect( '/\\G\)/' ); @@ -1407,14 +1434,14 @@ class Less_Parser { $args = $returned['args']; $this->expectChar( ')' ); } else { - $args = array(); + $args = []; } $important = $this->parseImportant(); if ( $this->parseEnd() ) { $this->forget(); - return $this->NewObj5( 'Less_Tree_Mixin_Call', array( $elements, $args, $index, $this->env->currentFileInfo, $important ) ); + return $this->NewObj( 'Less_Tree_Mixin_Call', [ $elements, $args, $index, $this->env->currentFileInfo, $important ] ); } } @@ -1422,7 +1449,7 @@ class Less_Parser { } private function parseMixinCallElements() { - $elements = array(); + $elements = []; $c = null; while ( true ) { @@ -1431,7 +1458,7 @@ class Less_Parser { if ( !$e ) { break; } - $elements[] = $this->NewObj4( 'Less_Tree_Element', array( $c, $e[0], $elemIndex, $this->env->currentFileInfo ) ); + $elements[] = $this->NewObj( 'Less_Tree_Element', [ $c, $e[0], $elemIndex, $this->env->currentFileInfo ] ); $c = $this->MatchChar( '>' ); } @@ -1439,22 +1466,22 @@ class Less_Parser { } /** - * @param boolean $isCall + * @param bool $isCall */ private function parseMixinArgs( $isCall ) { - $expressions = array(); - $argsSemiColon = array(); + $expressions = []; + $argsSemiColon = []; $isSemiColonSeperated = null; - $argsComma = array(); + $argsComma = []; $expressionContainsNamed = null; $name = null; - $returner = array( 'args' => array(), 'variadic' => false ); + $returner = [ 'args' => [], 'variadic' => false ]; $this->save(); while ( true ) { if ( $isCall ) { - $arg = $this->MatchFuncs( array( 'parseDetachedRuleset','parseExpression' ) ); + $arg = $this->MatchFuncs( [ 'parseDetachedRuleset', 'parseExpression' ] ); } else { $this->parseComments(); if ( $this->input[ $this->pos ] === '.' && $this->MatchReg( '/\\G\.{3}/' ) ) { @@ -1464,14 +1491,15 @@ class Less_Parser { } if ( $isSemiColonSeperated ) { - $argsSemiColon[] = array( 'variadic' => true ); + $argsSemiColon[] = [ 'variadic' => true ]; } else { - $argsComma[] = array( 'variadic' => true ); + $argsComma[] = [ 'variadic' => true ]; } break; } - $arg = $this->MatchFuncs( array( 'parseEntitiesVariable','parseEntitiesLiteral','parseEntitiesKeyword' ) ); + $arg = $this->MatchFuncs( [ 'parseEntitiesVariable', 'parseEntitiesLiteral', 'parseEntitiesKeyword' ] ); } + '@phan-var Less_Tree_DetachedRuleset|Less_Tree_Expression|Less_Tree_Variable|Less_Tree_Dimension|Less_Tree_Color|Less_Tree_Quoted|Less_Tree_UnicodeDescriptor|Less_Tree_Keyword|null $arg'; if ( !$arg ) { break; @@ -1519,7 +1547,7 @@ class Less_Parser { $this->Error( 'could not understand value for named argument' ); } else { $this->restore(); - $returner['args'] = array(); + $returner['args'] = []; return $returner; } } @@ -1531,9 +1559,9 @@ class Less_Parser { $isSemiColonSeperated = true; } if ( $isSemiColonSeperated ) { - $argsSemiColon[] = array( 'name' => $arg->name, 'variadic' => true ); + $argsSemiColon[] = [ 'name' => $arg->name, 'variadic' => true ]; } else { - $argsComma[] = array( 'name' => $arg->name, 'variadic' => true ); + $argsComma[] = [ 'name' => $arg->name, 'variadic' => true ]; } break; } elseif ( !$isCall ) { @@ -1546,7 +1574,7 @@ class Less_Parser { $expressions[] = $value; } - $argsComma[] = array( 'name' => $nameLoop, 'value' => $value ); + $argsComma[] = [ 'name' => $nameLoop, 'value' => $value ]; if ( $this->MatchChar( ',' ) ) { continue; @@ -1561,12 +1589,12 @@ class Less_Parser { $isSemiColonSeperated = true; if ( count( $expressions ) > 1 ) { - $value = $this->NewObj1( 'Less_Tree_Value', $expressions ); + $value = $this->NewObj( 'Less_Tree_Value', [ $expressions ] ); } - $argsSemiColon[] = array( 'name' => $name, 'value' => $value ); + $argsSemiColon[] = [ 'name' => $name, 'value' => $value ]; $name = null; - $expressions = array(); + $expressions = []; $expressionContainsNamed = false; } } @@ -1599,6 +1627,7 @@ class Less_Parser { $cond = null; $char = $this->input[$this->pos]; + // TODO: Less.js doesn't limit this to $char == '{'. if ( ( $char !== '.' && $char !== '#' ) || ( $char === '{' && $this->PeekReg( '/\\G[^{]*\}/' ) ) ) { return; } @@ -1619,7 +1648,6 @@ class Less_Parser { // .mixincall(@a: {rule: set;}); // so we have to be nice and restore if ( !$this->MatchChar( ')' ) ) { - $this->furthest = $this->pos; $this->restore(); return; } @@ -1632,9 +1660,9 @@ class Less_Parser { $ruleset = $this->parseBlock(); - if ( is_array( $ruleset ) ) { + if ( $ruleset !== null ) { $this->forget(); - return $this->NewObj5( 'Less_Tree_Mixin_Definition', array( $name, $params, $ruleset, $cond, $variadic ) ); + return $this->NewObj( 'Less_Tree_Mixin_Definition', [ $name, $params, $ruleset, $cond, $variadic ] ); } $this->restore(); @@ -1648,7 +1676,7 @@ class Less_Parser { // and can be found inside a rule's value. // private function parseEntity() { - return $this->MatchFuncs( array( 'parseEntitiesLiteral','parseEntitiesVariable','parseEntitiesUrl','parseEntitiesCall','parseEntitiesKeyword','parseEntitiesJavascript','parseComment' ) ); + return $this->MatchFuncs( [ 'parseEntitiesLiteral','parseEntitiesVariable','parseEntitiesUrl','parseEntitiesCall','parseEntitiesKeyword','parseEntitiesJavascript','parseComment' ] ); } // @@ -1681,33 +1709,45 @@ class Less_Parser { } $this->expectChar( ')' ); - return $this->NewObj1( 'Less_Tree_Alpha', $value ); + return $this->NewObj( 'Less_Tree_Alpha', [ $value ] ); } - // - // A Selector Element - // - // div - // + h1 - // #socks - // input[type="text"] - // - // Elements are the building blocks for Selectors, - // they are made out of a `Combinator` (see combinator rule), - // and an element name, such as a tag a class, or `*`. - // + /** + * A Selector Element + * + * div + * + h1 + * #socks + * input[type="text"] + * + * Elements are the building blocks for Selectors, + * they are made out of a `Combinator` (see combinator rule), + * and an element name, such as a tag a class, or `*`. + * + * @return Less_Tree_Element|null + * @see less-2.5.3.js#parsers.element + */ private function parseElement() { $c = $this->parseCombinator(); $index = $this->pos; - $e = $this->match( array( '/\\G(?:\d+\.\d+|\d+)%/', '/\\G(?:[.#]?|:*)(?:[\w-]|[^\x00-\x9f]|\\\\(?:[A-Fa-f0-9]{1,6} ?|[^A-Fa-f0-9]))+/', - '#*', '#&', 'parseAttribute', '/\\G\([^()@]+\)/', '/\\G[\.#](?=@)/', 'parseEntitiesVariableCurly' ) ); + // TODO: Speed up by calling MatchChar directly, like less.js does + $e = $this->matcher( [ + '/\\G(?:\d+\.\d+|\d+)%/', + '/\\G(?:[.#]?|:*)(?:[\w-]|[^\x00-\x9f]|\\\\(?:[A-Fa-f0-9]{1,6} ?|[^A-Fa-f0-9]))+/', + '#*', + '#&', + 'parseAttribute', + '/\\G\([^&()@]+\)/', + '/\\G[\.#:](?=@)/', + 'parseEntitiesVariableCurly' + ] ); - if ( is_null( $e ) ) { + if ( $e === null ) { $this->save(); if ( $this->MatchChar( '(' ) ) { if ( ( $v = $this->parseSelector() ) && $this->MatchChar( ')' ) ) { - $e = $this->NewObj1( 'Less_Tree_Paren', $v ); + $e = $this->NewObj( 'Less_Tree_Paren', [ $v ] ); $this->forget(); } else { $this->restore(); @@ -1717,8 +1757,8 @@ class Less_Parser { } } - if ( !is_null( $e ) ) { - return $this->NewObj4( 'Less_Tree_Element', array( $c, $e, $index, $this->env->currentFileInfo ) ); + if ( $e !== null ) { + return $this->NewObj( 'Less_Tree_Element', [ $c, $e, $index, $this->env->currentFileInfo ] ); } } @@ -1730,9 +1770,11 @@ class Less_Parser { // as it's an empty space. We have to check the previous character // in the input, to see if it's a ` ` character. // + // @see less-2.5.3.js#parsers.combinator private function parseCombinator() { if ( $this->pos < $this->input_len ) { $c = $this->input[$this->pos]; + // TODO: Figure out why less.js also handles '/' here, and implement with regression test. if ( $c === '>' || $c === '+' || $c === '~' || $c === '|' || $c === '^' ) { $this->pos++; @@ -1752,25 +1794,31 @@ class Less_Parser { } } - // - // A CSS selector (see selector below) - // with less extensions e.g. the ability to extend and guard - // + /** + * A CSS selector (see selector below) + * with less extensions e.g. the ability to extend and guard + * + * @return Less_Tree_Selector|null + * @see less-2.5.3.js#parsers.lessSelector + */ private function parseLessSelector() { return $this->parseSelector( true ); } - // - // A CSS Selector - // - // .class > div + h1 - // li a:hover - // - // Selectors are made out of one or more Elements, see above. - // + /** + * A CSS Selector + * + * .class > div + h1 + * li a:hover + * + * Selectors are made out of one or more Elements, see ::parseElement. + * + * @return Less_Tree_Selector|null + * @see less-2.5.3.js#parsers.selector + */ private function parseSelector( $isLess = false ) { - $elements = array(); - $extendList = array(); + $elements = []; + $extendList = []; $condition = null; $when = false; $extend = false; @@ -1796,12 +1844,13 @@ class Less_Parser { $e = null; } - if ( $c === '{' || $c === '}' || $c === ';' || $c === ',' || $c === ')' ) { break; + if ( $c === '{' || $c === '}' || $c === ';' || $c === ',' || $c === ')' ) { + break; } } if ( $elements ) { - return $this->NewObj5( 'Less_Tree_Selector', array( $elements, $extendList, $condition, $index, $this->env->currentFileInfo ) ); + return $this->NewObj( 'Less_Tree_Selector', [ $elements, $extendList, $condition, $index, $this->env->currentFileInfo ] ); } if ( $extendList ) { $this->Error( 'Extend must be used to extend a selector, it cannot be used on its own' ); @@ -1826,18 +1875,21 @@ class Less_Parser { $op = $this->MatchReg( '/\\G[|~*$^]?=/' ); if ( $op ) { - $val = $this->match( array( 'parseEntitiesQuoted','/\\G[0-9]+%/','/\\G[\w-]+/','parseEntitiesVariableCurly' ) ); + $val = $this->matcher( [ 'parseEntitiesQuoted','/\\G[0-9]+%/','/\\G[\w-]+/','parseEntitiesVariableCurly' ] ); } $this->expectChar( ']' ); - return $this->NewObj3( 'Less_Tree_Attribute', array( $key, $op === null ? null : $op[0], $val ) ); + return $this->NewObj( 'Less_Tree_Attribute', [ $key, $op === null ? null : $op[0], $val ] ); } - // - // The `block` rule is used by `ruleset` and `mixin.definition`. - // It's a wrapper around the `primary` rule, with added `{}`. - // + /** + * The `block` rule is used by `ruleset` and `mixin.definition`. + * It's a wrapper around the `primary` rule, with added `{}`. + * + * @return array|null + * @see less-2.5.3.js#parsers.block + */ private function parseBlock() { if ( $this->MatchChar( '{' ) ) { $content = $this->parsePrimary(); @@ -1851,24 +1903,31 @@ class Less_Parser { $block = $this->parseBlock(); if ( $block ) { - $block = $this->NewObj2( 'Less_Tree_Ruleset', array( null, $block ) ); + $block = $this->NewObj( 'Less_Tree_Ruleset', [ null, $block ] ); } return $block; } + /** @return Less_Tree_DetachedRuleset|null */ private function parseDetachedRuleset() { $blockRuleset = $this->parseBlockRuleset(); if ( $blockRuleset ) { - return $this->NewObj1( 'Less_Tree_DetachedRuleset', $blockRuleset ); + return $this->NewObj( 'Less_Tree_DetachedRuleset', [ $blockRuleset ] ); } } - // - // div, .class, body > p {...} - // + /** + * Ruleset such as: + * + * div, .class, body > p { + * } + * + * @return Less_Tree_Ruleset|null + * @see less-2.5.3.js#parsers.ruleset + */ private function parseRuleset() { - $selectors = array(); + $selectors = []; $this->save(); @@ -1897,25 +1956,24 @@ class Less_Parser { $rules = $this->parseBlock(); if ( is_array( $rules ) ) { $this->forget(); - return $this->NewObj2( 'Less_Tree_Ruleset', array( $selectors, $rules ) ); // Less_Environment::$strictImports + // TODO: Less_Environment::$strictImports is not yet ported + // It is passed here by less.js + return $this->NewObj( 'Less_Tree_Ruleset', [ $selectors, $rules ] ); } } // Backtrack - $this->furthest = $this->pos; $this->restore(); } /** * Custom less.php parse function for finding simple name-value css pairs * ex: width:100px; - * */ private function parseNameValue() { $index = $this->pos; $this->save(); - // $match = $this->MatchReg('/\\G([a-zA-Z\-]+)\s*:\s*((?:\'")?[a-zA-Z0-9\-% \.,!]+?(?:\'")?)\s*([;}])/'); $match = $this->MatchReg( '/\\G([a-zA-Z\-]+)\s*:\s*([\'"]?[#a-zA-Z0-9\-%\.,]+?[\'"]?) *(! *important)?\s*([;}])/' ); if ( $match ) { @@ -1927,63 +1985,68 @@ class Less_Parser { $match[2] .= ' !important'; } - return $this->NewObj4( 'Less_Tree_NameValue', array( $match[1], $match[2], $index, $this->env->currentFileInfo ) ); + return $this->NewObj( 'Less_Tree_NameValue', [ $match[1], $match[2], $index, $this->env->currentFileInfo ] ); } $this->restore(); } + // @see less-2.5.3.js#parsers.rule private function parseRule( $tryAnonymous = null ) { - $merge = false; + $value = null; $startOfRule = $this->pos; - $c = $this->input[$this->pos]; + $important = null; + $merge = false; + + // TODO: Figure out why less.js also handles ':' here, and implement with regression test. if ( $c === '.' || $c === '#' || $c === '&' ) { return; } $this->save(); - $name = $this->MatchFuncs( array( 'parseVariable','parseRuleProperty' ) ); + $name = $this->MatchFuncs( [ 'parseVariable', 'parseRuleProperty' ] ); if ( $name ) { - $isVariable = is_string( $name ); - $value = null; if ( $isVariable ) { $value = $this->parseDetachedRuleset(); } - $important = null; if ( !$value ) { - - // prefer to try to parse first if its a variable or we are compressing - // but always fallback on the other one - //if( !$tryAnonymous && is_string($name) && $name[0] === '@' ){ - if ( !$tryAnonymous && ( Less_Parser::$options['compress'] || $isVariable ) ) { - $value = $this->MatchFuncs( array( 'parseValue','parseAnonymousValue' ) ); - } else { - $value = $this->MatchFuncs( array( 'parseAnonymousValue','parseValue' ) ); - } - - $important = $this->parseImportant(); - // a name returned by this.ruleProperty() is always an array of the form: // [string-1, ..., string-n, ""] or [string-1, ..., string-n, "+"] // where each item is a tree.Keyword or tree.Variable - if ( !$isVariable && is_array( $name ) ) { - $nm = array_pop( $name ); - if ( $nm->value ) { - $merge = $nm->value; + if ( !$isVariable && count( $name ) > 1 ) { + $merge = array_pop( $name )->value; + } + + // prefer to try to parse first if its a variable or we are compressing + // but always fallback on the other one + $tryValueFirst = ( !$tryAnonymous && ( self::$options['compress'] || $isVariable ) ); + if ( $tryValueFirst ) { + $value = $this->parseValue(); + } + if ( !$value ) { + $value = $this->parseAnonymousValue(); + if ( $value ) { + $this->forget(); + // anonymous values absorb the end ';' which is required for them to work + return $this->NewObj( 'Less_Tree_Rule', [ $name, $value, false, $merge, $startOfRule, $this->env->currentFileInfo ] ); } } + if ( !$tryValueFirst && !$value ) { + $value = $this->parseValue(); + } + + $important = $this->parseImportant(); } if ( $value && $this->parseEnd() ) { $this->forget(); - return $this->NewObj6( 'Less_Tree_Rule', array( $name, $value, $important, $merge, $startOfRule, $this->env->currentFileInfo ) ); + return $this->NewObj( 'Less_Tree_Rule', [ $name, $value, $important, $merge, $startOfRule, $this->env->currentFileInfo ] ); } else { - $this->furthest = $this->pos; $this->restore(); if ( $value && !$tryAnonymous ) { return $this->parseRule( true ); @@ -1995,9 +2058,9 @@ class Less_Parser { } function parseAnonymousValue() { - if ( preg_match( '/\\G([^@+\/\'"*`(;{}-]*);/', $this->input, $match, 0, $this->pos ) ) { - $this->pos += strlen( $match[1] ); - return $this->NewObj1( 'Less_Tree_Anonymous', $match[1] ); + $match = $this->MatchReg( '/\\G([^@+\/\'"*`(;{}-]*);/' ); + if ( $match ) { + return $this->NewObj( 'Less_Tree_Anonymous', [ $match[1] ] ); } } @@ -2018,17 +2081,17 @@ class Less_Parser { if ( $dir ) { $options = $this->parseImportOptions(); - $path = $this->MatchFuncs( array( 'parseEntitiesQuoted','parseEntitiesUrl' ) ); + $path = $this->MatchFuncs( [ 'parseEntitiesQuoted','parseEntitiesUrl' ] ); if ( $path ) { $features = $this->parseMediaFeatures(); if ( $this->MatchChar( ';' ) ) { if ( $features ) { - $features = $this->NewObj1( 'Less_Tree_Value', $features ); + $features = $this->NewObj( 'Less_Tree_Value', [ $features ] ); } $this->forget(); - return $this->NewObj5( 'Less_Tree_Import', array( $path, $features, $options, $this->pos, $this->env->currentFileInfo ) ); + return $this->NewObj( 'Less_Tree_Import', [ $path, $features, $options, $this->pos, $this->env->currentFileInfo ] ); } } } @@ -2037,7 +2100,7 @@ class Less_Parser { } private function parseImportOptions() { - $options = array(); + $options = []; // list of options, surrounded by parens if ( !$this->MatchChar( '(' ) ) { @@ -2074,10 +2137,10 @@ class Less_Parser { } private function parseMediaFeature() { - $nodes = array(); + $nodes = []; do{ - $e = $this->MatchFuncs( array( 'parseEntitiesKeyword','parseEntitiesVariable' ) ); + $e = $this->MatchFuncs( [ 'parseEntitiesKeyword','parseEntitiesVariable' ] ); if ( $e ) { $nodes[] = $e; } elseif ( $this->MatchChar( '(' ) ) { @@ -2085,50 +2148,62 @@ class Less_Parser { $e = $this->parseValue(); if ( $this->MatchChar( ')' ) ) { if ( $p && $e ) { - $r = $this->NewObj7( 'Less_Tree_Rule', array( $p, $e, null, null, $this->pos, $this->env->currentFileInfo, true ) ); - $nodes[] = $this->NewObj1( 'Less_Tree_Paren', $r ); + $r = $this->NewObj( 'Less_Tree_Rule', [ $p, $e, null, null, $this->pos, $this->env->currentFileInfo, true ] ); + $nodes[] = $this->NewObj( 'Less_Tree_Paren', [ $r ] ); } elseif ( $e ) { - $nodes[] = $this->NewObj1( 'Less_Tree_Paren', $e ); + $nodes[] = $this->NewObj( 'Less_Tree_Paren', [ $e ] ); } else { return null; } - } else return null; - } - } while ( $e ); - - if ( $nodes ) { - return $this->NewObj1( 'Less_Tree_Expression', $nodes ); - } - } - - private function parseMediaFeatures() { - $features = array(); - - do{ - $e = $this->parseMediaFeature(); - if ( $e ) { - $features[] = $e; - if ( !$this->MatchChar( ',' ) ) break; - } else { - $e = $this->parseEntitiesVariable(); - if ( $e ) { - $features[] = $e; - if ( !$this->MatchChar( ',' ) ) break; + } else { + return null; } } } while ( $e ); - return $features ? $features : null; + if ( $nodes ) { + return $this->NewObj( 'Less_Tree_Expression', [ $nodes ] ); + } + } + + private function parseMediaFeatures() { + $features = []; + + do { + $e = $this->parseMediaFeature(); + if ( $e ) { + $features[] = $e; + if ( !$this->MatchChar( ',' ) ) { + break; + } + } else { + $e = $this->parseEntitiesVariable(); + if ( $e ) { + $features[] = $e; + if ( !$this->MatchChar( ',' ) ) { + break; + } + } + } + } while ( $e ); + + return $features ?: null; } private function parseMedia() { if ( $this->MatchReg( '/\\G@media/' ) ) { + $this->save(); + $features = $this->parseMediaFeatures(); $rules = $this->parseBlock(); - if ( is_array( $rules ) ) { - return $this->NewObj4( 'Less_Tree_Media', array( $rules, $features, $this->pos, $this->env->currentFileInfo ) ); + if ( $rules === null ) { + $this->restore(); + return; } + + $this->forget(); + return $this->NewObj( 'Less_Tree_Media', [ $rules, $features, $this->pos, $this->env->currentFileInfo ] ); } } @@ -2149,7 +2224,10 @@ class Less_Parser { $hasExpression = false; $hasUnknown = false; - $value = $this->MatchFuncs( array( 'parseImport','parseMedia' ) ); + $value = $this->MatchFuncs( [ + 'parseImport', + 'parseMedia' + ] ); if ( $value ) { return $value; } @@ -2158,7 +2236,9 @@ class Less_Parser { $name = $this->MatchReg( '/\\G@[a-z-]+/' ); - if ( !$name ) return; + if ( !$name ) { + return; + } $name = $name[0]; $nonVendorSpecificName = $name; @@ -2214,16 +2294,16 @@ class Less_Parser { if ( !$value ) { $this->error( "expected " . $name . " identifier" ); } - } else if ( $hasExpression ) { + } elseif ( $hasExpression ) { $value = $this->parseExpression(); if ( !$value ) { - $this->error( "expected " . $name. " expression" ); + $this->error( "expected " . $name . " expression" ); } - } else if ( $hasUnknown ) { + } elseif ( $hasUnknown ) { $value = $this->MatchReg( '/\\G[^{;]+/' ); if ( $value ) { - $value = $this->NewObj1( 'Less_Tree_Anonymous', trim( $value[0] ) ); + $value = $this->NewObj( 'Less_Tree_Anonymous', [ trim( $value[0] ) ] ); } } @@ -2233,7 +2313,7 @@ class Less_Parser { if ( $rules || ( !$hasBlock && $value && $this->MatchChar( ';' ) ) ) { $this->forget(); - return $this->NewObj5( 'Less_Tree_Directive', array( $name, $value, $rules, $index, $this->env->currentFileInfo ) ); + return $this->NewObj( 'Less_Tree_Directive', [ $name, $value, $rules, $index, $this->env->currentFileInfo ] ); } $this->restore(); @@ -2248,7 +2328,7 @@ class Less_Parser { // and before the `;`. // private function parseValue() { - $expressions = array(); + $expressions = []; do{ $e = $this->parseExpression(); @@ -2258,10 +2338,10 @@ class Less_Parser { break; } } - }while ( $e ); + } while ( $e ); if ( $expressions ) { - return $this->NewObj1( 'Less_Tree_Value', $expressions ); + return $this->NewObj( 'Less_Tree_Value', [ $expressions ] ); } } @@ -2276,7 +2356,7 @@ class Less_Parser { $a = $this->parseAddition(); if ( $a ) { $this->expectChar( ')' ); - return $this->NewObj2( 'Less_Tree_Expression', array( array( $a ), true ) ); // instead of $e->parens = true so the value is cached + return $this->NewObj( 'Less_Tree_Expression', [ [ $a ], true ] ); // instead of $e->parens = true so the value is cached } } } @@ -2312,11 +2392,10 @@ class Less_Parser { $m->parensInOp = true; $a->parensInOp = true; - $return = $this->NewObj3( 'Less_Tree_Operation', array( $op, array( $return, $a ), $isSpaced ) ); + $return = $this->NewObj( 'Less_Tree_Operation', [ $op, [ $return, $a ], $isSpaced ] ); } } return $return; - } /** @@ -2336,7 +2415,7 @@ class Less_Parser { $op = $op[0]; } else { if ( !$isSpaced ) { - $op = $this->match( array( '#+','#-' ) ); + $op = $this->matcher( [ '#+','#-' ] ); } if ( !$op ) { break; @@ -2350,7 +2429,7 @@ class Less_Parser { $m->parensInOp = true; $a->parensInOp = true; - $return = $this->NewObj3( 'Less_Tree_Operation', array( $op, array( $return, $a ), $isSpaced ) ); + $return = $this->NewObj( 'Less_Tree_Operation', [ $op, [ $return, $a ], $isSpaced ] ); } } @@ -2375,7 +2454,7 @@ class Less_Parser { break; } - $return = $this->NewObj4( 'Less_Tree_Condition', array( 'or', $return, $b, $index ) ); + $return = $this->NewObj( 'Less_Tree_Condition', [ 'or', $return, $b, $index ] ); } return $return; } @@ -2386,32 +2465,34 @@ class Less_Parser { $negate = false; $c = null; - if ( $this->MatchReg( '/\\Gnot/' ) ) $negate = true; + if ( $this->MatchReg( '/\\Gnot/' ) ) { + $negate = true; + } $this->expectChar( '(' ); - $a = $this->MatchFuncs( array( 'parseAddition','parseEntitiesKeyword','parseEntitiesQuoted' ) ); + $a = $this->MatchFuncs( [ 'parseAddition','parseEntitiesKeyword','parseEntitiesQuoted' ] ); if ( $a ) { $op = $this->MatchReg( '/\\G(?:>=|<=|=<|[<=>])/' ); if ( $op ) { - $b = $this->MatchFuncs( array( 'parseAddition','parseEntitiesKeyword','parseEntitiesQuoted' ) ); + $b = $this->MatchFuncs( [ 'parseAddition','parseEntitiesKeyword','parseEntitiesQuoted' ] ); if ( $b ) { - $c = $this->NewObj5( 'Less_Tree_Condition', array( $op[0], $a, $b, $index, $negate ) ); + $c = $this->NewObj( 'Less_Tree_Condition', [ $op[0], $a, $b, $index, $negate ] ); } else { $this->Error( 'Unexpected expression' ); } } else { - $k = $this->NewObj1( 'Less_Tree_Keyword', 'true' ); - $c = $this->NewObj5( 'Less_Tree_Condition', array( '=', $a, $k, $index, $negate ) ); + $k = $this->NewObj( 'Less_Tree_Keyword', [ 'true' ] ); + $c = $this->NewObj( 'Less_Tree_Condition', [ '=', $a, $k, $index, $negate ] ); } $this->expectChar( ')' ); - return $this->MatchReg( '/\\Gand/' ) ? $this->NewObj3( 'Less_Tree_Condition', array( 'and', $c, $this->parseCondition() ) ) : $c; + // @phan-suppress-next-line PhanPossiblyInfiniteRecursionSameParams + return $this->MatchReg( '/\\Gand/' ) ? $this->NewObj( 'Less_Tree_Condition', [ 'and', $c, $this->parseCondition() ] ) : $c; } } /** * An operand is anything that can be part of an operation, * such as a Color, or a Variable - * */ private function parseOperand() { $negate = false; @@ -2424,11 +2505,11 @@ class Less_Parser { $negate = $this->MatchChar( '-' ); } - $o = $this->MatchFuncs( array( 'parseSub','parseEntitiesDimension','parseEntitiesColor','parseEntitiesVariable','parseEntitiesCall' ) ); + $o = $this->MatchFuncs( [ 'parseSub','parseEntitiesDimension','parseEntitiesColor','parseEntitiesVariable','parseEntitiesCall' ] ); if ( $negate ) { $o->parensInOp = true; - $o = $this->NewObj1( 'Less_Tree_Negative', $o ); + $o = $this->NewObj( 'Less_Tree_Negative', [ $o ] ); } return $o; @@ -2438,30 +2519,27 @@ class Less_Parser { * Expressions either represent mathematical operations, * or white-space delimited Entities. * - * 1px solid black - * @var * 2 - * * @return Less_Tree_Expression|null */ private function parseExpression() { - $entities = array(); + $entities = []; - do{ - $e = $this->MatchFuncs( array( 'parseAddition','parseEntity' ) ); + do { + $e = $this->MatchFuncs( [ 'parseAddition','parseEntity' ] ); if ( $e ) { $entities[] = $e; // operations do not allow keyword "/" dimension (e.g. small/20px) so we support that here if ( !$this->PeekReg( '/\\G\/[\/*]/' ) ) { $delim = $this->MatchChar( '/' ); if ( $delim ) { - $entities[] = $this->NewObj1( 'Less_Tree_Anonymous', $delim ); + $entities[] = $this->NewObj( 'Less_Tree_Anonymous', [ $delim ] ); } } } - }while ( $e ); + } while ( $e ); if ( $entities ) { - return $this->NewObj1( 'Less_Tree_Expression', $entities ); + return $this->NewObj( 'Less_Tree_Expression', [ $entities ] ); } } @@ -2482,45 +2560,55 @@ class Less_Parser { * Parse a rule property * eg: 'color', 'width', 'height', etc * - * @return string + * @return array */ private function parseRuleProperty() { - $offset = $this->pos; - $name = array(); - $index = array(); - $length = 0; + $name = []; + $index = []; - $this->rulePropertyMatch( '/\\G(\*?)/', $offset, $length, $index, $name ); - while ( $this->rulePropertyMatch( '/\\G((?:[\w-]+)|(?:@\{[\w-]+\}))/', $offset, $length, $index, $name ) ); // ! + $this->save(); + + $simpleProperty = $this->MatchReg( '/\\G([_a-zA-Z0-9-]+)\s*:/' ); + if ( $simpleProperty ) { + $name[] = $this->NewObj( 'Less_Tree_Keyword', [ $simpleProperty[1] ] ); + $this->forget(); + return $name; + } + + $this->rulePropertyMatch( '/\\G(\*?)/', $index, $name ); + + // Consume! + // @phan-suppress-next-line PhanPluginEmptyStatementWhileLoop + while ( $this->rulePropertyMatch( '/\\G((?:[\w-]+)|(?:@\{[\w-]+\}))/', $index, $name ) ); + + if ( ( count( $name ) > 1 ) && $this->rulePropertyMatch( '/\\G\s*((?:\+_|\+)?)\s*:/', $index, $name ) ) { + $this->forget(); - if ( ( count( $name ) > 1 ) && $this->rulePropertyMatch( '/\\G\s*((?:\+_|\+)?)\s*:/', $offset, $length, $index, $name ) ) { // at last, we have the complete match now. move forward, // convert name particles to tree objects and return: - $this->skipWhitespace( $length ); - if ( $name[0] === '' ) { array_shift( $name ); array_shift( $index ); } foreach ( $name as $k => $s ) { if ( !$s || $s[0] !== '@' ) { - $name[$k] = $this->NewObj1( 'Less_Tree_Keyword', $s ); + $name[$k] = $this->NewObj( 'Less_Tree_Keyword', [ $s ] ); } else { - $name[$k] = $this->NewObj3( 'Less_Tree_Variable', array( '@' . substr( $s, 2, -1 ), $index[$k], $this->env->currentFileInfo ) ); + $name[$k] = $this->NewObj( 'Less_Tree_Variable', [ '@' . substr( $s, 2, -1 ), $index[$k], $this->env->currentFileInfo ] ); } } return $name; + } else { + $this->restore(); } - } - private function rulePropertyMatch( $re, &$offset, &$length, &$index, &$name ) { - preg_match( $re, $this->input, $a, 0, $offset ); - if ( $a ) { - $index[] = $this->pos + $length; - $length += strlen( $a[0] ); - $offset += strlen( $a[0] ); - $name[] = $a[1]; + private function rulePropertyMatch( $re, &$index, &$name ) { + $i = $this->pos; + $chunk = $this->MatchReg( $re ); + if ( $chunk ) { + $index[] = $i; + $name[] = $chunk[1]; return true; } } @@ -2529,15 +2617,16 @@ class Less_Parser { $s = ''; foreach ( $vars as $name => $value ) { - $s .= ( ( $name[0] === '@' ) ? '' : '@' ) . $name .': '. $value . ( ( substr( $value, -1 ) === ';' ) ? '' : ';' ); + $s .= ( ( $name[0] === '@' ) ? '' : '@' ) . $name . ': ' . $value . ( ( substr( $value, -1 ) === ';' ) ? '' : ';' ); } return $s; } /** - * Some versions of php have trouble with method_exists($a,$b) if $a is not an object + * Some versions of PHP have trouble with method_exists($a,$b) if $a is not an object * + * @param mixed $a * @param string $b */ public static function is_method( $a, $b ) { @@ -2547,11 +2636,10 @@ class Less_Parser { /** * Round numbers similarly to javascript * eg: 1.499999 to 1 instead of 2 - * */ - public static function round( $i, $precision = 0 ) { + public static function round( $input, $precision = 0 ) { $precision = pow( 10, $precision ); - $i = $i * $precision; + $i = $input * $precision; $ceil = ceil( $i ); $floor = floor( $i ); @@ -2563,83 +2651,32 @@ class Less_Parser { } /** - * Create Less_Tree_* objects and optionally generate a cache string + * Create a new instance of $class with args $args, and optionally generates a cache string. + * $class should be a Less_Tree_* class. * - * @return mixed + * @phan-template TClassName + * @phan-param class-string $class + * @phan-param array $args + * @phan-return TClassName + * + * @param string $class + * @param mixed[] $args + * @return Less_Tree Instance of $class subclass created with $args */ - public function NewObj0( $class ) { - $obj = new $class(); + public function NewObj( $class, $args = [] ) { + $obj = new $class( ...$args ); if ( $this->CacheEnabled() ) { - $obj->cache_string = ' new '.$class.'()'; + $argStrings = array_map( + [ __CLASS__, 'ArgString' ], + $args + ); + $argCache = implode( ',', $argStrings ); + // @phan-suppress-next-line PhanTypeExpectedObjectPropAccess False positive + $obj->cache_string = " new $class($argCache)"; } return $obj; } - public function NewObj1( $class, $arg ) { - $obj = new $class( $arg ); - if ( $this->CacheEnabled() ) { - $obj->cache_string = ' new '.$class.'('.Less_Parser::ArgString( $arg ).')'; - } - return $obj; - } - - public function NewObj2( $class, $args ) { - $obj = new $class( $args[0], $args[1] ); - if ( $this->CacheEnabled() ) { - $this->ObjCache( $obj, $class, $args ); - } - return $obj; - } - - public function NewObj3( $class, $args ) { - $obj = new $class( $args[0], $args[1], $args[2] ); - if ( $this->CacheEnabled() ) { - $this->ObjCache( $obj, $class, $args ); - } - return $obj; - } - - public function NewObj4( $class, $args ) { - $obj = new $class( $args[0], $args[1], $args[2], $args[3] ); - if ( $this->CacheEnabled() ) { - $this->ObjCache( $obj, $class, $args ); - } - return $obj; - } - - public function NewObj5( $class, $args ) { - $obj = new $class( $args[0], $args[1], $args[2], $args[3], $args[4] ); - if ( $this->CacheEnabled() ) { - $this->ObjCache( $obj, $class, $args ); - } - return $obj; - } - - public function NewObj6( $class, $args ) { - $obj = new $class( $args[0], $args[1], $args[2], $args[3], $args[4], $args[5] ); - if ( $this->CacheEnabled() ) { - $this->ObjCache( $obj, $class, $args ); - } - return $obj; - } - - public function NewObj7( $class, $args ) { - $obj = new $class( $args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6] ); - if ( $this->CacheEnabled() ) { - $this->ObjCache( $obj, $class, $args ); - } - return $obj; - } - - // caching - public function ObjCache( $obj, $class, $args = array() ) { - $obj->cache_string = ' new '.$class.'('. self::ArgCache( $args ).')'; - } - - public function ArgCache( $args ) { - return implode( ',', array_map( array( 'Less_Parser','ArgString' ), $args ) ); - } - /** * Convert an argument to a string for use in the parser cache * @@ -2656,7 +2693,7 @@ class Less_Parser { } elseif ( $type === 'array' ) { $string = ' Array('; foreach ( $arg as $k => $a ) { - $string .= var_export( $k, true ).' => '.self::ArgString( $a ).','; + $string .= var_export( $k, true ) . ' => ' . self::ArgString( $a ) . ','; } return $string . ')'; } @@ -2664,6 +2701,7 @@ class Less_Parser { return var_export( $arg, true ); } + /** @return never */ public function Error( $msg ) { throw new Less_Exception_Parser( $msg, null, $this->furthest, $this->env->currentFileInfo ); } @@ -2673,7 +2711,7 @@ class Less_Parser { } public static function AbsPath( $path, $winPath = false ) { - if ( strpos( $path, '//' ) !== false && preg_match( '_^(https?:)?//\\w+(\\.\\w+)+/\\w+_i', $path ) ) { + if ( strpos( $path, '//' ) !== false && preg_match( '/^(https?:)?\/\//i', $path ) ) { return $winPath ? '' : false; } else { $path = realpath( $path ); @@ -2685,7 +2723,7 @@ class Less_Parser { } public function CacheEnabled() { - return ( Less_Parser::$options['cache_method'] && ( Less_Cache::$cache_dir || ( Less_Parser::$options['cache_method'] == 'callback' ) ) ); + return ( self::$options['cache_method'] && ( Less_Cache::$cache_dir || ( self::$options['cache_method'] == 'callback' ) ) ); } } diff --git a/vendor/wikimedia/less.php/lib/Less/SourceMap/Base64VLQ.php b/vendor/wikimedia/less.php/lib/Less/SourceMap/Base64VLQ.php index 989a4ce..c27c6ed 100644 --- a/vendor/wikimedia/less.php/lib/Less/SourceMap/Base64VLQ.php +++ b/vendor/wikimedia/less.php/lib/Less/SourceMap/Base64VLQ.php @@ -1,31 +1,29 @@ 0, 'B' => 1, 'C' => 2, 'D' => 3, 'E' => 4, 'F' => 5, 'G' => 6, 'H' => 7,'I' => 8, 'J' => 9, 'K' => 10, 'L' => 11, 'M' => 12, 'N' => 13, 'O' => 14, 'P' => 15, 'Q' => 16, 'R' => 17, 'S' => 18, 'T' => 19, 'U' => 20, @@ -44,14 +42,14 @@ class Less_SourceMap_Base64VLQ { 'q' => 42, 'r' => 43, 's' => 44, 't' => 45, 'u' => 46, 'v' => 47, 'w' => 48, 'x' => 49, 'y' => 50, 'z' => 51, 0 => 52, 1 => 53, 2 => 54, 3 => 55, 4 => 56, 5 => 57, 6 => 58, 7 => 59, 8 => 60, 9 => 61, '+' => 62, '/' => 63, - ); + ]; /** * Integer to char map * * @var array */ - private $intToCharMap = array( + private $intToCharMap = [ 0 => 'A', 1 => 'B', 2 => 'C', 3 => 'D', 4 => 'E', 5 => 'F', 6 => 'G', 7 => 'H', 8 => 'I', 9 => 'J', 10 => 'K', 11 => 'L', 12 => 'M', 13 => 'N', 14 => 'O', 15 => 'P', 16 => 'Q', 17 => 'R', 18 => 'S', 19 => 'T', 20 => 'U', @@ -62,7 +60,7 @@ class Less_SourceMap_Base64VLQ { 49 => 'x', 50 => 'y', 51 => 'z', 52 => '0', 53 => '1', 54 => '2', 55 => '3', 56 => '4', 57 => '5', 58 => '6', 59 => '7', 60 => '8', 61 => '9', 62 => '+', 63 => '/', - ); + ]; /** * Constructor @@ -83,7 +81,7 @@ class Less_SourceMap_Base64VLQ { * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary) * We generate the value for 32 bit machines, hence -2147483648 becomes 1, not 4294967297, * even on a 64 bit machine. - * @param string $aValue + * @param int $aValue */ public function toVLQSigned( $aValue ) { return 0xffffffff & ( $aValue < 0 ? ( ( -$aValue ) << 1 ) + 1 : ( $aValue << 1 ) + 0 ); @@ -98,7 +96,7 @@ class Less_SourceMap_Base64VLQ { * Hence * 1 becomes -2147483648 * even on a 64 bit machine. - * @param integer $aValue + * @param int $aValue */ public function fromVLQSigned( $aValue ) { return $aValue & 1 ? $this->zeroFill( ~$aValue + 2, 1 ) | ( -1 - 0x7fffffff ) : $this->zeroFill( $aValue, 1 ); @@ -107,7 +105,7 @@ class Less_SourceMap_Base64VLQ { /** * Return the base 64 VLQ encoded value. * - * @param string $aValue The value to encode + * @param int $aValue The value to encode * @return string The encoded value */ public function encode( $aValue ) { @@ -130,7 +128,7 @@ class Less_SourceMap_Base64VLQ { * Return the value decoded from base 64 VLQ. * * @param string $encoded The encoded value to decode - * @return integer The decoded value + * @return int The decoded value */ public function decode( $encoded ) { $vlq = 0; @@ -148,9 +146,9 @@ class Less_SourceMap_Base64VLQ { /** * Right shift with zero fill. * - * @param integer $a number to shift - * @param integer $b number of bits to shift - * @return integer + * @param int $a number to shift + * @param int $b number of bits to shift + * @return int */ public function zeroFill( $a, $b ) { return ( $a >= 0 ) ? ( $a >> $b ) : ( $a >> $b ) & ( PHP_INT_MAX >> ( $b - 1 ) ); @@ -159,13 +157,13 @@ class Less_SourceMap_Base64VLQ { /** * Encode single 6-bit digit as base64. * - * @param integer $number + * @param int $number * @return string * @throws Exception If the number is invalid */ public function base64Encode( $number ) { if ( $number < 0 || $number > 63 ) { - throw new Exception( sprintf( 'Invalid number "%s" given. Must be between 0 and 63.', $number ) ); + throw new Exception( sprintf( 'Invalid number "%s" given. Must be between 0 and 63.', (string)$number ) ); } return $this->intToCharMap[$number]; } @@ -174,7 +172,7 @@ class Less_SourceMap_Base64VLQ { * Decode single 6-bit digit from base64 * * @param string $char - * @return number + * @return int * @throws Exception If the number is invalid */ public function base64Decode( $char ) { diff --git a/vendor/wikimedia/less.php/lib/Less/SourceMap/Generator.php b/vendor/wikimedia/less.php/lib/Less/SourceMap/Generator.php index eded501..7da9609 100644 --- a/vendor/wikimedia/less.php/lib/Less/SourceMap/Generator.php +++ b/vendor/wikimedia/less.php/lib/Less/SourceMap/Generator.php @@ -1,10 +1,8 @@ '' - ); + ]; /** * The base64 VLQ encoder @@ -55,7 +53,7 @@ class Less_SourceMap_Generator extends Less_Configurable { * * @var array */ - protected $mappings = array(); + protected $mappings = []; /** * The root node @@ -69,23 +67,24 @@ class Less_SourceMap_Generator extends Less_Configurable { * * @var array */ - protected $contentsMap = array(); + protected $contentsMap = []; /** * File to content map * * @var array */ - protected $sources = array(); - protected $source_keys = array(); + protected $sources = []; + protected $source_keys = []; /** * Constructor * * @param Less_Tree_Ruleset $root The root node + * @param array $contentsMap * @param array $options Array of options */ - public function __construct( Less_Tree_Ruleset $root, $contentsMap, $options = array() ) { + public function __construct( Less_Tree_Ruleset $root, $contentsMap, $options = [] ) { $this->root = $root; $this->contentsMap = $contentsMap; $this->encoder = new Less_SourceMap_Base64VLQ(); @@ -182,20 +181,20 @@ class Less_SourceMap_Generator extends Less_Configurable { /** * Adds a mapping * - * @param integer $generatedLine The line number in generated file - * @param integer $generatedColumn The column number in generated file - * @param integer $originalLine The line number in original file - * @param integer $originalColumn The column number in original file - * @param string $sourceFile The original source file + * @param int $generatedLine The line number in generated file + * @param int $generatedColumn The column number in generated file + * @param int $originalLine The line number in original file + * @param int $originalColumn The column number in original file + * @param array $fileInfo The original source file */ public function addMapping( $generatedLine, $generatedColumn, $originalLine, $originalColumn, $fileInfo ) { - $this->mappings[] = array( + $this->mappings[] = [ 'generated_line' => $generatedLine, 'generated_column' => $generatedColumn, 'original_line' => $originalLine, 'original_column' => $originalColumn, 'source_file' => $fileInfo['currentUri'] - ); + ]; $this->sources[$fileInfo['currentUri']] = $fileInfo['filename']; } @@ -207,7 +206,7 @@ class Less_SourceMap_Generator extends Less_Configurable { * @see https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit# */ protected function generateJson() { - $sourceMap = array(); + $sourceMap = []; $mappings = $this->generateMappings(); // File version (always the first entry in the object) and must be a positive integer. @@ -226,13 +225,13 @@ class Less_SourceMap_Generator extends Less_Configurable { } // A list of original sources used by the 'mappings' entry. - $sourceMap['sources'] = array(); + $sourceMap['sources'] = []; foreach ( $this->sources as $source_uri => $source_filename ) { $sourceMap['sources'][] = $this->normalizeFilename( $source_filename ); } // A list of symbol names used by the 'mappings' entry. - $sourceMap['names'] = array(); + $sourceMap['names'] = []; // A string with the encoded mapping data. $sourceMap['mappings'] = $mappings; @@ -261,7 +260,7 @@ class Less_SourceMap_Generator extends Less_Configurable { if ( empty( $this->sources ) ) { return; } - $content = array(); + $content = []; foreach ( $this->sources as $sourceFile ) { $content[] = file_get_contents( $sourceFile ); } @@ -281,7 +280,7 @@ class Less_SourceMap_Generator extends Less_Configurable { $this->source_keys = array_flip( array_keys( $this->sources ) ); // group mappings by generated line number. - $groupedMap = $groupedMapEncoded = array(); + $groupedMap = $groupedMapEncoded = []; foreach ( $this->mappings as $m ) { $groupedMap[$m['generated_line']][] = $m; } @@ -294,7 +293,7 @@ class Less_SourceMap_Generator extends Less_Configurable { $groupedMapEncoded[] = ';'; } - $lineMapEncoded = array(); + $lineMapEncoded = []; $lastGeneratedColumn = 0; foreach ( $line_map as $m ) { @@ -330,7 +329,7 @@ class Less_SourceMap_Generator extends Less_Configurable { * Finds the index for the filename * * @param string $filename - * @return integer|false + * @return int|false */ protected function findFileIndex( $filename ) { return $this->source_keys[$filename]; @@ -339,6 +338,7 @@ class Less_SourceMap_Generator extends Less_Configurable { /** * fix windows paths * @param string $path + * @param bool $addEndSlash * @return string */ public function fixWindowsPath( $path, $addEndSlash = false ) { diff --git a/vendor/wikimedia/less.php/lib/Less/Tree.php b/vendor/wikimedia/less.php/lib/Less/Tree.php index 7b48e9a..f606b58 100644 --- a/vendor/wikimedia/less.php/lib/Less/Tree.php +++ b/vendor/wikimedia/less.php/lib/Less/Tree.php @@ -3,12 +3,18 @@ /** * Tree * - * @package Less - * @subpackage tree + * TODO: Callers often use `property_exists(, 'value')` to distinguish + * tree nodes that are considerd value-holding. Refactor this to move + * the 'value' property that most subclasses implement to there, and use + * something else (special value, method, or intermediate class?) to + * signal whether a subclass is considered value-holding. */ class Less_Tree { public $cache_string; + public $parensInOp = false; + public $extendOnEveryPath; + public $allExtends; public function toCSS() { $output = new Less_Output(); @@ -25,7 +31,12 @@ class Less_Tree { public function genCSS( $output ) { } + public function compile( $env ) { + return $this; + } + /** + * @param Less_Output $output * @param Less_Tree_Ruleset[] $rules */ public static function outputRuleset( $output, $rules ) { @@ -45,8 +56,8 @@ class Less_Tree { } // Non-compressed - $tabSetStr = "\n".str_repeat( Less_Parser::$options['indentation'], Less_Environment::$tabLevel - 1 ); - $tabRuleStr = $tabSetStr.Less_Parser::$options['indentation']; + $tabSetStr = "\n" . str_repeat( Less_Parser::$options['indentation'], Less_Environment::$tabLevel - 1 ); + $tabRuleStr = $tabSetStr . Less_Parser::$options['indentation']; $output->add( " {" ); for ( $i = 0; $i < $ruleCnt; $i++ ) { @@ -54,8 +65,7 @@ class Less_Tree { $rules[$i]->genCSS( $output ); } Less_Environment::$tabLevel--; - $output->add( $tabSetStr.'}' ); - + $output->add( $tabSetStr . '}' ); } public function accept( $visitor ) { @@ -64,6 +74,7 @@ class Less_Tree { public static function ReferencedArray( $rules ) { foreach ( $rules as $rule ) { if ( method_exists( $rule, 'markReferenced' ) ) { + // @phan-suppress-next-line PhanUndeclaredMethod $rule->markReferenced(); } } diff --git a/vendor/wikimedia/less.php/lib/Less/Tree/Alpha.php b/vendor/wikimedia/less.php/lib/Less/Tree/Alpha.php index cd38c91..bdf5dee 100644 --- a/vendor/wikimedia/less.php/lib/Less/Tree/Alpha.php +++ b/vendor/wikimedia/less.php/lib/Less/Tree/Alpha.php @@ -1,10 +1,6 @@ value = $value; @@ -25,7 +21,7 @@ class Less_Tree_Anonymous extends Less_Tree { $this->currentFileInfo = $currentFileInfo; } - public function compile() { + public function compile( $env ) { return new Less_Tree_Anonymous( $this->value, $this->index, $this->currentFileInfo, $this->mapLines ); } diff --git a/vendor/wikimedia/less.php/lib/Less/Tree/Assignment.php b/vendor/wikimedia/less.php/lib/Less/Tree/Assignment.php index 69c7a4e..1f939a1 100644 --- a/vendor/wikimedia/less.php/lib/Less/Tree/Assignment.php +++ b/vendor/wikimedia/less.php/lib/Less/Tree/Assignment.php @@ -1,10 +1,6 @@ args as $a ) { $args[] = $a->compile( $env ); } @@ -48,41 +44,44 @@ class Less_Tree_Call extends Less_Tree { switch ( $nameLC ) { case '%': $nameLC = '_percent'; - break; + break; case 'get-unit': $nameLC = 'getunit'; - break; + break; case 'data-uri': $nameLC = 'datauri'; - break; + break; case 'svg-gradient': $nameLC = 'svggradient'; - break; + break; } $result = null; if ( $nameLC === 'default' ) { $result = Less_Tree_DefaultFunc::compile(); - } else { - - if ( method_exists( 'Less_Functions', $nameLC ) ) { // 1. - try { - - $func = new Less_Functions( $env, $this->currentFileInfo ); - $result = call_user_func_array( array( $func,$nameLC ), $args ); - - } catch ( Exception $e ) { - throw new Less_Exception_Compiler( 'error evaluating function `' . $this->name . '` '.$e->getMessage().' index: '. $this->index ); - } + $func = null; + if ( method_exists( 'Less_Functions', $nameLC ) ) { + $functions = new Less_Functions( $env, $this->currentFileInfo ); + $func = [ $functions, $nameLC ]; } elseif ( isset( $env->functions[$nameLC] ) && is_callable( $env->functions[$nameLC] ) ) { + $func = $env->functions[$nameLC]; + } + // If the function name isn't known to LESS, output it unchanged as CSS. + if ( $func ) { try { - $result = call_user_func_array( $env->functions[$nameLC], $args ); + $result = call_user_func_array( $func, $args ); } catch ( Exception $e ) { - throw new Less_Exception_Compiler( 'error evaluating function `' . $this->name . '` '.$e->getMessage().' index: '. $this->index ); + // Preserve original trace, especially from custom functions. + // https://github.com/wikimedia/less.php/issues/38 + throw new Less_Exception_Compiler( + 'error evaluating function `' . $this->name . '` ' . $e->getMessage() + . ' index: ' . $this->index, + $e + ); } } } diff --git a/vendor/wikimedia/less.php/lib/Less/Tree/Color.php b/vendor/wikimedia/less.php/lib/Less/Tree/Color.php index b0f79db..427f47d 100644 --- a/vendor/wikimedia/less.php/lib/Less/Tree/Color.php +++ b/vendor/wikimedia/less.php/lib/Less/Tree/Color.php @@ -1,10 +1,6 @@ rgb = array(); + $this->rgb = []; if ( is_array( $rgb ) ) { $this->rgb = $rgb; - } else if ( strlen( $rgb ) == 6 ) { + } elseif ( strlen( $rgb ) == 6 ) { foreach ( str_split( $rgb, 2 ) as $c ) { $this->rgb[] = hexdec( $c ); } } else { foreach ( str_split( $rgb, 1 ) as $c ) { - $this->rgb[] = hexdec( $c.$c ); + $this->rgb[] = hexdec( $c . $c ); } } $this->alpha = is_numeric( $a ) ? $a : 1; } - public function compile() { - return $this; - } - public function luma() { $r = $this->rgb[0] / 255; $g = $this->rgb[1] / 255; @@ -73,7 +65,7 @@ class Less_Tree_Color extends Less_Tree { return 'transparent'; } - $values = array(); + $values = []; foreach ( $this->rgb as $c ) { $values[] = Less_Functions::clamp( round( $c ), 255 ); } @@ -89,7 +81,7 @@ class Less_Tree_Color extends Less_Tree { // Convert color to short format if ( $color[1] === $color[2] && $color[3] === $color[4] && $color[5] === $color[6] ) { - $color = '#'.$color[1] . $color[3] . $color[5]; + $color = '#' . $color[1] . $color[3] . $color[5]; } } @@ -108,7 +100,7 @@ class Less_Tree_Color extends Less_Tree { * @param string $op */ public function operate( $op, $other ) { - $rgb = array(); + $rgb = []; $alpha = $this->alpha * ( 1 - $other->alpha ) + $other->alpha; for ( $c = 0; $c < 3; $c++ ) { $rgb[$c] = Less_Functions::operate( $op, $this->rgb[$c], $other->rgb[$c] ); @@ -136,16 +128,19 @@ class Less_Tree_Color extends Less_Tree { $s = $l > 0.5 ? $d / ( 2 - $max - $min ) : $d / ( $max + $min ); switch ( $max ) { - case $r: $h = ( $g - $b ) / $d + ( $g < $b ? 6 : 0 ); -break; - case $g: $h = ( $b - $r ) / $d + 2; -break; - case $b: $h = ( $r - $g ) / $d + 4; -break; + case $r: + $h = ( $g - $b ) / $d + ( $g < $b ? 6 : 0 ); + break; + case $g: + $h = ( $b - $r ) / $d + 2; + break; + case $b: + $h = ( $r - $g ) / $d + 4; + break; } $h /= 6; } - return array( 'h' => $h * 360, 's' => $s, 'l' => $l, 'a' => $a ); + return [ 'h' => $h * 360, 's' => $s, 'l' => $l, 'a' => $a ]; } // Adapted from http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript @@ -170,16 +165,19 @@ break; $h = 0; if ( $max !== $min ) { switch ( $max ) { - case $r: $h = ( $g - $b ) / $d + ( $g < $b ? 6 : 0 ); -break; - case $g: $h = ( $b - $r ) / $d + 2; -break; - case $b: $h = ( $r - $g ) / $d + 4; -break; + case $r: + $h = ( $g - $b ) / $d + ( $g < $b ? 6 : 0 ); + break; + case $g: + $h = ( $b - $r ) / $d + 2; + break; + case $b: + $h = ( $r - $g ) / $d + 4; + break; } $h /= 6; } - return array( 'h' => $h * 360, 's' => $s, 'v' => $v, 'a' => $a ); + return [ 'h' => $h * 360, 's' => $s, 'v' => $v, 'a' => $a ]; } public function toARGB() { @@ -223,7 +221,7 @@ break; } if ( $keyword === 'transparent' ) { - return new Less_Tree_Color( array( 0, 0, 0 ), 0, true ); + return new Less_Tree_Color( [ 0, 0, 0 ], 0, true ); } } diff --git a/vendor/wikimedia/less.php/lib/Less/Tree/Comment.php b/vendor/wikimedia/less.php/lib/Less/Tree/Comment.php index c7e6c0f..b4dd68c 100644 --- a/vendor/wikimedia/less.php/lib/Less/Tree/Comment.php +++ b/vendor/wikimedia/less.php/lib/Less/Tree/Comment.php @@ -1,10 +1,6 @@ value = $value; - $this->silent = !!$silent; + $this->silent = (bool)$silent; $this->currentFileInfo = $currentFileInfo; } @@ -40,10 +36,6 @@ class Less_Tree_Comment extends Less_Tree { return $this->silent || $isReference || $isCompressed; } - public function compile() { - return $this; - } - public function markReferenced() { $this->isReferenced = true; } diff --git a/vendor/wikimedia/less.php/lib/Less/Tree/Condition.php b/vendor/wikimedia/less.php/lib/Less/Tree/Condition.php index 355de8c..5204e83 100644 --- a/vendor/wikimedia/less.php/lib/Less/Tree/Condition.php +++ b/vendor/wikimedia/less.php/lib/Less/Tree/Condition.php @@ -1,10 +1,6 @@ op ) { case 'and': $result = $a && $b; - break; + break; case 'or': $result = $a || $b; - break; + break; default: if ( Less_Parser::is_method( $a, 'compare' ) ) { @@ -53,17 +49,17 @@ class Less_Tree_Condition extends Less_Tree { switch ( $result ) { case -1: $result = $this->op === '<' || $this->op === '=<' || $this->op === '<='; - break; + break; - case 0: + case 0: $result = $this->op === '=' || $this->op === '>=' || $this->op === '=<' || $this->op === '<='; - break; + break; - case 1: + case 1: $result = $this->op === '>' || $this->op === '>='; - break; + break; } - break; + break; } return $this->negate ? !$result : $result; diff --git a/vendor/wikimedia/less.php/lib/Less/Tree/DefaultFunc.php b/vendor/wikimedia/less.php/lib/Less/Tree/DefaultFunc.php index 41b78b6..66f0008 100644 --- a/vendor/wikimedia/less.php/lib/Less/Tree/DefaultFunc.php +++ b/vendor/wikimedia/less.php/lib/Less/Tree/DefaultFunc.php @@ -1,10 +1,6 @@ unit = $unit; } elseif ( $unit ) { - $this->unit = new Less_Tree_Unit( array( $unit ) ); + $this->unit = new Less_Tree_Unit( [ $unit ] ); } else { $this->unit = new Less_Tree_Unit(); } @@ -28,12 +24,8 @@ class Less_Tree_Dimension extends Less_Tree { $this->unit = $visitor->visitObj( $this->unit ); } - public function compile() { - return $this; - } - public function toColor() { - return new Less_Tree_Color( array( $this->value, $this->value, $this->value ) ); + return new Less_Tree_Color( [ $this->value, $this->value, $this->value ] ); } /** @@ -41,7 +33,7 @@ class Less_Tree_Dimension extends Less_Tree { */ public function genCSS( $output ) { if ( Less_Parser::$options['strictUnits'] && !$this->unit->isSingular() ) { - throw new Less_Exception_Compiler( "Multiple units in dimension. Correct the units or use the unit function. Bad unit: ".$this->unit->toString() ); + throw new Less_Exception_Compiler( "Multiple units in dimension. Correct the units or use the unit function. Bad unit: " . $this->unit->toString() ); } $value = Less_Functions::fround( $this->value ); @@ -49,7 +41,7 @@ class Less_Tree_Dimension extends Less_Tree { if ( $value !== 0 && $value < 0.000001 && $value > -0.000001 ) { // would be output 1e-6 etc. - $strValue = number_format( $strValue, 10 ); + $strValue = number_format( (float)$strValue, 10 ); $strValue = preg_replace( '/\.?0+$/', '', $strValue ); } @@ -57,7 +49,7 @@ class Less_Tree_Dimension extends Less_Tree { // Zero values doesn't need a unit if ( $value === 0 && $this->unit->isLength() ) { $output->add( $strValue ); - return $strValue; + return; } // Float values doesn't need a leading zero @@ -146,7 +138,7 @@ class Less_Tree_Dimension extends Less_Tree { } public function unify() { - return $this->convertTo( array( 'length' => 'px', 'duration' => 's', 'angle' => 'rad' ) ); + return $this->convertTo( [ 'length' => 'px', 'duration' => 's', 'angle' => 'rad' ] ); } public function convertTo( $conversions ) { @@ -154,10 +146,10 @@ class Less_Tree_Dimension extends Less_Tree { $unit = clone $this->unit; if ( is_string( $conversions ) ) { - $derivedConversions = array(); + $derivedConversions = []; foreach ( Less_Tree_UnitConversions::$groups as $i ) { if ( isset( Less_Tree_UnitConversions::${$i}[$conversions] ) ) { - $derivedConversions = array( $i => $conversions ); + $derivedConversions = [ $i => $conversions ]; } } $conversions = $derivedConversions; diff --git a/vendor/wikimedia/less.php/lib/Less/Tree/Directive.php b/vendor/wikimedia/less.php/lib/Less/Tree/Directive.php index 6c6a94f..dfada84 100644 --- a/vendor/wikimedia/less.php/lib/Less/Tree/Directive.php +++ b/vendor/wikimedia/less.php/lib/Less/Tree/Directive.php @@ -1,10 +1,6 @@ value->genCSS( $output ); } if ( $this->rules ) { - Less_Tree::outputRuleset( $output, array( $this->rules ) ); + Less_Tree::outputRuleset( $output, [ $this->rules ] ); } else { $output->add( ';' ); } diff --git a/vendor/wikimedia/less.php/lib/Less/Tree/Element.php b/vendor/wikimedia/less.php/lib/Less/Tree/Element.php index 5e25bc0..11b9ce4 100644 --- a/vendor/wikimedia/less.php/lib/Less/Tree/Element.php +++ b/vendor/wikimedia/less.php/lib/Less/Tree/Element.php @@ -1,28 +1,34 @@ value = $value; $this->value_is_object = is_object( $value ); - if ( $combinator ) { - $this->combinator = $combinator; - } + // see less-2.5.3.js#Combinator + $this->combinator = $combinator ?? ''; + $this->combinatorIsEmptyOrWhitespace = ( $combinator === null || trim( $combinator ) === '' ); $this->index = $index; $this->currentFileInfo = $currentFileInfo; @@ -35,15 +41,12 @@ class Less_Tree_Element extends Less_Tree { } public function compile( $env ) { - if ( Less_Environment::$mixin_stack ) { - return new Less_Tree_Element( $this->combinator, ( $this->value_is_object ? $this->value->compile( $env ) : $this->value ), $this->index, $this->currentFileInfo ); - } - - if ( $this->value_is_object ) { - $this->value = $this->value->compile( $env ); - } - - return $this; + return new Less_Tree_Element( + $this->combinator, + ( $this->value_is_object ? $this->value->compile( $env ) : $this->value ), + $this->index, + $this->currentFileInfo + ); } /** diff --git a/vendor/wikimedia/less.php/lib/Less/Tree/Expression.php b/vendor/wikimedia/less.php/lib/Less/Tree/Expression.php index cf06315..8324141 100644 --- a/vendor/wikimedia/less.php/lib/Less/Tree/Expression.php +++ b/vendor/wikimedia/less.php/lib/Less/Tree/Expression.php @@ -1,16 +1,11 @@ 1 ) { - $ret = array(); + $ret = []; foreach ( $this->value as $e ) { $ret[] = $e->compile( $env ); } @@ -82,7 +77,7 @@ class Less_Tree_Expression extends Less_Tree { public function throwAwayComments() { if ( is_array( $this->value ) ) { - $new_value = array(); + $new_value = []; foreach ( $this->value as $v ) { if ( $v instanceof Less_Tree_Comment ) { continue; diff --git a/vendor/wikimedia/less.php/lib/Less/Tree/Extend.php b/vendor/wikimedia/less.php/lib/Less/Tree/Extend.php index 4dd3665..362e284 100644 --- a/vendor/wikimedia/less.php/lib/Less/Tree/Extend.php +++ b/vendor/wikimedia/less.php/lib/Less/Tree/Extend.php @@ -1,17 +1,13 @@ allowBefore = true; $this->allowAfter = true; - break; + break; default: $this->allowBefore = false; $this->allowAfter = false; - break; + break; } // This must use a string (instead of int) so that array_merge() // preserves keys on arrays that use IDs in their keys. $this->object_id = 'id_' . $i++; - $this->parent_ids = array( + $this->parent_ids = [ $this->object_id => true - ); + ]; } public function accept( $visitor ) { @@ -62,7 +58,7 @@ class Less_Tree_Extend extends Less_Tree { } public function findSelfSelectors( $selectors ) { - $selfElements = array(); + $selfElements = []; for ( $i = 0, $selectors_len = count( $selectors ); $i < $selectors_len; $i++ ) { $selectorElements = $selectors[$i]->elements; @@ -74,7 +70,7 @@ class Less_Tree_Extend extends Less_Tree { $selfElements = array_merge( $selfElements, $selectors[$i]->elements ); } - $this->selfSelectors = array( new Less_Tree_Selector( $selfElements ) ); + $this->selfSelectors = [ new Less_Tree_Selector( $selfElements ) ]; } } diff --git a/vendor/wikimedia/less.php/lib/Less/Tree/Import.php b/vendor/wikimedia/less.php/lib/Less/Tree/Import.php index ffdac64..fc5e81d 100644 --- a/vendor/wikimedia/less.php/lib/Less/Tree/Import.php +++ b/vendor/wikimedia/less.php/lib/Less/Tree/Import.php @@ -1,7 +1,6 @@ currentFileInfo = $currentFileInfo; if ( is_array( $options ) ) { - $this->options += array( 'inline' => false ); + $this->options += [ 'inline' => false ]; if ( isset( $this->options['less'] ) || $this->options['inline'] ) { $this->css = !isset( $this->options['less'] ) || !$this->options['less'] || $this->options['inline']; } else { $pathValue = $this->getPath(); - if ( $pathValue && preg_match( '/css([\?;].*)?$/', $pathValue ) ) { + // Leave any ".css" file imports as literals for the browser. + // Also leave any remote HTTP resources as literals regardless of whether + // they contain ".css" in their filename. + if ( $pathValue && preg_match( '/^(https?:)?\/\/|\.css$/i', $pathValue ) ) { $this->css = true; } } @@ -97,13 +98,17 @@ class Less_Tree_Import extends Less_Tree { } /** - * @return string + * @return string|null */ public function getPath() { if ( $this->path instanceof Less_Tree_Quoted ) { $path = $this->path->value; $path = ( isset( $this->css ) || preg_match( '/(\.[a-z]*$)|([\?;].*)$/', $path ) ) ? $path : $path . '.less'; - } else if ( $this->path instanceof Less_Tree_URL ) { + + // During the first pass, Less_Tree_URL may contain a Less_Tree_Variable (not yet expanded), + // and thus has no value property defined yet. Return null until we reach the next phase. + // https://github.com/wikimedia/less.php/issues/29 + } elseif ( $this->path instanceof Less_Tree_URL && !( $this->path->value instanceof Less_Tree_Variable ) ) { $path = $this->path->value->value; } else { return null; @@ -129,7 +134,7 @@ class Less_Tree_Import extends Less_Tree { $pathValue = $path->value; // Add the base path if the import is relative if ( $pathValue && Less_Environment::isPathRelative( $pathValue ) ) { - $path->value = $this->currentFileInfo['uri_root'].$pathValue; + $path->value = $this->currentFileInfo['uri_root'] . $pathValue; } } $path->value = Less_Environment::normalizePath( $path->value ); @@ -159,26 +164,27 @@ class Less_Tree_Import extends Less_Tree { // import once if ( $evald->skip( $full_path, $env ) ) { - return array(); + return []; } + '@phan-var string $full_path'; if ( $this->options['inline'] ) { // todo needs to reference css file not import //$contents = new Less_Tree_Anonymous($this->root, 0, array('filename'=>$this->importedFilename), true ); Less_Parser::AddParsedFile( $full_path ); - $contents = new Less_Tree_Anonymous( file_get_contents( $full_path ), 0, array(), true ); + $contents = new Less_Tree_Anonymous( file_get_contents( $full_path ), 0, [], true ); if ( $this->features ) { - return new Less_Tree_Media( array( $contents ), $this->features->value ); + return new Less_Tree_Media( [ $contents ], $this->features->value ); } - return array( $contents ); + return [ $contents ]; } // optional (need to be before "CSS" to support optional CSS imports. CSS should be checked only if empty($this->currentFileInfo)) if ( isset( $this->options['optional'] ) && $this->options['optional'] && !file_exists( $full_path ) && ( !$evald->css || !empty( $this->currentFileInfo ) ) ) { - return array(); + return []; } // css ? @@ -192,15 +198,13 @@ class Less_Tree_Import extends Less_Tree { /** * Using the import directories, get the full absolute path and uri of the import - * - * @param Less_Tree_Import $evald */ public function PathAndUri() { $evald_path = $this->getPath(); if ( $evald_path ) { - $import_dirs = array(); + $import_dirs = []; if ( Less_Environment::isPathRelative( $evald_path ) ) { // if the path is relative, the file should be in the current directory @@ -226,20 +230,20 @@ class Less_Tree_Import extends Less_Tree { list( $path, $uri ) = call_user_func( $rooturi, $evald_path ); if ( is_string( $path ) ) { $full_path = $path; - return array( $full_path, $uri ); + return [ $full_path, $uri ]; } } elseif ( !empty( $rootpath ) ) { - $path = rtrim( $rootpath, '/\\' ).'/'.ltrim( $evald_path, '/\\' ); + $path = rtrim( $rootpath, '/\\' ) . '/' . ltrim( $evald_path, '/\\' ); if ( file_exists( $path ) ) { $full_path = Less_Environment::normalizePath( $path ); - $uri = Less_Environment::normalizePath( dirname( $rooturi.$evald_path ) ); - return array( $full_path, $uri ); - } elseif ( file_exists( $path.'.less' ) ) { - $full_path = Less_Environment::normalizePath( $path.'.less' ); - $uri = Less_Environment::normalizePath( dirname( $rooturi.$evald_path.'.less' ) ); - return array( $full_path, $uri ); + $uri = Less_Environment::normalizePath( dirname( $rooturi . $evald_path ) ); + return [ $full_path, $uri ]; + } elseif ( file_exists( $path . '.less' ) ) { + $full_path = Less_Environment::normalizePath( $path . '.less' ); + $uri = Less_Environment::normalizePath( dirname( $rooturi . $evald_path . '.less' ) ); + return [ $full_path, $uri ]; } } } @@ -249,6 +253,9 @@ class Less_Tree_Import extends Less_Tree { /** * Parse the import url and return the rules * + * @param string $full_path + * @param string|null $uri + * @param mixed $env * @return Less_Tree_Media|array */ public function ParseImport( $full_path, $uri, $env ) { @@ -264,7 +271,7 @@ class Less_Tree_Import extends Less_Tree { $parser = new Less_Parser( $import_env ); $root = $parser->parseFile( $full_path, $uri, true ); - $ruleset = new Less_Tree_Ruleset( array(), $root->rules ); + $ruleset = new Less_Tree_Ruleset( null, $root->rules ); $ruleset->evalImports( $import_env ); return $this->features ? new Less_Tree_Media( $ruleset->rules, $this->features->value ) : $ruleset->rules; @@ -273,9 +280,11 @@ class Less_Tree_Import extends Less_Tree { /** * Should the import be skipped? * - * @return boolean|null + * @param string|null $path + * @param Less_Environment $env + * @return bool|null */ - private function Skip( $path, $env ) { + private function skip( $path, $env ) { $path = Less_Parser::AbsPath( $path, true ); if ( $path && Less_Parser::FileParsed( $path ) ) { @@ -286,6 +295,5 @@ class Less_Tree_Import extends Less_Tree { return !isset( $this->options['multiple'] ) && !$env->importMultiple; } - } } diff --git a/vendor/wikimedia/less.php/lib/Less/Tree/Javascript.php b/vendor/wikimedia/less.php/lib/Less/Tree/Javascript.php index 179781a..218d481 100644 --- a/vendor/wikimedia/less.php/lib/Less/Tree/Javascript.php +++ b/vendor/wikimedia/less.php/lib/Less/Tree/Javascript.php @@ -1,10 +1,6 @@ escaped = $escaped; @@ -23,7 +19,7 @@ class Less_Tree_Javascript extends Less_Tree { $this->index = $index; } - public function compile() { + public function compile( $env ) { return new Less_Tree_Anonymous( '/* Sorry, can not do JavaScript evaluation in PHP... :( */' ); } diff --git a/vendor/wikimedia/less.php/lib/Less/Tree/Keyword.php b/vendor/wikimedia/less.php/lib/Less/Tree/Keyword.php index ed217cf..60663f0 100644 --- a/vendor/wikimedia/less.php/lib/Less/Tree/Keyword.php +++ b/vendor/wikimedia/less.php/lib/Less/Tree/Keyword.php @@ -1,10 +1,6 @@ value = $value; } - public function compile() { - return $this; - } - /** * @see Less_Tree::genCSS */ diff --git a/vendor/wikimedia/less.php/lib/Less/Tree/Media.php b/vendor/wikimedia/less.php/lib/Less/Tree/Media.php index ba25a67..3cb1fc4 100644 --- a/vendor/wikimedia/less.php/lib/Less/Tree/Media.php +++ b/vendor/wikimedia/less.php/lib/Less/Tree/Media.php @@ -1,10 +1,6 @@ index = $index; $this->currentFileInfo = $currentFileInfo; @@ -23,7 +19,7 @@ class Less_Tree_Media extends Less_Tree { $this->features = new Less_Tree_Value( $features ); - $this->rules = array( new Less_Tree_Ruleset( $selectors, $value ) ); + $this->rules = [ new Less_Tree_Ruleset( $selectors, $value ) ]; $this->rules[0]->allowImports = true; } @@ -39,11 +35,15 @@ class Less_Tree_Media extends Less_Tree { $output->add( '@media ', $this->currentFileInfo, $this->index ); $this->features->genCSS( $output ); Less_Tree::outputRuleset( $output, $this->rules ); - } + /** + * @param Less_Environment $env + * @return Less_Tree_Media|Less_Tree_Ruleset + * @see less-2.5.3.js#Media.prototype.eval + */ public function compile( $env ) { - $media = new Less_Tree_Media( array(), array(), $this->index, $this->currentFileInfo ); + $media = new Less_Tree_Media( [], [], $this->index, $this->currentFileInfo ); $strictMathBypass = false; if ( Less_Parser::$options['strictMath'] === false ) { @@ -61,7 +61,7 @@ class Less_Tree_Media extends Less_Tree { $env->mediaBlocks[] = $media; array_unshift( $env->frames, $this->rules[0] ); - $media->rules = array( $this->rules[0]->compile( $env ) ); + $media->rules = [ $this->rules[0]->compile( $env ) ]; array_shift( $env->frames ); array_pop( $env->mediaPath ); @@ -79,7 +79,7 @@ class Less_Tree_Media extends Less_Tree { public function emptySelectors() { $el = new Less_Tree_Element( '', '&', $this->index, $this->currentFileInfo ); - $sels = array( new Less_Tree_Selector( array( $el ), array(), null, $this->index, $this->currentFileInfo ) ); + $sels = [ new Less_Tree_Selector( [ $el ], [], null, $this->index, $this->currentFileInfo ) ]; $sels[0]->mediaEmpty = true; return $sels; } @@ -100,20 +100,26 @@ class Less_Tree_Media extends Less_Tree { $result->multiMedia = true; } - $env->mediaBlocks = array(); - $env->mediaPath = array(); + $env->mediaBlocks = []; + $env->mediaPath = []; return $result; } + /** + * @param Less_Environment $env + * @return Less_Tree_Ruleset + */ public function compileNested( $env ) { - $path = array_merge( $env->mediaPath, array( $this ) ); + $path = array_merge( $env->mediaPath, [ $this ] ); + '@phan-var array $path'; // Extract the media-query conditions separated with `,` (OR). foreach ( $path as $key => $p ) { $value = $p->features instanceof Less_Tree_Value ? $p->features->value : $p->features; - $path[$key] = is_array( $value ) ? $value : array( $value ); + $path[$key] = is_array( $value ) ? $value : [ $value ]; } + '@phan-var array> $path'; // Trace all permutations to generate the resulting media-query. // @@ -124,7 +130,7 @@ class Less_Tree_Media extends Less_Tree { // b and c and e $permuted = $this->permute( $path ); - $expressions = array(); + $expressions = []; foreach ( $permuted as $path ) { for ( $i = 0, $len = count( $path ); $i < $len; $i++ ) { @@ -132,7 +138,7 @@ class Less_Tree_Media extends Less_Tree { } for ( $i = count( $path ) - 1; $i > 0; $i-- ) { - array_splice( $path, $i, 0, array( new Less_Tree_Anonymous( 'and' ) ) ); + array_splice( $path, $i, 0, [ new Less_Tree_Anonymous( 'and' ) ] ); } $expressions[] = new Less_Tree_Expression( $path ); @@ -140,23 +146,25 @@ class Less_Tree_Media extends Less_Tree { $this->features = new Less_Tree_Value( $expressions ); // Fake a tree-node that doesn't output anything. - return new Less_Tree_Ruleset( array(), array() ); + return new Less_Tree_Ruleset( [], [] ); } public function permute( $arr ) { - if ( !$arr ) - return array(); + if ( !$arr ) { + return []; + } - if ( count( $arr ) == 1 ) + if ( count( $arr ) == 1 ) { return $arr[0]; + } - $result = array(); + $result = []; $rest = $this->permute( array_slice( $arr, 1 ) ); foreach ( $rest as $r ) { foreach ( $arr[0] as $a ) { $result[] = array_merge( - is_array( $a ) ? $a : array( $a ), - is_array( $r ) ? $r : array( $r ) + is_array( $a ) ? $a : [ $a ], + is_array( $r ) ? $r : [ $r ] ); } } @@ -165,9 +173,11 @@ class Less_Tree_Media extends Less_Tree { } public function bubbleSelectors( $selectors ) { - if ( !$selectors ) return; + if ( !$selectors ) { + return; + } - $this->rules = array( new Less_Tree_Ruleset( $selectors, array( $this->rules[0] ) ) ); + $this->rules = [ new Less_Tree_Ruleset( $selectors, [ $this->rules[0] ] ) ]; } } diff --git a/vendor/wikimedia/less.php/lib/Less/Tree/Mixin/Call.php b/vendor/wikimedia/less.php/lib/Less/Tree/Mixin/Call.php index 8e1eece..61e10fe 100644 --- a/vendor/wikimedia/less.php/lib/Less/Tree/Mixin/Call.php +++ b/vendor/wikimedia/less.php/lib/Less/Tree/Mixin/Call.php @@ -1,5 +1,7 @@ arguments as $a ) { - $args[] = array( 'name' => $a['name'], 'value' => $a['value']->compile( $env ) ); + $args[] = [ 'name' => $a['name'], 'value' => $a['value']->compile( $env ) ]; } foreach ( $env->frames as $frame ) { @@ -68,14 +70,17 @@ class Less_Tree_Mixin_Call extends Less_Tree { if ( $mixin->matchArgs( $args, $env ) ) { - $candidate = array( 'mixin' => $mixin, 'group' => $defNone ); + $candidate = [ 'mixin' => $mixin, 'group' => $defNone ]; if ( $mixin instanceof Less_Tree_Ruleset ) { - for ( $f = 0; $f < 2; $f++ ) { Less_Tree_DefaultFunc::value( $f ); $conditionResult[$f] = $mixin->matchCondition( $args, $env ); } + + // PhanTypeInvalidDimOffset -- False positive + '@phan-var array{0:bool,1:bool} $conditionResult'; + if ( $conditionResult[0] || $conditionResult[1] ) { if ( $conditionResult[0] != $conditionResult[1] ) { $candidate['group'] = $conditionResult[1] ? $defTrue : $defFalse; @@ -93,7 +98,7 @@ class Less_Tree_Mixin_Call extends Less_Tree { Less_Tree_DefaultFunc::reset(); - $count = array( 0, 0, 0 ); + $count = [ 0, 0, 0 ]; for ( $m = 0; $m < count( $candidates ); $m++ ) { $count[ $candidates[$m]['group'] ]++; } @@ -116,7 +121,7 @@ class Less_Tree_Mixin_Call extends Less_Tree { try{ $mixin = $candidates[$m]['mixin']; if ( !( $mixin instanceof Less_Tree_Mixin_Definition ) ) { - $mixin = new Less_Tree_Mixin_Definition( '', array(), $mixin->rules, null, false ); + $mixin = new Less_Tree_Mixin_Definition( '', [], $mixin->rules, null, false ); $mixin->originalRuleset = $mixins[$m]->originalRuleset; } $rules = array_merge( $rules, $mixin->evalCall( $env, $args, $this->important )->rules ); @@ -137,12 +142,11 @@ class Less_Tree_Mixin_Call extends Less_Tree { } if ( $isOneFound ) { - throw new Less_Exception_Compiler( 'No matching definition was found for `'.$this->Format( $args ).'`', null, $this->index, $this->currentFileInfo ); + throw new Less_Exception_Compiler( 'No matching definition was found for `' . $this->Format( $args ) . '`', null, $this->index, $this->currentFileInfo ); } else { - throw new Less_Exception_Compiler( trim( $this->selector->toCSS() ) . " is undefined in ".$this->currentFileInfo['filename'], null, $this->index ); + throw new Less_Exception_Compiler( trim( $this->selector->toCSS() ) . " is undefined in " . $this->currentFileInfo['filename'], null, $this->index ); } - } /** @@ -150,7 +154,7 @@ class Less_Tree_Mixin_Call extends Less_Tree { * */ private function Format( $args ) { - $message = array(); + $message = []; if ( $args ) { foreach ( $args as $a ) { $argValue = ''; diff --git a/vendor/wikimedia/less.php/lib/Less/Tree/Mixin/Definition.php b/vendor/wikimedia/less.php/lib/Less/Tree/Mixin/Definition.php index f9f2eb4..08bcd7a 100644 --- a/vendor/wikimedia/less.php/lib/Less/Tree/Mixin/Definition.php +++ b/vendor/wikimedia/less.php/lib/Less/Tree/Mixin/Definition.php @@ -1,22 +1,24 @@ name = $name; - $this->selectors = array( new Less_Tree_Selector( array( new Less_Tree_Element( null, $name ) ) ) ); + $this->selectors = [ new Less_Tree_Selector( [ new Less_Tree_Element( null, $name ) ] ) ]; $this->params = $params; $this->condition = $condition; @@ -47,8 +49,8 @@ class Less_Tree_Mixin_Definition extends Less_Tree_Ruleset { } // less.js : /lib/less/tree/mixin.js : tree.mixin.Definition.evalParams - public function compileParams( $env, $mixinFrames, $args = array(), &$evaldArguments = array() ) { - $frame = new Less_Tree_Ruleset( null, array() ); + public function compileParams( $env, $mixinFrames, $args = [], &$evaldArguments = [] ) { + $frame = new Less_Tree_Ruleset( null, [] ); $params = $this->params; $mixinEnv = null; $argsLength = 0; @@ -75,7 +77,7 @@ class Less_Tree_Mixin_Definition extends Less_Tree_Ruleset { $argsLength--; continue; } else { - throw new Less_Exception_Compiler( "Named argument for " . $this->name .' '.$args[$i]['name'] . ' not found' ); + throw new Less_Exception_Compiler( "Named argument for " . $this->name . ' ' . $args[$i]['name'] . ' not found' ); } } } @@ -95,7 +97,7 @@ class Less_Tree_Mixin_Definition extends Less_Tree_Ruleset { if ( isset( $param['name'] ) && $param['name'] ) { if ( isset( $param['variadic'] ) ) { - $varargs = array(); + $varargs = []; for ( $j = $argIndex; $j < $argsLength; $j++ ) { $varargs[] = $args[$j]['value']->compile( $env ); } @@ -106,11 +108,11 @@ class Less_Tree_Mixin_Definition extends Less_Tree_Ruleset { if ( $val ) { $val = $val->compile( $env ); - } else if ( isset( $param['value'] ) ) { + } elseif ( isset( $param['value'] ) ) { if ( !$mixinEnv ) { $mixinEnv = new Less_Environment(); - $mixinEnv->frames = array_merge( array( $frame ), $mixinFrames ); + $mixinEnv->frames = array_merge( [ $frame ], $mixinFrames ); } $val = $param['value']->compile( $mixinEnv ); @@ -145,10 +147,10 @@ class Less_Tree_Mixin_Definition extends Less_Tree_Ruleset { return new Less_Tree_Mixin_Definition( $this->name, $this->params, $this->rules, $this->condition, $this->variadic, $env->frames ); } - public function evalCall( $env, $args = NULL, $important = NULL ) { + public function evalCall( $env, $args = null, $important = null ) { Less_Environment::$mixin_stack++; - $_arguments = array(); + $_arguments = []; if ( $this->frames ) { $mixinFrames = array_merge( $this->frames, $env->frames ); @@ -165,7 +167,7 @@ class Less_Tree_Mixin_Definition extends Less_Tree_Ruleset { $ruleset->originalRuleset = $this->ruleset_id; $ruleSetEnv = new Less_Environment(); - $ruleSetEnv->frames = array_merge( array( $this, $frame ), $mixinFrames ); + $ruleSetEnv->frames = array_merge( [ $this, $frame ], $mixinFrames ); $ruleset = $ruleset->compile( $ruleSetEnv ); if ( $important ) { @@ -177,6 +179,7 @@ class Less_Tree_Mixin_Definition extends Less_Tree_Ruleset { return $ruleset; } + /** @return bool */ public function matchCondition( $args, $env ) { if ( !$this->condition ) { return true; @@ -184,14 +187,14 @@ class Less_Tree_Mixin_Definition extends Less_Tree_Ruleset { // set array to prevent error on array_merge if ( !is_array( $this->frames ) ) { - $this->frames = array(); + $this->frames = []; } $frame = $this->compileParams( $env, array_merge( $this->frames, $env->frames ), $args ); $compile_env = new Less_Environment(); $compile_env->frames = array_merge( - array( $frame ), // the parameter variables + [ $frame ], // the parameter variables $this->frames, // the parent namespace/mixin frames $env->frames // the current environment frames ); @@ -201,7 +204,7 @@ class Less_Tree_Mixin_Definition extends Less_Tree_Ruleset { return (bool)$this->condition->compile( $compile_env ); } - public function matchArgs( $args, $env = NULL ) { + public function matchArgs( $args, $env = null ) { $argsLength = count( $args ); if ( !$this->variadic ) { diff --git a/vendor/wikimedia/less.php/lib/Less/Tree/NameValue.php b/vendor/wikimedia/less.php/lib/Less/Tree/NameValue.php index 4f9aa97..88a2296 100644 --- a/vendor/wikimedia/less.php/lib/Less/Tree/NameValue.php +++ b/vendor/wikimedia/less.php/lib/Less/Tree/NameValue.php @@ -1,14 +1,14 @@ color:#FF0000; + * In bootstrap, there are about 600-1000 simple name-value pairs (depending on + * how forgiving the match is) -vs- 6,020 dynamic rules (Less_Tree_Rule). * - * @package Less - * @subpackage tree + * Using the name-value object can speed up bootstrap compilation slightly, but + * it breaks color keyword interpretation: `color: red` -> `color: #FF0000`. + * + * @private */ class Less_Tree_NameValue extends Less_Tree { diff --git a/vendor/wikimedia/less.php/lib/Less/Tree/Negative.php b/vendor/wikimedia/less.php/lib/Less/Tree/Negative.php index f0f36c8..516f1ee 100644 --- a/vendor/wikimedia/less.php/lib/Less/Tree/Negative.php +++ b/vendor/wikimedia/less.php/lib/Less/Tree/Negative.php @@ -1,10 +1,6 @@ value ) ); + $ret = new Less_Tree_Operation( '*', [ new Less_Tree_Dimension( -1 ), $this->value ] ); return $ret->compile( $env ); } return new Less_Tree_Negative( $this->value->compile( $env ) ); diff --git a/vendor/wikimedia/less.php/lib/Less/Tree/Operation.php b/vendor/wikimedia/less.php/lib/Less/Tree/Operation.php index d4eb9ac..4d79dc0 100644 --- a/vendor/wikimedia/less.php/lib/Less/Tree/Operation.php +++ b/vendor/wikimedia/less.php/lib/Less/Tree/Operation.php @@ -1,10 +1,6 @@ operate( $this->op, $b ); } - return new Less_Tree_Operation( $this->op, array( $a, $b ), $this->isSpaced ); + return new Less_Tree_Operation( $this->op, [ $a, $b ], $this->isSpaced ); } /** diff --git a/vendor/wikimedia/less.php/lib/Less/Tree/Paren.php b/vendor/wikimedia/less.php/lib/Less/Tree/Paren.php index 77ee48c..d659b84 100644 --- a/vendor/wikimedia/less.php/lib/Less/Tree/Paren.php +++ b/vendor/wikimedia/less.php/lib/Less/Tree/Paren.php @@ -1,16 +1,16 @@ value = $value; } diff --git a/vendor/wikimedia/less.php/lib/Less/Tree/Quoted.php b/vendor/wikimedia/less.php/lib/Less/Tree/Quoted.php index d01598b..0c5e190 100644 --- a/vendor/wikimedia/less.php/lib/Less/Tree/Quoted.php +++ b/vendor/wikimedia/less.php/lib/Less/Tree/Quoted.php @@ -1,10 +1,6 @@ value, $matches ) ) { foreach ( $matches as $i => $match ) { $js = new Less_Tree_JavaScript( $matches[1], $this->index, true ); - $js = $js->compile()->value; + $js = $js->compile( $env )->value; $value = str_replace( $matches[0][$i], $js, $value ); } } diff --git a/vendor/wikimedia/less.php/lib/Less/Tree/Rule.php b/vendor/wikimedia/less.php/lib/Less/Tree/Rule.php index 5f393eb..842ad0c 100644 --- a/vendor/wikimedia/less.php/lib/Less/Tree/Rule.php +++ b/vendor/wikimedia/less.php/lib/Less/Tree/Rule.php @@ -1,14 +1,11 @@ name = $name; - $this->value = ( $value instanceof Less_Tree_Value || $value instanceof Less_Tree_Ruleset ) ? $value : new Less_Tree_Value( array( $value ) ); + $this->value = ( $value instanceof Less_Tree ) + ? $value + : new Less_Tree_Value( [ $value ] ); $this->important = $important ? ' ' . trim( $important ) : ''; $this->merge = $merge; $this->index = $index; @@ -52,6 +51,10 @@ class Less_Tree_Rule extends Less_Tree { $output->add( $this->important . ( ( $this->inline || ( Less_Environment::$lastRule && Less_Parser::$options['compress'] ) ) ? "" : ";" ), $this->currentFileInfo, $this->index ); } + /** + * @param Less_Environment $env + * @return Less_Tree_Rule + */ public function compile( $env ) { $name = $this->name; if ( is_array( $name ) ) { @@ -84,7 +87,7 @@ class Less_Tree_Rule extends Less_Tree { $return = $this; } - }catch ( Less_Exception_Parser $e ) { + } catch ( Less_Exception_Parser $e ) { if ( !is_numeric( $e->index ) ) { $e->index = $this->index; $e->currentFile = $this->currentFileInfo; diff --git a/vendor/wikimedia/less.php/lib/Less/Tree/Ruleset.php b/vendor/wikimedia/less.php/lib/Less/Tree/Ruleset.php index 9bc8243..7acc6af 100644 --- a/vendor/wikimedia/less.php/lib/Less/Tree/Ruleset.php +++ b/vendor/wikimedia/less.php/lib/Less/Tree/Ruleset.php @@ -1,10 +1,6 @@ selectors = $selectors; $this->rules = $rules; - $this->lookups = array(); + $this->lookups = []; $this->strictImports = $strictImports; $this->SetRulesetIndex(); } public function accept( $visitor ) { - if ( $this->paths ) { + if ( $this->paths !== null ) { $paths_len = count( $this->paths ); - for ( $i = 0,$paths_len; $i < $paths_len; $i++ ) { + for ( $i = 0; $i < $paths_len; $i++ ) { $this->paths[$i] = $visitor->visitArray( $this->paths[$i] ); } } elseif ( $this->selectors ) { @@ -65,6 +66,11 @@ class Less_Tree_Ruleset extends Less_Tree { } } + /** + * @param Less_Environment $env + * @return Less_Tree_Ruleset + * @see less-2.5.3.js#Ruleset.prototype.eval + */ public function compile( $env ) { $ruleset = $this->PrepareRuleset( $env ); @@ -72,15 +78,13 @@ class Less_Tree_Ruleset extends Less_Tree { // so they can be evaluated like closures when the time comes. $rsRuleCnt = count( $ruleset->rules ); for ( $i = 0; $i < $rsRuleCnt; $i++ ) { + // These checks are the equivalent of the rule.evalFirst property in less.js if ( $ruleset->rules[$i] instanceof Less_Tree_Mixin_Definition || $ruleset->rules[$i] instanceof Less_Tree_DetachedRuleset ) { $ruleset->rules[$i] = $ruleset->rules[$i]->compile( $env ); } } - $mediaBlockCount = 0; - if ( $env instanceof Less_Environment ) { - $mediaBlockCount = count( $env->mediaBlocks ); - } + $mediaBlockCount = count( $env->mediaBlocks ); // Evaluate mixin calls. $this->EvalMixinCalls( $ruleset, $env, $rsRuleCnt ); @@ -107,7 +111,7 @@ class Less_Tree_Ruleset extends Less_Tree { for ( $j = 0; $j < count( $rule->rules ); $j++ ) { $subRule = $rule->rules[$j]; if ( !( $subRule instanceof Less_Tree_Rule ) || !$subRule->variable ) { - array_splice( $ruleset->rules, ++$i, 0, array( $subRule ) ); + array_splice( $ruleset->rules, ++$i, 0, [ $subRule ] ); $rsRuleCnt++; } } @@ -133,7 +137,7 @@ class Less_Tree_Ruleset extends Less_Tree { * Compile Less_Tree_Mixin_Call objects * * @param Less_Tree_Ruleset $ruleset - * @param integer $rsRuleCnt + * @param int $rsRuleCnt */ private function EvalMixinCalls( $ruleset, $env, &$rsRuleCnt ) { for ( $i = 0; $i < $rsRuleCnt; $i++ ) { @@ -142,7 +146,7 @@ class Less_Tree_Ruleset extends Less_Tree { if ( $rule instanceof Less_Tree_Mixin_Call ) { $rule = $rule->compile( $env ); - $temp = array(); + $temp = []; foreach ( $rule as $r ) { if ( ( $r instanceof Less_Tree_Rule ) && $r->variable ) { // do not pollute the scope if the variable is @@ -164,7 +168,7 @@ class Less_Tree_Ruleset extends Less_Tree { } elseif ( $rule instanceof Less_Tree_RulesetCall ) { $rule = $rule->compile( $env ); - $rules = array(); + $rules = []; foreach ( $rule->rules as $r ) { if ( ( $r instanceof Less_Tree_Rule ) && $r->variable ) { continue; @@ -185,14 +189,21 @@ class Less_Tree_Ruleset extends Less_Tree { /** * Compile the selectors and create a new ruleset object for the compile() method * + * @param Less_Environment $env + * @return Less_Tree_Ruleset */ private function PrepareRuleset( $env ) { + // NOTE: Preserve distinction between null and empty array when compiling + // $this->selectors to $selectors + $thisSelectors = $this->selectors; + $selectors = null; $hasOnePassingSelector = false; - $selectors = array(); - if ( $this->selectors ) { + + if ( $thisSelectors ) { Less_Tree_DefaultFunc::error( "it is currently only allowed in parametric mixin guards," ); - foreach ( $this->selectors as $s ) { + $selectors = []; + foreach ( $thisSelectors as $s ) { $selector = $s->compile( $env ); $selectors[] = $selector; if ( $selector->evaldCondition ) { @@ -206,15 +217,15 @@ class Less_Tree_Ruleset extends Less_Tree { } if ( $this->rules && $hasOnePassingSelector ) { + // Copy the array (no need for slice in PHP) $rules = $this->rules; } else { - $rules = array(); + $rules = []; } $ruleset = new Less_Tree_Ruleset( $selectors, $rules, $this->strictImports ); $ruleset->originalRuleset = $this->ruleset_id; - $ruleset->root = $this->root; $ruleset->firstRoot = $this->firstRoot; $ruleset->allowImports = $this->allowImports; @@ -243,7 +254,7 @@ class Less_Tree_Ruleset extends Less_Tree { $i += $temp_count; $rules_len += $temp_count; } else { - array_splice( $this->rules, $i, 1, array( $rules ) ); + array_splice( $this->rules, $i, 1, [ $rules ] ); } $this->resetCache(); @@ -252,7 +263,7 @@ class Less_Tree_Ruleset extends Less_Tree { } function makeImportant() { - $important_rules = array(); + $important_rules = []; foreach ( $this->rules as $rule ) { if ( $rule instanceof Less_Tree_Rule || $rule instanceof Less_Tree_Ruleset || $rule instanceof Less_Tree_NameValue ) { $important_rules[] = $rule->makeImportant(); @@ -264,7 +275,7 @@ class Less_Tree_Ruleset extends Less_Tree { return new Less_Tree_Ruleset( $this->selectors, $important_rules, $this->strictImports ); } - public function matchArgs( $args ) { + public function matchArgs( $args, $env = null ) { return !$args; } @@ -284,11 +295,11 @@ class Less_Tree_Ruleset extends Less_Tree { function resetCache() { $this->_rulesets = null; $this->_variables = null; - $this->lookups = array(); + $this->lookups = []; } public function variables() { - $this->_variables = array(); + $this->_variables = []; foreach ( $this->rules as $r ) { if ( $r instanceof Less_Tree_Rule && $r->variable === true ) { $this->_variables[$r->name] = $r; @@ -296,11 +307,15 @@ class Less_Tree_Ruleset extends Less_Tree { } } + /** + * @param string $name + * @return Less_Tree_Rule|null + */ public function variable( $name ) { - if ( is_null( $this->_variables ) ) { + if ( $this->_variables === null ) { $this->variables(); } - return isset( $this->_variables[$name] ) ? $this->_variables[$name] : null; + return $this->_variables[$name] ?? null; } public function find( $selector, $self = null ) { @@ -312,7 +327,7 @@ class Less_Tree_Ruleset extends Less_Tree { $self = $this->ruleset_id; } - $this->lookups[$key] = array(); + $this->lookups[$key] = []; $first_oelement = $selector->_oelements[0]; @@ -351,19 +366,24 @@ class Less_Tree_Ruleset extends Less_Tree { $tabRuleStr = $tabSetStr = ''; if ( !Less_Parser::$options['compress'] ) { if ( Less_Environment::$tabLevel ) { - $tabRuleStr = "\n".str_repeat( Less_Parser::$options['indentation'], Less_Environment::$tabLevel ); - $tabSetStr = "\n".str_repeat( Less_Parser::$options['indentation'], Less_Environment::$tabLevel - 1 ); + $tabRuleStr = "\n" . str_repeat( Less_Parser::$options['indentation'], Less_Environment::$tabLevel ); + $tabSetStr = "\n" . str_repeat( Less_Parser::$options['indentation'], Less_Environment::$tabLevel - 1 ); } else { $tabSetStr = $tabRuleStr = "\n"; } } - $ruleNodes = array(); - $rulesetNodes = array(); + $ruleNodes = []; + $rulesetNodes = []; foreach ( $this->rules as $rule ) { $class = get_class( $rule ); - if ( ( $class === 'Less_Tree_Media' ) || ( $class === 'Less_Tree_Directive' ) || ( $this->root && $class === 'Less_Tree_Comment' ) || ( $class === 'Less_Tree_Ruleset' && $rule->rules ) ) { + if ( + ( $class === 'Less_Tree_Media' ) || + ( $class === 'Less_Tree_Directive' ) || + ( $this->root && $class === 'Less_Tree_Comment' ) || + ( $rule instanceof Less_Tree_Ruleset && $rule->rules ) + ) { $rulesetNodes[] = $rule; } else { $ruleNodes[] = $rule; @@ -373,16 +393,6 @@ class Less_Tree_Ruleset extends Less_Tree { // If this is the root node, we don't render // a selector, or {}. if ( !$this->root ) { - - /* - debugInfo = tree.debugInfo(env, this, tabSetStr); - - if (debugInfo) { - output.add(debugInfo); - output.add(tabSetStr); - } - */ - $paths_len = count( $this->paths ); for ( $i = 0; $i < $paths_len; $i++ ) { $path = $this->paths[$i]; @@ -443,7 +453,6 @@ class Less_Tree_Ruleset extends Less_Tree { if ( !Less_Parser::$options['compress'] && $this->firstRoot ) { $output->add( "\n" ); } - } function markReferenced() { @@ -455,9 +464,14 @@ class Less_Tree_Ruleset extends Less_Tree { } } + /** + * @param Less_Tree_Selector[][] $context + * @param Less_Tree_Selector[]|null $selectors + * @return Less_Tree_Selector[][] + */ public function joinSelectors( $context, $selectors ) { - $paths = array(); - if ( is_array( $selectors ) ) { + $paths = []; + if ( $selectors !== null ) { foreach ( $selectors as $selector ) { $this->joinSelector( $paths, $context, $selector ); } @@ -465,26 +479,37 @@ class Less_Tree_Ruleset extends Less_Tree { return $paths; } - public function joinSelector( &$paths, $context, $selector ) { - $hasParentSelector = false; + public function joinSelector( array &$paths, array $context, Less_Tree_Selector $selector ) { + $newPaths = []; + $hadParentSelector = $this->replaceParentSelector( $newPaths, $context, $selector ); - foreach ( $selector->elements as $el ) { - if ( $el->value === '&' ) { - $hasParentSelector = true; - } - } - - if ( !$hasParentSelector ) { + if ( !$hadParentSelector ) { if ( $context ) { - foreach ( $context as $context_el ) { - $paths[] = array_merge( $context_el, array( $selector ) ); + $newPaths = []; + foreach ( $context as $path ) { + $newPaths[] = array_merge( $path, [ $selector ] ); } } else { - $paths[] = array( $selector ); + $newPaths = [ [ $selector ] ]; } - return; } + foreach ( $newPaths as $newPath ) { + $paths[] = $newPath; + } + } + + /** + * Replace all parent selectors inside $inSelector with $context. + * + * @param array &$paths Resulting selectors are appended to $paths. + * @param mixed $context + * @param Less_Tree_Selector $inSelector Inner selector from Less_Tree_Paren + * @return bool True if $inSelector contained at least one parent selector + */ + private function replaceParentSelector( array &$paths, $context, Less_Tree_Selector $inSelector ) { + $hadParentSelector = false; + // The paths are [[Selector]] // The first list is a list of comma separated selectors // The inner list is a list of inheritance separated selectors @@ -497,86 +522,70 @@ class Less_Tree_Ruleset extends Less_Tree { // // the elements from the current selector so far - $currentElements = array(); + $currentElements = []; // the current list of new selectors to add to the path. // We will build it up. We initiate it with one empty selector as we "multiply" the new selectors // by the parents - $newSelectors = array( array() ); + $newSelectors = [ + [] + ]; - foreach ( $selector->elements as $el ) { - - // non parent reference elements just get added + foreach ( $inSelector->elements as $el ) { + // non-parent reference elements just get added if ( $el->value !== '&' ) { - $currentElements[] = $el; + $nestedSelector = $this->findNestedSelector( $el ); + if ( $nestedSelector !== null ) { + $this->mergeElementsOnToSelectors( $currentElements, $newSelectors ); + + $nestedPaths = []; + $replacedNewSelectors = []; + $replaced = $this->replaceParentSelector( $nestedPaths, $context, $nestedSelector ); + $hadParentSelector = $hadParentSelector || $replaced; + // $nestedPaths is populated by replaceParentSelector() + // $nestedPaths should have exactly one TODO, replaceParentSelector does not multiply selectors + foreach ( $nestedPaths as $nestedPath ) { + $replacementSelector = $this->createSelector( $nestedPath, $el ); + + // join selector path from $newSelectors with every selector path in $addPaths array. + // $el contains the element that is being replaced by $addPaths + // + // @see less-2.5.3.js#Ruleset-addAllReplacementsIntoPath + $addPaths = [ $replacementSelector ]; + foreach ( $newSelectors as $newSelector ) { + $replacedNewSelectors[] = $this->addReplacementIntoPath( $newSelector, $addPaths, $el, $inSelector ); + } + } + $newSelectors = $replacedNewSelectors; + $currentElements = []; + } else { + $currentElements[] = $el; + } } else { + $hadParentSelector = true; + // the new list of selectors to add - $selectorsMultiplied = array(); + $selectorsMultiplied = []; // merge the current list of non parent selector elements // on to the current list of selectors to add - if ( $currentElements ) { - $this->mergeElementsOnToSelectors( $currentElements, $newSelectors ); - } + $this->mergeElementsOnToSelectors( $currentElements, $newSelectors ); - // loop through our current selectors foreach ( $newSelectors as $sel ) { - // if we don't have any parent paths, the & might be in a mixin so that it can be used // whether there are parents or not if ( !$context ) { // the combinator used on el should now be applied to the next element instead so that // it is not lost if ( $sel ) { - $sel[0]->elements = array_slice( $sel[0]->elements, 0 ); $sel[0]->elements[] = new Less_Tree_Element( $el->combinator, '', $el->index, $el->currentFileInfo ); } $selectorsMultiplied[] = $sel; } else { - // and the parent selectors foreach ( $context as $parentSel ) { // We need to put the current selectors // then join the last selector's elements on to the parents selectors - - // our new selector path - $newSelectorPath = array(); - // selectors from the parent after the join - $afterParentJoin = array(); - $newJoinedSelectorEmpty = true; - - // construct the joined selector - if & is the first thing this will be empty, - // if not newJoinedSelector will be the last set of elements in the selector - if ( $sel ) { - $newSelectorPath = $sel; - $lastSelector = array_pop( $newSelectorPath ); - $newJoinedSelector = $selector->createDerived( array_slice( $lastSelector->elements, 0 ) ); - $newJoinedSelectorEmpty = false; - } else { - $newJoinedSelector = $selector->createDerived( array() ); - } - - // put together the parent selectors after the join - if ( count( $parentSel ) > 1 ) { - $afterParentJoin = array_merge( $afterParentJoin, array_slice( $parentSel, 1 ) ); - } - - if ( $parentSel ) { - $newJoinedSelectorEmpty = false; - - // join the elements so far with the first part of the parent - $newJoinedSelector->elements[] = new Less_Tree_Element( $el->combinator, $parentSel[0]->elements[0]->value, $el->index, $el->currentFileInfo ); - - $newJoinedSelector->elements = array_merge( $newJoinedSelector->elements, array_slice( $parentSel[0]->elements, 1 ) ); - } - - if ( !$newJoinedSelectorEmpty ) { - // now add the joined selector - $newSelectorPath[] = $newJoinedSelector; - } - - // and the rest of the parent - $newSelectorPath = array_merge( $newSelectorPath, $afterParentJoin ); - + $newSelectorPath = $this->addReplacementIntoPath( $sel, $parentSel, $el, $inSelector ); // add that to our new set of selectors $selectorsMultiplied[] = $newSelectorPath; } @@ -585,30 +594,130 @@ class Less_Tree_Ruleset extends Less_Tree { // our new selectors has been multiplied, so reset the state $newSelectors = $selectorsMultiplied; - $currentElements = array(); + $currentElements = []; } } // if we have any elements left over (e.g. .a& .b == .b) // add them on to all the current selectors - if ( $currentElements ) { - $this->mergeElementsOnToSelectors( $currentElements, $newSelectors ); - } - foreach ( $newSelectors as $new_sel ) { - if ( $new_sel ) { - $paths[] = $new_sel; + $this->mergeElementsOnToSelectors( $currentElements, $newSelectors ); + + foreach ( $newSelectors as &$sel ) { + $length = count( $sel ); + if ( $length ) { + $paths[] = $sel; + $lastSelector = $sel[$length - 1]; + $sel[$length - 1] = $lastSelector->createDerived( $lastSelector->elements, $inSelector->extendList ); } } + + return $hadParentSelector; + } + + /** + * @param array $elementsToPak + * @param Less_Tree_Element $originalElement + * @return Less_Tree_Selector + */ + private function createSelector( array $elementsToPak, $originalElement ) { + if ( !$elementsToPak ) { + // This is an invalid call. Kept to match less.js. Appears unreachable. + // @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal + $containedElement = new Less_Tree_Paren( null ); + } else { + $insideParent = []; + foreach ( $elementsToPak as $elToPak ) { + $insideParent[] = new Less_Tree_Element( null, $elToPak, $originalElement->index, $originalElement->currentFileInfo ); + } + $containedElement = new Less_Tree_Paren( new Less_Tree_Selector( $insideParent ) ); + } + + $element = new Less_Tree_Element( null, $containedElement, $originalElement->index, $originalElement->currentFileInfo ); + return new Less_Tree_Selector( [ $element ] ); + } + + /** + * @param Less_Tree_Element $element + * @return Less_Tree_Selector|null + */ + private function findNestedSelector( $element ) { + $maybeParen = $element->value; + if ( !( $maybeParen instanceof Less_Tree_Paren ) ) { + return null; + } + $maybeSelector = $maybeParen->value; + if ( !( $maybeSelector instanceof Less_Tree_Selector ) ) { + return null; + } + return $maybeSelector; + } + + /** + * joins selector path from $beginningPath with selector path in $addPath. + * + * $replacedElement contains the element that is being replaced by $addPath + * + * @param Less_Tree_Selector[] $beginningPath + * @param Less_Tree_Selector[] $addPath + * @param Less_Tree_Element $replacedElement + * @param Less_Tree_Selector $originalSelector + * @return Less_Tree_Selector[] Concatenated path + * @see less-2.5.3.js#Ruleset-addReplacementIntoPath + */ + private function addReplacementIntoPath( array $beginningPath, array $addPath, $replacedElement, $originalSelector ) { + // our new selector path + $newSelectorPath = []; + + // construct the joined selector - if `&` is the first thing this will be empty, + // if not newJoinedSelector will be the last set of elements in the selector + if ( $beginningPath ) { + // NOTE: less.js uses Array slice() to copy. In PHP, arrays are naturally copied by value. + $newSelectorPath = $beginningPath; + $lastSelector = array_pop( $newSelectorPath ); + $newJoinedSelector = $originalSelector->createDerived( $lastSelector->elements ); + } else { + $newJoinedSelector = $originalSelector->createDerived( [] ); + } + + if ( $addPath ) { + // if the & does not have a combinator that is "" or " " then + // and there is a combinator on the parent, then grab that. + // this also allows `+ a { & .b { .a & { ...` + $combinator = $replacedElement->combinator; + $parentEl = $addPath[0]->elements[0]; + if ( $replacedElement->combinatorIsEmptyOrWhitespace && !$parentEl->combinatorIsEmptyOrWhitespace ) { + $combinator = $parentEl->combinator; + } + // join the elements so far with the first part of the parent + $newJoinedSelector->elements[] = new Less_Tree_Element( $combinator, $parentEl->value, $replacedElement->index, $replacedElement->currentFileInfo ); + $newJoinedSelector->elements = array_merge( + $newJoinedSelector->elements, + array_slice( $addPath[0]->elements, 1 ) + ); + } + + // now add the joined selector - but only if it is not empty + if ( $newJoinedSelector->elements ) { + $newSelectorPath[] = $newJoinedSelector; + } + + // put together the parent selectors after the join (e.g. the rest of the parent) + if ( count( $addPath ) > 1 ) { + $newSelectorPath = array_merge( $newSelectorPath, array_slice( $addPath, 1 ) ); + } + return $newSelectorPath; } function mergeElementsOnToSelectors( $elements, &$selectors ) { + if ( !$elements ) { + return; + } if ( !$selectors ) { - $selectors[] = array( new Less_Tree_Selector( $elements ) ); + $selectors[] = [ new Less_Tree_Selector( $elements ) ]; return; } foreach ( $selectors as &$sel ) { - // if the previous thing in sel is a parent this needs to join on to it if ( $sel ) { $last = count( $sel ) - 1; diff --git a/vendor/wikimedia/less.php/lib/Less/Tree/RulesetCall.php b/vendor/wikimedia/less.php/lib/Less/Tree/RulesetCall.php index 079ff4f..9c162b8 100644 --- a/vendor/wikimedia/less.php/lib/Less/Tree/RulesetCall.php +++ b/vendor/wikimedia/less.php/lib/Less/Tree/RulesetCall.php @@ -1,16 +1,15 @@ variable = $variable; } @@ -21,6 +20,7 @@ class Less_Tree_RulesetCall extends Less_Tree { public function compile( $env ) { $variable = new Less_Tree_Variable( $this->variable ); $detachedRuleset = $variable->compile( $env ); + '@phan-var Less_Tree_DetachedRuleset $detachedRuleset'; return $detachedRuleset->callEval( $env ); } } diff --git a/vendor/wikimedia/less.php/lib/Less/Tree/Selector.php b/vendor/wikimedia/less.php/lib/Less/Tree/Selector.php index 7ecfc6a..71182da 100644 --- a/vendor/wikimedia/less.php/lib/Less/Tree/Selector.php +++ b/vendor/wikimedia/less.php/lib/Less/Tree/Selector.php @@ -1,21 +1,17 @@ elements = $elements; $this->elements_len = count( $elements ); $this->extendList = $extendList; @@ -58,8 +54,16 @@ class Less_Tree_Selector extends Less_Tree { } public function createDerived( $elements, $extendList = null, $evaldCondition = null ) { - $newSelector = new Less_Tree_Selector( $elements, ( $extendList ? $extendList : $this->extendList ), null, $this->index, $this->currentFileInfo, $this->isReferenced ); - $newSelector->evaldCondition = $evaldCondition ? $evaldCondition : $this->evaldCondition; + $newSelector = new Less_Tree_Selector( + $elements, + ( $extendList ?: $this->extendList ), + null, + $this->index, + $this->currentFileInfo, + $this->isReferenced + ); + $newSelector->evaldCondition = $evaldCondition ?: $this->evaldCondition; + $newSelector->mediaEmpty = $this->mediaEmpty; return $newSelector; } @@ -78,8 +82,8 @@ class Less_Tree_Selector extends Less_Tree { } public function CacheElements() { - $this->_oelements = array(); - $this->_oelements_assoc = array(); + $this->_oelements = []; + $this->_oelements_assoc = []; $css = ''; @@ -119,12 +123,12 @@ class Less_Tree_Selector extends Less_Tree { } public function compile( $env ) { - $elements = array(); + $elements = []; foreach ( $this->elements as $el ) { $elements[] = $el->compile( $env ); } - $extendList = array(); + $extendList = []; foreach ( $this->extendList as $el ) { $extendList[] = $el->compile( $el ); } diff --git a/vendor/wikimedia/less.php/lib/Less/Tree/UnicodeDescriptor.php b/vendor/wikimedia/less.php/lib/Less/Tree/UnicodeDescriptor.php index 38e0526..304d191 100644 --- a/vendor/wikimedia/less.php/lib/Less/Tree/UnicodeDescriptor.php +++ b/vendor/wikimedia/less.php/lib/Less/Tree/UnicodeDescriptor.php @@ -1,10 +1,6 @@ add( $this->value ); } - - public function compile() { - return $this; - } } diff --git a/vendor/wikimedia/less.php/lib/Less/Tree/Unit.php b/vendor/wikimedia/less.php/lib/Less/Tree/Unit.php index 29230df..2fd8927 100644 --- a/vendor/wikimedia/less.php/lib/Less/Tree/Unit.php +++ b/vendor/wikimedia/less.php/lib/Less/Tree/Unit.php @@ -1,19 +1,15 @@ numerator = $numerator; $this->denominator = $denominator; $this->backupUnit = $backupUnit; @@ -39,7 +35,7 @@ class Less_Tree_Unit extends Less_Tree { public function toString() { $returnStr = implode( '*', $this->numerator ); foreach ( $this->denominator as $d ) { - $returnStr .= '/'.$d; + $returnStr .= '/' . $d; } return $returnStr; } @@ -61,7 +57,7 @@ class Less_Tree_Unit extends Less_Tree { public function isLength() { $css = $this->toCSS(); - return !!preg_match( '/px|em|%|in|cm|mm|pc|pt|ex/', $css ); + return (bool)preg_match( '/px|em|%|in|cm|mm|pc|pt|ex/', $css ); } public function isAngle() { @@ -77,7 +73,7 @@ class Less_Tree_Unit extends Less_Tree { } public function usedUnits() { - $result = array(); + $result = []; foreach ( Less_Tree_UnitConversions::$groups as $groupName ) { $group = Less_Tree_UnitConversions::${$groupName}; @@ -99,25 +95,25 @@ class Less_Tree_Unit extends Less_Tree { } public function cancel() { - $counter = array(); + $counter = []; $backup = null; foreach ( $this->numerator as $atomicUnit ) { if ( !$backup ) { $backup = $atomicUnit; } - $counter[$atomicUnit] = ( isset( $counter[$atomicUnit] ) ? $counter[$atomicUnit] : 0 ) + 1; + $counter[$atomicUnit] = ( $counter[$atomicUnit] ?? 0 ) + 1; } foreach ( $this->denominator as $atomicUnit ) { if ( !$backup ) { $backup = $atomicUnit; } - $counter[$atomicUnit] = ( isset( $counter[$atomicUnit] ) ? $counter[$atomicUnit] : 0 ) - 1; + $counter[$atomicUnit] = ( $counter[$atomicUnit] ?? 0 ) - 1; } - $this->numerator = array(); - $this->denominator = array(); + $this->numerator = []; + $this->denominator = []; foreach ( $counter as $atomicUnit => $count ) { if ( $count > 0 ) { diff --git a/vendor/wikimedia/less.php/lib/Less/Tree/UnitConversions.php b/vendor/wikimedia/less.php/lib/Less/Tree/UnitConversions.php index 7f857fb..31efe1c 100644 --- a/vendor/wikimedia/less.php/lib/Less/Tree/UnitConversions.php +++ b/vendor/wikimedia/less.php/lib/Less/Tree/UnitConversions.php @@ -1,16 +1,12 @@ 1, 'cm' => 0.01, 'mm' => 0.001, @@ -18,18 +14,18 @@ class Less_Tree_UnitConversions { 'px' => 0.000264583, // 0.0254 / 96, 'pt' => 0.000352778, // 0.0254 / 72, 'pc' => 0.004233333, // 0.0254 / 72 * 12 - ); + ]; - public static $duration = array( + public static $duration = [ 's' => 1, 'ms' => 0.001 - ); + ]; - public static $angle = array( + public static $angle = [ 'rad' => 0.1591549430919, // 1/(2*M_PI), 'deg' => 0.002777778, // 1/360, 'grad' => 0.0025, // 1/400, 'turn' => 1 - ); + ]; } diff --git a/vendor/wikimedia/less.php/lib/Less/Tree/Url.php b/vendor/wikimedia/less.php/lib/Less/Tree/Url.php index 4e7f114..6ae3518 100644 --- a/vendor/wikimedia/less.php/lib/Less/Tree/Url.php +++ b/vendor/wikimedia/less.php/lib/Less/Tree/Url.php @@ -1,10 +1,6 @@ value = $value; $this->currentFileInfo = $currentFileInfo; @@ -34,7 +35,7 @@ class Less_Tree_Url extends Less_Tree { } /** - * @param Less_Functions $ctx + * @param Less_Environment $ctx */ public function compile( $ctx ) { $val = $this->value->compile( $ctx ); diff --git a/vendor/wikimedia/less.php/lib/Less/Tree/Value.php b/vendor/wikimedia/less.php/lib/Less/Tree/Value.php index a4c0d85..bf45caf 100644 --- a/vendor/wikimedia/less.php/lib/Less/Tree/Value.php +++ b/vendor/wikimedia/less.php/lib/Less/Tree/Value.php @@ -1,16 +1,15 @@ $value + */ public function __construct( $value ) { $this->value = $value; } @@ -20,7 +19,7 @@ class Less_Tree_Value extends Less_Tree { } public function compile( $env ) { - $ret = array(); + $ret = []; $i = 0; foreach ( $this->value as $i => $v ) { $ret[] = $v->compile( $env ); diff --git a/vendor/wikimedia/less.php/lib/Less/Tree/Variable.php b/vendor/wikimedia/less.php/lib/Less/Tree/Variable.php index e36d3d4..dcb1823 100644 --- a/vendor/wikimedia/less.php/lib/Less/Tree/Variable.php +++ b/vendor/wikimedia/less.php/lib/Less/Tree/Variable.php @@ -1,10 +1,6 @@ currentFileInfo = $currentFileInfo; } + /** + * @param Less_Environment $env + * @return Less_Tree + * @see less-2.5.3.js#Ruleset.prototype.eval + */ public function compile( $env ) { if ( $this->name[1] === '@' ) { $v = new Less_Tree_Variable( substr( $this->name, 1 ), $this->index + 1, $this->currentFileInfo ); + // While some Less_Tree nodes have no 'value', we know these can't ocurr after a variable + // assignment (would have been a ParseError). + // TODO: Solve better (https://phabricator.wikimedia.org/T327082). + // @phan-suppress-next-line PhanUndeclaredProperty $name = '@' . $v->compile( $env )->value; } else { $name = $this->name; @@ -45,7 +50,7 @@ class Less_Tree_Variable extends Less_Tree { } } - throw new Less_Exception_Compiler( "variable " . $name . " is undefined in file ".$this->currentFileInfo["filename"], null, $this->index, $this->currentFileInfo ); + throw new Less_Exception_Compiler( "variable " . $name . " is undefined in file " . $this->currentFileInfo["filename"], null, $this->index, $this->currentFileInfo ); } } diff --git a/vendor/wikimedia/less.php/lib/Less/Version.php b/vendor/wikimedia/less.php/lib/Less/Version.php index 2d05c38..1c96e8e 100644 --- a/vendor/wikimedia/less.php/lib/Less/Version.php +++ b/vendor/wikimedia/less.php/lib/Less/Version.php @@ -2,13 +2,10 @@ /** * Release numbers - * - * @package Less - * @subpackage version */ class Less_Version { - public const version = '3.1.0'; // The current build number of less.php + public const version = '3.2.1'; // The current build number of less.php public const less_version = '2.5.3'; // The less.js version that this build should be compatible with public const cache_version = '253'; // The parser cache version diff --git a/vendor/wikimedia/less.php/lib/Less/Visitor.php b/vendor/wikimedia/less.php/lib/Less/Visitor.php index 4aed540..582f323 100644 --- a/vendor/wikimedia/less.php/lib/Less/Visitor.php +++ b/vendor/wikimedia/less.php/lib/Less/Visitor.php @@ -1,15 +1,11 @@ _visitFnCache = get_class_methods( get_class( $this ) ); @@ -17,7 +13,7 @@ class Less_Visitor { } public function visitObj( $node ) { - $funcName = 'visit'.$node->type; + $funcName = 'visit' . $node->type; if ( isset( $this->_visitFnCache[$funcName] ) ) { $visitDeeper = true; @@ -27,7 +23,7 @@ class Less_Visitor { $node->accept( $this ); } - $funcName = $funcName . "Out"; + $funcName .= "Out"; if ( isset( $this->_visitFnCache[$funcName] ) ) { $this->$funcName( $node ); } @@ -40,7 +36,9 @@ class Less_Visitor { } public function visitArray( $nodes ) { - array_map( array( $this,'visitObj' ), $nodes ); + foreach ( $nodes as $node ) { + $this->visitObj( $node ); + } return $nodes; } } diff --git a/vendor/wikimedia/less.php/lib/Less/Visitor/extendFinder.php b/vendor/wikimedia/less.php/lib/Less/Visitor/extendFinder.php index 7d5d3fd..8b3238d 100644 --- a/vendor/wikimedia/less.php/lib/Less/Visitor/extendFinder.php +++ b/vendor/wikimedia/less.php/lib/Less/Visitor/extendFinder.php @@ -1,20 +1,16 @@ contexts = array(); - $this->allExtendsStack = array( array() ); + $this->contexts = []; + $this->allExtendsStack = [ [] ]; parent::__construct(); } @@ -40,7 +36,7 @@ class Less_Visitor_extendFinder extends Less_Visitor { return; } - $allSelectorsExtendList = array(); + $allSelectorsExtendList = []; // get &:extend(.a); rules which apply to all selectors in this ruleset if ( $rulesetNode->rules ) { @@ -90,7 +86,7 @@ class Less_Visitor_extendFinder extends Less_Visitor { } public function visitMedia( $mediaNode ) { - $mediaNode->allExtends = array(); + $mediaNode->allExtends = []; $this->allExtendsStack[] =& $mediaNode->allExtends; } @@ -99,7 +95,7 @@ class Less_Visitor_extendFinder extends Less_Visitor { } public function visitDirective( $directiveNode ) { - $directiveNode->allExtends = array(); + $directiveNode->allExtends = []; $this->allExtendsStack[] =& $directiveNode->allExtends; } diff --git a/vendor/wikimedia/less.php/lib/Less/Visitor/joinSelector.php b/vendor/wikimedia/less.php/lib/Less/Visitor/joinSelector.php index bb08ece..a106830 100644 --- a/vendor/wikimedia/less.php/lib/Less/Visitor/joinSelector.php +++ b/vendor/wikimedia/less.php/lib/Less/Visitor/joinSelector.php @@ -1,14 +1,10 @@ contexts ); + $paths = []; if ( !$rulesetNode->root ) { - $selectors = array(); - - if ( $rulesetNode->selectors && $rulesetNode->selectors ) { - foreach ( $rulesetNode->selectors as $selector ) { + $selectors = $rulesetNode->selectors; + if ( $selectors !== null ) { + $filtered = []; + foreach ( $selectors as $selector ) { if ( $selector->getIsOutput() ) { - $selectors[] = $selector; + $filtered[] = $selector; } } + $selectors = $rulesetNode->selectors = $filtered ?: null; + if ( $selectors ) { + $paths = $rulesetNode->joinSelectors( $context, $selectors ); + } } - if ( !$selectors ) { - $rulesetNode->selectors = null; + if ( $selectors === null ) { $rulesetNode->rules = null; - } else { - $context = end( $this->contexts ); // $context = $this->contexts[ count($this->contexts) - 1]; - $paths = $rulesetNode->joinSelectors( $context, $selectors ); } $rulesetNode->paths = $paths; } - $this->contexts[] = $paths; // different from less.js. Placed after joinSelectors() so that $this->contexts will get correct $paths + // NOTE: Assigned here instead of at the start like less.js, + // because PHP arrays aren't by-ref + $this->contexts[] = $paths; } public function visitRulesetOut() { @@ -58,9 +57,9 @@ class Less_Visitor_joinSelector extends Less_Visitor { } public function visitMedia( $mediaNode ) { - $context = end( $this->contexts ); // $context = $this->contexts[ count($this->contexts) - 1]; + $context = end( $this->contexts ); - if ( !count( $context ) || ( is_object( $context[0] ) && $context[0]->multiMedia ) ) { + if ( count( $context ) === 0 || ( is_object( $context[0] ) && $context[0]->multiMedia ) ) { $mediaNode->rules[0]->root = true; } } diff --git a/vendor/wikimedia/less.php/lib/Less/Visitor/processExtends.php b/vendor/wikimedia/less.php/lib/Less/Visitor/processExtends.php index 65082a4..9491f3c 100644 --- a/vendor/wikimedia/less.php/lib/Less/Visitor/processExtends.php +++ b/vendor/wikimedia/less.php/lib/Less/Visitor/processExtends.php @@ -1,10 +1,6 @@ allExtends = $this->doExtendChaining( $root->allExtends, $root->allExtends ); - $this->allExtendsStack = array(); + $this->allExtendsStack = []; $this->allExtendsStack[] = &$root->allExtends; return $this->visitObj( $root ); @@ -38,7 +34,7 @@ class Less_Visitor_processExtends extends Less_Visitor { // this is also the most expensive.. and a match on one selector can cause an extension of a selector we had already processed if // we look at each selector at a time, as is done in visitRuleset - $extendsToAdd = array(); + $extendsToAdd = []; // loop through comparing every extend with every target extend. // a target extend is the one on the ruleset we are looking at copy/edit/pasting in place @@ -52,14 +48,14 @@ class Less_Visitor_processExtends extends Less_Visitor { $extend = $extendsList[$extendIndex]; $targetExtend = $extendsListTarget[$targetExtendIndex]; - // Optimisation: Explicit reference,  + // Optimisation: Explicit reference, if ( \array_key_exists( $targetExtend->object_id, $extend->parent_ids ) ) { // ignore circular references continue; } // find a match in the target extends self selector (the bit before :extend) - $selectorPath = array( $targetExtend->selfSelectors[0] ); + $selectorPath = [ $targetExtend->selfSelectors[0] ]; $matches = $this->findMatch( $extend, $selectorPath ); if ( $matches ) { @@ -75,7 +71,7 @@ class Less_Visitor_processExtends extends Less_Visitor { $newExtend->selfSelectors = $newSelector; // add the extend onto the list of extends for that selector - end( $newSelector )->extendList = array( $newExtend ); + end( $newSelector )->extendList = [ $newExtend ]; // $newSelector[ count($newSelector)-1]->extendList = array($newExtend); // record that we need to add it. @@ -171,6 +167,11 @@ class Less_Visitor_processExtends extends Less_Visitor { } } + /** + * @param Less_Tree_Extend $extend + * @param Less_Tree_Selector[] $haystackSelectorPath + * @return false|array + */ private function findMatch( $extend, $haystackSelectorPath ) { if ( !$this->HasMatches( $extend, $haystackSelectorPath ) ) { return false; @@ -181,10 +182,10 @@ class Less_Visitor_processExtends extends Less_Visitor { // returns an array of selector matches that can then be replaced // $needleElements = $extend->selector->elements; - $potentialMatches = array(); + $potentialMatches = []; $potentialMatches_len = 0; $potentialMatch = null; - $matches = array(); + $matches = []; // loop through the haystack elements $haystack_path_len = count( $haystackSelectorPath ); @@ -198,7 +199,7 @@ class Less_Visitor_processExtends extends Less_Visitor { // if we allow elements before our match we can add a potential match every time. otherwise only at the first element. if ( $extend->allowBefore || ( $haystackSelectorIndex === 0 && $hackstackElementIndex === 0 ) ) { - $potentialMatches[] = array( 'pathIndex' => $haystackSelectorIndex, 'index' => $hackstackElementIndex, 'matched' => 0, 'initialCombinator' => $haystackElement->combinator ); + $potentialMatches[] = [ 'pathIndex' => $haystackSelectorIndex, 'index' => $hackstackElementIndex, 'matched' => 0, 'initialCombinator' => $haystackElement->combinator ]; $potentialMatches_len++; } @@ -222,7 +223,7 @@ class Less_Visitor_processExtends extends Less_Visitor { $potentialMatch['length'] = $extend->selector->elements_len; $potentialMatch['endPathIndex'] = $haystackSelectorIndex; $potentialMatch['endPathElementIndex'] = $hackstackElementIndex + 1; // index after end of match - $potentialMatches = array(); // we don't allow matches to overlap, so start matching again + $potentialMatches = []; // we don't allow matches to overlap, so start matching again $potentialMatches_len = 0; $matches[] = $potentialMatch; } @@ -253,7 +254,7 @@ class Less_Visitor_processExtends extends Less_Visitor { return true; } - // Optimisation: Explicit reference,  + // Optimisation: Explicit reference, if ( \array_key_exists( $first_el, $hackstackSelector->_oelements_assoc ) ) { return true; } @@ -263,7 +264,7 @@ class Less_Visitor_processExtends extends Less_Visitor { } /** - * @param integer $hackstackElementIndex + * @param int $hackstackElementIndex */ private function PotentialMatch( $potentialMatch, $needleElements, $haystackElement, $hackstackElementIndex ) { if ( $potentialMatch['matched'] > 0 ) { @@ -292,6 +293,11 @@ class Less_Visitor_processExtends extends Less_Visitor { return $potentialMatch; } + /** + * @param string|Less_Tree_Attribute|Less_Tree_Dimension|Less_Tree_Keyword $elementValue1 + * @param string|Less_Tree_Attribute|Less_Tree_Dimension|Less_Tree_Keyword $elementValue2 + * @return bool + */ private function isElementValuesEqual( $elementValue1, $elementValue2 ) { if ( $elementValue1 === $elementValue2 ) { return true; @@ -353,8 +359,8 @@ class Less_Visitor_processExtends extends Less_Visitor { return true; } - $elementValue1 = ( $elementValue1->value->value ? $elementValue1->value->value : $elementValue1->value ); - $elementValue2 = ( $elementValue2->value->value ? $elementValue2->value->value : $elementValue2->value ); + $elementValue1 = ( $elementValue1->value->value ?: $elementValue1->value ); + $elementValue2 = ( $elementValue2->value->value ?: $elementValue2->value ); return $elementValue1 === $elementValue2; } @@ -364,7 +370,7 @@ class Less_Visitor_processExtends extends Less_Visitor { $currentSelectorPathIndex = 0; $currentSelectorPathElementIndex = 0; - $path = array(); + $path = []; $selectorPath_len = count( $selectorPath ); for ( $matchIndex = 0, $matches_len = count( $matches ); $matchIndex < $matches_len; $matchIndex++ ) { @@ -388,7 +394,7 @@ class Less_Visitor_processExtends extends Less_Visitor { $newElements = array_merge( array_slice( $selector->elements, $currentSelectorPathElementIndex, ( $match['index'] - $currentSelectorPathElementIndex ) ), // last parameter of array_slice is different than the last parameter of javascript's slice - array( $firstElement ), + [ $firstElement ], array_slice( $replacementSelector->elements, 1 ) ); diff --git a/vendor/wikimedia/less.php/lib/Less/Visitor/toCSS.php b/vendor/wikimedia/less.php/lib/Less/Visitor/toCSS.php index e90f211..6c476d2 100644 --- a/vendor/wikimedia/less.php/lib/Less/Visitor/toCSS.php +++ b/vendor/wikimedia/less.php/lib/Less/Visitor/toCSS.php @@ -1,10 +1,6 @@ variable ) { - return array(); + return []; } return $ruleNode; } @@ -31,17 +27,17 @@ class Less_Visitor_toCSS extends Less_VisitorReplacing { public function visitMixinDefinition( $mixinNode ) { // mixin definitions do not get eval'd - this means they keep state // so we have to clear that state here so it isn't used if toCSS is called twice - $mixinNode->frames = array(); - return array(); + $mixinNode->frames = []; + return []; } public function visitExtend() { - return array(); + return []; } public function visitComment( $commentNode ) { if ( $commentNode->isSilent() ) { - return array(); + return []; } return $commentNode; } @@ -51,14 +47,14 @@ class Less_Visitor_toCSS extends Less_VisitorReplacing { $visitDeeper = false; if ( !$mediaNode->rules ) { - return array(); + return []; } return $mediaNode; } public function visitDirective( $directiveNode ) { if ( isset( $directiveNode->currentFileInfo['reference'] ) && ( !property_exists( $directiveNode, 'isReferenced' ) || !$directiveNode->isReferenced ) ) { - return array(); + return []; } if ( $directiveNode->name === '@charset' ) { // Only output the debug info together with subsequent @charset definitions @@ -72,7 +68,7 @@ class Less_Visitor_toCSS extends Less_VisitorReplacing { // return $this->visit($comment); //} - return array(); + return []; } $this->charset = true; } @@ -86,7 +82,7 @@ class Less_Visitor_toCSS extends Less_VisitorReplacing { foreach ( $rulesetNode->rules as $ruleNode ) { if ( $ruleNode instanceof Less_Tree_Rule && !$ruleNode->variable ) { - $msg = "properties must be inside selector blocks, they cannot be in the root. Index ".$ruleNode->index.( $ruleNode->currentFileInfo ? ( ' Filename: '.$ruleNode->currentFileInfo['filename'] ) : null ); + $msg = "properties must be inside selector blocks, they cannot be in the root. Index " . $ruleNode->index . ( $ruleNode->currentFileInfo ? ( ' Filename: ' . $ruleNode->currentFileInfo['filename'] ) : null ); throw new Less_Exception_Compiler( $msg ); } } @@ -101,7 +97,7 @@ class Less_Visitor_toCSS extends Less_VisitorReplacing { return $this->visitRulesetRoot( $rulesetNode ); } - $rulesets = array(); + $rulesets = []; $rulesetNode->paths = $this->visitRulesetPaths( $rulesetNode ); // Compile rules and rulesets @@ -134,7 +130,7 @@ class Less_Visitor_toCSS extends Less_VisitorReplacing { // now decide whether we keep the ruleset if ( $rulesetNode->paths ) { // array_unshift($rulesets, $rulesetNode); - array_splice( $rulesets, 0, 0, array( $rulesetNode ) ); + array_splice( $rulesets, 0, 0, [ $rulesetNode ] ); } } @@ -156,7 +152,7 @@ class Less_Visitor_toCSS extends Less_VisitorReplacing { if ( $rulesetNode->firstRoot || $rulesetNode->rules ) { return $rulesetNode; } - return array(); + return []; } /** @@ -165,7 +161,7 @@ class Less_Visitor_toCSS extends Less_VisitorReplacing { * @return array */ private function visitRulesetPaths( $rulesetNode ) { - $paths = array(); + $paths = []; foreach ( $rulesetNode->paths as $p ) { if ( $p[0]->elements[0]->combinator === ' ' ) { $p[0]->elements[0]->combinator = ''; @@ -184,7 +180,7 @@ class Less_Visitor_toCSS extends Less_VisitorReplacing { protected function _removeDuplicateRules( &$rules ) { // remove duplicates - $ruleCache = array(); + $ruleCache = []; for ( $i = count( $rules ) - 1; $i >= 0; $i-- ) { $rule = $rules[$i]; if ( $rule instanceof Less_Tree_Rule || $rule instanceof Less_Tree_NameValue ) { @@ -195,7 +191,7 @@ class Less_Visitor_toCSS extends Less_VisitorReplacing { $ruleList =& $ruleCache[$rule->name]; if ( $ruleList instanceof Less_Tree_Rule || $ruleList instanceof Less_Tree_NameValue ) { - $ruleList = $ruleCache[$rule->name] = array( $ruleCache[$rule->name]->toCSS() ); + $ruleList = $ruleCache[$rule->name] = [ $ruleCache[$rule->name]->toCSS() ]; } $ruleCSS = $rule->toCSS(); @@ -210,7 +206,7 @@ class Less_Visitor_toCSS extends Less_VisitorReplacing { } protected function _mergeRules( &$rules ) { - $groups = array(); + $groups = []; // obj($rules); @@ -226,7 +222,7 @@ class Less_Visitor_toCSS extends Less_VisitorReplacing { } if ( !isset( $groups[$key] ) ) { - $groups[$key] = array(); + $groups[$key] = []; } else { array_splice( $rules, $i--, 1 ); $rules_len--; @@ -240,15 +236,15 @@ class Less_Visitor_toCSS extends Less_VisitorReplacing { if ( count( $parts ) > 1 ) { $rule = $parts[0]; - $spacedGroups = array(); - $lastSpacedGroup = array(); - $parts_mapped = array(); + $spacedGroups = []; + $lastSpacedGroup = []; + $parts_mapped = []; foreach ( $parts as $p ) { if ( $p->merge === '+' ) { if ( $lastSpacedGroup ) { $spacedGroups[] = self::toExpression( $lastSpacedGroup ); } - $lastSpacedGroup = array(); + $lastSpacedGroup = []; } $lastSpacedGroup[] = $p; } @@ -257,11 +253,10 @@ class Less_Visitor_toCSS extends Less_VisitorReplacing { $rule->value = self::toValue( $spacedGroups ); } } - } public static function toExpression( $values ) { - $mapped = array(); + $mapped = []; foreach ( $values as $p ) { $mapped[] = $p->value; } @@ -271,7 +266,7 @@ class Less_Visitor_toCSS extends Less_VisitorReplacing { public static function toValue( $values ) { // return new Less_Tree_Value($values); ?? - $mapped = array(); + $mapped = []; foreach ( $values as $p ) { $mapped[] = $p; } diff --git a/vendor/wikimedia/less.php/lib/Less/VisitorReplacing.php b/vendor/wikimedia/less.php/lib/Less/VisitorReplacing.php index cd401ad..ae8b82e 100644 --- a/vendor/wikimedia/less.php/lib/Less/VisitorReplacing.php +++ b/vendor/wikimedia/less.php/lib/Less/VisitorReplacing.php @@ -1,15 +1,11 @@ type; + $funcName = 'visit' . $node->type; if ( isset( $this->_visitFnCache[$funcName] ) ) { $visitDeeper = true; @@ -20,7 +16,7 @@ class Less_VisitorReplacing extends Less_Visitor { $node->accept( $this ); } - $funcName = $funcName . "Out"; + $funcName .= "Out"; if ( isset( $this->_visitFnCache[$funcName] ) ) { $this->$funcName( $node ); } @@ -34,7 +30,7 @@ class Less_VisitorReplacing extends Less_Visitor { } public function visitArray( $nodes ) { - $newNodes = array(); + $newNodes = []; foreach ( $nodes as $node ) { $evald = $this->visitObj( $node ); if ( $evald ) {