Skip to content

Commit 551ed01

Browse files
committed
Add phpstan level 4 ci pass
1 parent 133ab20 commit 551ed01

11 files changed

+71
-43
lines changed

.gitattributes

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
* text=auto
22

3-
/test export-ignore
3+
/tests export-ignore
44
/.editorconfig export-ignore
55
/.gitattributes export-ignore
66
/.gitignore export-ignore

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ install: composer update --prefer-dist
3131

3232
script:
3333
- vendor/bin/phpunit
34+
- composer phpstan

composer.json

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "knplabs/knp-snappy",
33
"type": "library",
4-
"description": "PHP5 library allowing thumbnail, snapshot or PDF generation from a url or a html page. Wrapper for wkhtmltopdf/wkhtmltoimage.",
4+
"description": "PHP library allowing thumbnail, snapshot or PDF generation from a url or a html page. Wrapper for wkhtmltopdf/wkhtmltoimage.",
55
"keywords": ["pdf", "thumbnail", "snapshot", "knplabs", "knp", "wkhtmltopdf"],
66
"homepage": "http://github.com/KnpLabs/snappy",
77
"license": "MIT",
88
"authors": [
99
{
10-
"name": "KnpLabs Team",
10+
"name": "KNP Labs Team",
1111
"homepage": "http://knplabs.com"
1212
},
1313
{
@@ -21,7 +21,9 @@
2121
"psr/log": "^1.0"
2222
},
2323
"require-dev": {
24-
"phpunit/phpunit": "~7.4"
24+
"phpunit/phpunit": "~7.4",
25+
"phpstan/phpstan": "^0.12.7",
26+
"phpstan/phpstan-phpunit": "^0.12.6"
2527
},
2628
"suggest": {
2729
"h4cc/wkhtmltopdf-amd64": "Provides wkhtmltopdf-amd64 binary for Linux-compatible machines, use version `~0.12` as dependency",
@@ -35,6 +37,14 @@
3537
"Knp\\Snappy\\": "src/Knp/Snappy"
3638
}
3739
},
40+
"autoload-dev": {
41+
"psr-4": {
42+
"Tests\\": "tests/"
43+
}
44+
},
45+
"scripts": {
46+
"phpstan": "vendor/bin/phpstan analyse --ansi"
47+
},
3848
"extra": {
3949
"branch-alias": {
4050
"dev-master": "1.x-dev"

phpstan.neon

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
includes:
2+
- vendor/phpstan/phpstan-phpunit/extension.neon
3+
4+
parameters:
5+
level: 4
6+
paths:
7+
- src/
8+
- tests/
9+
inferPrivatePropertyTypeFromConstructor: true
10+
reportUnmatchedIgnoredErrors: false
11+
ignoreErrors:
12+
- "#^Call to an undefined static method #"

phpunit.xml.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
>
1313
<testsuites>
1414
<testsuite name="Snappy Test Suite">
15-
<directory>./test</directory>
15+
<directory>./tests</directory>
1616
</testsuite>
1717
</testsuites>
1818
</phpunit>

src/Knp/Snappy/AbstractGenerator.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ public function __construct($binary, array $options = [], array $env = null)
5252
$this->setOptions($options);
5353
$this->env = empty($env) ? null : $env;
5454

55-
register_shutdown_function([$this, 'removeTemporaryFiles']);
55+
if (is_callable([$this, 'removeTemporaryFiles'])) {
56+
register_shutdown_function([$this, 'removeTemporaryFiles']);
57+
}
5658
}
5759

5860
public function __destruct()
@@ -91,7 +93,7 @@ public function setDefaultExtension($defaultExtension)
9193
/**
9294
* Gets the default extension.
9395
*
94-
* @return $string
96+
* @return string
9597
*/
9698
public function getDefaultExtension()
9799
{
@@ -430,7 +432,7 @@ protected function createTemporaryFile($content = null, $extension = null)
430432
/**
431433
* Removes all temporary files.
432434
*/
433-
public function removeTemporaryFiles()
435+
public function removeTemporaryFiles(): void
434436
{
435437
foreach ($this->temporaryFiles as $file) {
436438
$this->unlink($file);
@@ -441,7 +443,7 @@ public function removeTemporaryFiles()
441443
* Builds the command string.
442444
*
443445
* @param string $binary The binary path/name
444-
* @param string/array $input Url(s) or file location(s) of the page(s) to process
446+
* @param string|array $input Url(s) or file location(s) of the page(s) to process
445447
* @param string $output File location to the image-to-be
446448
* @param array $options An array of options
447449
*

src/Knp/Snappy/Pdf.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function generate($input, $output, array $options = [], $overwrite = fals
6666
/**
6767
* Convert option content or url to file if it is needed.
6868
*
69-
* @param $option
69+
* @param mixed $option
7070
*
7171
* @return bool
7272
*/

test/Knp/Snappy/ImageTest.php

-14
This file was deleted.

test/Knp/Snappy/AbstractGeneratorTest.php tests/Knp/Snappy/AbstractGeneratorTest.php

+17-16
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
<?php
22

3-
namespace Knp\Snappy;
3+
namespace Tests\Knp\Snappy;
44

5+
use Knp\Snappy\AbstractGenerator;
56
use PHPUnit\Framework\TestCase;
67
use Psr\Log\LoggerInterface;
78

89
class AbstractGeneratorTest extends TestCase
910
{
1011
public function testAddOption()
1112
{
12-
$media = $this->getMockForAbstractClass('Knp\Snappy\AbstractGenerator', [], '', false);
13+
$media = $this->getMockForAbstractClass(AbstractGenerator::class, [], '', false);
1314

1415
$this->assertEquals([], $media->getOptions());
1516

@@ -36,13 +37,13 @@ public function testAddOption()
3637
$r->invokeArgs($media, ['baz', 'bat']);
3738
$this->fail($message);
3839
} catch (\InvalidArgumentException $e) {
39-
$this->anything($message);
40+
$this->anything();
4041
}
4142
}
4243

4344
public function testAddOptions()
4445
{
45-
$media = $this->getMockForAbstractClass('Knp\Snappy\AbstractGenerator', [], '', false);
46+
$media = $this->getMockForAbstractClass(AbstractGenerator::class, [], '', false);
4647

4748
$this->assertEquals([], $media->getOptions());
4849

@@ -78,7 +79,7 @@ public function testAddOptions()
7879
$r->invokeArgs($media, [['bak' => 'bam', 'bah' => 'bap', 'baz' => 'bat']]);
7980
$this->fail($message);
8081
} catch (\InvalidArgumentException $e) {
81-
$this->anything($message);
82+
$this->anything();
8283
}
8384
}
8485

@@ -117,7 +118,7 @@ public function testSetOption()
117118
$media->setOption('bad', 'def');
118119
$this->fail($message);
119120
} catch (\InvalidArgumentException $e) {
120-
$this->anything($message);
121+
$this->anything();
121122
}
122123
}
123124

@@ -157,7 +158,7 @@ public function testSetOptions()
157158
$media->setOptions(['foo' => 'abc', 'baz' => 'def', 'bad' => 'ghi']);
158159
$this->fail($message);
159160
} catch (\InvalidArgumentException $e) {
160-
$this->anything($message);
161+
$this->anything();
161162
}
162163
}
163164

