diff --git a/builder/index.php b/builder/index.php index 9cb8c1a6..d4ea38c1 100644 --- a/builder/index.php +++ b/builder/index.php @@ -1,4 +1,4 @@ -encode(); $he->sendAll(); - } else { // echo status "0" or "1" header('Content-Type: text/plain'); diff --git a/builder/test.php b/builder/test.php index 88e8da05..c139ec60 100644 --- a/builder/test.php +++ b/builder/test.php @@ -37,7 +37,7 @@ echo "

\$_SERVER['SUBDOMAIN_DOCUMENT_ROOT'] is set. " . "You may need to set \$min_documentRoot to this in config.php

"; } - + } -//*/ \ No newline at end of file +//*/ diff --git a/config-test.php b/config-test.php index 7524a3d1..8b903a54 100644 --- a/config-test.php +++ b/config-test.php @@ -4,7 +4,6 @@ * * To test config options, place them in this file and add "&test" to your Minify URL. * Note that if this is on a public server, anyone can execute your test. - * + * * @package Minify */ - diff --git a/config.php b/config.php index 02f01ca5..3eb084d8 100644 --- a/config.php +++ b/config.php @@ -2,7 +2,7 @@ /** * Configuration for "min", the default application built with the Minify * library - * + * * @package Minify */ @@ -47,7 +47,7 @@ * /min/f=file1.js send the cookie minDebug=file1.js * You can manually enable debugging by appending "&debug" to a URI. * E.g. /min/?f=script1.js,script2.js&debug - * + * * In 'debug' mode, Minify combines files with no minification and adds comments * to indicate line #s of the original files. */ @@ -73,11 +73,11 @@ /** * Leave an empty string to use PHP's $_SERVER['DOCUMENT_ROOT']. * - * On some servers, this value may be misconfigured or missing. If so, set this + * On some servers, this value may be misconfigured or missing. If so, set this * to your full document root path with no trailing slash. * E.g. '/home/accountname/public_html' or 'c:\\xampp\\htdocs' * - * If /min/ is directly inside your document root, just uncomment the + * If /min/ is directly inside your document root, just uncomment the * second line. The third line might work on some Apache servers. */ $min_documentRoot = ''; @@ -87,7 +87,7 @@ /** - * Cache file locking. Set to false if filesystem is NFS. On at least one + * Cache file locking. Set to false if filesystem is NFS. On at least one * NFS system flock-ing attempts stalled PHP for 30 seconds! */ $min_cacheFileLocking = true; @@ -96,9 +96,9 @@ /** * Combining multiple CSS files can place @import declarations after rules, which * is invalid. Minify will attempt to detect when this happens and place a - * warning comment at the top of the CSS output. To resolve this you can either - * move the @imports within your CSS files, or enable this option, which will - * move all @imports to the top of the output. Note that moving @imports could + * warning comment at the top of the CSS output. To resolve this you can either + * move the @imports within your CSS files, or enable this option, which will + * move all @imports to the top of the output. Note that moving @imports could * affect CSS values (which is why this option is disabled by default). */ $min_serveOptions['bubbleCssImports'] = false; @@ -134,8 +134,8 @@ * particular directories below DOCUMENT_ROOT, set this here. * You will still need to include the directory in the * f or b GET parameters. - * - * // = shortcut for DOCUMENT_ROOT + * + * // = shortcut for DOCUMENT_ROOT */ //$min_serveOptions['minApp']['allowDirs'] = array('//js', '//css'); @@ -149,7 +149,7 @@ /** * By default, Minify will not minify files with names containing .min or -min * before the extension. E.g. myFile.min.js will not be processed by JSMin - * + * * To minify all files, set this option to null. You could also specify your * own pattern that is matched against the filename. */ @@ -160,8 +160,8 @@ * If you minify CSS files stored in symlink-ed directories, the URI rewriting * algorithm can fail. To prevent this, provide an array of link paths to * target paths, where the link paths are within the document root. - * - * Because paths need to be normalized for this to work, use "//" to substitute + * + * Because paths need to be normalized for this to work, use "//" to substitute * the doc root in the link paths (the array keys). E.g.: * * array('//symlink' => '/real/target/path') // unix @@ -173,17 +173,17 @@ /** * If you upload files from Windows to a non-Windows server, Windows may report - * incorrect mtimes for the files. This may cause Minify to keep serving stale + * incorrect mtimes for the files. This may cause Minify to keep serving stale * cache files when source file changes are made too frequently (e.g. more than * once an hour). - * - * Immediately after modifying and uploading a file, use the touch command to + * + * Immediately after modifying and uploading a file, use the touch command to * update the mtime on the server. If the mtime jumps ahead by a number of hours, - * set this variable to that number. If the mtime moves back, this should not be + * set this variable to that number. If the mtime moves back, this should not be * needed. * - * In the Windows SFTP client WinSCP, there's an option that may fix this - * issue without changing the variable below. Under login > environment, + * In the Windows SFTP client WinSCP, there's an option that may fix this + * issue without changing the variable below. Under login > environment, * select the option "Adjust remote timestamp with DST". * @link http://winscp.net/eng/docs/ui_login_environment#daylight_saving_time */ @@ -198,4 +198,3 @@ */ //$min_factories['minify'] = ... a callable accepting a Minify\App object //$min_factories['controller'] = ... a callable accepting a Minify\App object - diff --git a/index.php b/index.php index 7b58bcc7..e3fea30c 100644 --- a/index.php +++ b/index.php @@ -1,9 +1,9 @@ options['quiet']) { $this->errorExit($this->options['badRequestHeader'], self::URL_DEBUG); } else { - list(,$statusCode) = explode(' ', $this->options['badRequestHeader']); + list(, $statusCode) = explode(' ', $this->options['badRequestHeader']); return array( 'success' => false, @@ -470,7 +470,7 @@ public function combine($sources, $options = array()) public function errorExit($header, $url = '', $msgHtml = '') { $url = htmlspecialchars($url, ENT_QUOTES); - list(,$h1) = explode(' ', $header, 2); + list(, $h1) = explode(' ', $header, 2); $h1 = htmlspecialchars($h1); // FastCGI environments require 3rd arg to header() to be set list(, $code) = explode(' ', $header, 3); @@ -593,7 +593,8 @@ protected function combineMinify() ! $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(); diff --git a/lib/Minify/App.php b/lib/Minify/App.php index bc885b21..4ed15a60 100644 --- a/lib/Minify/App.php +++ b/lib/Minify/App.php @@ -82,8 +82,7 @@ public function __construct($dir) $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); }); diff --git a/lib/Minify/CSSmin.php b/lib/Minify/CSSmin.php index 753c5109..0003f735 100644 --- a/lib/Minify/CSSmin.php +++ b/lib/Minify/CSSmin.php @@ -73,16 +73,16 @@ public static function minify($css, $options = array()) } 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'] ); } } diff --git a/lib/Minify/Cache/Null.php b/lib/Minify/Cache/Null.php index 4f654a6c..165043ee 100644 --- a/lib/Minify/Cache/Null.php +++ b/lib/Minify/Cache/Null.php @@ -64,4 +64,4 @@ public function display($id) public function fetch($id) { } -} \ No newline at end of file +} diff --git a/lib/Minify/Cache/WinCache.php b/lib/Minify/Cache/WinCache.php index 46e285a7..3dd1c40f 100644 --- a/lib/Minify/Cache/WinCache.php +++ b/lib/Minify/Cache/WinCache.php @@ -136,4 +136,4 @@ private function _fetch($id) return true; } -} \ No newline at end of file +} diff --git a/lib/Minify/Controller/Files.php b/lib/Minify/Controller/Files.php index 85a76d0e..7d517f4d 100644 --- a/lib/Minify/Controller/Files.php +++ b/lib/Minify/Controller/Files.php @@ -68,4 +68,3 @@ public function createConfiguration(array $options) return new Minify_ServeConfiguration($options, $sources); } } - diff --git a/lib/Minify/Controller/Groups.php b/lib/Minify/Controller/Groups.php index af8af336..d3813f2c 100644 --- a/lib/Minify/Controller/Groups.php +++ b/lib/Minify/Controller/Groups.php @@ -73,4 +73,3 @@ public function createConfiguration(array $options) return parent::createConfiguration($options); } } - diff --git a/lib/Minify/Controller/Page.php b/lib/Minify/Controller/Page.php index 7001fe0e..ca2778c9 100644 --- a/lib/Minify/Controller/Page.php +++ b/lib/Minify/Controller/Page.php @@ -66,4 +66,3 @@ public function createConfiguration(array $options) return new Minify_ServeConfiguration($options, $sources, $selectionId); } } - diff --git a/lib/Minify/ControllerInterface.php b/lib/Minify/ControllerInterface.php index 35b4de3f..1527ff6c 100644 --- a/lib/Minify/ControllerInterface.php +++ b/lib/Minify/ControllerInterface.php @@ -19,4 +19,4 @@ public function createConfiguration(array $options); * @return Minify_Env */ public function getEnv(); -} \ No newline at end of file +} diff --git a/lib/Minify/HTML.php b/lib/Minify/HTML.php index 5dfb095d..ef98b386 100644 --- a/lib/Minify/HTML.php +++ b/lib/Minify/HTML.php @@ -99,32 +99,34 @@ public function process() // replace SCRIPTs (and minify) with placeholders $this->_html = preg_replace_callback( - '/(\\s*)]*?>)([\\s\\S]*?)<\\/script>(\\s*)/iu' - ,array($this, '_removeScriptCB') - ,$this->_html); + '/(\\s*)]*?>)([\\s\\S]*?)<\\/script>(\\s*)/iu', + array($this, '_removeScriptCB'), + $this->_html + ); // replace STYLEs (and minify) with placeholders $this->_html = preg_replace_callback( - '/\\s*]*>)([\\s\\S]*?)<\\/style>\\s*/iu' - ,array($this, '_removeStyleCB') - ,$this->_html); + '/\\s*]*>)([\\s\\S]*?)<\\/style>\\s*/iu', + array($this, '_removeStyleCB'), + $this->_html + ); // remove HTML comments (not containing IE conditional comments). $this->_html = preg_replace_callback( - '//u' - ,array($this, '_commentCB') - ,$this->_html); + '//u', + array($this, '_commentCB'), + $this->_html + ); // replace PREs with placeholders - $this->_html = preg_replace_callback('/\\s*]*?>[\\s\\S]*?<\\/pre>)\\s*/iu' - ,array($this, '_removePreCB') - ,$this->_html); + $this->_html = preg_replace_callback('/\\s*]*?>[\\s\\S]*?<\\/pre>)\\s*/iu', array($this, '_removePreCB'), $this->_html); // replace TEXTAREAs with placeholders $this->_html = preg_replace_callback( - '/\\s*]*?>[\\s\\S]*?<\\/textarea>)\\s*/iu' - ,array($this, '_removeTextareaCB') - ,$this->_html); + '/\\s*]*?>[\\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 @@ public function process() // remove ws outside of all elements $this->_html = preg_replace( - '/>(\\s(?:\\s*))?([^<]+)(\\s(?:\s*))?$1$2$3<' - ,$this->_html); + '/>(\\s(?:\\s*))?([^<]+)(\\s(?:\s*))?$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 @@ protected function _removeStyleCB($m) : 'trim'; $css = call_user_func($minifier, $css); - return $this->_reservePlace($this->_needsCdata($css) + return $this->_reservePlace( + $this->_needsCdata($css) ? "{$openStyle}/**/" : "{$openStyle}{$css}" ); @@ -238,7 +242,8 @@ protected function _removeScriptCB($m) : 'trim'; $js = call_user_func($minifier, $js); - return $this->_reservePlace($this->_needsCdata($js) + return $this->_reservePlace( + $this->_needsCdata($js) ? "{$ws1}{$openScript}/**/{$ws2}" : "{$ws1}{$openScript}{$js}{$ws2}" ); diff --git a/lib/Minify/ImportProcessor.php b/lib/Minify/ImportProcessor.php index 85d9ff51..f8ed4b45 100644 --- a/lib/Minify/ImportProcessor.php +++ b/lib/Minify/ImportProcessor.php @@ -66,7 +66,7 @@ private function _getContent($file, $is_imported = false) $this->_currentDir = dirname($file); // remove UTF-8 BOM if present - if (pack("CCC",0xef,0xbb,0xbf) === substr($content, 0, 3)) { + if (pack("CCC", 0xef, 0xbb, 0xbf) === substr($content, 0, 3)) { $content = substr($content, 3); } // ensure uniform EOLs diff --git a/lib/Minify/JS/ClosureCompiler.php b/lib/Minify/JS/ClosureCompiler.php index b8426220..19190351 100644 --- a/lib/Minify/JS/ClosureCompiler.php +++ b/lib/Minify/JS/ClosureCompiler.php @@ -195,13 +195,13 @@ protected function getResponse($postBody) curl_close($ch); } else { throw new Minify_JS_ClosureCompiler_Exception( - "Could not make HTTP request: allow_url_open is false and cURL not available" + "Could not make HTTP request: allow_url_open is false and cURL not available" ); } if (false === $contents) { throw new Minify_JS_ClosureCompiler_Exception( - "No HTTP response from server" + "No HTTP response from server" ); } diff --git a/lib/Minify/NailgunClosureCompiler.php b/lib/Minify/NailgunClosureCompiler.php index bdc49da8..8ce45200 100644 --- a/lib/Minify/NailgunClosureCompiler.php +++ b/lib/Minify/NailgunClosureCompiler.php @@ -110,4 +110,4 @@ private function startServer() $this->shell("$serverCommand /dev/null 2>/dev/null & sleep 10"); } -} \ No newline at end of file +} diff --git a/lib/Minify/Source/Factory.php b/lib/Minify/Source/Factory.php index f36d1b25..3e6e378c 100644 --- a/lib/Minify/Source/Factory.php +++ b/lib/Minify/Source/Factory.php @@ -170,7 +170,7 @@ public function makeSource($spec) if ($this->options['noMinPattern'] && preg_match($this->options['noMinPattern'], $basename)) { if (preg_match('~\.(css|less)$~i', $basename)) { $spec['minifyOptions']['compress'] = false; - // we still want URI rewriting to work for CSS + // we still want URI rewriting to work for CSS } else { $spec['minifier'] = 'Minify::nullMinifier'; } diff --git a/lib/Minify/YUICompressor.php b/lib/Minify/YUICompressor.php index a45f5723..47723fc9 100644 --- a/lib/Minify/YUICompressor.php +++ b/lib/Minify/YUICompressor.php @@ -154,4 +154,3 @@ private static function _prepare() } } } - diff --git a/lib/MrClay/Cli.php b/lib/MrClay/Cli.php index e9ef3b3b..fc736abe 100644 --- a/lib/MrClay/Cli.php +++ b/lib/MrClay/Cli.php @@ -390,4 +390,3 @@ protected function addError($letter, $msg, $value = null) $this->errors[$letter][] = sprintf($msg, $value); } } - diff --git a/min_extras/cli/rewrite-uris.php b/min_extras/cli/rewrite-uris.php index 0ca560f1..08ca7c8e 100755 --- a/min_extras/cli/rewrite-uris.php +++ b/min_extras/cli/rewrite-uris.php @@ -27,7 +27,7 @@ $testRun = $cli->values['t']; $docRoot = $cli->values['d']; -$pathRewriter = function($css, $options) { +$pathRewriter = function ($css, $options) { return Minify_CSS_UriRewriter::rewrite($css, $options['currentDir'], $options['docRoot']); }; @@ -54,9 +54,8 @@ if ($testRun) { echo $combined; echo Minify_CSS_UriRewriter::$debugText . "\n"; -} else { +} else { $fp = $cli->openOutput(); fwrite($fp, $combined); $cli->closeOutput(); } - diff --git a/min_extras/config.php b/min_extras/config.php index cb33edd1..c7143b62 100644 --- a/min_extras/config.php +++ b/min_extras/config.php @@ -4,6 +4,6 @@ require __DIR__ . '/../config.php'; -$minifyCachePath = isset($min_cachePath) - ? $min_cachePath +$minifyCachePath = isset($min_cachePath) + ? $min_cachePath : ''; diff --git a/min_extras/tools/minifyTextarea.php b/min_extras/tools/minifyTextarea.php index a5b5926e..64c04f80 100644 --- a/min_extras/tools/minifyTextarea.php +++ b/min_extras/tools/minifyTextarea.php @@ -13,7 +13,8 @@ $env = $app->env; -function h($txt) { +function h($txt) +{ return htmlspecialchars($txt, ENT_QUOTES, 'UTF-8'); } @@ -22,13 +23,12 @@ function h($txt) { } if ($env->post('method') === 'Minify and serve') { - $base = trim($env->post('base')); if ($base) { $textIn = preg_replace( - '@(]*>)@i' - ,'$1' - ,$textIn + '@(]*>)@i', + '$1', + $textIn ); } @@ -58,7 +58,6 @@ function h($txt) { $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 @@ function h($txt) { * @param string $input * @return string HTML */ -function getExceptionMsg(Exception $e, $input) { +function getExceptionMsg(Exception $e, $input) +{ $msg = "

" . h($e->getMessage()) . "

"; if (0 === strpos(get_class($e), 'JSMin_Unterminated') && preg_match('~byte (\d+)~', $e->getMessage(), $m)) { @@ -113,37 +113,35 @@ 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'); ?> minifyTextarea

Warning! Please do not place this application on a public site. This should be used only for testing.

Bytes in{$vars['inBytes']} (after line endings normalized to \\n) Bytes out{$vars['outBytes']} (reduced " . round(100 - (100 * $vars['outBytes'] / $vars['inBytes'])) . "%) Time (s)" . round($vars['time'], 5) . " "; -} -?> + } ?>

+ echo h($vars['output']); + } ?>

