浏览代码

Fix up config.

mscherer 3 年之前
父节点
当前提交
cabe5700bb
共有 4 个文件被更改,包括 44 次插入8 次删除
  1. 2 2
      composer.json
  2. 25 0
      phpcs.xml
  3. 16 5
      src/View/Icon/IconCollection.php
  4. 1 1
      src/View/Icon/MaterialIcon.php

+ 2 - 2
composer.json

@@ -61,8 +61,8 @@
 		"test-coverage": "phpunit --log-junit webroot/coverage/unitreport.xml --coverage-html webroot/coverage --coverage-clover webroot/coverage/coverage.xml",
 		"lowest": "validate-prefer-lowest",
 		"lowest-setup": "composer update --prefer-lowest --prefer-stable --prefer-dist --no-interaction && cp composer.json composer.backup && composer require --dev dereuromark/composer-prefer-lowest && mv composer.backup composer.json",
-		"cs-check": "phpcs -p -s --standard=vendor/fig-r/psr2r-sniffer/PSR2R/ruleset.xml --extensions=php --ignore=/config/Migrations/,/tests/test_files/ src/ tests/ config/",
-		"cs-fix": "phpcbf -p --standard=vendor/fig-r/psr2r-sniffer/PSR2R/ruleset.xml --extensions=php --ignore=/config/Migrations/,/tests/test_files/ src/ tests/ config/"
+		"cs-check": "phpcs --extensions=php",
+		"cs-fix": "phpcbf --extensions=php"
 	},
 	"prefer-stable": true,
 	"config": {

+ 25 - 0
phpcs.xml

@@ -0,0 +1,25 @@
+<?xml version="1.0"?>
+<ruleset name="app">
+	<config name="installed_paths" value="../../fig-r/psr2r-sniffer"/>
+
+	<arg value="nps"/>
+
+	<file>src/</file>
+	<file>config/</file>
+	<file>tests/</file>
+
+	<exclude-pattern>\.git/</exclude-pattern>
+	<exclude-pattern>/*/tmp/</exclude-pattern>
+	<exclude-pattern>/tests/test_files/</exclude-pattern>
+	<exclude-pattern>/tests/test_app/</exclude-pattern>
+
+	<rule ref="PSR2R"/>
+
+	<rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace">
+		<exclude-pattern>*/config/Migrations/*</exclude-pattern>
+	</rule>
+	<rule ref="Spryker.Classes.ClassFileName.NoMatch">
+		<exclude-pattern>*/config/Migrations/*</exclude-pattern>
+	</rule>
+
+</ruleset>

+ 16 - 5
src/View/Icon/IconCollection.php

@@ -29,14 +29,25 @@ class IconCollection {
 	 * @param array<string, mixed> $config
 	 */
 	public function __construct(array $config = []) {
-		/** @var array<class-string<\Tools\View\Icon\IconInterface>> $sets */
+		/** @var array<class-string<\Tools\View\Icon\IconInterface>|array<string, mixed>> $sets */
 		$sets = $config['sets'] ?? [];
 		unset($config['sets']);
 
-		foreach ($sets as $set => $className) {
-			$iconConfig = $config['config'][$set] ?? [];
-			$iconConfig += $config;
-			$this->iconSets[$set] = new $className($iconConfig);
+		foreach ($sets as $set => $setConfig) {
+			if (is_string($setConfig)) {
+				$setConfig = [
+					'class' => $setConfig,
+				];
+			} else {
+				if (empty($setConfig['class'])) {
+					throw new RuntimeException('You must define a `class` for each icon set.');
+				}
+			}
+
+			/** @var class-string<\Tools\View\Icon\IconInterface> $className */
+			$className = $setConfig['class'];
+			$setConfig += $config;
+			$this->iconSets[$set] = new $className($setConfig);
 		}
 
 		$key = array_key_first($sets);

+ 1 - 1
src/View/Icon/MaterialIcon.php

@@ -26,7 +26,7 @@ class MaterialIcon implements IconInterface {
 		];
 
 		$this->template = new StringTemplate(['icon' => $config['template']]);
-		$this->namespace = $config['namespace'] ?? 'material-symbols-outlined';
+		$this->namespace = $config['namespace'] ?? 'material-icons';
 	}
 
 	/**