1
0
mirror of https://github.com/mrclay/minify.git synced 2025-08-09 23:56:43 +02:00

Apply php-cs-fixer fixers

- braces
- function_declaration
- lowercase_keywords
- method_argument_space
- no_spaces_inside_parenthesis
- no_trailing_whitespace
- no_trailing_whitespace_in_comment
- single_blank_line_at_eof
This commit is contained in:
Elan Ruusamäe
2020-04-03 10:43:07 +03:00
parent 031e804d08
commit b31855f6b8
50 changed files with 217 additions and 188 deletions

View File

@@ -29,7 +29,6 @@ if ($app->env->get('hello')) {
));
$he->encode();
$he->sendAll();
} else {
// echo status "0" or "1"
header('Content-Type: text/plain');

View File

@@ -7,4 +7,3 @@
*
* @package Minify
*/

View File

@@ -198,4 +198,3 @@ $min_uploaderHoursBehind = 0;
*/
//$min_factories['minify'] = ... a callable accepting a Minify\App object
//$min_factories['controller'] = ... a callable accepting a Minify\App object

View File

@@ -204,9 +204,10 @@ class HTTP_Encoder
}
// gzip checks (slow)
if (preg_match(
'@(?:^|,)\\s*((?:x-)?gzip)\\s*(?:$|,|;\\s*q=(?:0\\.|1))@'
,$ae
,$m)) {
'@(?:^|,)\\s*((?:x-)?gzip)\\s*(?:$|,|;\\s*q=(?:0\\.|1))@',
$ae,
$m
)) {
return array('gzip', $m[1]);
}
if ($allowDeflate) {
@@ -217,14 +218,17 @@ class HTTP_Encoder
|| 0 === strpos($ae, 'deflate,') // opera
// slow parsing
|| preg_match(
'@(?:^|,)\\s*deflate\\s*(?:$|,|;\\s*q=(?:0\\.|1))@', $ae)) {
'@(?:^|,)\\s*deflate\\s*(?:$|,|;\\s*q=(?:0\\.|1))@',
$ae
)) {
return array('deflate', 'deflate');
}
}
if ($allowCompress && preg_match(
'@(?:^|,)\\s*((?:x-)?compress)\\s*(?:$|,|;\\s*q=(?:0\\.|1))@'
,$ae
,$m)) {
'@(?:^|,)\\s*((?:x-)?compress)\\s*(?:$|,|;\\s*q=(?:0\\.|1))@',
$ae,
$m
)) {
return array('compress', $m[1]);
}

View File

@@ -593,7 +593,8 @@ class Minify
! $source // yes, we ran out of sources
|| $type === self::TYPE_CSS // yes, to process CSS individually (avoiding PCRE bugs/limits)
|| $minifier !== $lastMinifier // yes, minifier changed
|| $options !== $lastOptions)) { // yes, options changed
|| $options !== $lastOptions // yes, options changed
)) {
// minify previous sources with last settings
$imploded = implode($implodeSeparator, $groupToProcessTogether);
$groupToProcessTogether = array();

View File

@@ -82,8 +82,7 @@ class App extends Container
$varDefined = get_defined_vars();
$varNames = array_filter($varNames, function($name) use($varDefined)
{
$varNames = array_filter($varNames, function ($name) use ($varDefined) {
return array_key_exists($name, $varDefined);
});

View File

@@ -73,16 +73,16 @@ class Minify_CSSmin
}
if ($options['currentDir']) {
return Minify_CSS_UriRewriter::rewrite(
$css
,$options['currentDir']
,$options['docRoot']
,$options['symlinks']
$css,
$options['currentDir'],
$options['docRoot'],
$options['symlinks']
);
}
return Minify_CSS_UriRewriter::prepend(
$css
,$options['prependRelativePath']
$css,
$options['prependRelativePath']
);
}
}

View File

@@ -68,4 +68,3 @@ class Minify_Controller_Files extends Minify_Controller_Base
return new Minify_ServeConfiguration($options, $sources);
}
}

View File

@@ -73,4 +73,3 @@ class Minify_Controller_Groups extends Minify_Controller_Files
return parent::createConfiguration($options);
}
}

View File