Minify with: - +

...or this HTML to the browser. Also minify: : diff --git a/min_extras/tools/minifyUrl.php b/min_extras/tools/minifyUrl.php index a2629e60..8851c87c 100644 --- a/min_extras/tools/minifyUrl.php +++ b/min_extras/tools/minifyUrl.php @@ -12,7 +12,8 @@ $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')); @@ -88,13 +90,13 @@ function sniffType($headers) { die('Unrecognized Content-Type: ' . $type['sent']); } - if ($type['minify'] === 'text/html' + if ($type['minify'] === 'text/html' && isset($_POST['addBase']) && ! preg_match('@]*>)@i' - ,'$1' - ,$content + '@(]*>)@i', + '$1', + $content ); } diff --git a/min_extras/tools/testRewriteUri.php b/min_extras/tools/testRewriteUri.php index f2f00112..3977e2ea 100644 --- a/min_extras/tools/testRewriteUri.php +++ b/min_extras/tools/testRewriteUri.php @@ -8,9 +8,13 @@ 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 ""; diff --git a/server-info.php b/server-info.php index e0c6af87..e6369c28 100644 --- a/server-info.php +++ b/server-info.php @@ -13,7 +13,8 @@ die('Set $enabled to true to see server info.'); } -function assertTrue($test, $message) { +function assertTrue($test, $message) +{ if (!$test) { echo "Warning: $message\n"; } diff --git a/static/gen.php b/static/gen.php index f07aac21..c39cefae 100644 --- a/static/gen.php +++ b/static/gen.php @@ -7,12 +7,12 @@ $bootstrap_file = __DIR__ . '/../bootstrap.php'; } -$send_400 = function($content = 'Bad URL') { +$send_400 = function ($content = 'Bad URL') { http_response_code(400); die($content); }; -$send_301 = function($url) { +$send_301 = function ($url) { http_response_code(301); header("Cache-Control: max-age=31536000"); header("Location: $url"); diff --git a/static/lib.php b/static/lib.php index 665bc131..864e0f77 100644 --- a/static/lib.php +++ b/static/lib.php @@ -10,7 +10,8 @@ * @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) { diff --git a/tests/HTTPEncoderTest.php b/tests/HTTPEncoderTest.php index a3b3359b..b512e3c5 100644 --- a/tests/HTTPEncoderTest.php +++ b/tests/HTTPEncoderTest.php @@ -166,15 +166,15 @@ function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null) $len = strlen($data); - if ($len < 18 || strcmp(substr($data,0,2),"\x1f\x8b")) { + if ($len < 18 || strcmp(substr($data, 0, 2), "\x1f\x8b")) { $error = "Not in GZIP format."; if ($mbIntEnc !== null) { mb_internal_encoding($mbIntEnc); } return null; // Not GZIP format (See RFC 1952) } - $method = ord(substr($data,2,1)); // Compression method - $flags = ord(substr($data,3,1)); // Flags + $method = ord(substr($data, 2, 1)); // Compression method + $flags = ord(substr($data, 3, 1)); // Flags if ($flags & 31 != $flags) { $error = "Reserved bits not allowed."; if ($mbIntEnc !== null) { @@ -183,10 +183,10 @@ function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null) return null; } // NOTE: $mtime may be negative (PHP integer limitations) - $mtime = unpack("V", substr($data,4,4)); + $mtime = unpack("V", substr($data, 4, 4)); $mtime = $mtime[1]; - $xfl = substr($data,8,1); - $os = substr($data,8,1); + $xfl = substr($data, 8, 1); + $os = substr($data, 8, 1); $headerlen = 10; $extralen = 0; $extra = ""; @@ -198,7 +198,7 @@ function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null) } return false; // invalid } - $extralen = unpack("v",substr($data,8,2)); + $extralen = unpack("v", substr($data, 8, 2)); $extralen = $extralen[1]; if ($len - $headerlen - 2 - $extralen < 8) { if ($mbIntEnc !== null) { @@ -206,7 +206,7 @@ function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null) } return false; // invalid } - $extra = substr($data,10,$extralen); + $extra = substr($data, 10, $extralen); $headerlen += 2 + $extralen; } $filenamelen = 0; @@ -219,14 +219,14 @@ function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null) } return false; // invalid } - $filenamelen = strpos(substr($data,$headerlen),chr(0)); + $filenamelen = strpos(substr($data, $headerlen), chr(0)); if ($filenamelen === false || $len - $headerlen - $filenamelen - 1 < 8) { if ($mbIntEnc !== null) { mb_internal_encoding($mbIntEnc); } return false; // invalid } - $filename = substr($data,$headerlen,$filenamelen); + $filename = substr($data, $headerlen, $filenamelen); $headerlen += $filenamelen + 1; } $commentlen = 0; @@ -239,14 +239,14 @@ function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null) } return false; // invalid } - $commentlen = strpos(substr($data,$headerlen),chr(0)); + $commentlen = strpos(substr($data, $headerlen), chr(0)); if ($commentlen === false || $len - $headerlen - $commentlen - 1 < 8) { if ($mbIntEnc !== null) { mb_internal_encoding($mbIntEnc); } return false; // Invalid header format } - $comment = substr($data,$headerlen,$commentlen); + $comment = substr($data, $headerlen, $commentlen); $headerlen += $commentlen + 1; } $headercrc = ""; @@ -258,8 +258,8 @@ function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null) } return false; // invalid } - $calccrc = crc32(substr($data,0,$headerlen)) & 0xffff; - $headercrc = unpack("v", substr($data,$headerlen,2)); + $calccrc = crc32(substr($data, 0, $headerlen)) & 0xffff; + $headercrc = unpack("v", substr($data, $headerlen, 2)); $headercrc = $headercrc[1]; if ($headercrc != $calccrc) { $error = "Header checksum failed."; @@ -271,9 +271,9 @@ function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null) $headerlen += 2; } // GZIP FOOTER - $datacrc = unpack("V",substr($data,-8,4)); - $datacrc = sprintf('%u',$datacrc[1] & 0xFFFFFFFF); - $isize = unpack("V",substr($data,-4)); + $datacrc = unpack("V", substr($data, -8, 4)); + $datacrc = sprintf('%u', $datacrc[1] & 0xFFFFFFFF); + $isize = unpack("V", substr($data, -4)); $isize = $isize[1]; // decompression: $bodylen = $len-$headerlen-8; @@ -284,13 +284,13 @@ function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null) } return null; } - $body = substr($data,$headerlen,$bodylen); + $body = substr($data, $headerlen, $bodylen); $data = ""; if ($bodylen > 0) { switch ($method) { case 8: // Currently the only supported compression method: - $data = gzinflate($body,$maxlength); + $data = gzinflate($body, $maxlength); break; default: $error = "Unknown compression method."; @@ -301,11 +301,11 @@ function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null) } } // zero-byte body content is allowed // Verifiy CRC32 - $crc = sprintf("%u",crc32($data)); + $crc = sprintf("%u", crc32($data)); $crcOK = $crc == $datacrc; $lenOK = $isize == strlen($data); if (!$lenOK || !$crcOK) { - $error = ( $lenOK ? '' : 'Length check FAILED. ') . ( $crcOK ? '' : 'Checksum FAILED.'); + $error = ($lenOK ? '' : 'Length check FAILED. ') . ($crcOK ? '' : 'Checksum FAILED.'); $ret = false; } $ret = $data; @@ -313,4 +313,4 @@ function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null) mb_internal_encoding($mbIntEnc); } return $ret; -} \ No newline at end of file +} diff --git a/tests/JSMinTest.php b/tests/JSMinTest.php index 66c19c06..dc94c099 100644 --- a/tests/JSMinTest.php +++ b/tests/JSMinTest.php @@ -126,4 +126,4 @@ public function JSMinExceptionDataProvider() ), ); } -} \ No newline at end of file +} diff --git a/tests/JsClosureCompilerTest.php b/tests/JsClosureCompilerTest.php index 1d3ffab8..d9f7a7ab 100644 --- a/tests/JsClosureCompilerTest.php +++ b/tests/JsClosureCompilerTest.php @@ -32,8 +32,11 @@ public function test2() $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 @@ public function test3() $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 @@ public function test5() )); } 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 @@ public function test6() )); } 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() diff --git a/tests/LessSourceTest.php b/tests/LessSourceTest.php index 037d055a..16c0715d 100644 --- a/tests/LessSourceTest.php +++ b/tests/LessSourceTest.php @@ -39,4 +39,4 @@ public function testLessTimestamp() $this->assertEquals("/min/g=less&{$max}", $res); } -} \ No newline at end of file +} diff --git a/tests/MinifyBuildTest.php b/tests/MinifyBuildTest.php index f0ab9948..6e5ae6b3 100644 --- a/tests/MinifyBuildTest.php +++ b/tests/MinifyBuildTest.php @@ -25,4 +25,4 @@ public function test() $this->assertEquals($b->uri('/path'), "/path?{$maxTime}", 'uri() with no querystring'); $this->assertEquals($b->uri('/path?hello'), "/path?hello&{$maxTime}", 'uri() with existing querystring'); } -} \ No newline at end of file +} diff --git a/tests/MinifyCSSUriRewriterTest.php b/tests/MinifyCSSUriRewriterTest.php index 83871bf1..63e4ebe6 100644 --- a/tests/MinifyCSSUriRewriterTest.php +++ b/tests/MinifyCSSUriRewriterTest.php @@ -16,9 +16,10 @@ public function test1() $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 @@ public function test4() $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); diff --git a/tests/MinifyCacheAPCTest.php b/tests/MinifyCacheAPCTest.php index 447f72b3..15b3b69c 100644 --- a/tests/MinifyCacheAPCTest.php +++ b/tests/MinifyCacheAPCTest.php @@ -22,4 +22,4 @@ public function test1() $cache = new Minify_Cache_APC(); $this->assertTestCache($cache, $id, $data); } -} \ No newline at end of file +} diff --git a/tests/MinifyCacheMemcacheTest.php b/tests/MinifyCacheMemcacheTest.php index 6d71c27d..4758a530 100644 --- a/tests/MinifyCacheMemcacheTest.php +++ b/tests/MinifyCacheMemcacheTest.php @@ -45,4 +45,3 @@ public function test2() $this->assertTestCache($cache, $id, $data); } } - diff --git a/tests/MinifyCacheWinCacheTest.php b/tests/MinifyCacheWinCacheTest.php index 4ef00e32..511ef2ee 100644 --- a/tests/MinifyCacheWinCacheTest.php +++ b/tests/MinifyCacheWinCacheTest.php @@ -21,4 +21,4 @@ public function test1() $cache = new Minify_Cache_WinCache(); $this->assertTestCache($cache, $id, $data); } -} \ No newline at end of file +} diff --git a/tests/MinifyCacheZendPlatformTest.php b/tests/MinifyCacheZendPlatformTest.php index e93f800b..79988e9b 100644 --- a/tests/MinifyCacheZendPlatformTest.php +++ b/tests/MinifyCacheZendPlatformTest.php @@ -22,4 +22,4 @@ public function test1() $cache = new Minify_Cache_ZendPlatform(); $this->assertTestCache($cache, $id, $data); } -} \ No newline at end of file +} diff --git a/tests/MinifyCommentPreserverTest.php b/tests/MinifyCommentPreserverTest.php index 77222eb4..e0e1ffbe 100644 --- a/tests/MinifyCommentPreserverTest.php +++ b/tests/MinifyCommentPreserverTest.php @@ -31,4 +31,4 @@ public static function _test_MCP_processor($content, $options = array()) ++$callCount; return $callCount . strtoupper($content); } -} \ No newline at end of file +} diff --git a/tests/MinifyHTMLHelperTest.php b/tests/MinifyHTMLHelperTest.php index 94e336b6..cba88447 100644 --- a/tests/MinifyHTMLHelperTest.php +++ b/tests/MinifyHTMLHelperTest.php @@ -80,4 +80,4 @@ public function test1() $this->assertEquals($maxTime, $output, 'utils.php : Minify_mtime w/ obj & group'); } } -} \ No newline at end of file +} diff --git a/tests/MinifyImportProcessorTest.php b/tests/MinifyImportProcessorTest.php index 34cdba47..c330b391 100644 --- a/tests/MinifyImportProcessorTest.php +++ b/tests/MinifyImportProcessorTest.php @@ -23,7 +23,10 @@ public function test() 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' + ); } } diff --git a/tests/MinifyNailgunClosureCompilerTest.php b/tests/MinifyNailgunClosureCompilerTest.php index 1b1dc41c..96ded32a 100644 --- a/tests/MinifyNailgunClosureCompilerTest.php +++ b/tests/MinifyNailgunClosureCompilerTest.php @@ -54,4 +54,4 @@ protected function assertHasJar() $this->markTestSkipped($e->getMessage()); } } -} \ No newline at end of file +} diff --git a/tests/MinifyTest.php b/tests/MinifyTest.php index ffeb6725..6d142b8c 100644 --- a/tests/MinifyTest.php +++ b/tests/MinifyTest.php @@ -62,8 +62,8 @@ public function test_Minify() $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 @@ public function test_Minify() )); $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 @@ public function test_Minify() '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 diff --git a/tests/MinifyYuiCSSTest.php b/tests/MinifyYuiCSSTest.php index b26cb159..4a240f73 100644 --- a/tests/MinifyYuiCSSTest.php +++ b/tests/MinifyYuiCSSTest.php @@ -60,4 +60,4 @@ protected function assertHasJar() $this->markTestSkipped($e->getMessage()); } } -} \ No newline at end of file +} diff --git a/tests/ScssSourceTest.php b/tests/ScssSourceTest.php index 2a2dec95..96f64014 100644 --- a/tests/ScssSourceTest.php +++ b/tests/ScssSourceTest.php @@ -39,4 +39,4 @@ public function testTimestamp() $this->assertEquals("/min/g=scss&{$max}", $res); } -} \ No newline at end of file +} diff --git a/tests/TestCase.php b/tests/TestCase.php index fda57d32..141df2c0 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -70,4 +70,4 @@ protected function getDataFile($filename) return $contents; } -} \ No newline at end of file +} diff --git a/utils.php b/utils.php index 46e29d76..dddffab0 100644 --- a/utils.php +++ b/utils.php @@ -48,7 +48,7 @@ function Minify_getUri($keyOrFiles, $opts = array()) * * Since this makes a bunch of stat() calls, you might not want to check this * on every request. - * + * * @param array $keysAndFiles group keys and/or file paths/URIs. * @return int latest modification time of all given keys/files */