Skip to content

Commit 414fd2f

Browse files
author
Eugene Matvejev
authored
Merge pull request #27 from cheprasov/master
RC4 - filename optimization
2 parents 3d440d4 + 8a5edb2 commit 414fd2f

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/Container/File.php

+15-15
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ class File
1010
const TYPE_SASS = 'sass';
1111
const TYPE_COMPASS = 'compass';
1212
const TYPE_LESS = 'less';
13+
const TYPE_UNKNOWN = 'unknown';
14+
/**
15+
* @var string[]
16+
*/
17+
private static $extensions = [
18+
self::TYPE_SCSS,
19+
self::TYPE_SASS,
20+
self::TYPE_COMPASS,
21+
self::TYPE_LESS,
22+
];
1323
/**
1424
* @var string
1525
*/
@@ -157,21 +167,11 @@ public function setType($type)
157167
*/
158168
private function detectSourceTypeFromPath($path)
159169
{
160-
switch (true) {
161-
case 0 !== preg_match('/^.*\.' . static::TYPE_SCSS . '/', $path):
162-
$this->type = static::TYPE_SCSS;
163-
break;
164-
case 0 !== preg_match('/^.*\.' . static::TYPE_SASS . '/', $path):
165-
$this->type = static::TYPE_SASS;
166-
break;
167-
case 0 !== preg_match('/^.*\.' . static::TYPE_COMPASS . '/', $path):
168-
$this->type = static::TYPE_COMPASS;
169-
break;
170-
case 0 !== preg_match('/^.*\.' . static::TYPE_LESS . '/', $path):
171-
$this->type = static::TYPE_LESS;
172-
break;
173-
default:
174-
$this->type = 'unknown';
170+
$extension = strtolower(pathinfo($path, PATHINFO_EXTENSION));
171+
if (in_array($extension, static::$extensions)) {
172+
$this->type = $extension;
173+
} else {
174+
$this->type = static::TYPE_UNKNOWN;
175175
}
176176
}
177177

0 commit comments

Comments
 (0)