@@ -66,4 +66,3 @@ class Minify_Controller_Page extends Minify_Controller_Base
return new Minify_ServeConfiguration($options, $sources, $selectionId);
}
}

View File

@@ -99,32 +99,34 @@ class Minify_HTML
// replace SCRIPTs (and minify) with placeholders
$this->_html = preg_replace_callback(
'/(\\s*)<script(\\b[^>]*?>)([\\s\\S]*?)<\\/script>(\\s*)/iu'
,array($this, '_removeScriptCB')
,$this->_html);
'/(\\s*)<script(\\b[^>]*?>)([\\s\\S]*?)<\\/script>(\\s*)/iu',
array($this, '_removeScriptCB'),
$this->_html
);
// replace STYLEs (and minify) with placeholders
$this->_html = preg_replace_callback(
'/\\s*<style(\\b[^>]*>)([\\s\\S]*?)<\\/style>\\s*/iu'
,array($this, '_removeStyleCB')
,$this->_html);
'/\\s*<style(\\b[^>]*>)([\\s\\S]*?)<\\/style>\\s*/iu',
array($this, '_removeStyleCB'),
$this->_html
);
// remove HTML comments (not containing IE conditional comments).
$this->_html = preg_replace_callback(
'/<!--([\\s\\S]*?)-->/u'
,array($this, '_commentCB')
,$this->_html);
'/<!--([\\s\\S]*?)-->/u',
array($this, '_commentCB'),
$this->_html
);
// replace PREs with placeholders
$this->_html = preg_replace_callback('/\\s*<pre(\\b[^>]*?>[\\s\\S]*?<\\/pre>)\\s*/iu'
,array($this, '_removePreCB')
,$this->_html);
$this->_html = preg_replace_callback('/\\s*<pre(\\b[^>]*?>[\\s\\S]*?<\\/pre>)\\s*/iu', array($this, '_removePreCB'), $this->_html);
// replace TEXTAREAs with placeholders
$this->_html = preg_replace_callback(
'/\\s*<textarea(\\b[^>]*?>[\\s\\S]*?<\\/textarea>)\\s*/iu'
,array($this, '_removeTextareaCB')
,$this->_html);
'/\\s*<textarea(\\b[^>]*?>[\\s\\S]*?<\\/textarea>)\\s*/iu',
array($this, '_removeTextareaCB'),
$this->_html
);
// trim each line.
// @todo take into account attribute values that span multiple lines.
@@ -139,24 +141,25 @@ class Minify_HTML
// remove ws outside of all elements
$this->_html = preg_replace(
'/>(\\s(?:\\s*))?([^<]+)(\\s(?:\s*))?</u'
,'>$1$2$3<'
,$this->_html);
'/>(\\s(?:\\s*))?([^<]+)(\\s(?:\s*))?</u',
'>$1$2$3<',
$this->_html
);
// use newlines before 1st attribute in open tags (to limit line lengths)
$this->_html = preg_replace('/(<[a-z\\-]+)\\s+([^>]+>)/iu', "$1\n$2", $this->_html);
// fill placeholders
$this->_html = str_replace(
array_keys($this->_placeholders)
,array_values($this->_placeholders)
,$this->_html
array_keys($this->_placeholders),
array_values($this->_placeholders),
$this->_html
);
// issue 229: multi-pass to catch scripts that didn't get replaced in textareas
$this->_html = str_replace(
array_keys($this->_placeholders)
,array_values($this->_placeholders)
,$this->_html
array_keys($this->_placeholders),
array_values($this->_placeholders),
$this->_html
);
return $this->_html;
@@ -209,7 +212,8 @@ class Minify_HTML
: 'trim';
$css = call_user_func($minifier, $css);
return $this->_reservePlace($this->_needsCdata($css)
return $this->_reservePlace(
$this->_needsCdata($css)
? "{$openStyle}/*<![CDATA[*/{$css}/*]]>*/</style>"
: "{$openStyle}{$css}</style>"
);
@@ -238,7 +242,8 @@ class Minify_HTML
: 'trim';
$js = call_user_func($minifier, $js);
return $this->_reservePlace($this->_needsCdata($js)
return $this->_reservePlace(
$this->_needsCdata($js)
? "{$ws1}{$openScript}/*<![CDATA[*/{$js}/*]]>*/</script>{$ws2}"
: "{$ws1}{$openScript}{$js}</script>{$ws2}"
);

View File

@@ -154,4 +154,3 @@ class Minify_YUICompressor
}
}
}

