1
0
mirror of https://github.com/mrclay/minify.git synced 2025-08-30 00:59:48 +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

@@ -27,7 +27,7 @@ $outfile = $cli->values['o'];
$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 @@ $combined = Minify::combine($sources) . "\n";
if ($testRun) {
echo $combined;
echo Minify_CSS_UriRewriter::$debugText . "\n";
} else {
} else {
$fp = $cli->openOutput();
fwrite($fp, $combined);
$cli->closeOutput();
}

View File

@@ -4,6 +4,6 @@
require __DIR__ . '/../config.php';
$minifyCachePath = isset($min_cachePath)
? $min_cachePath
$minifyCachePath = isset($min_cachePath)
? $min_cachePath
: '';

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,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'); ?>
<!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>
<?php
if (isset($vars['exceptionMsg'])) {
echo $vars['exceptionMsg'];
}
if (isset($vars['time'])) {
echo "
echo $vars['exceptionMsg'];
}
if (isset($vars['time'])) {
echo "
<table>
<tr><th>Bytes in</th><td>{$vars['inBytes']} (after line endings normalized to <code>\\n</code>)</td></tr>
<tr><th>Bytes out</th><td>{$vars['outBytes']} (reduced " . round(100 - (100 * $vars['outBytes'] / $vars['inBytes'])) . "%)</td></tr>
<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>
echo h($vars['output']);
} ?></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'));
@@ -88,13 +90,13 @@ if (isset($_POST['url'])) {
die('Unrecognized Content-Type: ' . $type['sent']);
}
if ($type['minify'] === 'text/html'
if ($type['minify'] === 'text/html'
&& 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}' />";