Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e7616e5

Browse files
author
Eugene Matvejev
authored
Merge pull request #23 from learn-symfony/master
sync with main repository
2 parents 0238ac6 + 63021f1 commit e7616e5

File tree

5 files changed

+93
-48
lines changed

5 files changed

+93
-48
lines changed

‎ScriptHandler.php‎

Lines changed: 0 additions & 17 deletions
This file was deleted.

‎composer.json‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@
1212
"autoload": {
1313
"psr-4": {
1414
"EM\\CssCompiler\\": "src/"
15-
},
16-
"classmap": [
17-
"ScriptHandler.php"
18-
]
15+
}
1916
},
2017
"autoload-dev": {
2118
"psr-4": {

‎src/Processor/Processor.php‎

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -157,25 +157,47 @@ public function processFile(FileContainer $file)
157157
{
158158
switch ($file->getType()) {
159159
case FileContainer::TYPE_SCSS:
160-
try {
161-
$this->sass->addImportPath(dirname($file->getInputPath()));
162-
$content = $this->sass->compile($file->getInputContent());
163-
164-
return $file->setOutputContent($content);
165-
} catch (ParserException $e) {
166-
throw new CompilerException($e->getMessage(), 1, $e);
167-
}
160+
return $this->compileSCSS($file);
168161
case FileContainer::TYPE_LESS:
169-
try {
170-
return $file->setOutputContent($this->less->compileFile($file->getInputPath()));
171-
} catch (\Exception $e) {
172-
throw new CompilerException($e->getMessage(), 1, $e);
173-
}
162+
return $this->compileLESS($file);
174163
}
175164

176165
throw new CompilerException('unknown compiler');
177166
}
178167

168+
/**
169+
* @param FileContainer $file
170+
*
171+
* @return $this
172+
* @throws CompilerException
173+
*/
174+
protected function compileSCSS(FileContainer $file)
175+
{
176+
try {
177+
$this->sass->addImportPath(dirname($file->getInputPath()));
178+
$content = $this->sass->compile($file->getInputContent());
179+
180+
return $file->setOutputContent($content);
181+
} catch (ParserException $e) {
182+
throw new CompilerException($e->getMessage(), 1, $e);
183+
}
184+
}
185+
186+
/**
187+
* @param FileContainer $file
188+
*
189+
* @return $this
190+
* @throws CompilerException
191+
*/
192+
protected function compileLESS(FileContainer $file)
193+
{
194+
try {
195+
return $file->setOutputContent($this->less->compileFile($file->getInputPath()));
196+
} catch (\Exception $e) {
197+
throw new CompilerException($e->getMessage(), 1, $e);
198+
}
199+
}
200+
179201
/**
180202
* @param string $formatter
181203
*

‎src/ScriptHandler.php‎

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

66-
foreach ($config[static::CONFIG_MAIN_KEY] as $index => $el) {
67-
if (!is_array($el)) {
68-
throw new \InvalidArgumentException("the extra.css-compiler[{$index}]." . static::OPTION_KEY_INPUT . ' array');
66+
return static::validateOptions($config[static::CONFIG_MAIN_KEY]);
67+
}
68+
69+
/**
70+
* @param array $config
71+
*
72+
* @return bool
73+
* @throws \InvalidArgumentException
74+
*/
75+
protected static function validateOptions(array $config)
76+
{
77+
foreach ($config as $option) {
78+
if (!is_array($option)) {
79+
throw new \InvalidArgumentException('extra.' . static::CONFIG_MAIN_KEY . "[]." . static::OPTION_KEY_INPUT . ' array');
6980
}
7081

71-
static::validateOptions($el);
82+
static::validateMandatoryOptions($option);
7283
}
7384

7485
return true;
@@ -80,18 +91,49 @@ protected static function validateConfiguration(array $config)
8091
* @return bool
8192
* @throws \InvalidArgumentException
8293
*/
83-
protected static function validateOptions(array $config)
94+
protected static function validateMandatoryOptions(array $config)
8495
{
8596
foreach (static::$mandatoryOptions as $option) {
8697
if (empty($config[$option])) {
87-
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;
88108
}
89109
}
90-
if (!is_array($config[static::OPTION_KEY_INPUT])) {
91-
throw new \InvalidArgumentException('The extra.css-compiler[].' . static::OPTION_KEY_INPUT . ' should be array!');
110+
111+
return true;
112+
}
113+
114+
/**
115+
* @param array $option
116+
*
117+
* @return bool
118+
*/
119+
protected static function validateIsArray($option)
120+
{
121+
if (!is_array($option)) {
122+
throw new \InvalidArgumentException('extra.' . static::CONFIG_MAIN_KEY . '[]' . static::OPTION_KEY_INPUT . ' should be array!');
92123
}
93-
if (!is_string($config[static::OPTION_KEY_OUTPUT])) {
94-
throw new \InvalidArgumentException('The extra.css-compiler[].' . static::OPTION_KEY_OUTPUT . ' should string!');
124+
125+
return true;
126+
}
127+
128+
/**
129+
* @param string $option
130+
*
131+
* @return bool
132+
*/
133+
protected static function validateIsString($option)
134+
{
135+
if (!is_string($option)) {
136+
throw new \InvalidArgumentException('extra.' . static::CONFIG_MAIN_KEY . '[]' . static::OPTION_KEY_OUTPUT . ' should string!');
95137
}
96138

97139
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(newScriptHandler(), '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(newScriptHandler(), 'validateOptions', [$options]);
141142

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

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /