Skip to content

Commit e7c0549

Browse files
danopzakrabat
authored andcommitted
add phpstan for static code analysis
1 parent f1c37fa commit e7c0549

File tree

6 files changed

+18
-16
lines changed

6 files changed

+18
-16
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ script:
2020
- if [[ "$TRAVIS_PHP_VERSION" == '7.0' ]]; then mkdir -p build/logs && phpunit --coverage-clover build/logs/clover.xml ; fi
2121
- if [[ "$TRAVIS_PHP_VERSION" != '7.0' ]]; then vendor/bin/phpunit ; fi
2222
- if [[ "$TRAVIS_PHP_VERSION" == '7.0' ]]; then vendor/bin/phpcs ; fi
23+
- vendor/bin/phpstan analyse -l 3 src/
2324

2425
after_script:
2526
- if [[ "$TRAVIS_PHP_VERSION" == '7.0' ]]; then php vendor/bin/coveralls -v ; fi

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"require-dev": {
3030
"squizlabs/php_codesniffer": "^2.5",
3131
"phpunit/phpunit": "^6.0|^7.0",
32-
"php-http/psr7-integration-tests": "dev-master"
32+
"php-http/psr7-integration-tests": "dev-master",
33+
"phpstan/phpstan": "^0.9"
3334
},
3435
"provide": {
3536
"psr/http-message-implementation": "1.0"

src/Cookies.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ protected function toHeader($name, array $properties)
156156
* Parse HTTP request `Cookie:` header and extract
157157
* into a PHP associative array.
158158
*
159-
* @param string $header The raw HTTP request `Cookie:` header
159+
* @param string|string[] $header The raw HTTP request `Cookie:` header
160160
*
161161
* @return array Associative array of cookie names and values
162162
*

src/Request.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ class Request extends Message implements ServerRequestInterface
7474
/**
7575
* The request attributes (route segment names and values)
7676
*
77-
* @var \Slim\Collection
77+
* @var Collection
7878
*/
7979
protected $attributes;
8080

8181
/**
8282
* The request body parsed (if possible) into a PHP array or object
8383
*
84-
* @var null|array|object
84+
* @var null|array|object|false
8585
*/
8686
protected $bodyParsed = false;
8787

@@ -263,13 +263,13 @@ public function withMethod($method)
263263
* Validate the HTTP method
264264
*
265265
* @param null|string $method
266-
* @return null|string
266+
* @return string
267267
* @throws \InvalidArgumentException on invalid HTTP method.
268268
*/
269269
protected function filterMethod($method)
270270
{
271271
if ($method === null) {
272-
return $method;
272+
return '';
273273
}
274274

275275
if (!is_string($method)) {
@@ -1051,7 +1051,7 @@ public function registerMediaTypeParser($mediaType, callable $callable)
10511051
if ($callable instanceof Closure) {
10521052
$callable = $callable->bindTo($this);
10531053
}
1054-
$this->bodyParsers[(string)$mediaType] = $callable;
1054+
$this->bodyParsers[$mediaType] = $callable;
10551055
}
10561056

10571057
/*******************************************************************************

src/Stream.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -40,35 +40,35 @@ class Stream implements StreamInterface
4040
/**
4141
* The underlying stream resource
4242
*
43-
* @var resource
43+
* @var resource|null
4444
*/
4545
protected $stream;
4646

4747
/**
4848
* Stream metadata
4949
*
50-
* @var array
50+
* @var array|null
5151
*/
5252
protected $meta;
5353

5454
/**
5555
* Is this stream readable?
5656
*
57-
* @var bool
57+
* @var bool|null
5858
*/
5959
protected $readable;
6060

6161
/**
6262
* Is this stream writable?
6363
*
64-
* @var bool
64+
* @var bool|null
6565
*/
6666
protected $writable;
6767

6868
/**
6969
* Is this stream seekable?
7070
*
71-
* @var bool
71+
* @var bool|null
7272
*/
7373
protected $seekable;
7474

@@ -82,7 +82,7 @@ class Stream implements StreamInterface
8282
/**
8383
* Is this stream a pipe?
8484
*
85-
* @var bool
85+
* @var bool|null
8686
*/
8787
protected $isPipe;
8888

src/Uri.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ protected function filterScheme($scheme)
275275
throw new InvalidArgumentException('Uri scheme must be a string');
276276
}
277277

278-
$scheme = str_replace('://', '', strtolower((string)$scheme));
278+
$scheme = str_replace('://', '', strtolower($scheme));
279279
if (!isset($valid[$scheme])) {
280280
throw new InvalidArgumentException('Uri scheme must be one of: "", "https", "http"');
281281
}
@@ -656,7 +656,7 @@ public function withQuery($query)
656656
if (!is_string($query) && !method_exists($query, '__toString')) {
657657
throw new InvalidArgumentException('Uri query must be a string');
658658
}
659-
$query = ltrim((string)$query, '?');
659+
$query = ltrim($query, '?');
660660
$clone = clone $this;
661661
$clone->query = $this->filterQuery($query);
662662

@@ -724,7 +724,7 @@ public function withFragment($fragment)
724724
if (!is_string($fragment) && !method_exists($fragment, '__toString')) {
725725
throw new InvalidArgumentException('Uri fragment must be a string');
726726
}
727-
$fragment = ltrim((string)$fragment, '#');
727+
$fragment = ltrim($fragment, '#');
728728
$clone = clone $this;
729729
$clone->fragment = $this->filterQuery($fragment);
730730

0 commit comments

Comments
 (0)