1
0
mirror of https://github.com/mrclay/minify.git synced 2025-01-17 13:18:13 +01:00

phpcs: enable psr2

This commit is contained in:
Elan Ruusamäe 2016-10-16 16:46:43 +03:00
parent 0cc631c5a9
commit 5fb7ea1ed1
44 changed files with 175 additions and 109 deletions

View File

@ -5,7 +5,7 @@ $finder = Symfony\CS\Finder\DefaultFinder::create()
;
return Symfony\CS\Config\Config::create()
->level(Symfony\CS\FixerInterface::NONE_LEVEL)
->level(Symfony\CS\FixerInterface::PSR2_LEVEL)
->setUsingCache(true)
->fixers(array(
'linefeed',
@ -21,6 +21,7 @@ return Symfony\CS\Config\Config::create()
'controls_spaces',
'elseif',
'-eof_ending',
'-method_argument_space',
))
->finder($finder)
;

View File

@ -60,7 +60,8 @@
* @subpackage HTTP
* @author Stephen Clay <steve@mrclay.org>
*/
class HTTP_ConditionalGet {
class HTTP_ConditionalGet
{
/**
* Does the client have a valid copy of the requested resource?
@ -340,7 +341,8 @@ class HTTP_ConditionalGet {
*
* @return string
*/
protected function normalizeEtag($etag) {
protected function normalizeEtag($etag)
{
$etag = trim($etag);
return $this->_stripEtag

View File

@ -43,7 +43,8 @@
* @subpackage HTTP
* @author Stephen Clay <steve@mrclay.org>
*/
class HTTP_Encoder {
class HTTP_Encoder
{
/**
* Should the encoder allow HTTP encoding to IE6?
@ -97,8 +98,7 @@ class HTTP_Encoder {
$this->_headers['Content-Type'] = $spec['type'];
}
if (isset($spec['method'])
&& in_array($spec['method'], array('gzip', 'deflate', 'compress', '')))
{
&& in_array($spec['method'], array('gzip', 'deflate', 'compress', ''))) {
$this->_encodeMethod = array($spec['method'], $spec['method']);
} else {
$this->_encodeMethod = self::getAcceptedEncoding();
@ -192,8 +192,7 @@ class HTTP_Encoder {
// @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
if (! isset($_SERVER['HTTP_ACCEPT_ENCODING'])
|| self::isBuggyIe())
{
|| self::isBuggyIe()) {
return array('', '');
}
$ae = $_SERVER['HTTP_ACCEPT_ENCODING'];
@ -259,8 +258,7 @@ class HTTP_Encoder {
}
if ('' === $this->_encodeMethod[0]
|| ($compressionLevel == 0)
|| !extension_loaded('zlib'))
{
|| !extension_loaded('zlib')) {
return false;
}
if ($this->_encodeMethod[0] === 'deflate') {

View File

@ -24,7 +24,8 @@ use Psr\Log\LoggerInterface;
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link https://github.com/mrclay/minify
*/
class Minify {
class Minify
{
/**
* API version
@ -87,7 +88,8 @@ class Minify {
* @param Minify_CacheInterface $cache
* @param LoggerInterface $logger
*/
public function __construct(Minify_CacheInterface $cache, LoggerInterface $logger = null) {
public function __construct(Minify_CacheInterface $cache, LoggerInterface $logger = null)
{
$this->cache = $cache;
$this->logger = $logger;
}
@ -492,7 +494,8 @@ class Minify {
* @param string $content
* @return string
*/
public static function nullMinifier($content) {
public static function nullMinifier($content)
{
if (isset($content[0]) && $content[0] === "\xef") {
$content = substr($content, 3);
}
@ -506,7 +509,7 @@ class Minify {
*/
protected function setupUriRewrites()
{
foreach($this->sources as $key => $source) {
foreach ($this->sources as $key => $source) {
$file = $this->env->normalizePath($source->getFilePath());
$minifyOptions = $source->getMinifierOptions();
@ -594,8 +597,7 @@ class Minify {
|| $type === self::TYPE_CSS // yes, to process CSS individually (avoiding PCRE bugs/limits)
|| $minifier !== $lastMinifier // yes, minifier changed
|| $options !== $lastOptions) // yes, options changed
)
{
) {
// minify previous sources with last settings
$imploded = implode($implodeSeparator, $groupToProcessTogether);
$groupToProcessTogether = array();
@ -718,7 +720,6 @@ class Minify {
if (!empty($options['contentType'])) {
// just verify sources have null content type or match the options
if ($sourceType !== null && $sourceType !== $options['contentType']) {
$this->logger && $this->logger->warning('ContentType mismatch');
$this->sources = array();
@ -732,7 +733,6 @@ class Minify {
if ($type === null) {
$type = $sourceType;
} elseif ($sourceType !== $type) {
$this->logger && $this->logger->warning('ContentType mismatch');
$this->sources = array();

View File

@ -21,7 +21,8 @@ use Props\Container;
* @property \Minify_Source_Factory $sourceFactory
* @property array $sourceFactoryOptions
*/
class App extends Container {
class App extends Container
{
/**
* Constructor
@ -249,7 +250,8 @@ class App extends Container {
};
}
public function runServer() {
public function runServer()
{
if (!$this->env->get('f') && $this->env->get('g') === null) {
// no spec given
$msg = '<p>No "f" or "g" parameters were detected.</p>';
@ -265,7 +267,8 @@ class App extends Container {
* @param mixed $var
* @return string
*/
private function typeOf($var) {
private function typeOf($var)
{
$type = gettype($var);
return $type === 'object' ? get_class($var) : $type;

View File

@ -34,7 +34,8 @@
* @package Minify
* @author Stephen Clay <steve@mrclay.org>
*/
class Minify_Build {
class Minify_Build
{
/**
* Last modification time of all files in the build
@ -67,7 +68,8 @@ class Minify_Build {
* append the timestamp to the URI.
* @return string
*/
public function uri($uri, $forceAmpersand = false) {
public function uri($uri, $forceAmpersand = false)
{
$sep = ($forceAmpersand || strpos($uri, '?') !== false)
? self::$ampersand
: '?';

View File

@ -16,7 +16,8 @@
*
* @deprecated Use Minify_CSSmin
*/
class Minify_CSS {
class Minify_CSS
{
/**
* Minify a CSS string

View File

@ -26,7 +26,8 @@
*
* @deprecated Use CSSmin (tubalmartin/cssmin)
*/
class Minify_CSS_Compressor {
class Minify_CSS_Compressor
{
/**
* Minify a CSS string
@ -61,7 +62,8 @@ class Minify_CSS_Compressor {
*
* @param array $options (currently ignored)
*/
private function __construct($options) {
private function __construct($options)
{
$this->_options = $options;
}

View File

@ -10,7 +10,8 @@
* @package Minify
* @author Stephen Clay <steve@mrclay.org>
*/
class Minify_CSS_UriRewriter {
class Minify_CSS_UriRewriter
{
/**
* rewrite() and rewriteRelative() append debugging information here
@ -326,7 +327,8 @@ class Minify_CSS_UriRewriter {
* @param string $css
* @return string
*/
private static function _owlifySvgPaths($css) {
private static function _owlifySvgPaths($css)
{
return preg_replace('~\b((?:clip-path|mask|-webkit-mask)\s*\:\s*)url(\(\s*#\w+\s*\))~', '$1owl$2', $css);
}
@ -338,7 +340,8 @@ class Minify_CSS_UriRewriter {
* @param string $css
* @return string
*/
private static function _unOwlify($css) {
private static function _unOwlify($css)
{
return preg_replace('~\b((?:clip-path|mask|-webkit-mask)\s*\:\s*)owl~', '$1url', $css);
}
}

View File

@ -12,7 +12,8 @@
* @package Minify
* @author Stephen Clay <steve@mrclay.org>
*/
class Minify_CSSmin {
class Minify_CSSmin
{
/**
* Minify a CSS string

View File

@ -14,7 +14,8 @@
* @package Minify
* @author Chris Edwards
**/
class Minify_Cache_APC implements Minify_CacheInterface {
class Minify_Cache_APC implements Minify_CacheInterface
{
/**
* Create a Minify_Cache_APC object, to be passed to

View File

@ -6,7 +6,8 @@
use Psr\Log\LoggerInterface;
class Minify_Cache_File implements Minify_CacheInterface {
class Minify_Cache_File implements Minify_CacheInterface
{
/**
* @var string

View File

@ -17,7 +17,8 @@
* }
* </code>
**/
class Minify_Cache_Memcache implements Minify_CacheInterface {
class Minify_Cache_Memcache implements Minify_CacheInterface
{
/**
* Create a Minify_Cache_Memcache object, to be passed to

View File

@ -8,7 +8,8 @@
*
* @package Minify
*/
class Minify_Cache_Null implements Minify_CacheInterface {
class Minify_Cache_Null implements Minify_CacheInterface
{
/**
* Write data to cache.
*

View File

@ -99,12 +99,12 @@ class Minify_Cache_WinCache implements Minify_CacheInterface
return $this->_fetch($id) ? $this->_data : '';
}
private $_exp = NULL;
private $_exp = null;
// cache of most recently fetched id
private $_lm = NULL;
private $_data = NULL;
private $_id = NULL;
private $_lm = null;
private $_data = null;
private $_id = null;
/**
* Fetch data and timestamp from WinCache, store in instance
@ -121,7 +121,7 @@ class Minify_Cache_WinCache implements Minify_CacheInterface
$suc = false;
$ret = wincache_ucache_get($id, $suc);
if (!$suc) {
$this->_id = NULL;
$this->_id = null;
return false;
}

View File

@ -17,7 +17,8 @@
* @package Minify
* @author Elan Ruusamäe <glen@delfi.ee>
**/
class Minify_Cache_XCache implements Minify_CacheInterface {
class Minify_Cache_XCache implements Minify_CacheInterface
{
/**
* Create a Minify_Cache_XCache object, to be passed to

View File

@ -16,7 +16,8 @@
* @package Minify
* @author Patrick van Dissel
*/
class Minify_Cache_ZendPlatform implements Minify_CacheInterface {
class Minify_Cache_ZendPlatform implements Minify_CacheInterface
{
/**
* Create a Minify_Cache_ZendPlatform object, to be passed to

View File

@ -9,7 +9,8 @@
*
* @package Minify
*/
interface Minify_CacheInterface {
interface Minify_CacheInterface
{
/**
* Write data to cache.
*

View File

@ -10,7 +10,8 @@
* @package Minify
* @author Stephen Clay <steve@mrclay.org>
*/
class Minify_CommentPreserver {
class Minify_CommentPreserver
{
/**
* String to be prepended to each preserved comment

View File

@ -15,7 +15,8 @@ use Monolog\Logger;
* @package Minify
* @author Stephen Clay <steve@mrclay.org>
*/
abstract class Minify_Controller_Base implements Minify_ControllerInterface {
abstract class Minify_Controller_Base implements Minify_ControllerInterface
{
/**
* @var Minify_Env

View File

@ -28,7 +28,8 @@ use Monolog\Logger;
* @package Minify
* @author Stephen Clay <steve@mrclay.org>
*/
class Minify_Controller_Files extends Minify_Controller_Base {
class Minify_Controller_Files extends Minify_Controller_Base
{
/**
* Set up file sources
@ -40,7 +41,8 @@ class Minify_Controller_Files extends Minify_Controller_Base {
*
* 'files': (required) array of complete file paths, or a single path
*/
public function createConfiguration(array $options) {
public function createConfiguration(array $options)
{
// strip controller options
$files = $options['files'];

View File

@ -23,7 +23,8 @@
* @package Minify
* @author Stephen Clay <steve@mrclay.org>
*/
class Minify_Controller_Groups extends Minify_Controller_Files {
class Minify_Controller_Groups extends Minify_Controller_Files
{
/**
* Set up groups of files as sources
@ -35,7 +36,8 @@ class Minify_Controller_Groups extends Minify_Controller_Files {
*
* @return array Minify options
*/
public function createConfiguration(array $options) {
public function createConfiguration(array $options)
{
// strip controller options
$groups = $options['groups'];
unset($options['groups']);

View File

@ -10,7 +10,8 @@
* @package Minify
* @author Stephen Clay <steve@mrclay.org>
*/
class Minify_Controller_MinApp extends Minify_Controller_Base {
class Minify_Controller_MinApp extends Minify_Controller_Base
{
/**
* Set up groups of files as sources
@ -19,7 +20,8 @@ class Minify_Controller_MinApp extends Minify_Controller_Base {
*
* @return array Minify options
*/
public function createConfiguration(array $options) {
public function createConfiguration(array $options)
{
// PHP insecure by default: realpath() and other FS functions can't handle null bytes.
$get = $this->env->get();
foreach (array('g', 'b', 'f') as $key) {

View File

@ -11,7 +11,8 @@
* @package Minify
* @author Stephen Clay <steve@mrclay.org>
*/
class Minify_Controller_Page extends Minify_Controller_Base {
class Minify_Controller_Page extends Minify_Controller_Base
{
/**
* Set up source of HTML content
@ -31,7 +32,8 @@ class Minify_Controller_Page extends Minify_Controller_Base {
* 'minifyAll': should all CSS and Javascript blocks be individually
* minified? (default false)
*/
public function createConfiguration(array $options) {
public function createConfiguration(array $options)
{
if (isset($options['file'])) {
$sourceSpec = array(
'filepath' => $options['file']

View File

@ -1,7 +1,8 @@
<?php
interface Minify_ControllerInterface {
interface Minify_ControllerInterface
{
/**
* Create controller sources and options for Minify::serve()

View File

@ -6,7 +6,8 @@
* @package Minify
* @author Stephen Clay <steve@mrclay.org>
*/
class Minify_DebugDetector {
class Minify_DebugDetector
{
public static function shouldDebugRequest(Minify_Env $env)
{
if ($env->get('debug') !== null) {

View File

@ -1,6 +1,7 @@
<?php
class Minify_Env {
class Minify_Env
{
/**
* @return string

View File

@ -16,7 +16,8 @@
* @package Minify
* @author Stephen Clay <steve@mrclay.org>
*/
class Minify_HTML {
class Minify_HTML
{
/**
* @var boolean
*/
@ -40,7 +41,8 @@ class Minify_HTML {
*
* @return string
*/
public static function minify($html, $options = array()) {
public static function minify($html, $options = array())
{
$min = new self($html, $options);
return $min->process();

View File

@ -10,7 +10,8 @@
* @package Minify
* @author Stephen Clay <steve@mrclay.org>
*/
class Minify_HTML_Helper {
class Minify_HTML_Helper
{
public $rewriteWorks = true;
public $minAppUri = '/min';
public $groupsConfigFile = '';
@ -190,7 +191,8 @@ class Minify_HTML_Helper {
* @param int $pos index to check
* @return mixed a common char or '' if any do not match
*/
protected static function _getCommonCharAtPos($arr, $pos) {
protected static function _getCommonCharAtPos($arr, $pos)
{
if (!isset($arr[0][$pos])) {
return '';
}
@ -215,7 +217,8 @@ class Minify_HTML_Helper {
* @param string $minRoot root-relative URI of the "min" application
* @return string
*/
protected static function _getShortestUri($paths, $minRoot = '/min/') {
protected static function _getShortestUri($paths, $minRoot = '/min/')
{
$pos = 0;
$base = '';
while (true) {

View File

@ -18,8 +18,8 @@
* @author Stephen Clay <steve@mrclay.org>
* @author Simon Schick <simonsimcity@gmail.com>
*/
class Minify_ImportProcessor {
class Minify_ImportProcessor
{
public static $filesIncluded = array();
public static function process($file)
@ -173,8 +173,7 @@ class Minify_ImportProcessor {
$arFrom = explode($ps, rtrim($realFrom, $ps));
$arTo = explode($ps, rtrim($realTo, $ps));
while (count($arFrom) && count($arTo) && ($arFrom[0] == $arTo[0]))
{
while (count($arFrom) && count($arTo) && ($arFrom[0] == $arTo[0])) {
array_shift($arFrom);
array_shift($arTo);
}
@ -191,18 +190,21 @@ class Minify_ImportProcessor {
private function truepath($path)
{
// whether $path is unix or not
$unipath = strlen($path) == 0 || $path{0} != '/';
$unipath = strlen($path) == 0 || $path{0}
!= '/';
// attempts to detect if path is relative in which case, add cwd
if (strpos($path, ':') === false && $unipath)
if (strpos($path, ':') === false && $unipath) {
$path = $this->_currentDir . DIRECTORY_SEPARATOR . $path;
}
// resolve path parts (single dot, double dot and double delimiters)
$path = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $path);
$parts = array_filter(explode(DIRECTORY_SEPARATOR, $path), 'strlen');
$absolutes = array();
foreach ($parts as $part) {
if ('.' == $part)
if ('.' == $part) {
continue;
}
if ('..' == $part) {
array_pop($absolutes);
} else {
@ -211,8 +213,9 @@ class Minify_ImportProcessor {
}
$path = implode(DIRECTORY_SEPARATOR, $absolutes);
// resolve any symlinks
if (file_exists($path) && linkinfo($path) > 0)
if (file_exists($path) && linkinfo($path) > 0) {
$path = readlink($path);
}
// put initial separator that could have been lost
$path = !$unipath ? '/' . $path : $path;

View File

@ -13,7 +13,8 @@
*
* @todo can use a stream wrapper to unit test this?
*/
class Minify_JS_ClosureCompiler {
class Minify_JS_ClosureCompiler
{
/**
* @var string The option key for the maximum POST byte size
@ -228,4 +229,6 @@ class Minify_JS_ClosureCompiler {
}
}
class Minify_JS_ClosureCompiler_Exception extends Exception {}
class Minify_JS_ClosureCompiler_Exception extends Exception
{
}

View File

@ -1,6 +1,7 @@
<?php
class Minify_LessCssSource extends Minify_Source {
class Minify_LessCssSource extends Minify_Source
{
/**
* @var Minify_CacheInterface
*/
@ -16,7 +17,8 @@ class Minify_LessCssSource extends Minify_Source {
/**
* @inheritdoc
*/
public function __construct(array $spec, Minify_CacheInterface $cache) {
public function __construct(array $spec, Minify_CacheInterface $cache)
{
parent::__construct($spec);
$this->cache = $cache;
@ -27,7 +29,8 @@ class Minify_LessCssSource extends Minify_Source {
*
* @return int
*/
public function getLastModified() {
public function getLastModified()
{
$cache = $this->getCache();
return $cache['lastModified'];
@ -38,7 +41,8 @@ class Minify_LessCssSource extends Minify_Source {
*
* @return string
*/
public function getContent() {
public function getContent()
{
$cache = $this->getCache();
return $cache['compiled'];
@ -49,7 +53,8 @@ class Minify_LessCssSource extends Minify_Source {
*
* @return array
*/
private function getCache() {
private function getCache()
{
// cache for single run
// so that getLastModified and getContent in single request do not add additional cache roundtrips (i.e memcache)
if (isset($this->parsed)) {
@ -100,7 +105,8 @@ class Minify_LessCssSource extends Minify_Source {
*
* @return string
*/
private function getCacheId($prefix = 'minify') {
private function getCacheId($prefix = 'minify')
{
$md5 = md5($this->filepath);
return "{$prefix}_less2_{$md5}";
@ -111,7 +117,8 @@ class Minify_LessCssSource extends Minify_Source {
*
* @return lessc
*/
private function getCompiler() {
private function getCompiler()
{
$less = new lessc();
// do not spend CPU time letting less doing minify
$less->setPreserveComments(true);

View File

@ -11,7 +11,8 @@
* @author Stephen Clay <steve@mrclay.org>
* @author Adam Pedersen (Issue 55 fix)
*/
class Minify_Lines {
class Minify_Lines
{
/**
* Add line numbers in C-style comments
@ -156,7 +157,8 @@ class Minify_Lines {
* @param string $token Token being checked
* @return bool
*/
private static function _find($str, $token) {
private static function _find($str, $token)
{
switch ($token) {
case '//':
$fakes = array(

View File

@ -19,7 +19,8 @@
*
* @package Minify
*/
class Minify_Packer {
class Minify_Packer
{
public static function minify($code, $options = array())
{
// @todo: set encoding options based on $options :)

View File

@ -8,7 +8,8 @@ use Leafo\ScssPhp\Version;
*
* @link https://github.com/leafo/scssphp/
*/
class Minify_ScssCssSource extends Minify_Source {
class Minify_ScssCssSource extends Minify_Source
{
/**
* @var Minify_CacheInterface
*/

View File

@ -9,7 +9,8 @@
*
* @package Minify
*/
class Minify_ServeConfiguration {
class Minify_ServeConfiguration
{
/**
* @var Minify_SourceInterface[]

View File

@ -13,7 +13,8 @@
* @package Minify
* @author Stephen Clay <steve@mrclay.org>
*/
class Minify_Source implements Minify_SourceInterface {
class Minify_Source implements Minify_SourceInterface
{
/**
* @var int time of last modification
@ -70,13 +71,13 @@ class Minify_Source implements Minify_SourceInterface {
if (isset($spec['filepath'])) {
$ext = pathinfo($spec['filepath'], PATHINFO_EXTENSION);
switch ($ext) {
case 'js' : $this->contentType = Minify::TYPE_JS;
case 'js': $this->contentType = Minify::TYPE_JS;
break;
case 'less' : // fallthrough
case 'css' : $this->contentType = Minify::TYPE_CSS;
case 'less': // fallthrough
case 'css': $this->contentType = Minify::TYPE_CSS;
break;
case 'htm' : // fallthrough
case 'html' : $this->contentType = Minify::TYPE_HTML;
case 'htm': // fallthrough
case 'html': $this->contentType = Minify::TYPE_HTML;
break;
}
$this->filepath = $spec['filepath'];
@ -203,7 +204,8 @@ class Minify_Source implements Minify_SourceInterface {
/**
* {@inheritdoc}
*/
public function setupUriRewrites() {
public function setupUriRewrites()
{
if ($this->filepath
&& !isset($this->minifyOptions['currentDir'])
&& !isset($this->minifyOptions['prependRelativePath'])

View File

@ -1,6 +1,7 @@
<?php
class Minify_Source_Factory {
class Minify_Source_Factory
{
/**
* @var array

View File

@ -1,3 +1,5 @@
<?php
class Minify_Source_FactoryException extends Exception {}
class Minify_Source_FactoryException extends Exception
{
}

View File

@ -12,7 +12,8 @@
*
* @package Minify
*/
interface Minify_SourceInterface {
interface Minify_SourceInterface
{
/**
* Get the minifier

View File

@ -7,7 +7,8 @@
/**
* @package Minify
*/
class Minify_SourceSet {
class Minify_SourceSet
{
/**
* Get unique string for a set of sources

View File

@ -29,7 +29,8 @@
* @package Minify
* @author Stephen Clay <steve@mrclay.org>
*/
class Minify_YUICompressor {
class Minify_YUICompressor
{
/**
* Filepath of the YUI Compressor jar file. This must be set before

View File

@ -18,7 +18,8 @@ use InvalidArgumentException;
* @author Steve Clay <steve@mrclay.org>
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
class Cli {
class Cli
{
/**
* @var array validation errors

View File

@ -43,7 +43,8 @@ use BadMethodCallException;
* @author Steve Clay <steve@mrclay.org>
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
class Arg {
class Arg
{
/**
* @return array
*/