diff --git a/.gitattributes b/.gitattributes
index e64d2a0..2f6a21b 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -11,3 +11,4 @@
/makefile export-ignore
/phpunit.xml export-ignore
/README.md export-ignore
+/ruleset.xml.dist export-ignore
diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php
index 880bcfd..601f944 100644
--- a/.php-cs-fixer.php
+++ b/.php-cs-fixer.php
@@ -5,10 +5,16 @@ $finder = PhpCsFixer\Finder::create()
->in(__DIR__);
$config = new PhpCsFixer\Config();
-return $config->setRules(array(
- '@Symfony' => true,
- 'array_syntax' => array('syntax' => 'long'),
- 'visibility_required' => array('elements' => array('property', 'method')),
-))
+
+return $config
+ ->setRules(array(
+ '@Symfony' => true,
+ 'array_syntax' => array('syntax' => 'long'),
+ 'single_line_throw' => false,
+ 'yoda_style' => array('equal' => false, 'identical' => false, 'less_and_greater' => false),
+ '@PSR12' => true,
+ 'class_definition' => false, // @see https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/5463
+ 'visibility_required' => array('elements' => array('property', 'method')),
+ ))
->setFinder($finder)
->setUsingCache(false);
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 2f4a361..3e2949d 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -41,7 +41,7 @@ to run php-cs-fixer before submitting the code, it'll take care of the
formatting for you:
```sh
-make php-cs-fixer
+make format
```
Document the code thoroughly!
diff --git a/Dockerfile b/Dockerfile
index 1568fa5..dc07b8b 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -9,5 +9,5 @@ RUN apt-get install --reinstall -y ca-certificates
RUN apt-get install -y zip unzip libzip-dev git
RUN docker-php-ext-install zip pcntl
RUN pecl install xdebug || pecl install xdebug-3.1.6 || pecl install xdebug-2.7.2 && docker-php-ext-enable xdebug || true
-RUN curl -sS https://getcomposer.org/installer | php
-RUN ./composer.phar install
+RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
+RUN composer install
diff --git a/composer.json b/composer.json
index af830a8..4b840a1 100644
--- a/composer.json
+++ b/composer.json
@@ -19,9 +19,10 @@
"matthiasmullie/path-converter": "~1.1"
},
"require-dev": {
+ "friendsofphp/php-cs-fixer": ">=2.0",
"matthiasmullie/scrapbook": ">=1.3",
"phpunit/phpunit": ">=4.8",
- "friendsofphp/php-cs-fixer": ">=2.0"
+ "squizlabs/php_codesniffer": ">=3.0"
},
"suggest": {
"psr/cache-implementation": "Cache implementation to use with Minify::cache"
diff --git a/makefile b/makefile
index 2ec89cb..a0be7c0 100644
--- a/makefile
+++ b/makefile
@@ -11,8 +11,8 @@ test:
test $$(docker images -q matthiasmullie/minify:$$VERSION) || docker build -t matthiasmullie/minify:$$VERSION . --build-arg VERSION=$$VERSION;\
docker run -v $$(pwd)/src:/var/www/src -v $$(pwd)/tests:/var/www/tests -v $$(pwd)/build:/var/www/build matthiasmullie/minify:$$VERSION env XDEBUG_MODE=coverage vendor/bin/phpunit $(TEST) --coverage-clover build/coverage-$(PHP)-$(TEST).clover
-php-cs-fixer:
+format:
test $$(docker images -q matthiasmullie/minify:cli) || docker build -t matthiasmullie/minify:cli .
- docker run -v $$(pwd)/src:/var/www/src -v $$(pwd)/tests:/var/www/tests matthiasmullie/minify:cli vendor/bin/php-cs-fixer fix
+ docker run -v $$(pwd)/src:/var/www/src -v $$(pwd)/tests:/var/www/tests matthiasmullie/minify:cli sh -c "vendor/bin/php-cs-fixer fix && vendor/bin/phpcbf --standard=ruleset.xml"
.PHONY: docs
diff --git a/ruleset.xml b/ruleset.xml
new file mode 100644
index 0000000..cbb5f5d
--- /dev/null
+++ b/ruleset.xml
@@ -0,0 +1,10 @@
+
+
+
+
+ ./src
+ ./tests
+
+
+
+
diff --git a/src/CSS.php b/src/CSS.php
index 0d357f0..a8bd125 100644
--- a/src/CSS.php
+++ b/src/CSS.php
@@ -1,4 +1,5 @@
importExtensions[$extension].';base64,'.$importContent.')';
+ $replace[] = 'url(' . $this->importExtensions[$extension] . ';base64,' . $importContent . ')';
}
}
@@ -432,7 +433,7 @@ class CSS extends Minify
// loop all urls
foreach ($matches as $match) {
// determine if it's a url() or an @import match
- $type = (0 === strpos($match[0], '@import') ? 'import' : 'url');
+ $type = (strpos($match[0], '@import') === 0 ? 'import' : 'url');
$url = $match['path'];
if ($this->canImportByPath($url)) {
@@ -462,15 +463,15 @@ class CSS extends Minify
*/
$url = trim($url);
if (preg_match('/[\s\)\'"#\x{7f}-\x{9f}]/u', $url)) {
- $url = $match['quotes'].$url.$match['quotes'];
+ $url = $match['quotes'] . $url . $match['quotes'];
}
// build replacement
$search[] = $match[0];
- if ('url' === $type) {
- $replace[] = 'url('.$url.')';
- } elseif ('import' === $type) {
- $replace[] = '@import "'.$url.'"';
+ if ($type === 'url') {
+ $replace[] = 'url(' . $url . ')';
+ } elseif ($type === 'import') {
+ $replace[] = '@import "' . $url . '"';
}
}
@@ -529,7 +530,7 @@ class CSS extends Minify
);
return preg_replace_callback(
- '/(?<=[: ])('.implode('|', array_keys($colors)).')(?=[; }])/i',
+ '/(?<=[: ])(' . implode('|', array_keys($colors)) . ')(?=[; }])/i',
function ($match) use ($colors) {
return $colors[strtoupper($match[0])];
},
@@ -552,10 +553,10 @@ class CSS extends Minify
);
$callback = function ($match) use ($weights) {
- return $match[1].$weights[$match[2]];
+ return $match[1] . $weights[$match[2]];
};
- return preg_replace_callback('/(font-weight\s*:\s*)('.implode('|', array_keys($weights)).')(?=[;}])/', $callback, $content);
+ return preg_replace_callback('/(font-weight\s*:\s*)(' . implode('|', array_keys($weights)) . ')(?=[;}])/', $callback, $content);
}
/**
@@ -587,19 +588,19 @@ class CSS extends Minify
// practice, Webkit (especially Safari) seems to stumble over at least
// 0%, potentially other units as well. Only stripping 'px' for now.
// @see https://github.com/matthiasmullie/minify/issues/60
- $content = preg_replace('/'.$before.'(-?0*(\.0+)?)(?<=0)px'.$after.'/', '\\1', $content);
+ $content = preg_replace('/' . $before . '(-?0*(\.0+)?)(?<=0)px' . $after . '/', '\\1', $content);
// strip 0-digits (.0 -> 0)
- $content = preg_replace('/'.$before.'\.0+'.$units.'?'.$after.'/', '0\\1', $content);
+ $content = preg_replace('/' . $before . '\.0+' . $units . '?' . $after . '/', '0\\1', $content);
// strip trailing 0: 50.10 -> 50.1, 50.10px -> 50.1px
- $content = preg_replace('/'.$before.'(-?[0-9]+\.[0-9]+)0+'.$units.'?'.$after.'/', '\\1\\2', $content);
+ $content = preg_replace('/' . $before . '(-?[0-9]+\.[0-9]+)0+' . $units . '?' . $after . '/', '\\1\\2', $content);
// strip trailing 0: 50.00 -> 50, 50.00px -> 50px
- $content = preg_replace('/'.$before.'(-?[0-9]+)\.0+'.$units.'?'.$after.'/', '\\1\\2', $content);
+ $content = preg_replace('/' . $before . '(-?[0-9]+)\.0+' . $units . '?' . $after . '/', '\\1\\2', $content);
// strip leading 0: 0.1 -> .1, 01.1 -> 1.1
- $content = preg_replace('/'.$before.'(-?)0+([0-9]*\.[0-9]+)'.$units.'?'.$after.'/', '\\1\\2\\3', $content);
+ $content = preg_replace('/' . $before . '(-?)0+([0-9]*\.[0-9]+)' . $units . '?' . $after . '/', '\\1\\2\\3', $content);
// strip negative zeroes (-0 -> 0) & truncate zeroes (00 -> 0)
- $content = preg_replace('/'.$before.'-?0+'.$units.'?'.$after.'/', '0\\1', $content);
+ $content = preg_replace('/' . $before . '-?0+' . $units . '?' . $after . '/', '0\\1', $content);
// IE doesn't seem to understand a unitless flex-basis value (correct -
// it goes against the spec), so let's add it in again (make it `%`,
@@ -635,7 +636,7 @@ class CSS extends Minify
$minifier = $this;
$callback = function ($match) use ($minifier) {
$count = count($minifier->extracted);
- $placeholder = '/*'.$count.'*/';
+ $placeholder = '/*' . $count . '*/';
$minifier->extracted[$placeholder] = $match[0];
return $placeholder;
@@ -673,7 +674,7 @@ class CSS extends Minify
// not in things like `calc(3px + 2px)`, shorthands like `3px -2px`, or
// selectors like `div.weird- p`
$pseudos = array('nth-child', 'nth-last-child', 'nth-last-of-type', 'nth-of-type');
- $content = preg_replace('/:('.implode('|', $pseudos).')\(\s*([+-]?)\s*(.+?)\s*([+-]?)\s*(.*?)\s*\)/', ':$1($2$3$4$5)', $content);
+ $content = preg_replace('/:(' . implode('|', $pseudos) . ')\(\s*([+-]?)\s*(.+?)\s*([+-]?)\s*(.*?)\s*\)/', ':$1($2$3$4$5)', $content);
// remove semicolon/whitespace followed by closing bracket
$content = str_replace(';}', '}', $content);
@@ -688,7 +689,7 @@ class CSS extends Minify
protected function extractMath()
{
$functions = array('calc', 'clamp', 'min', 'max');
- $pattern = '/\b('.implode('|', $functions).')(\(.+?)(?=$|;|})/m';
+ $pattern = '/\b(' . implode('|', $functions) . ')(\(.+?)(?=$|;|})/m';
// PHP only supports $this inside anonymous functions since 5.4
$minifier = $this;
@@ -706,25 +707,25 @@ class CSS extends Minify
for ($i = 0; $i < $length; ++$i) {
$char = $match[2][$i];
$expr .= $char;
- if ('(' === $char) {
+ if ($char === '(') {
++$opened;
- } elseif (')' === $char && 0 === --$opened) {
+ } elseif ($char === ')' && --$opened === 0) {
break;
}
}
// now that we've figured out where the calc() starts and ends, extract it
$count = count($minifier->extracted);
- $placeholder = 'math('.$count.')';
- $minifier->extracted[$placeholder] = $function.'('.trim(substr($expr, 1, -1)).')';
+ $placeholder = 'math(' . $count . ')';
+ $minifier->extracted[$placeholder] = $function . '(' . trim(substr($expr, 1, -1)) . ')';
// and since we've captured more code than required, we may have some leftover
// calc() in here too - go recursive on the remaining but of code to go figure
// that out and extract what is needed
- $rest = $minifier->str_replace_first($function.$expr, '', $match[0]);
+ $rest = $minifier->str_replace_first($function . $expr, '', $match[0]);
$rest = preg_replace_callback($pattern, $callback, $rest);
- return $placeholder.$rest;
+ return $placeholder . $rest;
};
$this->registerPattern($pattern, $callback);
@@ -741,8 +742,8 @@ class CSS extends Minify
$this->registerPattern(
'/(?<=^|[;}{])\s*(--[^:;{}"\'\s]+)\s*:([^;{}]+)/m',
function ($match) use ($minifier) {
- $placeholder = '--custom-'.count($minifier->extracted).':0';
- $minifier->extracted[$placeholder] = $match[1].':'.trim($match[2]);
+ $placeholder = '--custom-' . count($minifier->extracted) . ':0';
+ $minifier->extracted[$placeholder] = $match[1] . ':' . trim($match[2]);
return $placeholder;
}
@@ -770,7 +771,7 @@ class CSS extends Minify
*/
protected function canImportByPath($path)
{
- return 0 === preg_match('/^(data:|https?:|\\/)/', $path);
+ return preg_match('/^(data:|https?:|\\/)/', $path) === 0;
}
/**
diff --git a/src/Exception.php b/src/Exception.php
index 0a87ad7..1c947a9 100644
--- a/src/Exception.php
+++ b/src/Exception.php
@@ -1,4 +1,5 @@
keywordsReserved = file($dataDir.'keywords_reserved.txt', $options);
- $this->keywordsBefore = file($dataDir.'keywords_before.txt', $options);
- $this->keywordsAfter = file($dataDir.'keywords_after.txt', $options);
- $this->operators = file($dataDir.'operators.txt', $options);
- $this->operatorsBefore = file($dataDir.'operators_before.txt', $options);
- $this->operatorsAfter = file($dataDir.'operators_after.txt', $options);
+ $this->keywordsReserved = file($dataDir . 'keywords_reserved.txt', $options);
+ $this->keywordsBefore = file($dataDir . 'keywords_before.txt', $options);
+ $this->keywordsAfter = file($dataDir . 'keywords_after.txt', $options);
+ $this->operators = file($dataDir . 'operators.txt', $options);
+ $this->operatorsBefore = file($dataDir . 'operators_before.txt', $options);
+ $this->operatorsAfter = file($dataDir . 'operators_after.txt', $options);
}
/**
@@ -176,7 +177,7 @@ class JS extends Minify
$js = $this->stripWhitespace($js);
// combine js: separating the scripts by a ;
- $content .= $js.';';
+ $content .= $js . ';';
}
// clean up leftover `;`s from the combination of multiple scripts
@@ -201,20 +202,20 @@ class JS extends Minify
$minifier = $this;
$callback = function ($match) use ($minifier) {
if (
- '!' === substr($match[2], 0, 1) ||
- false !== strpos($match[2], '@license') ||
- false !== strpos($match[2], '@preserve')
+ substr($match[2], 0, 1) === '!' ||
+ strpos($match[2], '@license') !== false ||
+ strpos($match[2], '@preserve') !== false
) {
// preserve multi-line comments that start with /*!
// or contain @license or @preserve annotations
$count = count($minifier->extracted);
- $placeholder = '/*'.$count.'*/';
+ $placeholder = '/*' . $count . '*/';
$minifier->extracted[$placeholder] = $match[0];
- return $match[1].$placeholder.$match[3];
+ return $match[1] . $placeholder . $match[3];
}
- return $match[1].$match[3];
+ return $match[1] . $match[3];
};
// multi-line comments
@@ -247,7 +248,7 @@ class JS extends Minify
$minifier = $this;
$callback = function ($match) use ($minifier) {
$count = count($minifier->extracted);
- $placeholder = '"'.$count.'"';
+ $placeholder = '"' . $count . '"';
$minifier->extracted[$placeholder] = $match[0];
return $placeholder;
@@ -266,7 +267,7 @@ class JS extends Minify
// of the RegExp methods (a `\` followed by a variable or value is
// likely part of a division, not a regex)
$keywords = array('do', 'in', 'new', 'else', 'throw', 'yield', 'delete', 'return', 'typeof');
- $before = '(^|[=:,;\+\-\*\?\/\}\(\{\[&\|!]|'.implode('|', $keywords).')\s*';
+ $before = '(^|[=:,;\+\-\*\?\/\}\(\{\[&\|!]|' . implode('|', $keywords) . ')\s*';
$propertiesAndMethods = array(
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#Properties_2
'constructor',
@@ -286,8 +287,8 @@ class JS extends Minify
);
$delimiters = array_fill(0, count($propertiesAndMethods), '/');
$propertiesAndMethods = array_map('preg_quote', $propertiesAndMethods, $delimiters);
- $after = '(?=\s*([\.,;:\)\}&\|+]|\/\/|$|\.('.implode('|', $propertiesAndMethods).')))';
- $this->registerPattern('/'.$before.'\K'.$pattern.$after.'/', $callback);
+ $after = '(?=\s*([\.,;:\)\}&\|+]|\/\/|$|\.(' . implode('|', $propertiesAndMethods) . ')))';
+ $this->registerPattern('/' . $before . '\K' . $pattern . $after . '/', $callback);
// regular expressions following a `)` are rather annoying to detect...
// quite often, `/` after `)` is a division operator & if it happens to
@@ -301,8 +302,8 @@ class JS extends Minify
// if a regex following `)` is not followed by `.`,
// it's quite likely not a regex
$before = '\)\s*';
- $after = '(?=\s*\.('.implode('|', $propertiesAndMethods).'))';
- $this->registerPattern('/'.$before.'\K'.$pattern.$after.'/', $callback);
+ $after = '(?=\s*\.(' . implode('|', $propertiesAndMethods) . '))';
+ $this->registerPattern('/' . $before . '\K' . $pattern . $after . '/', $callback);
// 1 more edge case: a regex can be followed by a lot more operators or
// keywords if there's a newline (ASI) in between, where the operator
@@ -310,8 +311,8 @@ class JS extends Minify
// (https://github.com/matthiasmullie/minify/issues/56)
$operators = $this->getOperatorsForRegex($this->operatorsBefore, '/');
$operators += $this->getOperatorsForRegex($this->keywordsReserved, '/');
- $after = '(?=\s*\n\s*('.implode('|', $operators).'))';
- $this->registerPattern('/'.$pattern.$after.'/', $callback);
+ $after = '(?=\s*\n\s*(' . implode('|', $operators) . '))';
+ $this->registerPattern('/' . $pattern . $after . '/', $callback);
}
/**
@@ -355,8 +356,8 @@ class JS extends Minify
unset($operatorsBefore['+'], $operatorsBefore['-'], $operatorsAfter['+'], $operatorsAfter['-']);
$content = preg_replace(
array(
- '/('.implode('|', $operatorsBefore).')\s+/',
- '/\s+('.implode('|', $operatorsAfter).')/',
+ '/(' . implode('|', $operatorsBefore) . ')\s+/',
+ '/\s+(' . implode('|', $operatorsAfter) . ')/',
),
'\\1',
$content
@@ -373,8 +374,8 @@ class JS extends Minify
);
// collapse whitespace around reserved words into single space
- $content = preg_replace('/(^|[;\}\s])\K('.implode('|', $keywordsBefore).')\s+/', '\\2 ', $content);
- $content = preg_replace('/\s+('.implode('|', $keywordsAfter).')(?=([;\{\s]|$))/', ' \\1', $content);
+ $content = preg_replace('/(^|[;\}\s])\K(' . implode('|', $keywordsBefore) . ')\s+/', '\\2 ', $content);
+ $content = preg_replace('/\s+(' . implode('|', $keywordsAfter) . ')(?=([;\{\s]|$))/', ' \\1', $content);
/*
* We didn't strip whitespace after a couple of operators because they
@@ -384,8 +385,8 @@ class JS extends Minify
*/
$operatorsDiffBefore = array_diff($operators, $operatorsBefore);
$operatorsDiffAfter = array_diff($operators, $operatorsAfter);
- $content = preg_replace('/('.implode('|', $operatorsDiffBefore).')[^\S\n]+/', '\\1', $content);
- $content = preg_replace('/[^\S\n]+('.implode('|', $operatorsDiffAfter).')/', '\\1', $content);
+ $content = preg_replace('/(' . implode('|', $operatorsDiffBefore) . ')[^\S\n]+/', '\\1', $content);
+ $content = preg_replace('/[^\S\n]+(' . implode('|', $operatorsDiffAfter) . ')/', '\\1', $content);
/*
* Whitespace after `return` can be omitted in a few occasions
@@ -494,7 +495,7 @@ class JS extends Minify
// don't confuse = with other assignment shortcuts (e.g. +=)
$chars = preg_quote('+-*\=<>%&|', $delimiter);
- $operators['='] = '(?getKeywordsForRegex($keywords);
- $keywords = '(?canImportFile($path)) {
- throw new IOException('The file "'.$path.'" could not be opened for reading. Check if PHP has enough permissions.');
+ throw new IOException('The file "' . $path . '" could not be opened for reading. Check if PHP has enough permissions.');
}
$this->add($path);
@@ -151,7 +152,7 @@ abstract class Minify
$content = $this->execute($path);
// save to path
- if (null !== $path) {
+ if ($path !== null) {
$this->save($content, $path);
}
@@ -172,7 +173,7 @@ abstract class Minify
$content = gzencode($content, $level, FORCE_GZIP);
// save to path
- if (null !== $path) {
+ if ($path !== null) {
$this->save($content, $path);
}
@@ -217,7 +218,7 @@ abstract class Minify
$data = file_get_contents($data);
// strip BOM, if any
- if ("\xef\xbb\xbf" == substr($data, 0, 3)) {
+ if (substr($data, 0, 3) == "\xef\xbb\xbf") {
$data = substr($data, 3);
}
}
@@ -286,7 +287,7 @@ abstract class Minify
// we can safely ignore patterns for positions we've unset earlier,
// because we know these won't show up anymore
- if (false == array_key_exists($i, $positions)) {
+ if (array_key_exists($i, $positions) == false) {
continue;
}
@@ -383,7 +384,7 @@ abstract class Minify
$minifier = $this;
$callback = function ($match) use ($minifier, $placeholderPrefix) {
// check the second index here, because the first always contains a quote
- if ('' === $match[2]) {
+ if ($match[2] === '') {
/*
* Empty strings need no placeholder; they can't be confused for
* anything else anyway.
@@ -394,8 +395,8 @@ abstract class Minify
}
$count = count($minifier->extracted);
- $placeholder = $match[1].$placeholderPrefix.$count.$match[1];
- $minifier->extracted[$placeholder] = $match[1].$match[2].$match[1];
+ $placeholder = $match[1] . $placeholderPrefix . $count . $match[1];
+ $minifier->extracted[$placeholder] = $match[1] . $match[2] . $match[1];
return $placeholder;
};
@@ -412,7 +413,7 @@ abstract class Minify
* considered as escape-char (times 2) and to get it in the regex,
* escaped (times 2)
*/
- $this->registerPattern('/(['.$chars.'])(.*?(?registerPattern('/([' . $chars . '])(.*?(?expectException('MatthiasMullie\Minify\Exceptions\FileImportException');
- $testFile = __DIR__.'/sample/loop/first.css';
+ $testFile = __DIR__ . '/sample/loop/first.css';
$minifier = $this->mockMinifier();
$minifier->add($testFile);
@@ -106,8 +106,8 @@ class CSSTest extends CompatTestCase
// passing in an array of css inputs
$tests[] = array(
array(
- __DIR__.'/sample/combine_imports/index.css',
- __DIR__.'/sample/bom/bom.css',
+ __DIR__ . '/sample/combine_imports/index.css',
+ __DIR__ . '/sample/bom/bom.css',
'p { width: 55px , margin: 0 0 0 0}',
),
'body{color:red}body{color:red}p{width:55px,margin:0 0 0 0}',
@@ -115,27 +115,27 @@ class CSSTest extends CompatTestCase
// try importing, with both @import syntax types & media queries
$tests[] = array(
- __DIR__.'/sample/combine_imports/index.css',
+ __DIR__ . '/sample/combine_imports/index.css',
'body{color:red}',
);
$tests[] = array(
- __DIR__.'/sample/combine_imports/index2.css',
+ __DIR__ . '/sample/combine_imports/index2.css',
'body{color:red}',
);
$tests[] = array(
- __DIR__.'/sample/combine_imports/index3.css',
+ __DIR__ . '/sample/combine_imports/index3.css',
'body{color:red}body{color:red}',
);
$tests[] = array(
- __DIR__.'/sample/combine_imports/index4.css',
+ __DIR__ . '/sample/combine_imports/index4.css',
'@media only screen{body{color:red}}@media only screen{body{color:red}}',
);
$tests[] = array(
- __DIR__.'/sample/combine_imports/index5.css',
+ __DIR__ . '/sample/combine_imports/index5.css',
'body{color:red}body{color:red}',
);
$tests[] = array(
- __DIR__.'/sample/combine_imports/index6a.css',
+ __DIR__ . '/sample/combine_imports/index6a.css',
'body{color:red}',
);
@@ -147,8 +147,8 @@ class CSSTest extends CompatTestCase
// import files
$tests[] = array(
- __DIR__.'/sample/import_files/index.css',
- 'body{background:url(data:image/png;base64,'.base64_encode(file_get_contents(__DIR__.'/sample/import_files/file.png')).')}',
+ __DIR__ . '/sample/import_files/index.css',
+ 'body{background:url(data:image/png;base64,' . base64_encode(file_get_contents(__DIR__ . '/sample/import_files/file.png')) . ')}',
);
// strip comments
@@ -194,7 +194,7 @@ class CSSTest extends CompatTestCase
);
$tests[] = array(
-<<<'JS'
+ <<<'JS'
p * i , html
/* remove spaces */
@@ -231,7 +231,7 @@ JS
// strip BOM
$tests[] = array(
- __DIR__.'/sample/bom/bom.css',
+ __DIR__ . '/sample/bom/bom.css',
'body{color:red}',
);
@@ -337,15 +337,15 @@ margin-left: -0.3125rem;
// https://github.com/matthiasmullie/minify/issues/49
$tests[] = array(
- __DIR__.'/sample/import_files/issue49.css',
- '.social-btn a[href*="facebook"]{background-image:url(data:image/png;base64,'.base64_encode(file_get_contents(__DIR__.'/sample/import_files/facebook.png')).')}'.
- '.social-btn a[href*="vimeo"]{background-image:url(data:image/png;base64,'.base64_encode(file_get_contents(__DIR__.'/sample/import_files/vimeo.png')).')}'.
- '.social-btn a[href*="instagram"]{background-image:url(data:image/png;base64,'.base64_encode(file_get_contents(__DIR__.'/sample/import_files/instagram.png')).')}',
+ __DIR__ . '/sample/import_files/issue49.css',
+ '.social-btn a[href*="facebook"]{background-image:url(data:image/png;base64,' . base64_encode(file_get_contents(__DIR__ . '/sample/import_files/facebook.png')) . ')}' .
+ '.social-btn a[href*="vimeo"]{background-image:url(data:image/png;base64,' . base64_encode(file_get_contents(__DIR__ . '/sample/import_files/vimeo.png')) . ')}' .
+ '.social-btn a[href*="instagram"]{background-image:url(data:image/png;base64,' . base64_encode(file_get_contents(__DIR__ . '/sample/import_files/instagram.png')) . ')}',
);
// https://github.com/matthiasmullie/minify/issues/68
$tests[] = array(
- __DIR__.'/sample/external_imports/issue68.css',
+ __DIR__ . '/sample/external_imports/issue68.css',
'@import url(http://localhost/file.css);body{background:green}',
);
@@ -494,15 +494,15 @@ only screen and (min-device-pixel-ratio: 1.5) {
// https://github.com/matthiasmullie/minify/issues/139
$tests[] = array(
- __DIR__.'/sample/line_endings/lf/parent.css',
+ __DIR__ . '/sample/line_endings/lf/parent.css',
'p{color:green}body{color:red}',
);
$tests[] = array(
- __DIR__.'/sample/line_endings/cr/parent.css',
+ __DIR__ . '/sample/line_endings/cr/parent.css',
'p{color:green}body{color:red}',
);
$tests[] = array(
- __DIR__.'/sample/line_endings/crlf/parent.css',
+ __DIR__ . '/sample/line_endings/crlf/parent.css',
'p{color:green}body{color:red}',
);
@@ -864,73 +864,73 @@ margin-left: calc(20px + var(--some-var));
{
$tests = array();
- $source = __DIR__.'/sample/convert_relative_path/source';
- $target = __DIR__.'/sample/convert_relative_path/target';
+ $source = __DIR__ . '/sample/convert_relative_path/source';
+ $target = __DIR__ . '/sample/convert_relative_path/target';
// external link
$tests[] = array(
- $source.'/external.css',
- $target.'/external.css',
- file_get_contents($source.'/external.css'),
+ $source . '/external.css',
+ $target . '/external.css',
+ file_get_contents($source . '/external.css'),
);
// absolute path
$tests[] = array(
- $source.'/absolute.css',
- $target.'/absolute.css',
- file_get_contents($source.'/absolute.css'),
+ $source . '/absolute.css',
+ $target . '/absolute.css',
+ file_get_contents($source . '/absolute.css'),
);
// relative paths
$tests[] = array(
- $source.'/relative.css',
- $target.'/relative.css',
+ $source . '/relative.css',
+ $target . '/relative.css',
'@import url(stylesheet.css);',
);
$tests[] = array(
- $source.'/../source/relative.css',
- $target.'/target/relative.css',
+ $source . '/../source/relative.css',
+ $target . '/target/relative.css',
'@import url(../stylesheet.css);',
);
// https://github.com/matthiasmullie/minify/issues/29
$tests[] = array(
- $source.'/issue29.css',
- $target.'/issue29.css',
+ $source . '/issue29.css',
+ $target . '/issue29.css',
'@import url(http://myurl.de);',
);
// https://github.com/matthiasmullie/minify/issues/38
$tests[] = array(
- $source.'/relative.css',
+ $source . '/relative.css',
null, // no output file
- file_get_contents($source.'/relative.css'),
+ file_get_contents($source . '/relative.css'),
);
// https://github.com/matthiasmullie/minify/issues/39
$tests[] = array(
- $source.'/issue39.css',
+ $source . '/issue39.css',
null, // no output file
// relative paths should remain untouched
"@font-face{font-family:'blackcat';src:url(../webfont/blackcat.eot);src:url('../webfont/blackcat.eot?#iefix') format('embedded-opentype'),url('../webfont/blackcat.svg#blackcat') format('svg'),url(../webfont/blackcat.woff) format('woff'),url(../webfont/blackcat.ttf) format('truetype');font-weight:400;font-style:normal}",
);
$tests[] = array(
- $source.'/issue39.css',
- $target.'/issue39.css',
+ $source . '/issue39.css',
+ $target . '/issue39.css',
// relative paths should remain untouched
"@font-face{font-family:'blackcat';src:url(../webfont/blackcat.eot);src:url('../webfont/blackcat.eot?#iefix') format('embedded-opentype'),url('../webfont/blackcat.svg#blackcat') format('svg'),url(../webfont/blackcat.woff) format('woff'),url(../webfont/blackcat.ttf) format('truetype');font-weight:400;font-style:normal}",
);
$tests[] = array(
- $source.'/issue39.css',
- $target.'/target/issue39.css',
+ $source . '/issue39.css',
+ $target . '/target/issue39.css',
// relative paths should have changed
"@font-face{font-family:'blackcat';src:url(../../webfont/blackcat.eot);src:url('../../webfont/blackcat.eot?#iefix') format('embedded-opentype'),url('../../webfont/blackcat.svg#blackcat') format('svg'),url(../../webfont/blackcat.woff) format('woff'),url(../../webfont/blackcat.ttf) format('truetype');font-weight:400;font-style:normal}",
);
// https://github.com/forkcms/forkcms/issues/1121
$tests[] = array(
- $source.'/nested/nested.css',
- $target.'/nested.css',
+ $source . '/nested/nested.css',
+ $target . '/nested.css',
'@import url(stylesheet.css);',
);
@@ -946,8 +946,8 @@ margin-left: calc(20px + var(--some-var));
// https://github.com/matthiasmullie/minify/issues/77#issuecomment-172844822
$tests[] = array(
- $source.'/get-params.css',
- $target.'/get-params.css',
+ $source . '/get-params.css',
+ $target . '/get-params.css',
'@import url(../source/some-file.css?some=param);',
);
@@ -956,113 +956,113 @@ margin-left: calc(20px + var(--some-var));
// from and/or to are relative links
$tests[] = array(
- $sourceRelative.'/relative.css',
- $target.'/relative.css',
+ $sourceRelative . '/relative.css',
+ $target . '/relative.css',
'@import url(stylesheet.css);',
);
// note: relative target only works if the file already exists: it has
// to be able to realpath()
$tests[] = array(
- $source.'/relative.css',
- $targetRelative.'/relative.css',
+ $source . '/relative.css',
+ $targetRelative . '/relative.css',
'@import url(stylesheet.css);',
);
$tests[] = array(
- $sourceRelative.'/relative.css',
- $targetRelative.'/relative.css',
+ $sourceRelative . '/relative.css',
+ $targetRelative . '/relative.css',
'@import url(stylesheet.css);',
);
- $source = __DIR__.'/sample/symlink';
- $target = __DIR__.'/sample/symlink/target';
+ $source = __DIR__ . '/sample/symlink';
+ $target = __DIR__ . '/sample/symlink/target';
$sourceRelative = 'tests/CSS/sample/symlink';
$targetRelative = 'tests/CSS/sample/symlink/target';
// import symlinked files: relative, absolute & mix
$tests[] = array(
- $source.'/import_symlinked_file.css',
- $target.'/import_symlinked_file.css',
+ $source . '/import_symlinked_file.css',
+ $target . '/import_symlinked_file.css',
'',
);
$tests[] = array(
- $sourceRelative.'/import_symlinked_file.css',
- $targetRelative.'/import_symlinked_file.css',
+ $sourceRelative . '/import_symlinked_file.css',
+ $targetRelative . '/import_symlinked_file.css',
'',
);
$tests[] = array(
- $source.'/import_symlinked_file.css',
- $targetRelative.'/import_symlinked_file.css',
+ $source . '/import_symlinked_file.css',
+ $targetRelative . '/import_symlinked_file.css',
'',
);
$tests[] = array(
- $sourceRelative.'/import_symlinked_file.css',
- $target.'/import_symlinked_file.css',
+ $sourceRelative . '/import_symlinked_file.css',
+ $target . '/import_symlinked_file.css',
'',
);
// move symlinked files: relative, absolute & mix
$tests[] = array(
- $source.'/move_symlinked_file.css',
- $target.'/move_symlinked_file.css',
+ $source . '/move_symlinked_file.css',
+ $target . '/move_symlinked_file.css',
'body{background-url:url(../assets/symlink.bmp)}',
);
$tests[] = array(
- $sourceRelative.'/move_symlinked_file.css',
- $targetRelative.'/move_symlinked_file.css',
+ $sourceRelative . '/move_symlinked_file.css',
+ $targetRelative . '/move_symlinked_file.css',
'body{background-url:url(../assets/symlink.bmp)}',
);
$tests[] = array(
- $source.'/move_symlinked_file.css',
- $targetRelative.'/move_symlinked_file.css',
+ $source . '/move_symlinked_file.css',
+ $targetRelative . '/move_symlinked_file.css',
'body{background-url:url(../assets/symlink.bmp)}',
);
$tests[] = array(
- $source.'/move_symlinked_file.css',
- $targetRelative.'/move_symlinked_file.css',
+ $source . '/move_symlinked_file.css',
+ $targetRelative . '/move_symlinked_file.css',
'body{background-url:url(../assets/symlink.bmp)}',
);
// import symlinked folders: relative, absolute & mix
$tests[] = array(
- $source.'/import_symlinked_folder.css',
- $target.'/import_symlinked_folder.css',
+ $source . '/import_symlinked_folder.css',
+ $target . '/import_symlinked_folder.css',
'',
);
$tests[] = array(
- $sourceRelative.'/import_symlinked_folder.css',
- $targetRelative.'/import_symlinked_folder.css',
+ $sourceRelative . '/import_symlinked_folder.css',
+ $targetRelative . '/import_symlinked_folder.css',
'',
);
$tests[] = array(
- $source.'/import_symlinked_folder.css',
- $targetRelative.'/import_symlinked_folder.css',
+ $source . '/import_symlinked_folder.css',
+ $targetRelative . '/import_symlinked_folder.css',
'',
);
$tests[] = array(
- $sourceRelative.'/import_symlinked_folder.css',
- $target.'/import_symlinked_folder.css',
+ $sourceRelative . '/import_symlinked_folder.css',
+ $target . '/import_symlinked_folder.css',
'',
);
// move symlinked folders: relative, absolute & mix
$tests[] = array(
- $source.'/move_symlinked_folder.css',
- $target.'/move_symlinked_folder.css',
+ $source . '/move_symlinked_folder.css',
+ $target . '/move_symlinked_folder.css',
'body{background-url:url(../assets_symlink/asset.bmp)}',
);
$tests[] = array(
- $sourceRelative.'/move_symlinked_folder.css',
- $targetRelative.'/move_symlinked_folder.css',
+ $sourceRelative . '/move_symlinked_folder.css',
+ $targetRelative . '/move_symlinked_folder.css',
'body{background-url:url(../assets_symlink/asset.bmp)}',
);
$tests[] = array(
- $source.'/move_symlinked_folder.css',
- $targetRelative.'/move_symlinked_folder.css',
+ $source . '/move_symlinked_folder.css',
+ $targetRelative . '/move_symlinked_folder.css',
'body{background-url:url(../assets_symlink/asset.bmp)}',
);
$tests[] = array(
- $sourceRelative.'/move_symlinked_folder.css',
- $target.'/move_symlinked_folder.css',
+ $sourceRelative . '/move_symlinked_folder.css',
+ $target . '/move_symlinked_folder.css',
'body{background-url:url(../assets_symlink/asset.bmp)}',
);
diff --git a/tests/JS/AbstractTest.php b/tests/JS/AbstractTest.php
index 64afd33..cb76ae1 100644
--- a/tests/JS/AbstractTest.php
+++ b/tests/JS/AbstractTest.php
@@ -14,8 +14,8 @@ class AbstractTest extends CompatTestCase
{
public function testConstruct()
{
- $path1 = __DIR__.'/sample/source/script1.js';
- $path2 = __DIR__.'/sample/source/script2.js';
+ $path1 = __DIR__ . '/sample/source/script1.js';
+ $path2 = __DIR__ . '/sample/source/script2.js';
$content1 = file_get_contents($path1);
$content2 = file_get_contents($path2);
@@ -29,7 +29,7 @@ class AbstractTest extends CompatTestCase
$minifier = new Minify\JS($content1, $content2);
$result = $minifier->minify();
- $this->assertEquals($content1.';'.$content2, $result);
+ $this->assertEquals($content1 . ';' . $content2, $result);
// file in constructor
$minifier = new Minify\JS($path1);
@@ -41,13 +41,13 @@ class AbstractTest extends CompatTestCase
$minifier = new Minify\JS($path1, $path2);
$result = $minifier->minify();
- $this->assertEquals($content1.';'.$content2, $result);
+ $this->assertEquals($content1 . ';' . $content2, $result);
}
public function testAdd()
{
- $path1 = __DIR__.'/sample/source/script1.js';
- $path2 = __DIR__.'/sample/source/script2.js';
+ $path1 = __DIR__ . '/sample/source/script1.js';
+ $path2 = __DIR__ . '/sample/source/script2.js';
$content1 = file_get_contents($path1);
$content2 = file_get_contents($path2);
$content3 = 'var test=3';
@@ -65,7 +65,7 @@ class AbstractTest extends CompatTestCase
$minifier->add($content2);
$result = $minifier->minify();
- $this->assertEquals($content1.';'.$content2, $result);
+ $this->assertEquals($content1 . ';' . $content2, $result);
// file in add
$minifier = new Minify\JS();
@@ -80,27 +80,27 @@ class AbstractTest extends CompatTestCase
$minifier->add($path2);
$result = $minifier->minify();
- $this->assertEquals($content1.';'.$content2, $result);
+ $this->assertEquals($content1 . ';' . $content2, $result);
// array of files in add
$minifier = new Minify\JS();
$minifier->add(array($path1, $path2));
$result = $minifier->minify();
- $this->assertEquals($content1.';'.$content2, $result);
+ $this->assertEquals($content1 . ';' . $content2, $result);
// array of files + overload in add
$minifier = new Minify\JS();
$minifier->add(array($path1, $path2), $content3);
$result = $minifier->minify();
- $this->assertEquals($content1.';'.$content2.';'.$content3, $result);
+ $this->assertEquals($content1 . ';' . $content2 . ';' . $content3, $result);
$minifier = new Minify\JS();
$minifier->add($path1, array($path2, $content3));
$result = $minifier->minify();
- $this->assertEquals($content1.';'.$content2.';'.$content3, $result);
+ $this->assertEquals($content1 . ';' . $content2 . ';' . $content3, $result);
}
public function testLoadBigString()
@@ -128,11 +128,11 @@ class AbstractTest extends CompatTestCase
*/
$pid = pcntl_fork();
- if (-1 === $pid) {
+ if ($pid === -1) {
// can't fork, ignore this test...
- } elseif (0 === $pid) {
+ } elseif ($pid === 0) {
// https://github.com/matthiasmullie/minify/issues/111
- ini_set('open_basedir', __DIR__.'/../..');
+ ini_set('open_basedir', __DIR__ . '/../..');
// instead of displaying warnings & moving to the next test, just
// quit with the error code; the other thread will pick it up
@@ -159,9 +159,9 @@ class AbstractTest extends CompatTestCase
public function testSave()
{
- $path = __DIR__.'/sample/source/script1.js';
+ $path = __DIR__ . '/sample/source/script1.js';
$content = file_get_contents($path);
- $savePath = __DIR__.'/sample/target/script1.js';
+ $savePath = __DIR__ . '/sample/target/script1.js';
$minifier = new Minify\JS($path);
$minifier->minify($savePath);
@@ -199,9 +199,9 @@ class AbstractTest extends CompatTestCase
public function testGzip()
{
- $path = __DIR__.'/sample/source/script1.js';
+ $path = __DIR__ . '/sample/source/script1.js';
$content = file_get_contents($path);
- $savePath = __DIR__.'/sample/target/script1.js.gz';
+ $savePath = __DIR__ . '/sample/target/script1.js.gz';
$minifier = new Minify\JS($path);
$minifier->gzip($savePath, 9);
@@ -211,7 +211,7 @@ class AbstractTest extends CompatTestCase
public function testCache()
{
- $path = __DIR__.'/sample/source/script1.js';
+ $path = __DIR__ . '/sample/source/script1.js';
$content = file_get_contents($path);
$cache = new MemoryStore();
diff --git a/tests/JS/JSTest.php b/tests/JS/JSTest.php
index 02756dd..98654fc 100644
--- a/tests/JS/JSTest.php
+++ b/tests/JS/JSTest.php
@@ -34,7 +34,7 @@ class JSTest extends CompatTestCase
public function testAddFile()
{
$minifier = $this->mockMinifier();
- $minifier->addFile(__DIR__.'/sample/source/script1.js');
+ $minifier->addFile(__DIR__ . '/sample/source/script1.js');
$result = $minifier->minify();
@@ -65,8 +65,8 @@ class JSTest extends CompatTestCase
// adding multiple files
$tests[] = array(
array(
- __DIR__.'/sample/source/script1.js',
- __DIR__.'/sample/source/script2.js',
+ __DIR__ . '/sample/source/script1.js',
+ __DIR__ . '/sample/source/script2.js',
),
'var test=1;var test=2',
);
@@ -74,9 +74,9 @@ class JSTest extends CompatTestCase
// adding multiple files and string
$tests[] = array(
array(
- __DIR__.'/sample/source/script1.js',
+ __DIR__ . '/sample/source/script1.js',
'console.log(test)',
- __DIR__.'/sample/source/script2.js',
+ __DIR__ . '/sample/source/script2.js',
),
'var test=1;console.log(test);var test=2',
);
@@ -869,15 +869,15 @@ String(dateString).match(/^[0-9]*$/);',
// https://github.com/matthiasmullie/minify/issues/139
$tests[] = array(
- __DIR__.'/sample/line_endings/lf/script.js',
+ __DIR__ . '/sample/line_endings/lf/script.js',
'var a=1',
);
$tests[] = array(
- __DIR__.'/sample/line_endings/cr/script.js',
+ __DIR__ . '/sample/line_endings/cr/script.js',
'var a=1',
);
$tests[] = array(
- __DIR__.'/sample/line_endings/crlf/script.js',
+ __DIR__ . '/sample/line_endings/crlf/script.js',
'var a=1',
);
@@ -1267,14 +1267,14 @@ a = \'b\';',
// https://github.com/matthiasmullie/minify/issues/227
$tests[] = array(
- __DIR__.'/sample/bugs/227/original.js',
- file_get_contents(__DIR__.'/sample/bugs/227/minified.js'),
+ __DIR__ . '/sample/bugs/227/original.js',
+ file_get_contents(__DIR__ . '/sample/bugs/227/minified.js'),
);
// https://github.com/matthiasmullie/minify/issues/229
$tests[] = array(
- __DIR__.'/sample/bugs/229/original.js',
- file_get_contents(__DIR__.'/sample/bugs/229/minified.js'),
+ __DIR__ . '/sample/bugs/229/original.js',
+ file_get_contents(__DIR__ . '/sample/bugs/229/minified.js'),
);
// https://github.com/matthiasmullie/minify/issues/231
@@ -1367,7 +1367,7 @@ b=2',
// known minified files to help doublecheck changes in places not yet
// anticipated in these tests
- $files = glob(__DIR__.'/sample/minified/*.js');
+ $files = glob(__DIR__ . '/sample/minified/*.js');
foreach ($files as $file) {
$content = trim(file_get_contents($file));
$tests[] = array($content, $content);
@@ -1381,8 +1381,8 @@ b=2',
// some other files that are minified correctly, ensure they stay like this
// https://github.com/matthiasmullie/minify/issues/393
- $source = trim(file_get_contents(__DIR__.'/sample/source/Decrypt.js'));
- $minified = trim(file_get_contents(__DIR__.'/sample/minified2/Decrypt.min.js'));
+ $source = trim(file_get_contents(__DIR__ . '/sample/source/Decrypt.js'));
+ $minified = trim(file_get_contents(__DIR__ . '/sample/minified2/Decrypt.min.js'));
$tests[] = array($source, $minified);
return $tests;
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index 991ea43..d21c14d 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -1,3 +1,3 @@