Skip to content

Commit 68ce379

Browse files
authored
Merge pull request #71 from tedious/version_upgrades
upgrade dependencies, php requirements, formatting
2 parents 917ef60 + da7c580 commit 68ce379

File tree

5 files changed

+32
-30
lines changed

5 files changed

+32
-30
lines changed

.travis.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ sudo: false
22
language: php
33

44
php:
5-
- 5.6
65
- 7.0
76
- 7.1
8-
- hhvm
7+
- 7.2
98

109
before_script:
1110
- composer self-update && composer install

composer.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
"php": "^5.6|^7.0"
1616
},
1717
"require-dev": {
18-
"phpunit/phpunit": "4.0.*",
19-
"fabpot/php-cs-fixer": "0.4.0",
20-
"satooshi/php-coveralls": "^0.7.0"
18+
"phpunit/phpunit": "^6",
19+
"friendsofphp/php-cs-fixer": "^2.8",
20+
"php-coveralls/php-coveralls": "^1.1.0"
2121
},
2222
"autoload": {
2323
"psr-0": {"JShrink": "src/"}

src/JShrink/Minifier.php

+23-21
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@ public static function minify($js, $options = array())
120120
unset($jshrink);
121121

122122
return $js;
123-
124123
} catch (\Exception $e) {
125-
126124
if (isset($jshrink)) {
127125
// Since the breakdownScript function probably wasn't finished
128126
// we clean it out before discarding it.
@@ -181,7 +179,6 @@ protected function initialize($js, $options)
181179
protected function loop()
182180
{
183181
while ($this->a !== false && !is_null($this->a) && $this->a !== '') {
184-
185182
switch ($this->a) {
186183
// new lines
187184
case "\n":
@@ -194,14 +191,17 @@ protected function loop()
194191

195192
// if B is a space we skip the rest of the switch block and go down to the
196193
// string/regex check below, resetting $this->b with getReal
197-
if($this->b === ' ')
194+
if ($this->b === ' ') {
198195
break;
196+
}
199197

200198
// otherwise we treat the newline like a space
201199

200+
// no break
202201
case ' ':
203-
if(static::isAlphaNumeric($this->b))
202+
if (static::isAlphaNumeric($this->b)) {
204203
echo $this->a;
204+
}
205205

206206
$this->saveString();
207207
break;
@@ -222,9 +222,11 @@ protected function loop()
222222
break;
223223

224224
case ' ':
225-
if(!static::isAlphaNumeric($this->a))
225+
if (!static::isAlphaNumeric($this->a)) {
226226
break;
227+
}
227228

229+
// no break
228230
default:
229231
// check for some regex that breaks stuff
230232
if ($this->a === '/' && ($this->b === '\'' || $this->b === '"')) {
@@ -241,8 +243,9 @@ protected function loop()
241243
// do reg check of doom
242244
$this->b = $this->getReal();
243245

244-
if(($this->b == '/' && strpos('(,=:[!&|?', $this->a) !== false))
246+
if (($this->b == '/' && strpos('(,=:[!&|?', $this->a) !== false)) {
245247
$this->saveRegex();
248+
}
246249
}
247250
}
248251

@@ -272,7 +275,7 @@ protected function getChar()
272275
$char = $this->c;
273276
unset($this->c);
274277

275-
// Otherwise we start pulling from the input.
278+
// Otherwise we start pulling from the input.
276279
} else {
277280
$char = substr($this->input, $this->index, 1);
278281

@@ -287,9 +290,9 @@ protected function getChar()
287290

288291
// Normalize all whitespace except for the newline character into a
289292
// standard space.
290-
if($char !== "\n" && ord($char) < 32)
291-
293+
if ($char !== "\n" && ord($char) < 32) {
292294
return ' ';
295+
}
293296

294297
return $char;
295298
}
@@ -320,7 +323,6 @@ protected function getReal()
320323
$this->processOneLineComments($startIndex);
321324

322325
return $this->getReal();
323-
324326
} elseif ($this->c === '*') {
325327
$this->processMultiLineComments($startIndex);
326328

@@ -367,14 +369,13 @@ protected function processMultiLineComments($startIndex)
367369

368370
// kill everything up to the next */ if it's there
369371
if ($this->getNext('*/')) {
370-
371372
$this->getChar(); // get *
372373
$this->getChar(); // get /
373374
$char = $this->getChar(); // get next real character
374375

375376
// Now we reinsert conditional comments and YUI-style licensing comments
376377
if (($this->options['flaggedComments'] && $thirdCommentString === '!')
377-
|| ($thirdCommentString === '@') ) {
378+
|| ($thirdCommentString === '@')) {
378379

379380
// If conditional comments or flagged comments are not the first thing in the script
380381
// we need to echo a and fill it with a space before moving on.
@@ -395,13 +396,13 @@ protected function processMultiLineComments($startIndex)
395396

396397
return;
397398
}
398-
399399
} else {
400400
$char = false;
401401
}
402402

403-
if($char === false)
403+
if ($char === false) {
404404
throw new \RuntimeException('Unclosed multiline comment at position: ' . ($this->index - 2));
405+
}
405406

406407
// if we're here c is part of the comment and therefore tossed
407408
$this->c = $char;
@@ -421,9 +422,9 @@ protected function getNext($string)
421422
$pos = strpos($this->input, $string, $this->index);
422423

423424
// If it's not there return false.
424-
if($pos === false)
425-
425+
if ($pos === false) {
426426
return false;
427+
}
427428

428429
// Adjust position of index to jump ahead to the asked for string
429430
$this->index = $pos;
@@ -479,7 +480,7 @@ protected function saveString()
479480
if ($stringType === '`') {
480481
echo $this->a;
481482
} else {
482-
throw new \RuntimeException('Unclosed string at position: ' . $startpos );
483+
throw new \RuntimeException('Unclosed string at position: ' . $startpos);
483484
}
484485
break;
485486

@@ -520,16 +521,18 @@ protected function saveRegex()
520521
echo $this->a . $this->b;
521522

522523
while (($this->a = $this->getChar()) !== false) {
523-
if($this->a === '/')
524+
if ($this->a === '/') {
524525
break;
526+
}
525527

526528
if ($this->a === '\\') {
527529
echo $this->a;
528530
$this->a = $this->getChar();
529531
}
530532

531-
if($this->a === "\n")
533+
if ($this->a === "\n") {
532534
throw new \RuntimeException('Unclosed regex pattern at position: ' . $this->index);
535+
}
533536

534537
echo $this->a;
535538
}
@@ -590,5 +593,4 @@ protected function unlock($js)
590593

591594
return $js;
592595
}
593-
594596
}

tests/JShrink/Test/JShrinkTest.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use JShrink\Minifier;
1515

16-
class JShrinkTest extends \PHPUnit_Framework_TestCase
16+
class JShrinkTest extends \PHPUnit\Framework\TestCase
1717
{
1818
/**
1919
* @expectedException RuntimeException
@@ -103,8 +103,9 @@ public function getTestFiles($group)
103103

104104
$testFiles = scandir($testDir);
105105
foreach ($testFiles as $testFile) {
106-
if(substr($testFile, -3) !== '.js' || !file_exists(($expectDir . $testFile)))
106+
if (substr($testFile, -3) !== '.js' || !file_exists(($expectDir . $testFile))) {
107107
continue;
108+
}
108109

109110
$testInput = file_get_contents($testDir . $testFile);
110111
$testOutput = file_get_contents($expectDir . $testFile);

tests/runTests.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ set -e
33

44
echo 'Running unit tests.'
55
./vendor/bin/phpunit --verbose --coverage-clover build/logs/clover.xml
6-
6+
77
echo ''
88
echo ''
99
echo ''
1010
echo 'Testing for Coding Styling Compliance.'
1111
echo 'All code should follow PSR standards.'
12-
./vendor/bin/php-cs-fixer fix ./ --level="all" -vv --dry-run
12+
./vendor/bin/php-cs-fixer fix ./ -vv --dry-run

0 commit comments

Comments
 (0)