Skip to content

RC5 - improved source type detection from filename #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 20, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 22 additions & 26 deletions src/Container/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,16 @@

class File
{
const TYPE_SCSS = 'scss';
const TYPE_SASS = 'sass';
const TYPE_COMPASS = 'compass';
const TYPE_LESS = 'less';
const TYPE_UNKNOWN = 'unknown';
/**
* @var string[]
*/
private static $extensions = [
self::TYPE_SCSS,
self::TYPE_SASS,
const TYPE_UNKNOWN = 'unknown';
const TYPE_COMPASS = 'compass';
const TYPE_SASS = 'sass';
const TYPE_SCSS = 'scss';
const TYPE_LESS = 'less';
const SUPPORTED_TYPES = [
self::TYPE_COMPASS,
self::TYPE_LESS,
self::TYPE_SASS,
self::TYPE_SCSS,
self::TYPE_LESS
];
/**
* @var string
Expand Down Expand Up @@ -64,15 +61,15 @@ public function getSourcePath()
public function setSourcePath($path)
{
$this->sourcePath = $path;
$this->detectSourceTypeFromPath($path);
$this->type = $this->detectSourceTypeFromPath($path);

return $this;
}

/**
* @return string
*/
public function getOutputPath()
public function getOutputPath()
{
return $this->outputPath;
}
Expand Down Expand Up @@ -113,7 +110,7 @@ public function setSourceContent($content)
* @return File
* @throws FileException
*/
public function setSourceContentFromSourcePath()
public function setSourceContentFromSourcePath()
{
$this->sourceContent = $this->readSourceContentByPath();

Expand All @@ -133,7 +130,7 @@ public function getParsedContent()
*
* @return File
*/
public function setParsedContent($content)
public function setParsedContent($content)
{
$this->parsedContent = $content;

Expand All @@ -143,7 +140,7 @@ public function setParsedContent($content)
/**
* @return string
*/
public function getType()
public function getType()
{
return $this->type;
}
Expand All @@ -162,24 +159,23 @@ public function setType($type)

/**
* @param string $path
*
* @return void
*
* @return string
*/
private function detectSourceTypeFromPath($path)
protected function detectSourceTypeFromPath($path)
{
$extension = strtolower(pathinfo($path, PATHINFO_EXTENSION));
if (in_array($extension, static::$extensions)) {
$this->type = $extension;
} else {
$this->type = static::TYPE_UNKNOWN;
}

return in_array($extension, static::SUPPORTED_TYPES)
? $extension
: static::TYPE_UNKNOWN;
}

/**
* @return string
* @throws FileException
*/
private function readSourceContentByPath()
protected function readSourceContentByPath()
{
if (!file_exists($this->getSourcePath())) {
throw new FileException("file: {$this->sourcePath} doesn't exists");
Expand Down