Skip to content

Commit

Permalink
Merge pull request #71 from tedious/version_upgrades
Browse files Browse the repository at this point in the history
upgrade dependencies, php requirements, formatting
  • Loading branch information
tedivm authored Dec 8, 2017
2 parents 917ef60 + da7c580 commit 68ce379
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 30 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ sudo: false
language: php

php:
- 5.6
- 7.0
- 7.1
- hhvm
- 7.2

before_script:
- composer self-update && composer install
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/"}
Expand Down
44 changes: 23 additions & 21 deletions src/JShrink/Minifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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":
Expand All @@ -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;
Expand All @@ -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 === '"')) {
Expand All @@ -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();
}
}
}

Expand Down Expand Up @@ -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);

Expand All @@ -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;
}
Expand Down Expand Up @@ -320,7 +323,6 @@ protected function getReal()
$this->processOneLineComments($startIndex);

return $this->getReal();

} elseif ($this->c === '*') {
$this->processMultiLineComments($startIndex);

Expand Down Expand Up @@ -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.
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -590,5 +593,4 @@ protected function unlock($js)

return $js;
}

}
5 changes: 3 additions & 2 deletions tests/JShrink/Test/JShrinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use JShrink\Minifier;

class JShrinkTest extends \PHPUnit_Framework_TestCase
class JShrinkTest extends \PHPUnit\Framework\TestCase
{
/**
* @expectedException RuntimeException
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions tests/runTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
./vendor/bin/php-cs-fixer fix ./ -vv --dry-run

0 comments on commit 68ce379

Please sign in to comment.