Skip to content

Commit 2394634

Browse files
[4.1] PHPStan Analysis (#399)
1 parent a6142d2 commit 2394634

21 files changed

+111
-49
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
/.github export-ignore
66
/.gitignore export-ignore
77
/.travis.yml export-ignore
8+
/phpstan.neon.dist export-ignore
89
/phpunit.xml.dist export-ignore
910
/README.md export-ignore
1011
/UPGRADING.md export-ignore
12+
/vendor-bin export-ignore

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,9 @@ matrix:
3636
dist: bionic
3737
install: travis_retry docker run -it -w /data -v ${PWD}:/data:delegated --entrypoint composer registry.gitlab.com/grahamcampbell/php:7.4 install --no-suggest --prefer-dist -n -o
3838
script: docker run -it -w /data -v ${PWD}:/data:delegated --entrypoint vendor/bin/phpunit registry.gitlab.com/grahamcampbell/php:7.4
39+
- name: PHPStan
40+
dist: bionic
41+
install:
42+
- travis_retry docker run -it -w /data -v ${PWD}:/data:delegated --entrypoint composer registry.gitlab.com/grahamcampbell/php:7.4 install --no-suggest --prefer-dist -n -o
43+
- travis_retry docker run -it -w /data -v ${PWD}:/data:delegated --entrypoint composer registry.gitlab.com/grahamcampbell/php:7.4 bin phpstan install --no-suggest --prefer-dist -n -o
44+
script: docker run -it -w /data -v ${PWD}:/data:delegated --entrypoint vendor/bin/phpstan registry.gitlab.com/grahamcampbell/php:7.4 analyse src

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"symfony/polyfill-ctype": "^1.9"
2222
},
2323
"require-dev": {
24-
"phpunit/phpunit": "^4.8.35 || ^5.0 || ^6.0 || ^7.0"
24+
"phpunit/phpunit": "^4.8.35 || ^5.0 || ^6.0 || ^7.0",
25+
"bamarni/composer-bin-plugin": "^1.3"
2526
},
2627
"autoload": {
2728
"psr-4": {

phpstan.neon.dist

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
parameters:
2+
level: max
3+
ignoreErrors:
4+
- '#Method Dotenv\\Loader\\Parser::processChar\(\) should return Dotenv\\Result\\Result<array<int, bool\|int\|string>, string> but return statement is missing.#'
5+
- '#Method Dotenv\\Repository\\AdapterRepository::getInternal\(\) should return string\|null but return statement is missing.#'
6+
- '#Variable \$defaults might not be defined.#'
7+
- '/^Parameter \#1 \$readers of class Dotenv\\Repository\\[a-zA-Z]*Repository[a-zA-Z]* constructor expects/'
8+
- '/^Parameter \#2 \$writers of class Dotenv\\Repository\\[a-zA-Z]*Repository[a-zA-Z]* constructor expects/'
9+
- '#Method Dotenv\\Repository\\AbstractRepository::offset[a-zA-Z\(\)\$ ]* typehint specified.#'
10+
- '#Method Dotenv\\Loader\\Lines::getCharPairs\(\) should return array\(array\(string, string\|null\)\) but returns array\<int, mixed\>.#'

src/Loader/Lines.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static function process(array $lines)
3737
* @param string $line
3838
* @param string[] $buffer
3939
*
40-
* @return array
40+
* @return array{bool,string,string[]}
4141
*/
4242
private static function multilineProcess($multiline, $line, array $buffer)
4343
{
@@ -105,7 +105,7 @@ private static function looksLikeMultilineStop($line, $started)
105105
*
106106
* @param string $line
107107
*
108-
* @return bool[]
108+
* @return array{array{string,string|null}}
109109
*/
110110
private static function getCharPairs($line)
111111
{

src/Loader/Loader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function load(RepositoryInterface $repository, $content)
2222
{
2323
return self::processEntries(
2424
$repository,
25-
Lines::process(preg_split("/(\r\n|\n|\r)/", $content))
25+
Lines::process(Regex::split("/(\r\n|\n|\r)/", $content)->getSuccess())
2626
);
2727
}
2828

src/Loader/Parser.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Parser
2323
*
2424
* @throws \Dotenv\Exception\InvalidFileException
2525
*
26-
* @return array<string|null>
26+
* @return array{string,\Dotenv\Loader\Value|null}
2727
*/
2828
public static function parse($entry)
2929
{
@@ -39,7 +39,7 @@ public static function parse($entry)
3939
*
4040
* @throws \Dotenv\Exception\InvalidFileException
4141
*
42-
* @return array<string|null>
42+
* @return array{string,string|null}
4343
*/
4444
private static function splitStringIntoParts($line)
4545
{
@@ -105,7 +105,7 @@ private static function isValidName($name)
105105
private static function parseValue($value)
106106
{
107107
if ($value === null) {
108-
return;
108+
return null;
109109
}
110110

111111
if (trim($value) === '') {
@@ -129,7 +129,7 @@ private static function parseValue($value)
129129
* @param int $state
130130
* @param string $char
131131
*
132-
* @return \Dotenv\Result\Result
132+
* @return \Dotenv\Result\Result<array{string,bool,int},string>
133133
*/
134134
private static function processChar($state, $char)
135135
{

src/Regex/Regex.php

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Regex
1515
* @param string $pattern
1616
* @param string $subject
1717
*
18-
* @return \Dotenv\Result\Result
18+
* @return \Dotenv\Result\Result<int,string>
1919
*/
2020
public static function match($pattern, $subject)
2121
{
@@ -32,7 +32,7 @@ public static function match($pattern, $subject)
3232
* @param string $subject
3333
* @param int|null $limit
3434
*
35-
* @return \Dotenv\Result\Result
35+
* @return \Dotenv\Result\Result<string,string>
3636
*/
3737
public static function replace($pattern, $replacement, $subject, $limit = null)
3838
{
@@ -49,7 +49,7 @@ public static function replace($pattern, $replacement, $subject, $limit = null)
4949
* @param string $subject
5050
* @param int|null $limit
5151
*
52-
* @return \Dotenv\Result\Result
52+
* @return \Dotenv\Result\Result<string,string>
5353
*/
5454
public static function replaceCallback($pattern, callable $callback, $subject, $limit = null)
5555
{
@@ -58,13 +58,30 @@ public static function replaceCallback($pattern, callable $callback, $subject, $
5858
}, $subject);
5959
}
6060

61+
/**
62+
* Perform a preg split, wrapping up the result.
63+
*
64+
* @param string $pattern
65+
* @param string $subject
66+
*
67+
* @return \Dotenv\Result\Result<string[],string>
68+
*/
69+
public static function split($pattern, $subject)
70+
{
71+
return self::pregAndWrap(function ($subject) use ($pattern) {
72+
return (array) @preg_split($pattern, $subject);
73+
}, $subject);
74+
}
75+
6176
/**
6277
* Perform a preg operation, wrapping up the result.
6378
*
64-
* @param callable $operation
65-
* @param string $subject
79+
* @template V
80+
*
81+
* @param callable(string): V $operation
82+
* @param string $subject
6683
*
67-
* @return \Dotenv\Result\Result
84+
* @return \Dotenv\Result\Result<V,string>
6885
*/
6986
private static function pregAndWrap(callable $operation, $subject)
7087
{

src/Repository/Adapter/ApacheAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function isSupported()
2626
*
2727
* @param string $name
2828
*
29-
* @return \PhpOption\Option
29+
* @return \PhpOption\Option<string>
3030
*/
3131
public function get($name)
3232
{

src/Repository/Adapter/ArrayAdapter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class ArrayAdapter implements AvailabilityInterface, ReaderInterface, WriterInte
1010
/**
1111
* The variables and their values.
1212
*
13-
* @return array<string,string|null>
13+
* @var array<string,string|null>
1414
*/
1515
private $variables = [];
1616

@@ -29,7 +29,7 @@ public function isSupported()
2929
*
3030
* @param string $name
3131
*
32-
* @return \PhpOption\Option
32+
* @return \PhpOption\Option<string>
3333
*/
3434
public function get($name)
3535
{

0 commit comments

Comments
 (0)