Skip to content

Commit

Permalink
[4.1] PHPStan Analysis (#399)
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamCampbell authored Dec 12, 2019
1 parent a6142d2 commit 2394634
Show file tree
Hide file tree
Showing 21 changed files with 111 additions and 49 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
/.github export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/phpstan.neon.dist export-ignore
/phpunit.xml.dist export-ignore
/README.md export-ignore
/UPGRADING.md export-ignore
/vendor-bin export-ignore
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,9 @@ matrix:
dist: bionic
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
script: docker run -it -w /data -v ${PWD}:/data:delegated --entrypoint vendor/bin/phpunit registry.gitlab.com/grahamcampbell/php:7.4
- name: PHPStan
dist: bionic
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
- 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
script: docker run -it -w /data -v ${PWD}:/data:delegated --entrypoint vendor/bin/phpstan registry.gitlab.com/grahamcampbell/php:7.4 analyse src
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"symfony/polyfill-ctype": "^1.9"
},
"require-dev": {
"phpunit/phpunit": "^4.8.35 || ^5.0 || ^6.0 || ^7.0"
"phpunit/phpunit": "^4.8.35 || ^5.0 || ^6.0 || ^7.0",
"bamarni/composer-bin-plugin": "^1.3"
},
"autoload": {
"psr-4": {
Expand Down
10 changes: 10 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
parameters:
level: max
ignoreErrors:
- '#Method Dotenv\\Loader\\Parser::processChar\(\) should return Dotenv\\Result\\Result<array<int, bool\|int\|string>, string> but return statement is missing.#'
- '#Method Dotenv\\Repository\\AdapterRepository::getInternal\(\) should return string\|null but return statement is missing.#'
- '#Variable \$defaults might not be defined.#'
- '/^Parameter \#1 \$readers of class Dotenv\\Repository\\[a-zA-Z]*Repository[a-zA-Z]* constructor expects/'
- '/^Parameter \#2 \$writers of class Dotenv\\Repository\\[a-zA-Z]*Repository[a-zA-Z]* constructor expects/'
- '#Method Dotenv\\Repository\\AbstractRepository::offset[a-zA-Z\(\)\$ ]* typehint specified.#'
- '#Method Dotenv\\Loader\\Lines::getCharPairs\(\) should return array\(array\(string, string\|null\)\) but returns array\<int, mixed\>.#'
4 changes: 2 additions & 2 deletions src/Loader/Lines.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static function process(array $lines)
* @param string $line
* @param string[] $buffer
*
* @return array
* @return array{bool,string,string[]}
*/
private static function multilineProcess($multiline, $line, array $buffer)
{
Expand Down Expand Up @@ -105,7 +105,7 @@ private static function looksLikeMultilineStop($line, $started)
*
* @param string $line
*
* @return bool[]
* @return array{array{string,string|null}}
*/
private static function getCharPairs($line)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Loader/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function load(RepositoryInterface $repository, $content)
{
return self::processEntries(
$repository,
Lines::process(preg_split("/(\r\n|\n|\r)/", $content))
Lines::process(Regex::split("/(\r\n|\n|\r)/", $content)->getSuccess())
);
}

Expand Down
8 changes: 4 additions & 4 deletions src/Loader/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Parser
*
* @throws \Dotenv\Exception\InvalidFileException
*
* @return array<string|null>
* @return array{string,\Dotenv\Loader\Value|null}
*/
public static function parse($entry)
{
Expand All @@ -39,7 +39,7 @@ public static function parse($entry)
*
* @throws \Dotenv\Exception\InvalidFileException
*
* @return array<string|null>
* @return array{string,string|null}
*/
private static function splitStringIntoParts($line)
{
Expand Down Expand Up @@ -105,7 +105,7 @@ private static function isValidName($name)
private static function parseValue($value)
{
if ($value === null) {
return;
return null;
}

if (trim($value) === '') {
Expand All @@ -129,7 +129,7 @@ private static function parseValue($value)
* @param int $state
* @param string $char
*
* @return \Dotenv\Result\Result
* @return \Dotenv\Result\Result<array{string,bool,int},string>
*/
private static function processChar($state, $char)
{
Expand Down
29 changes: 23 additions & 6 deletions src/Regex/Regex.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Regex
* @param string $pattern
* @param string $subject
*
* @return \Dotenv\Result\Result
* @return \Dotenv\Result\Result<int,string>
*/
public static function match($pattern, $subject)
{
Expand All @@ -32,7 +32,7 @@ public static function match($pattern, $subject)
* @param string $subject
* @param int|null $limit
*
* @return \Dotenv\Result\Result
* @return \Dotenv\Result\Result<string,string>
*/
public static function replace($pattern, $replacement, $subject, $limit = null)
{
Expand All @@ -49,7 +49,7 @@ public static function replace($pattern, $replacement, $subject, $limit = null)
* @param string $subject
* @param int|null $limit
*
* @return \Dotenv\Result\Result
* @return \Dotenv\Result\Result<string,string>
*/
public static function replaceCallback($pattern, callable $callback, $subject, $limit = null)
{
Expand All @@ -58,13 +58,30 @@ public static function replaceCallback($pattern, callable $callback, $subject, $
}, $subject);
}

/**
* Perform a preg split, wrapping up the result.
*
* @param string $pattern
* @param string $subject
*
* @return \Dotenv\Result\Result<string[],string>
*/
public static function split($pattern, $subject)
{
return self::pregAndWrap(function ($subject) use ($pattern) {
return (array) @preg_split($pattern, $subject);
}, $subject);
}

/**
* Perform a preg operation, wrapping up the result.
*
* @param callable $operation
* @param string $subject
* @template V
*
* @param callable(string): V $operation
* @param string $subject
*
* @return \Dotenv\Result\Result
* @return \Dotenv\Result\Result<V,string>
*/
private static function pregAndWrap(callable $operation, $subject)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Repository/Adapter/ApacheAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function isSupported()
*
* @param string $name
*
* @return \PhpOption\Option
* @return \PhpOption\Option<string>
*/
public function get($name)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Repository/Adapter/ArrayAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ArrayAdapter implements AvailabilityInterface, ReaderInterface, WriterInte
/**
* The variables and their values.
*
* @return array<string,string|null>
* @var array<string,string|null>
*/
private $variables = [];

Expand All @@ -29,7 +29,7 @@ public function isSupported()
*
* @param string $name
*
* @return \PhpOption\Option
* @return \PhpOption\Option<string>
*/
public function get($name)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Repository/Adapter/EnvConstAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function isSupported()
*
* @param string $name
*
* @return \PhpOption\Option
* @return \PhpOption\Option<string>
*/
public function get($name)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Repository/Adapter/PutenvAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function isSupported()
*
* @param string $name
*
* @return \PhpOption\Option
* @return \PhpOption\Option<string>
*/
public function get($name)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Repository/Adapter/ReaderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface ReaderInterface extends AvailabilityInterface
*
* @param string $name
*
* @return \PhpOption\Option
* @return \PhpOption\Option<string>
*/
public function get($name);
}
2 changes: 1 addition & 1 deletion src/Repository/Adapter/ServerConstAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function isSupported()
*
* @param string $name
*
* @return \PhpOption\Option
* @return \PhpOption\Option<string>
*/
public function get($name)
{
Expand Down
10 changes: 5 additions & 5 deletions src/Repository/RepositoryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ class RepositoryBuilder
/**
* Create a new repository builder instance.
*
* @param \Dotenv\Repository\Adapter\ReaderInterface[]|null
* @param \Dotenv\Repository\Adapter\WriterInterface[]|null
* @param bool $immutable
* @param \Dotenv\Repository\Adapter\ReaderInterface[]|null $readers
* @param \Dotenv\Repository\Adapter\WriterInterface[]|null $writers
* @param bool $immutable
*
* @return void
*/
Expand All @@ -60,7 +60,7 @@ public static function create()
/**
* Creates a repository builder with the given readers.
*
* @param \Dotenv\Repository\Adapter\ReaderInterface[]|null
* @param \Dotenv\Repository\Adapter\ReaderInterface[]|null $readers
*
* @return \Dotenv\Repository\RepositoryBuilder
*/
Expand All @@ -74,7 +74,7 @@ public function withReaders(array $readers = null)
/**
* Creates a repository builder with the given writers.
*
* @param \Dotenv\Repository\Adapter\WriterInterface[]|null
* @param \Dotenv\Repository\Adapter\WriterInterface[]|null $writers
*
* @return \Dotenv\Repository\RepositoryBuilder
*/
Expand Down
3 changes: 3 additions & 0 deletions src/Repository/RepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use ArrayAccess;

/**
* @extends \ArrayAccess<string,string|null>
*/
interface RepositoryInterface extends ArrayAccess
{
/**
Expand Down
21 changes: 13 additions & 8 deletions src/Result/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,22 @@
use PhpOption\None;
use PhpOption\Some;

/**
* @template T
* @template E
* @extends \Dotenv\Result\Result<T,E>
*/
class Error extends Result
{
/**
* @var mixed
* @var E
*/
private $value;

/**
* Internal constructor for an error value.
*
* @param mixed $value
* @param E $value
*
* @return void
*/
Expand All @@ -27,9 +32,9 @@ private function __construct($value)
/**
* Create a new error value.
*
* @param mixed $value
* @param E $value
*
* @return \Dotenv\Result\Result
* @return \Dotenv\Result\Result<T,E>
*/
public static function create($value)
{
Expand All @@ -39,7 +44,7 @@ public static function create($value)
/**
* Get the success option value.
*
* @return \PhpOption\Option
* @return \PhpOption\Option<T>
*/
public function success()
{
Expand All @@ -51,7 +56,7 @@ public function success()
*
* @param callable $f
*
* @return \Dotenv\Result\Result
* @return \Dotenv\Result\Result<T,E>
*/
public function mapSuccess(callable $f)
{
Expand All @@ -61,7 +66,7 @@ public function mapSuccess(callable $f)
/**
* Get the error option value.
*
* @return \PhpOption\Option
* @return \PhpOption\Option<E>
*/
public function error()
{
Expand All @@ -73,7 +78,7 @@ public function error()
*
* @param callable $f
*
* @return \Dotenv\Result\Result
* @return \Dotenv\Result\Result<T,E>
*/
public function mapError(callable $f)
{
Expand Down
Loading

0 comments on commit 2394634

Please sign in to comment.