Skip to content

Commit 5b6093f

Browse files
fix build
1 parent d0c9e5b commit 5b6093f

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

src/ScriptHandler.php

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ protected static function validateConfiguration(array $config)
6363
throw new \InvalidArgumentException('the extra.css-compiler setting must be an array of objects');
6464
}
6565

66-
return static::validateOptions($config);
66+
return static::validateOptions($config[static::CONFIG_MAIN_KEY]);
6767
}
6868

6969
/**
@@ -74,9 +74,9 @@ protected static function validateConfiguration(array $config)
7474
*/
7575
protected static function validateOptions(array $config)
7676
{
77-
foreach ($config[static::CONFIG_MAIN_KEY] as $index => $option) {
77+
foreach ($config as $option) {
7878
if (!is_array($option)) {
79-
throw new \InvalidArgumentException("the extra.css-compiler[{$index}]." . static::OPTION_KEY_INPUT . ' array');
79+
throw new \InvalidArgumentException('extra.' . static::CONFIG_MAIN_KEY . "[]." . static::OPTION_KEY_INPUT . ' array');
8080
}
8181

8282
static::validateMandatoryOptions($option);
@@ -85,7 +85,6 @@ protected static function validateOptions(array $config)
8585
return true;
8686
}
8787

88-
8988
/**
9089
* @param array $config
9190
*
@@ -96,37 +95,45 @@ protected static function validateMandatoryOptions(array $config)
9695
{
9796
foreach (static::$mandatoryOptions as $option) {
9897
if (empty($config[$option])) {
99-
throw new \InvalidArgumentException("The extra.css-compiler[].{$option} required!");
98+
throw new \InvalidArgumentException('extra.' . static::CONFIG_MAIN_KEY . "[].{$option} is required!");
99+
}
100+
101+
switch ($option) {
102+
case static::OPTION_KEY_INPUT:
103+
static::validateIsArray($config[$option]);
104+
break;
105+
case static::OPTION_KEY_OUTPUT:
106+
static::validateIsString($config[$option]);
107+
break;
100108
}
101109
}
102-
static::validateInputOption($config);
103-
static::validateOutputOption($config);
104110

105111
return true;
106112
}
113+
107114
/**
108-
* @param array $config
115+
* @param array $option
109116
*
110117
* @return bool
111118
*/
112-
protected static function validateInputOption(array $config)
119+
protected static function validateIsArray($option)
113120
{
114-
if (!is_array($config[static::OPTION_KEY_INPUT])) {
115-
throw new \InvalidArgumentException('The extra.css-compiler[].' . static::OPTION_KEY_INPUT . ' should be array!');
121+
if (!is_array($option)) {
122+
throw new \InvalidArgumentException('extra.' . static::CONFIG_MAIN_KEY . '[]' . static::OPTION_KEY_INPUT . ' should be array!');
116123
}
117124

118125
return true;
119126
}
120127

121128
/**
122-
* @param array $config
129+
* @param string $option
123130
*
124131
* @return bool
125132
*/
126-
protected static function validateOutputOption(array $config)
133+
protected static function validateIsString($option)
127134
{
128-
if (!is_string($config[static::OPTION_KEY_OUTPUT])) {
129-
throw new \InvalidArgumentException('The extra.css-compiler[].' . static::OPTION_KEY_OUTPUT . ' should string!');
135+
if (!is_string($option)) {
136+
throw new \InvalidArgumentException('extra.' . static::CONFIG_MAIN_KEY . '[]' . static::OPTION_KEY_OUTPUT . ' should string!');
130137
}
131138

132139
return true;

tests/phpunit/ScriptHandlerTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ function validateConfigurationExpectedExceptionOnEmpty()
3232
{
3333
$this->invokeMethod(new ScriptHandler(), 'validateConfiguration', [[ScriptHandler::CONFIG_MAIN_KEY]]);
3434
}
35+
3536
/**
3637
* @see ScriptHandler::validateConfiguration
3738
* @test
@@ -134,10 +135,10 @@ function validateOptionsExpectedExceptionOnOutputNotString()
134135
*/
135136
function validateOptionsOnValid()
136137
{
137-
$result = $this->invokeMethod(new ScriptHandler(), 'validateOptions', [[
138-
ScriptHandler::OPTION_KEY_INPUT => ['string'],
139-
ScriptHandler::OPTION_KEY_OUTPUT => 'string'
140-
]]);
138+
$options = [
139+
[ScriptHandler::OPTION_KEY_INPUT => ['string'], ScriptHandler::OPTION_KEY_OUTPUT => 'string']
140+
];
141+
$result = $this->invokeMethod(new ScriptHandler(), 'validateOptions', [$options]);
141142

142143
$this->assertTrue($result);
143144
}

0 commit comments

Comments
 (0)