From 8a02eee5bdd9db4d597a6e8d4ec3cd26dd798152 Mon Sep 17 00:00:00 2001 From: Mario Borna Mjertan Date: Fri, 25 Mar 2022 15:18:19 +0100 Subject: [PATCH 01/10] Use DIRECTORY_SEPARATOR instead of / --- src/Blocks/AbstractBlocksCli.php | 14 ++++++++------ src/Cli/AbstractCli.php | 33 +++++++++++++++++++------------- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/Blocks/AbstractBlocksCli.php b/src/Blocks/AbstractBlocksCli.php index 45943077f..7061bfb6f 100644 --- a/src/Blocks/AbstractBlocksCli.php +++ b/src/Blocks/AbstractBlocksCli.php @@ -38,7 +38,8 @@ protected function blocksMove(array $assocArgs, string $outputDir, bool $isCompo $root = $this->getProjectRootPath(); $rootNode = $this->getFrontendLibsBlockPath(); - $sourcePathFolder = "{$rootNode}/{$outputDir}/"; + $ds = DIRECTORY_SEPARATOR; + $sourcePathFolder = "{$rootNode}{$ds}{$outputDir}{$ds}"; $blocks = \scandir($sourcePathFolder); $blocksFullList = \array_diff((array)$blocks, ['..', '.']); @@ -53,13 +54,13 @@ protected function blocksMove(array $assocArgs, string $outputDir, bool $isCompo // Iterate blocks/components. foreach ($blocks as $block) { - $path = "{$outputDir}/{$block}"; + $path = "{$outputDir}{$ds}{$block}"; $sourcePath = "{$sourcePathFolder}{$block}"; if (!\getenv('TEST')) { - $destinationPath = $root . \DIRECTORY_SEPARATOR . $path; + $destinationPath = "{$root}{$ds}{$path}"; } else { - $destinationPath = $this->getProjectRootPath(true) . '/cliOutput'; + $destinationPath = "{$this->getProjectRootPath(true)}{$ds}cliOutput"; } $typePlural = !$isComponents ? 'blocks' : 'components'; @@ -115,11 +116,12 @@ protected function blocksMove(array $assocArgs, string $outputDir, bool $isCompo */ private function moveBlock(string $destinationPath, string $sourcePath, string $name, array $assocArgs, string $path, string $typeSingular): void { + $ds = DIRECTORY_SEPARATOR; // Create folder in project if missing. - \mkdir("{$destinationPath}/"); + \mkdir("{$destinationPath}{$ds}"); // Move block/component to project folder. - $this->copyRecursively($sourcePath, "{$destinationPath}/"); + $this->copyRecursively($sourcePath, "{$destinationPath}{$ds}"); $typeSingular = \ucfirst($typeSingular); diff --git a/src/Cli/AbstractCli.php b/src/Cli/AbstractCli.php index 8ae16d816..7bdc91b3d 100644 --- a/src/Cli/AbstractCli.php +++ b/src/Cli/AbstractCli.php @@ -246,11 +246,12 @@ function ($item) { */ public function getExampleTemplate(string $currentDir, string $fileName, bool $skipMissing = false): self { - $path = "{$currentDir}/{$this->getExampleFileName( $fileName )}.php"; + $ds = DIRECTORY_SEPARATOR; + $path = "{$currentDir}{$ds}{$this->getExampleFileName( $fileName )}.php"; // If you pass file name with extension the version will be used. if (\strpos($fileName, '.') !== false) { - $path = "{$currentDir}/{$fileName}"; + $path = "{$currentDir}{$ds}{$fileName}"; } $templateFile = ''; @@ -345,10 +346,11 @@ public function outputWrite(string $outputDir, string $outputFile, array $args = */ public function getOutputDir(string $path = ''): string { + $ds = DIRECTORY_SEPARATOR; if (\function_exists('\add_action') && !\getenv('TEST')) { $root = $this->getProjectRootPath(); } else { - $root = $this->getProjectRootPath(true) . '/cliOutput'; + $root = "{$this->getProjectRootPath(true)}{$ds}cliOutput"; } $ds = \DIRECTORY_SEPARATOR; @@ -657,11 +659,12 @@ public function searchReplaceString(string $oldString, string $newString): self */ public function getComposer(array $args = []): array { + $ds = DIRECTORY_SEPARATOR; if (!isset($args['config_path'])) { if (\function_exists('\add_action')) { - $composerPath = $this->getProjectRootPath() . '/composer.json'; + $composerPath = "{$this->getProjectRootPath()}{$ds}composer.json"; } else { - $composerPath = $this->getProjectRootPath(true) . '/composer.json'; + $composerPath = "{$this->getProjectRootPath(true)}{$ds}composer.json"; } } else { $composerPath = $args['config_path']; @@ -834,7 +837,8 @@ public function getProjectConfigRootPath(bool $isDev = false): string */ public function getFrontendLibsPath(string $path = ''): string { - return "{$this->getProjectRootPath()}/node_modules/@eightshift/frontend-libs/{$path}"; + $ds = DIRECTORY_SEPARATOR; + return "{$this->getProjectRootPath()}{$ds}node_modules{$ds}@eightshift{$ds}frontend-libs{$ds}{$path}"; } /** @@ -846,11 +850,12 @@ public function getFrontendLibsPath(string $path = ''): string */ public function getLibsPath(string $path = ''): string { + $ds = DIRECTORY_SEPARATOR; if (\getenv('TEST')) { - return "{$this->getProjectRootPath()}/{$path}"; + return "{$this->getProjectRootPath()}{$ds}{$path}"; } - return "{$this->getProjectRootPath()}/vendor/infinum/eightshift-libs/{$path}"; + return "{$this->getProjectRootPath()}{$ds}vendor{$ds}infinum{$ds}eightshift-libs{$ds}{$path}"; } /** @@ -860,7 +865,8 @@ public function getLibsPath(string $path = ''): string */ public function getFrontendLibsBlockPath(): string { - return $this->getFrontendLibsPath('blocks/init'); + $ds = DIRECTORY_SEPARATOR; + return $this->getFrontendLibsPath("blocks{$ds}init"); } /** @@ -872,16 +878,17 @@ public function getFrontendLibsBlockPath(): string */ public function getFullBlocksFiles(string $name): array { + $ds = DIRECTORY_SEPARATOR; return [ "{$name}.php", "{$name}-block.js", "{$name}-hooks.js", "{$name}-transforms.js", "{$name}.js", - "docs/story.js", - "components/{$name}-editor.js", - "components/{$name}-toolbar.js", - "components/{$name}-options.js", + "docs{$ds}story.js", + "components{$ds}{$name}-editor.js", + "components{$ds}{$name}-toolbar.js", + "components{$ds}{$name}-options.js", ]; } From fcea148a1e5a8922556a5cfbb4f43c2074817186 Mon Sep 17 00:00:00 2001 From: Mario Borna Mjertan Date: Fri, 25 Mar 2022 15:19:09 +0100 Subject: [PATCH 02/10] Do not prepend DIRECTORY_SEPARATOR to dirname output, root paths --- src/Cli/AbstractCli.php | 2 +- src/Helpers/Components.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Cli/AbstractCli.php b/src/Cli/AbstractCli.php index 7bdc91b3d..4722e3129 100644 --- a/src/Cli/AbstractCli.php +++ b/src/Cli/AbstractCli.php @@ -361,7 +361,7 @@ public function getOutputDir(string $path = ''): string $path = \rtrim($path, $ds); $path = \trim($path, $ds); - return "{$ds}{$root}{$ds}{$path}"; + return "{$root}{$ds}{$path}"; } /** diff --git a/src/Helpers/Components.php b/src/Helpers/Components.php index 3f93cc089..d8f243fea 100644 --- a/src/Helpers/Components.php +++ b/src/Helpers/Components.php @@ -215,7 +215,7 @@ public static function getManifestDirect(string $path): array $sep = \DIRECTORY_SEPARATOR; $path = \trim($path, $sep); - $manifest = "{$sep}{$path}{$sep}manifest.json"; + $manifest = "{$path}{$sep}manifest.json"; if (!\file_exists($manifest)) { throw ComponentException::throwUnableToLocateComponent($manifest); From 08c7d2fc91259ac24287ad68dbd306d715e676f5 Mon Sep 17 00:00:00 2001 From: Mario Borna Mjertan Date: Fri, 25 Mar 2022 15:19:37 +0100 Subject: [PATCH 03/10] Do not pass quoted arguments when running WP CLI commands --- src/Blocks/BlocksCli.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Blocks/BlocksCli.php b/src/Blocks/BlocksCli.php index 68aa43162..a6bb34bc1 100644 --- a/src/Blocks/BlocksCli.php +++ b/src/Blocks/BlocksCli.php @@ -144,11 +144,11 @@ private function blocksInit(array $args): void WP_CLI::runcommand("{$this->commandParentName} use_wrapper {$this->prepareArgsManual($args)}"); foreach (static::COMPONENTS as $component) { - WP_CLI::runcommand("{$this->commandParentName} use_component --name='{$component}' {$this->prepareArgsManual($args)}"); + WP_CLI::runcommand("{$this->commandParentName} use_component --name={$component} {$this->prepareArgsManual($args)}"); } foreach (static::BLOCKS as $block) { - WP_CLI::runcommand("{$this->commandParentName} use_block --name='{$block}' {$this->prepareArgsManual($args)}"); + WP_CLI::runcommand("{$this->commandParentName} use_block --name={$block} {$this->prepareArgsManual($args)}"); } WP_CLI::success('Blocks successfully set.'); From d17575b3f3b08265255163178db3876c35c348ec Mon Sep 17 00:00:00 2001 From: Mario Borna Mjertan Date: Fri, 25 Mar 2022 15:34:14 +0100 Subject: [PATCH 04/10] Prepend / to getOutputDir path on Unix systems --- src/Cli/AbstractCli.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Cli/AbstractCli.php b/src/Cli/AbstractCli.php index 4722e3129..29ec447ed 100644 --- a/src/Cli/AbstractCli.php +++ b/src/Cli/AbstractCli.php @@ -361,6 +361,10 @@ public function getOutputDir(string $path = ''): string $path = \rtrim($path, $ds); $path = \trim($path, $ds); + if ($ds === '/') { + return "{$ds}{$root}{$ds}{$path}"; + } + return "{$root}{$ds}{$path}"; } From 28896bdd1a548a0baa5a24885a5337c80534f08b Mon Sep 17 00:00:00 2001 From: Mario Borna Mjertan Date: Fri, 25 Mar 2022 15:35:48 +0100 Subject: [PATCH 05/10] Prepend / to getManifestDirect path on Unix systems --- src/Helpers/Components.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Helpers/Components.php b/src/Helpers/Components.php index d8f243fea..05df38782 100644 --- a/src/Helpers/Components.php +++ b/src/Helpers/Components.php @@ -216,6 +216,10 @@ public static function getManifestDirect(string $path): array $path = \trim($path, $sep); $manifest = "{$path}{$sep}manifest.json"; + + if ($sep === '/') { + $manifest = "{$sep}{$manifest}"; + } if (!\file_exists($manifest)) { throw ComponentException::throwUnableToLocateComponent($manifest); From 6f777a2dc0d50eca4d7e1e8cc888f29bdd36a27a Mon Sep 17 00:00:00 2001 From: Mario Borna Mjertan Date: Mon, 28 Mar 2022 15:20:13 +0200 Subject: [PATCH 06/10] Fix phpcs reported issues --- src/Blocks/AbstractBlocksCli.php | 4 ++-- src/Cli/AbstractCli.php | 16 ++++++++-------- src/Helpers/Components.php | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Blocks/AbstractBlocksCli.php b/src/Blocks/AbstractBlocksCli.php index 7061bfb6f..937e3717e 100644 --- a/src/Blocks/AbstractBlocksCli.php +++ b/src/Blocks/AbstractBlocksCli.php @@ -38,7 +38,7 @@ protected function blocksMove(array $assocArgs, string $outputDir, bool $isCompo $root = $this->getProjectRootPath(); $rootNode = $this->getFrontendLibsBlockPath(); - $ds = DIRECTORY_SEPARATOR; + $ds = \DIRECTORY_SEPARATOR; $sourcePathFolder = "{$rootNode}{$ds}{$outputDir}{$ds}"; $blocks = \scandir($sourcePathFolder); @@ -116,7 +116,7 @@ protected function blocksMove(array $assocArgs, string $outputDir, bool $isCompo */ private function moveBlock(string $destinationPath, string $sourcePath, string $name, array $assocArgs, string $path, string $typeSingular): void { - $ds = DIRECTORY_SEPARATOR; + $ds = \DIRECTORY_SEPARATOR; // Create folder in project if missing. \mkdir("{$destinationPath}{$ds}"); diff --git a/src/Cli/AbstractCli.php b/src/Cli/AbstractCli.php index 29ec447ed..48fa7e990 100644 --- a/src/Cli/AbstractCli.php +++ b/src/Cli/AbstractCli.php @@ -246,7 +246,7 @@ function ($item) { */ public function getExampleTemplate(string $currentDir, string $fileName, bool $skipMissing = false): self { - $ds = DIRECTORY_SEPARATOR; + $ds = \DIRECTORY_SEPARATOR; $path = "{$currentDir}{$ds}{$this->getExampleFileName( $fileName )}.php"; // If you pass file name with extension the version will be used. @@ -346,7 +346,7 @@ public function outputWrite(string $outputDir, string $outputFile, array $args = */ public function getOutputDir(string $path = ''): string { - $ds = DIRECTORY_SEPARATOR; + $ds = \DIRECTORY_SEPARATOR; if (\function_exists('\add_action') && !\getenv('TEST')) { $root = $this->getProjectRootPath(); } else { @@ -364,7 +364,7 @@ public function getOutputDir(string $path = ''): string if ($ds === '/') { return "{$ds}{$root}{$ds}{$path}"; } - + return "{$root}{$ds}{$path}"; } @@ -663,7 +663,7 @@ public function searchReplaceString(string $oldString, string $newString): self */ public function getComposer(array $args = []): array { - $ds = DIRECTORY_SEPARATOR; + $ds = \DIRECTORY_SEPARATOR; if (!isset($args['config_path'])) { if (\function_exists('\add_action')) { $composerPath = "{$this->getProjectRootPath()}{$ds}composer.json"; @@ -841,7 +841,7 @@ public function getProjectConfigRootPath(bool $isDev = false): string */ public function getFrontendLibsPath(string $path = ''): string { - $ds = DIRECTORY_SEPARATOR; + $ds = \DIRECTORY_SEPARATOR; return "{$this->getProjectRootPath()}{$ds}node_modules{$ds}@eightshift{$ds}frontend-libs{$ds}{$path}"; } @@ -854,7 +854,7 @@ public function getFrontendLibsPath(string $path = ''): string */ public function getLibsPath(string $path = ''): string { - $ds = DIRECTORY_SEPARATOR; + $ds = \DIRECTORY_SEPARATOR; if (\getenv('TEST')) { return "{$this->getProjectRootPath()}{$ds}{$path}"; } @@ -869,7 +869,7 @@ public function getLibsPath(string $path = ''): string */ public function getFrontendLibsBlockPath(): string { - $ds = DIRECTORY_SEPARATOR; + $ds = \DIRECTORY_SEPARATOR; return $this->getFrontendLibsPath("blocks{$ds}init"); } @@ -882,7 +882,7 @@ public function getFrontendLibsBlockPath(): string */ public function getFullBlocksFiles(string $name): array { - $ds = DIRECTORY_SEPARATOR; + $ds = \DIRECTORY_SEPARATOR; return [ "{$name}.php", "{$name}-block.js", diff --git a/src/Helpers/Components.php b/src/Helpers/Components.php index 05df38782..e024bd124 100644 --- a/src/Helpers/Components.php +++ b/src/Helpers/Components.php @@ -216,7 +216,7 @@ public static function getManifestDirect(string $path): array $path = \trim($path, $sep); $manifest = "{$path}{$sep}manifest.json"; - + if ($sep === '/') { $manifest = "{$sep}{$manifest}"; } From a1d3c3443b969584c6b1cb44716155165d7f4f6a Mon Sep 17 00:00:00 2001 From: Mario Borna Mjertan Date: Tue, 29 Mar 2022 10:58:36 +0200 Subject: [PATCH 07/10] Fix phpcs, phpstan warnings --- src/Cli/CliInitAll.php | 5 +++-- src/Enqueue/Blocks/AbstractEnqueueBlocks.php | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Cli/CliInitAll.php b/src/Cli/CliInitAll.php index 958c22f10..691bb2996 100644 --- a/src/Cli/CliInitAll.php +++ b/src/Cli/CliInitAll.php @@ -42,8 +42,9 @@ public function getCommandName(): string public function getDoc(): array { return [ - 'shortdesc' => 'Generates initial setup for all service classes in the WordPress theme project. - This command is used only in develop mode. For this to work you must set global constant ES_DEVELOP_MODE to true.', + 'shortdesc' => + 'Generates initial setup for all service classes in the WordPress theme project. + This command is used only in develop mode. For this to work you must set global constant ES_DEVELOP_MODE to true.', ]; } diff --git a/src/Enqueue/Blocks/AbstractEnqueueBlocks.php b/src/Enqueue/Blocks/AbstractEnqueueBlocks.php index 4673588ff..104cd4eea 100644 --- a/src/Enqueue/Blocks/AbstractEnqueueBlocks.php +++ b/src/Enqueue/Blocks/AbstractEnqueueBlocks.php @@ -29,7 +29,7 @@ abstract class AbstractEnqueueBlocks extends AbstractAssets /** * Instance variable of manifest data. * - * @var ManifestInterface + * @var \EightshiftLibs\Manifest\ManifestInterface */ protected ManifestInterface $manifest; From 1f29bbc25b3df3e605a0cec48861a3c6a65f69ba Mon Sep 17 00:00:00 2001 From: Mario Borna Mjertan Date: Tue, 29 Mar 2022 11:02:03 +0200 Subject: [PATCH 08/10] Reference ManifestInterface using 'use' instead of FQCN --- src/Enqueue/Blocks/AbstractEnqueueBlocks.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Enqueue/Blocks/AbstractEnqueueBlocks.php b/src/Enqueue/Blocks/AbstractEnqueueBlocks.php index 104cd4eea..327343501 100644 --- a/src/Enqueue/Blocks/AbstractEnqueueBlocks.php +++ b/src/Enqueue/Blocks/AbstractEnqueueBlocks.php @@ -10,6 +10,7 @@ namespace EightshiftLibs\Enqueue\Blocks; +use EightshiftLibs\Manifest\ManifestInterface; // phpcs:ignore SlevomatCodingStandard.Namespaces.UnusedUses.UnusedUse use EightshiftLibs\Enqueue\AbstractAssets; use EightshiftLibs\Manifest\ManifestInterface; @@ -29,7 +30,7 @@ abstract class AbstractEnqueueBlocks extends AbstractAssets /** * Instance variable of manifest data. * - * @var \EightshiftLibs\Manifest\ManifestInterface + * @var ManifestInterface */ protected ManifestInterface $manifest; From 4c3aea01a41666727310bdd1eb5d79ca43f535ec Mon Sep 17 00:00:00 2001 From: Mario Borna Mjertan Date: Thu, 14 Apr 2022 11:22:53 +0200 Subject: [PATCH 09/10] Remove double 'use' statement --- src/Enqueue/Blocks/AbstractEnqueueBlocks.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Enqueue/Blocks/AbstractEnqueueBlocks.php b/src/Enqueue/Blocks/AbstractEnqueueBlocks.php index 327343501..4673588ff 100644 --- a/src/Enqueue/Blocks/AbstractEnqueueBlocks.php +++ b/src/Enqueue/Blocks/AbstractEnqueueBlocks.php @@ -10,7 +10,6 @@ namespace EightshiftLibs\Enqueue\Blocks; -use EightshiftLibs\Manifest\ManifestInterface; // phpcs:ignore SlevomatCodingStandard.Namespaces.UnusedUses.UnusedUse use EightshiftLibs\Enqueue\AbstractAssets; use EightshiftLibs\Manifest\ManifestInterface; From a7856a7076d1bbe452008618718c1283b69c17b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ruz=CC=8Cevic=CC=81?= Date: Fri, 6 May 2022 14:55:05 +0200 Subject: [PATCH 10/10] small fix for css variables --- src/Helpers/CssVariablesTrait.php | 156 +++++++++++++++--------------- 1 file changed, 77 insertions(+), 79 deletions(-) diff --git a/src/Helpers/CssVariablesTrait.php b/src/Helpers/CssVariablesTrait.php index f0f36025f..3d76fbbf5 100644 --- a/src/Helpers/CssVariablesTrait.php +++ b/src/Helpers/CssVariablesTrait.php @@ -151,104 +151,102 @@ public static function outputCssVariablesInline(): string return ''; } + // Prepare final output. + $output = ''; + $styles = Components::getStyles(); // Bailout if styles are missing. - if (!$styles) { - return ''; - } - - // Define variables from globalManifest. - $breakpointsData = self::getSettingsGlobalVariablesBreakpoints(); - - // Sort breakpoints in ascending order. - \asort($breakpointsData); - - // Populate min values. - $breakpointsMin = \array_map( - static function ($item) { - return "min---{$item}"; - }, - \array_values($breakpointsData) - ); - // Append 0 value. - \array_unshift($breakpointsMin, 'min---0'); - - // Populate max values. - $breakpointsMax = \array_map( - static function ($item) { - return "max---{$item}"; - }, - \array_reverse(\array_values($breakpointsData)) - ); - // Append 0 value. - \array_unshift($breakpointsMax, 'max---0'); - - // Return empty array of items. - $breakpoints = \array_map( - static function () { - return ''; - }, - \array_flip(\array_values(\array_merge($breakpointsMin, $breakpointsMax))) - ); + if ($styles) { + // Define variables from globalManifest. + $breakpointsData = self::getSettingsGlobalVariablesBreakpoints(); - // Loop styles. - foreach ($styles as $style) { - $name = $style['name'] ?? ''; - $unique = $style['unique'] ?? ''; - $variables = $style['variables'] ?? []; + // Sort breakpoints in ascending order. + \asort($breakpointsData); - // Bailout if variables are missing. - if (!$variables) { - continue; - } + // Populate min values. + $breakpointsMin = \array_map( + static function ($item) { + return "min---{$item}"; + }, + \array_values($breakpointsData) + ); + // Append 0 value. + \array_unshift($breakpointsMin, 'min---0'); - $uniqueSelector = "[data-id='{$unique}']"; + // Populate max values. + $breakpointsMax = \array_map( + static function ($item) { + return "max---{$item}"; + }, + \array_reverse(\array_values($breakpointsData)) + ); + // Append 0 value. + \array_unshift($breakpointsMax, 'max---0'); - if (!$unique) { - $uniqueSelector = ''; - } + // Return empty array of items. + $breakpoints = \array_map( + static function () { + return ''; + }, + \array_flip(\array_values(\array_merge($breakpointsMin, $breakpointsMax))) + ); - foreach ($variables as $data) { - $type = $data['type'] ?? ''; - $value = $data['value'] ?? ''; - $variable = $data['variable'] ?? ''; + // Loop styles. + foreach ($styles as $style) { + $name = $style['name'] ?? ''; + $unique = $style['unique'] ?? ''; + $variables = $style['variables'] ?? []; - // Bailout if variable is missing. - if (!$variable) { + // Bailout if variables are missing. + if (!$variables) { continue; } - // Bailout if breakpont is missing. - if (!isset($breakpoints["{$type}---{$value}"])) { - continue; - } + $uniqueSelector = "[data-id='{$unique}']"; - // Populate breakpoint. - $breakpoints["{$type}---{$value}"] .= "\n.{$name}{$uniqueSelector}{\n{$variable}\n} "; - } - } + if (!$unique) { + $uniqueSelector = ''; + } - // Prepare final output. - $output = ''; + foreach ($variables as $data) { + $type = $data['type'] ?? ''; + $value = $data['value'] ?? ''; + $variable = $data['variable'] ?? ''; - // Loop breakpoints in correct order. - foreach ($breakpoints as $breakpointKey => $breakpointValue) { - $breakpointKey = \explode('---', $breakpointKey); + // Bailout if variable is missing. + if (!$variable) { + continue; + } - $type = $breakpointKey[0] ?? ''; - $value = $breakpointKey[1] ?? ''; + // Bailout if breakpont is missing. + if (!isset($breakpoints["{$type}---{$value}"])) { + continue; + } - // Bailout if empty value. - if (!$breakpointValue) { - continue; + // Populate breakpoint. + $breakpoints["{$type}---{$value}"] .= "\n.{$name}{$uniqueSelector}{\n{$variable}\n} "; + } } - // If value is 0 then this breakpoint has no media query. - if ($value === '0') { - $output .= "{$breakpointValue}\n"; - } else { - $output .= "\n@media ({$type}-width:{$value}px){{$breakpointValue}}\n "; + // Loop breakpoints in correct order. + foreach ($breakpoints as $breakpointKey => $breakpointValue) { + $breakpointKey = \explode('---', $breakpointKey); + + $type = $breakpointKey[0] ?? ''; + $value = $breakpointKey[1] ?? ''; + + // Bailout if empty value. + if (!$breakpointValue) { + continue; + } + + // If value is 0 then this breakpoint has no media query. + if ($value === '0') { + $output .= "{$breakpointValue}\n"; + } else { + $output .= "\n@media ({$type}-width:{$value}px){{$breakpointValue}}\n "; + } } }