@@ -493,7 +494,7 @@ public function testGetOutputFromHtmlWithHtmlArray()
493494

494495
public function testMergeOptions()
495496
{
496-
$media = $this->getMockForAbstractClass('Knp\Snappy\AbstractGenerator', [], '', false);
497+
$media = $this->getMockForAbstractClass(AbstractGenerator::class, [], '', false);
497498

498499
$originalOptions = ['foo' => 'bar', 'baz' => 'bat'];
499500

@@ -538,7 +539,7 @@ public function testMergeOptions()
538539
$r->invokeArgs($media, [['foo' => 'ban', 'bad' => 'bah']]);
539540
$this->fail($message);
540541
} catch (\InvalidArgumentException $e) {
541-
$this->anything($message);
542+
$this->anything();
542543
}
543544
}
544545

@@ -547,7 +548,7 @@ public function testMergeOptions()
547548
*/
548549
public function testBuildCommand($binary, $url, $path, $options, $expected)
549550
{
550-
$media = $this->getMockForAbstractClass('Knp\Snappy\AbstractGenerator', [], '', false);
551+
$media = $this->getMockForAbstractClass(AbstractGenerator::class, [], '', false);
551552

552553
$r = new \ReflectionMethod($media, 'buildCommand');
553554
$r->setAccessible(true);
@@ -679,7 +680,7 @@ public function testCheckOutput()
679680

680681
try {
681682
$r->invokeArgs($media, ['the_output_file', 'the command']);
682-
$this->anything($message);
683+
$this->anything();
683684
} catch (\RuntimeException $e) {
684685
$this->fail($message);
685686
}
@@ -712,7 +713,7 @@ public function testCheckOutputWhenTheFileDoesNotExist()
712713
$r->invokeArgs($media, ['the_output_file', 'the command']);
713714
$this->fail($message);
714715
} catch (\RuntimeException $e) {
715-
$this->anything($message);
716+
$this->anything();
716717
}
717718
}
718719

