Skip to content

Commit af6a350

Browse files
author
Eugene Matvejev
authored
Merge pull request #37 from eugene-matvejev/improved_file_detection
RC5 - improved source type detection from filename
2 parents a8f3533 + c4de281 commit af6a350

File tree

1 file changed

+22
-26
lines changed

1 file changed

+22
-26
lines changed

src/Container/File.php

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,16 @@
66

77
class File
88
{
9-
const TYPE_SCSS = 'scss';
10-
const TYPE_SASS = 'sass';
11-
const TYPE_COMPASS = 'compass';
12-
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,
9+
const TYPE_UNKNOWN = 'unknown';
10+
const TYPE_COMPASS = 'compass';
11+
const TYPE_SASS = 'sass';
12+
const TYPE_SCSS = 'scss';
13+
const TYPE_LESS = 'less';
14+
const SUPPORTED_TYPES = [
2015
self::TYPE_COMPASS,
21-
self::TYPE_LESS,
16+
self::TYPE_SASS,
17+
self::TYPE_SCSS,
18+
self::TYPE_LESS
2219
];
2320
/**
2421
* @var string
@@ -64,15 +61,15 @@ public function getSourcePath()
6461
public function setSourcePath($path)
6562
{
6663
$this->sourcePath = $path;
67-
$this->detectSourceTypeFromPath($path);
64+
$this->type = $this->detectSourceTypeFromPath($path);
6865

6966
return $this;
7067
}
7168

7269
/**
7370
* @return string
7471
*/
75-
public function getOutputPath()
72+
public function getOutputPath()
7673
{
7774
return $this->outputPath;
7875
}
@@ -113,7 +110,7 @@ public function setSourceContent($content)
113110
* @return File
114111
* @throws FileException
115112
*/
116-
public function setSourceContentFromSourcePath()
113+
public function setSourceContentFromSourcePath()
117114
{
118115
$this->sourceContent = $this->readSourceContentByPath();
119116

@@ -133,7 +130,7 @@ public function getParsedContent()
133130
*
134131
* @return File
135132
*/
136-
public function setParsedContent($content)
133+
public function setParsedContent($content)
137134
{
138135
$this->parsedContent = $content;
139136

@@ -143,7 +140,7 @@ public function setParsedContent($content)
143140
/**
144141
* @return string
145142
*/
146-
public function getType()
143+
public function getType()
147144
{
148145
return $this->type;
149146
}
@@ -162,24 +159,23 @@ public function setType($type)
162159

163160
/**
164161
* @param string $path
165-
*
166-
* @return void
162+
*
163+
* @return string
167164
*/
168-
private function detectSourceTypeFromPath($path)
165+
protected function detectSourceTypeFromPath($path)
169166
{
170167
$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;
175-
}
168+
169+
return in_array($extension, static::SUPPORTED_TYPES)
170+
? $extension
171+
: static::TYPE_UNKNOWN;
176172
}
177173

178174
/**
179175
* @return string
180176
* @throws FileException
181177
*/
182-
private function readSourceContentByPath()
178+
protected function readSourceContentByPath()
183179
{
184180
if (!file_exists($this->getSourcePath())) {
185181
throw new FileException("file: {$this->sourcePath} doesn't exists");

0 commit comments

Comments
 (0)