Skip to content

Commit cebcb16

Browse files
author
Eugene Matvejev
authored
Merge pull request #8 from learn-symfony/master
sync with main repository
2 parents 9136fc4 + 06ecebb commit cebcb16

File tree

9 files changed

+354
-135
lines changed

9 files changed

+354
-135
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
var/
2+
bin/
23
vendor/
4+
composer.lock

.scrutinizer.yml

+10-7
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ build:
1111
environment:
1212
php:
1313
version: "7.0.4"
14-
# tests:
15-
# override:
16-
# -
17-
# command: "php bin/phpunit -c phpunit.xml --colors=always --verbose --coverage-clover=coverage.xml"
18-
# coverage:
19-
# file: "coverage.xml"
20-
# format: "php-clover"
14+
tests:
15+
override:
16+
-
17+
command: "composer validate"
18+
override:
19+
-
20+
command: "php bin/phpunit -c phpunit.xml --colors=always --verbose --coverage-clover=coverage.xml"
21+
coverage:
22+
file: "coverage.xml"
23+
format: "php-clover"

.travis.yml

+14-22
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
1-
language: php
2-
#
3-
#sudo: false
4-
#
5-
#cache:
6-
# directories:
7-
# - $HOME/.composer/cache/files
8-
#
9-
#matrix:
10-
# include:
11-
## - php: 5.6
12-
# - php: 7.0
13-
# - php: hhvm
14-
#
15-
#before_script:
16-
# - if [ "$DEPENDENCIES" = "dev" ]; then perl -pi -e 's/^}$/,"minimum-stability":"dev"}/' composer.json; fi;
17-
# - composer update $COMPOSER_FLAGS
18-
#
19-
#script: phpunit --coverage-text --coverage-clover=coverage.clover
20-
#
21-
#after_script:
22-
# - wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover coverage.clover
1+
language: "php"
2+
php:
3+
- "5.6"
4+
- "7.0.4"
5+
- "hhvm"
6+
7+
before_script:
8+
- "composer install --no-progress --no-interaction"
9+
10+
script:
11+
- "php bin/phpunit -c phpunit.xml --colors=always --verbose --coverage-clover=coverage.xml"
12+
13+
after_success:
14+
- "bash <(curl -s https://codecov.io/bash)"

composer.json

+14-6
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,31 @@
1111
],
1212
"autoload": {
1313
"psr-4": {
14-
"EM\\CssCompiler\\Handler\\": "",
1514
"EM\\CssCompiler\\": "src/"
16-
}
15+
},
16+
"classmap": [
17+
"ScriptHandler.php"
18+
]
1719
},
1820
"autoload-dev": {
1921
"psr-4": {
20-
"EM\\Tests\\CssCompiler\\": "tests/"
21-
}
22+
"EM\\Tests\\PHPUnit\\": "tests/phpunit"
23+
},
24+
"classmap": [
25+
"tests/shared-enviroment/IntegrationTestSuite.php"
26+
]
27+
},
28+
"config": {
29+
"bin-dir": "bin/"
2230
},
2331
"require": {
24-
"php": ">= 5.5.9 || 7.0.0 - 7.0.4 || >= 7.0.6",
32+
"php": ">= 5.6.0 || 7.0.0 - 7.0.4 || >= 7.0.6",
2533
"leafo/lessphp": "^0.5",
2634
"leafo/scssphp": "@dev",
2735
"leafo/scssphp-compass": "@dev"
2836
},
2937
"require-dev": {
3038
"composer/composer": "^1.1",
31-
"phpunit/phpunit": "^4.8"
39+
"phpunit/phpunit": "^5.3"
3240
}
3341
}

src/Container/File.php

+50-54
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+
static $supportedTypes = [
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
@@ -51,28 +48,10 @@ public function __construct($sourcePath, $outputPath)
5148
$this->outputPath = $outputPath;
5249
}
5350

54-
public function getSourcePath()
55-
{
56-
return $this->sourcePath;
57-
}
58-
59-
/**
60-
* @param string $path
61-
*
62-
* @return File
63-
*/
64-
public function setSourcePath($path)
65-
{
66-
$this->sourcePath = $path;
67-
$this->detectSourceTypeFromPath($path);
68-
69-
return $this;
70-
}
71-
7251
/**
7352
* @return string
7453
*/
75-
public function getOutputPath()
54+
public function getOutputPath()
7655
{
7756
return $this->outputPath;
7857
}
@@ -113,13 +92,44 @@ public function setSourceContent($content)
11392
* @return File
11493
* @throws FileException
11594
*/
116-
public function setSourceContentFromSourcePath()
95+
public function setSourceContentFromSourcePath()
11796
{
11897
$this->sourceContent = $this->readSourceContentByPath();
11998

12099
return $this;
121100
}
122101

102+
/**
103+
* @return string
104+
* @throws FileException
105+
*/
106+
protected function readSourceContentByPath()
107+
{
108+
if (!file_exists($this->getSourcePath())) {
109+
throw new FileException("file: {$this->sourcePath} doesn't exists");
110+
}
111+
112+
return file_get_contents($this->getSourcePath());
113+
}
114+
115+
public function getSourcePath()
116+
{
117+
return $this->sourcePath;
118+
}
119+
120+
/**
121+
* @param string $path
122+
*
123+
* @return File
124+
*/
125+
public function setSourcePath($path)
126+
{
127+
$this->sourcePath = $path;
128+
$this->type = $this->detectSourceTypeFromPath($path);
129+
130+
return $this;
131+
}
132+
123133
/**
124134
* @return string
125135
*/
@@ -133,7 +143,7 @@ public function getParsedContent()
133143
*
134144
* @return File
135145
*/
136-
public function setParsedContent($content)
146+
public function setParsedContent($content)
137147
{
138148
$this->parsedContent = $content;
139149

@@ -143,7 +153,7 @@ public function setParsedContent($content)
143153
/**
144154
* @return string
145155
*/
146-
public function getType()
156+
public function getType()
147157
{
148158
return $this->type;
149159
}
@@ -162,29 +172,15 @@ public function setType($type)
162172

163173
/**
164174
* @param string $path
165-
*
166-
* @return void
167-
*/
168-
private function detectSourceTypeFromPath($path)
169-
{
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;
175-
}
176-
}
177-
178-
/**
175+
*
179176
* @return string
180-
* @throws FileException
181177
*/
182-
private function readSourceContentByPath()
178+
protected function detectSourceTypeFromPath($path)
183179
{
184-
if (!file_exists($this->getSourcePath())) {
185-
throw new FileException("file: {$this->sourcePath} doesn't exists");
186-
}
180+
$extension = strtolower(pathinfo($path, PATHINFO_EXTENSION));
187181

188-
return file_get_contents($this->getSourcePath());
182+
return in_array($extension, static::$supportedTypes)
183+
? $extension
184+
: static::TYPE_UNKNOWN;
189185
}
190186
}

0 commit comments

Comments
 (0)