From 60daeea486b1bb11c6ad1d693f55263e5c69e97a Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Thu, 7 Dec 2017 16:48:36 -0800 Subject: [PATCH 1/2] upgrade dependencies, php requirements, formatting --- .travis.yml | 2 +- composer.json | 6 ++-- src/JShrink/Minifier.php | 44 ++++++++++++++++-------------- tests/JShrink/Test/JShrinkTest.php | 5 ++-- tests/runTests.sh | 4 +-- 5 files changed, 32 insertions(+), 29 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5a94c4d..2bc8cb4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,9 +2,9 @@ sudo: false language: php php: - - 5.6 - 7.0 - 7.1 + - 7.2 - hhvm before_script: diff --git a/composer.json b/composer.json index 62b5cf4..9483d5e 100644 --- a/composer.json +++ b/composer.json @@ -15,9 +15,9 @@ "php": "^5.6|^7.0" }, "require-dev": { - "phpunit/phpunit": "4.0.*", - "fabpot/php-cs-fixer": "0.4.0", - "satooshi/php-coveralls": "^0.7.0" + "phpunit/phpunit": "^6", + "friendsofphp/php-cs-fixer": "^2.8", + "php-coveralls/php-coveralls": "^1.1.0" }, "autoload": { "psr-0": {"JShrink": "src/"} diff --git a/src/JShrink/Minifier.php b/src/JShrink/Minifier.php index fc3fee7..76f4ced 100644 --- a/src/JShrink/Minifier.php +++ b/src/JShrink/Minifier.php @@ -120,9 +120,7 @@ public static function minify($js, $options = array()) unset($jshrink); return $js; - } catch (\Exception $e) { - if (isset($jshrink)) { // Since the breakdownScript function probably wasn't finished // we clean it out before discarding it. @@ -181,7 +179,6 @@ protected function initialize($js, $options) protected function loop() { while ($this->a !== false && !is_null($this->a) && $this->a !== '') { - switch ($this->a) { // new lines case "\n": @@ -194,14 +191,17 @@ protected function loop() // if B is a space we skip the rest of the switch block and go down to the // string/regex check below, resetting $this->b with getReal - if($this->b === ' ') + if ($this->b === ' ') { break; + } // otherwise we treat the newline like a space + // no break case ' ': - if(static::isAlphaNumeric($this->b)) + if (static::isAlphaNumeric($this->b)) { echo $this->a; + } $this->saveString(); break; @@ -222,9 +222,11 @@ protected function loop() break; case ' ': - if(!static::isAlphaNumeric($this->a)) + if (!static::isAlphaNumeric($this->a)) { break; + } + // no break default: // check for some regex that breaks stuff if ($this->a === '/' && ($this->b === '\'' || $this->b === '"')) { @@ -241,8 +243,9 @@ protected function loop() // do reg check of doom $this->b = $this->getReal(); - if(($this->b == '/' && strpos('(,=:[!&|?', $this->a) !== false)) + if (($this->b == '/' && strpos('(,=:[!&|?', $this->a) !== false)) { $this->saveRegex(); + } } } @@ -272,7 +275,7 @@ protected function getChar() $char = $this->c; unset($this->c); - // Otherwise we start pulling from the input. + // Otherwise we start pulling from the input. } else { $char = substr($this->input, $this->index, 1); @@ -287,9 +290,9 @@ protected function getChar() // Normalize all whitespace except for the newline character into a // standard space. - if($char !== "\n" && ord($char) < 32) - + if ($char !== "\n" && ord($char) < 32) { return ' '; + } return $char; } @@ -320,7 +323,6 @@ protected function getReal() $this->processOneLineComments($startIndex); return $this->getReal(); - } elseif ($this->c === '*') { $this->processMultiLineComments($startIndex); @@ -367,14 +369,13 @@ protected function processMultiLineComments($startIndex) // kill everything up to the next */ if it's there if ($this->getNext('*/')) { - $this->getChar(); // get * $this->getChar(); // get / $char = $this->getChar(); // get next real character // Now we reinsert conditional comments and YUI-style licensing comments if (($this->options['flaggedComments'] && $thirdCommentString === '!') - || ($thirdCommentString === '@') ) { + || ($thirdCommentString === '@')) { // If conditional comments or flagged comments are not the first thing in the script // we need to echo a and fill it with a space before moving on. @@ -395,13 +396,13 @@ protected function processMultiLineComments($startIndex) return; } - } else { $char = false; } - if($char === false) + if ($char === false) { throw new \RuntimeException('Unclosed multiline comment at position: ' . ($this->index - 2)); + } // if we're here c is part of the comment and therefore tossed $this->c = $char; @@ -421,9 +422,9 @@ protected function getNext($string) $pos = strpos($this->input, $string, $this->index); // If it's not there return false. - if($pos === false) - + if ($pos === false) { return false; + } // Adjust position of index to jump ahead to the asked for string $this->index = $pos; @@ -479,7 +480,7 @@ protected function saveString() if ($stringType === '`') { echo $this->a; } else { - throw new \RuntimeException('Unclosed string at position: ' . $startpos ); + throw new \RuntimeException('Unclosed string at position: ' . $startpos); } break; @@ -520,16 +521,18 @@ protected function saveRegex() echo $this->a . $this->b; while (($this->a = $this->getChar()) !== false) { - if($this->a === '/') + if ($this->a === '/') { break; + } if ($this->a === '\\') { echo $this->a; $this->a = $this->getChar(); } - if($this->a === "\n") + if ($this->a === "\n") { throw new \RuntimeException('Unclosed regex pattern at position: ' . $this->index); + } echo $this->a; } @@ -590,5 +593,4 @@ protected function unlock($js) return $js; } - } diff --git a/tests/JShrink/Test/JShrinkTest.php b/tests/JShrink/Test/JShrinkTest.php index 0f89fa5..912f481 100644 --- a/tests/JShrink/Test/JShrinkTest.php +++ b/tests/JShrink/Test/JShrinkTest.php @@ -13,7 +13,7 @@ use JShrink\Minifier; -class JShrinkTest extends \PHPUnit_Framework_TestCase +class JShrinkTest extends \PHPUnit\Framework\TestCase { /** * @expectedException RuntimeException @@ -103,8 +103,9 @@ public function getTestFiles($group) $testFiles = scandir($testDir); foreach ($testFiles as $testFile) { - if(substr($testFile, -3) !== '.js' || !file_exists(($expectDir . $testFile))) + if (substr($testFile, -3) !== '.js' || !file_exists(($expectDir . $testFile))) { continue; + } $testInput = file_get_contents($testDir . $testFile); $testOutput = file_get_contents($expectDir . $testFile); diff --git a/tests/runTests.sh b/tests/runTests.sh index cb79e66..1c642cc 100755 --- a/tests/runTests.sh +++ b/tests/runTests.sh @@ -3,10 +3,10 @@ set -e echo 'Running unit tests.' ./vendor/bin/phpunit --verbose --coverage-clover build/logs/clover.xml - + echo '' echo '' echo '' echo 'Testing for Coding Styling Compliance.' echo 'All code should follow PSR standards.' -./vendor/bin/php-cs-fixer fix ./ --level="all" -vv --dry-run \ No newline at end of file +./vendor/bin/php-cs-fixer fix ./ -vv --dry-run \ No newline at end of file From da7c5800e63d1cbd0061d5d0f40f4bc59261b013 Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Thu, 7 Dec 2017 16:57:47 -0800 Subject: [PATCH 2/2] drop hhvm in testing --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 2bc8cb4..c3bdb12 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,6 @@ php: - 7.0 - 7.1 - 7.2 - - hhvm before_script: - composer self-update && composer install