View File

@@ -390,4 +390,3 @@ class Cli
$this->errors[$letter][] = sprintf($msg, $value);
}
}

View File

@@ -59,4 +59,3 @@ if ($testRun) {
fwrite($fp, $combined);
$cli->closeOutput();
}

View File

@@ -13,7 +13,8 @@ $app->cache = new Minify_Cache_Null();
$env = $app->env;
function h($txt) {
function h($txt)
{
return htmlspecialchars($txt, ENT_QUOTES, 'UTF-8');
}
@@ -22,13 +23,12 @@ if ($env->post('textIn')) {
}
if ($env->post('method') === 'Minify and serve') {
$base = trim($env->post('base'));
if ($base) {
$textIn = preg_replace(
'@(<head\\b[^>]*>)@i'
,'$1<base href="' . h($base) . '" />'
,$textIn
'@(<head\\b[^>]*>)@i',
'$1<base href="' . h($base) . '" />',
$textIn
);
}
@@ -58,7 +58,6 @@ $tpl = array();
$tpl['classes'] = array('Minify_HTML', 'JSMin\\JSMin', 'Minify_CSS', 'Minify_Lines');
if (in_array($env->post('method'), $tpl['classes'])) {
$args = array($textIn);
if ($env->post('method') === 'Minify_HTML') {
$args[] = array(
@@ -88,7 +87,8 @@ sendPage($tpl);
* @param string $input
* @return string HTML
*/
function getExceptionMsg(Exception $e, $input) {
function getExceptionMsg(Exception $e, $input)
{
$msg = "<p>" . h($e->getMessage()) . "</p>";
if (0 === strpos(get_class($e), 'JSMin_Unterminated')
&& preg_match('~byte (\d+)~', $e->getMessage(), $m)) {
@@ -113,9 +113,9 @@ function getExceptionMsg(Exception $e, $input) {
*
* @param array $vars
*/
function sendPage($vars) {
header('Content-Type: text/html; charset=utf-8');
?>
function sendPage($vars)
{
header('Content-Type: text/html; charset=utf-8'); ?>
<!DOCTYPE html><head><title>minifyTextarea</title></head>
<p><strong>Warning! Please do not place this application on a public site.</strong> This should be used only for testing.</p>
@@ -132,18 +132,16 @@ if (isset($vars['time'])) {
<tr><th>Time (s)</th><td>" . round($vars['time'], 5) . "</td></tr>
</table>
";
}
?>
} ?>
<form action="?2" method="post">
<p><label>Content<br><textarea name="textIn" cols="80" rows="35" style="width:99%"><?php
if (isset($vars['output'])) {
echo h($vars['output']);
}
?></textarea></label></p>
} ?></textarea></label></p>
<p>Minify with:
<?php foreach ($vars['classes'] as $minClass): ?>
<input type="submit" name="method" value="<?php echo $minClass; ?>">
<?php endForEach; ?>
<?php endforeach; ?>
</p>
<p>...or <input type="submit" name="method" value="Minify and serve"> this HTML to the browser. Also minify:
<label>CSS <input type="checkbox" name="minCss" checked></label> :

View File

@@ -12,7 +12,8 @@ $app->cache = new Minify_Cache_Null();
$env = $app->env;
function getPost($key) {
function getPost($key)
{
if (! isset($_POST[$key])) {
return null;
}
@@ -21,14 +22,16 @@ function getPost($key) {
: $_POST[$key];
}
function sniffType($headers) {
function sniffType($headers)
{
$charset = 'utf-8';
$type = null;
$headers = "\n\n" . implode("\n\n", $headers) . "\n\n";
if (preg_match(
'@\\n\\nContent-Type: *([\\w/\\+-]+)( *; *charset *= *([\\w-]+))? *\\n\\n@i'
,$headers
,$m)) {
'@\\n\\nContent-Type: *([\\w/\\+-]+)( *; *charset *= *([\\w-]+))? *\\n\\n@i',
$headers,
$m
)) {
$sentType = $m[1];
if (isset($m[3])) {
$charset = $m[3];
@@ -49,7 +52,6 @@ function sniffType($headers) {
}
if (isset($_POST['url'])) {
require '../config.php';
$url = trim($env->post('url'));
@@ -92,9 +94,9 @@ if (isset($_POST['url'])) {
&& isset($_POST['addBase'])
&& ! preg_match('@<base\\b@i', $content)) {
$content = preg_replace(
'@(<head\\b[^>]*>)@i'
,'$1<base href="' . htmlspecialchars($url, ENT_QUOTES, 'UTF-8') . '" />'
,$content
'@(<head\\b[^>]*>)@i',
'$1<base href="' . htmlspecialchars($url, ENT_QUOTES, 'UTF-8') . '" />',
$content
);
}

View File

@@ -8,9 +8,13 @@ $env = $app->env;
header('Content-Type: text/html;charset=utf-8');
function h($str) { return htmlspecialchars($str, ENT_QUOTES); }
function h($str)
{
return htmlspecialchars($str, ENT_QUOTES);
}
function getInput($name, $default = '', $size = 50) {
function getInput($name, $default = '', $size = 50)
{
global $env;
$val = $env->post($name, $default);
return "<input type='text' name='{$name}' value='" . h($val) . "' size='{$size}' />";

View File

@@ -13,7 +13,8 @@ if (!$enabled) {
die('Set $enabled to true to see server info.');
}
function assertTrue($test, $message) {
function assertTrue($test, $message)
{
if (!$test) {
echo "Warning: $message\n";
}

View File

@@ -10,7 +10,8 @@ namespace Minify\StaticService;
* @param string $type "css" or "js"
* @return string
*/
function build_uri($static_uri, $query, $type) {
function build_uri($static_uri, $query, $type)
{
$static_uri = rtrim($static_uri, '/');
$query = ltrim($query, '?');
@@ -30,7 +31,8 @@ function build_uri($static_uri, $query, $type) {
* @param bool $auto_create Automatically create the directory if missing?
* @return null|string null if missing or can't create
*/
function get_cache_time($auto_create = true) {
function get_cache_time($auto_create = true)
{
foreach (scandir(__DIR__) as $entry) {
if (ctype_digit($entry)) {
return $entry;
@@ -50,14 +52,16 @@ function get_cache_time($auto_create = true) {
return $time;
}
function flush_cache() {
function flush_cache()
{
$time = get_cache_time(false);
if ($time) {
remove_tree(__DIR__ . "/$time");
}
}
function remove_tree($dir) {
function remove_tree($dir)
{
$files = array_diff(scandir($dir), array('.', '..'));
foreach ($files as $file) {

View File

@@ -32,8 +32,11 @@ class JsClosureCompilerTest extends TestCase
$this->compile($src);
} catch (Minify_JS_ClosureCompiler_Exception $e) {
}
$this->assertInstanceOf('Minify_JS_ClosureCompiler_Exception', $e,
'Throws Minify_JS_ClosureCompiler_Exception');
$this->assertInstanceOf(
'Minify_JS_ClosureCompiler_Exception',
$e,
'Throws Minify_JS_ClosureCompiler_Exception'
);
}
// Test maximum byte size check (default)
@@ -46,8 +49,11 @@ class JsClosureCompilerTest extends TestCase
$this->compile($src);
} catch (Minify_JS_ClosureCompiler_Exception $e) {
}
$this->assertInstanceOf('Minify_JS_ClosureCompiler_Exception', $e,
'Throws Minify_JS_ClosureCompiler_Exception');
$this->assertInstanceOf(
'Minify_JS_ClosureCompiler_Exception',
$e,
'Throws Minify_JS_ClosureCompiler_Exception'
);
$expected = 'POST content larger than ' . Minify_JS_ClosureCompiler::DEFAULT_MAX_BYTES . ' bytes';
$this->assertEquals($expected, $e->getMessage(), 'Message must tell how big maximum byte size is');
@@ -76,8 +82,11 @@ class JsClosureCompilerTest extends TestCase
));
} catch (Minify_JS_ClosureCompiler_Exception $e) {
}
$this->assertInstanceOf('Minify_JS_ClosureCompiler_Exception', $e,
'Throws Minify_JS_ClosureCompiler_Exception');
$this->assertInstanceOf(
'Minify_JS_ClosureCompiler_Exception',
$e,
'Throws Minify_JS_ClosureCompiler_Exception'
);
$expected = 'POST content larger than ' . $allowedBytes . ' bytes';
$this->assertEquals($expected, $e->getMessage(), 'Message must tell how big maximum byte size is');
@@ -96,8 +105,11 @@ class JsClosureCompilerTest extends TestCase
));
} catch (Minify_JS_ClosureCompiler_Exception $e) {
}
$this->assertInstanceOf('Minify_JS_ClosureCompiler_Exception', $e,
'Throws Minify_JS_ClosureCompiler_Exception');
$this->assertInstanceOf(
'Minify_JS_ClosureCompiler_Exception',
$e,
'Throws Minify_JS_ClosureCompiler_Exception'
);
}
public function test7()

View File

@@ -16,9 +16,10 @@ class MinifyCSSUriRewriterTest extends TestCase
$in = file_get_contents(self::$test_files . '/css_uriRewriter/in.css');
$expected = file_get_contents(self::$test_files . '/css_uriRewriter/exp.css');
$actual = Minify_CSS_UriRewriter::rewrite(
$in
, self::$test_files . '/css_uriRewriter' // currentDir
, self::$document_root // use DOCUMENT_ROOT = '/full/path/to/min_unit_tests'
$in,
self::$test_files . '/css_uriRewriter' // currentDir
,
self::$document_root // use DOCUMENT_ROOT = '/full/path/to/min_unit_tests'
);
$this->assertEquals($expected, $actual, 'rewrite, debug: ' . Minify_CSS_UriRewriter::$debugText);
@@ -47,9 +48,9 @@ class MinifyCSSUriRewriterTest extends TestCase
$in = '../../../../assets/skins/sam/sprite.png';
$exp = '/yui/assets/skins/sam/sprite.png';
$actual = Minify_CSS_UriRewriter::rewriteRelative(
$in
, 'sf_root_dir\web\yui\menu\assets\skins\sam'
, 'sf_root_dir\web'
$in,
'sf_root_dir\web\yui\menu\assets\skins\sam',
'sf_root_dir\web'
);
$this->assertEquals($exp, $actual, 'Issue 99, debug: ' . Minify_CSS_UriRewriter::$debugText);

View File

@@ -45,4 +45,3 @@ class MinifyCacheMemcacheTest extends TestCase
$this->assertTestCache($cache, $id, $data);
}
}

View File

@@ -23,7 +23,10 @@ class MinifyImportProcessorTest extends TestCase
realpath($linDir . '/lib/css/example.css'),
);
$this->assertEquals($expectedIncludes, Minify_ImportProcessor::$filesIncluded,
'included right files in right order');
$this->assertEquals(
$expectedIncludes,
Minify_ImportProcessor::$filesIncluded,
'included right files in right order'
);
}
}

View File

@@ -62,8 +62,8 @@ class MinifyTest extends TestCase
$content = preg_replace('/\\r\\n?/', "\n", file_get_contents($minifyTestPath . '/minified.js'));
$lastModified = max(
filemtime($minifyTestPath . '/email.js')
, filemtime($minifyTestPath . '/QueryString.js')
filemtime($minifyTestPath . '/email.js'),
filemtime($minifyTestPath . '/QueryString.js')
);
$expected = array(
'success' => true,
@@ -153,8 +153,10 @@ class MinifyTest extends TestCase
));
$output = $output['content'];
$this->assertFalse(strpos($output, $defaultOptions['importWarning']),
'Issue 89 : don\'t warn about valid imports');
$this->assertFalse(
strpos($output, $defaultOptions['importWarning']),
'Issue 89 : don\'t warn about valid imports'
);
// Test Issue 132
if (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2)) {
@@ -164,8 +166,11 @@ class MinifyTest extends TestCase
'encodeOutput' => false,
));
$this->assertEquals(77, $output['headers']['Content-Length'],
'Issue 132 : mbstring.func_overload shouldn\'t cause incorrect Content-Length');
$this->assertEquals(
77,
$output['headers']['Content-Length'],
'Issue 132 : mbstring.func_overload shouldn\'t cause incorrect Content-Length'
);
}
// Test minifying CSS and responding with Etag/Last-Modified