@@ -750,7 +751,7 @@ public function testCheckOutputWhenTheFileIsEmpty()
750751
$r->invokeArgs($media, ['the_output_file', 'the command']);
751752
$this->fail($message);
752753
} catch (\RuntimeException $e) {
753-
$this->anything($message);
754+
$this->anything();
754755
}
755756
}
756757

@@ -767,14 +768,14 @@ public function testCheckProcessStatus()
767768

768769
try {
769770
$r->invokeArgs($media, [0, '', '', 'the command']);
770-
$this->anything('0 status means success');
771+
$this->anything();
771772
} catch (\RuntimeException $e) {
772773
$this->fail('0 status means success');
773774
}
774775

775776
try {
776777
$r->invokeArgs($media, [1, '', '', 'the command']);
777-
$this->anything('1 status means failure, but no stderr content');
778+
$this->anything();
778779
} catch (\RuntimeException $e) {
779780
$this->fail('1 status means failure, but no stderr content');
780781
}
@@ -792,7 +793,7 @@ public function testCheckProcessStatus()
792793
*/
793794
public function testIsAssociativeArray($array, $isAssociativeArray)
794795
{
795-
$generator = $this->getMockForAbstractClass('Knp\Snappy\AbstractGenerator', [], '', false);
796+
$generator = $this->getMockForAbstractClass(AbstractGenerator::class, [], '', false);
796797

797798
$r = new \ReflectionMethod($generator, 'isAssociativeArray');
798799
$r->setAccessible(true);

tests/Knp/Snappy/ImageTest.php

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Tests\Knp\Snappy;
4+
5+
use Knp\Snappy\Image;
6+
use PHPUnit\Framework\TestCase;
7+
8+
class ImageTest extends TestCase
9+
{
10+
public function testCreateInstance()
11+
{
12+
$testObject = new Image();
13+
$this->assertInstanceOf(Image::class, $testObject);
14+
}
15+
}

test/Knp/Snappy/PdfTest.php tests/Knp/Snappy/PdfTest.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?php
22

3-
namespace Knp\Snappy;
3+
namespace Tests\Knp\Snappy;
44

5+
use Knp\Snappy\Pdf;
56
use PHPUnit\Framework\Error\Error;
67
use PHPUnit\Framework\TestCase;
78

@@ -40,8 +41,8 @@ function ($filename) {
4041

4142
public function testCreateInstance()
4243
{
43-
$testObject = new \Knp\Snappy\Pdf();
44-
$this->assertInstanceOf('\Knp\Snappy\Pdf', $testObject);
44+
$testObject = new Pdf();
45+
$this->assertInstanceOf(Pdf::class, $testObject);
4546
}
4647

4748
public function testThatSomethingUsingTmpFolder()

0 commit comments

Comments
 (0)