Skip to content

Commit 6f9c9bc

Browse files
committed
Phpstan fixes
1 parent 1f2bb5d commit 6f9c9bc

File tree

6 files changed

+58
-13
lines changed

6 files changed

+58
-13
lines changed

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
language: php
22

33
php:
4-
- 7.1
5-
- 7.2
64
- 7.3
75
- 7.4
86

composer.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
}
1010
],
1111
"require": {
12+
"php": "^7.3",
1213
"webmozart/path-util": "^2.3",
1314
"dms/phpunit-arraysubset-asserts": "dev-master",
1415
"phpspec/prophecy-phpunit": "dev-master"
@@ -32,5 +33,12 @@
3233
"branch-alias": {
3334
"dev-master": "1.0.x-dev"
3435
}
36+
},
37+
"scripts": {
38+
"integrate": [
39+
"vendor/bin/php-cs-fixer fix",
40+
"vendor/bin/phpstan analyse lib -c phpstan.neon",
41+
"vendor/bin/phpunit"
42+
]
3543
}
3644
}

lib/ExtractOffset.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
*/
99
class ExtractOffset
1010
{
11-
public static function fromSource($source, $marker = '<>')
11+
/**
12+
* @return array<string>
13+
*/
14+
public static function fromSource(string $source, string $marker = '<>'): array
1215
{
1316
list($source, $offsetStart) = self::extractOffset($source, $marker);
1417
list($source, $offsetEnd) = self::extractOffset($source, $marker);
@@ -19,10 +22,12 @@ public static function fromSource($source, $marker = '<>')
1922
/**
2023
* Extract the byte offset from the given marked source
2124
* and remove the <> mark.
25+
*
26+
* @return array<mixed>
2227
*/
23-
private static function extractOffset($source, $marker)
28+
private static function extractOffset(string $source, string $marker): array
2429
{
25-
$offset = $offset = mb_strpos($source, $marker);
30+
$offset = mb_strpos($source, $marker);
2631

2732
if (!$offset) {
2833
return [ $source, null ];

lib/PHPUnit/TestCase.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace Phpactor\TestUtils\PHPUnit {
4+
5+
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
6+
use PHPUnit\Framework\TestCase as PhpUnitTestCase;
7+
use Prophecy\PhpUnit\ProphecyTrait;
8+
9+
class TestCase extends PhpUnitTestCase
10+
{
11+
use ArraySubsetAsserts;
12+
use ProphecyTrait;
13+
}
14+
}
15+
16+
// add stubs for PHPUnit < 8
17+
// when all packages are using PHPUnit 9 these can be removed
18+
19+
namespace DMS\PHPUnitExtensions\ArraySubset{
20+
if (!trait_exists(ArraySubsetAsserts::class)) {
21+
trait ArraySubsetAsserts
22+
{
23+
}
24+
}
25+
}
26+
27+
namespace Prophecy\PhpUnit {
28+
if (!trait_exists(ProphecyTrait::class)) {
29+
trait ProphecyTrait
30+
{
31+
}
32+
}
33+
}

lib/Workspace.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function getContents(string $path): string
6464
return $contents;
6565
}
6666

67-
public function reset()
67+
public function reset(): void
6868
{
6969
if (file_exists($this->path)) {
7070
$this->remove($this->path);
@@ -84,7 +84,7 @@ public function put(string $path, string $contents): Workspace
8484
return $this;
8585
}
8686

87-
public function mkdir($path): Workspace
87+
public function mkdir(string $path): Workspace
8888
{
8989
$path = $this->path($path);
9090

@@ -100,7 +100,7 @@ public function mkdir($path): Workspace
100100
return $this;
101101
}
102102

103-
public function loadManifest(string $manifest)
103+
public function loadManifest(string $manifest): void
104104
{
105105
foreach ($this->parseManifest($manifest) as $path => $contents) {
106106
$path = $this->path . DIRECTORY_SEPARATOR . $path;
@@ -113,7 +113,10 @@ public function loadManifest(string $manifest)
113113
}
114114
}
115115

116-
private function parseManifest(string $manifest)
116+
/**
117+
* @return array<string>
118+
*/
119+
private function parseManifest(string $manifest): array
117120
{
118121
$lines = explode(PHP_EOL, $manifest);
119122

@@ -144,7 +147,7 @@ private function parseManifest(string $manifest)
144147
}, $buffer);
145148
}
146149

147-
private function remove($path = '')
150+
private function remove(string $path = ''): void
148151
{
149152
if ($path) {
150153
$splFileInfo = new SplFileInfo($path);

phpstan.neon

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
includes:
2-
- vendor/phpstan/phpstan/conf/config.level7.neon
3-
41
parameters:
2+
level: 7
53
inferPrivatePropertyTypeFromConstructor: true
64
ignoreErrors:
75

0 commit comments

Comments
 (0)