Skip to content

Commit

Permalink
Merge pull request #168 from Kharhamel/fix/phpstanIgnore
Browse files Browse the repository at this point in the history
fixed a lot of ignored errors
  • Loading branch information
Kharhamel committed Dec 16, 2019
2 parents 4f55454 + 863cb1a commit 04e226d
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -108,7 +108,7 @@
"squizlabs/php_codesniffer": "^3.2"
},
"scripts": {
"phpstan": "phpstan analyse lib -c phpstan.neon --level=7 --no-progress -vvv",
"phpstan": "phpstan analyse lib -c phpstan.neon --level=max --no-progress -vvv",
"cs-fix": "phpcbf",
"cs-check": "phpcs"
},
Expand Down
2 changes: 1 addition & 1 deletion generator/composer.json
Expand Up @@ -23,7 +23,7 @@
"php-coveralls/php-coveralls": "^2.1"
},
"scripts": {
"phpstan": "phpstan analyse src -c phpstan.neon --level=7 --no-progress -vvv",
"phpstan": "phpstan analyse src -c phpstan.neon --level=max --no-progress -vvv",
"cs-fix": "phpcbf",
"cs-check": "phpcs"
},
Expand Down
2 changes: 0 additions & 2 deletions generator/phpstan.neon
@@ -1,6 +1,4 @@
parameters:
ignoreErrors:
- "#subject of function str_replace expects array|string, string|true given#"
- "#createExceptionFile\\(\\) expects string, int|string given#"
includes:
- vendor/thecodingmachine/phpstan-strict-rules/phpstan-strict-rules.neon
20 changes: 16 additions & 4 deletions generator/src/DocPage.php
Expand Up @@ -49,6 +49,9 @@ private function getIsDeprecated(string $file): bool
public function detectFalsyFunction(): bool
{
$file = file_get_contents($this->path);
if ($file === false) {
throw new \RuntimeException('An error occured while reading '.$this->path);
}

if ($this->getIsDeprecated($file)) {
return false;
Expand Down Expand Up @@ -116,6 +119,9 @@ public function detectFalsyFunction(): bool
public function detectNullsyFunction(): bool
{
$file = \file_get_contents($this->path);
if ($file === false) {
throw new \RuntimeException('An error occured while reading '.$this->path);
}

if ($this->getIsDeprecated($file)) {
return false;
Expand All @@ -141,6 +147,9 @@ public function getMethodSynopsis(): array
$cleanedFunctions = [];

$file = \file_get_contents($this->path);
if ($file === false) {
throw new \RuntimeException('An error occured while reading '.$this->path);
}
if (!preg_match_all('/<\/?methodsynopsis[\s\S]*?>[\s\S]*?<\/methodsynopsis>/m', $file, $functions, PREG_SET_ORDER, 0)) {
return [];
}
Expand Down Expand Up @@ -171,6 +180,9 @@ public function getMethodSynopsis(): array
public function loadAndResolveFile(): \SimpleXMLElement
{
$content = \file_get_contents($this->path);
if ($content === false) {
throw new \RuntimeException('An error occured while reading '.$this->path);
}
$strpos = \strpos($content, '?>')+2;
if (!\file_exists(__DIR__.'/../doc/entities/generated.ent')) {
self::buildEntities();
Expand Down Expand Up @@ -237,10 +249,10 @@ private function arrayFlatten(array $array): array

public static function buildEntities(): void
{
$file1 = \file_get_contents(__DIR__.'/../doc/doc-en/en/language-defs.ent');
$file2 = \file_get_contents(__DIR__.'/../doc/doc-en/en/language-snippets.ent');
$file3 = \file_get_contents(__DIR__.'/../doc/doc-en/en/extensions.ent');
$file4 = \file_get_contents(__DIR__.'/../doc/doc-en/doc-base/entities/global.ent');
$file1 = \file_get_contents(__DIR__.'/../doc/doc-en/en/language-defs.ent') ?: '';
$file2 = \file_get_contents(__DIR__.'/../doc/doc-en/en/language-snippets.ent') ?: '';
$file3 = \file_get_contents(__DIR__.'/../doc/doc-en/en/extensions.ent') ?: '';
$file4 = \file_get_contents(__DIR__.'/../doc/doc-en/doc-base/entities/global.ent') ?: '';

$completeFile = $file1 . self::extractXmlHeader($file2) . self::extractXmlHeader($file3) . $file4;

Expand Down
4 changes: 2 additions & 2 deletions generator/src/GenerateCommand.php
Expand Up @@ -47,7 +47,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

foreach ($modules as $moduleName => $foo) {
$fileCreator->createExceptionFile($moduleName);
$fileCreator->createExceptionFile((string) $moduleName);
}

$this->runCsFix($output);
Expand Down Expand Up @@ -106,7 +106,7 @@ private function rmGenerated(): void

private function runCsFix(OutputInterface $output): void
{
$process = new Process('vendor/bin/phpcbf', __DIR__.'/../..');
$process = new Process(['vendor/bin/phpcbf'], __DIR__.'/../..');
$process->setTimeout(600);
$process->run(function ($type, $buffer) use ($output) {
if (Process::ERR === $type) {
Expand Down
4 changes: 2 additions & 2 deletions generator/src/PhpStanFunctions/PhpStanType.php
Expand Up @@ -43,12 +43,12 @@ public function __construct(string $data, bool $writeOnly = false)
//remove 'null' from the list to identify if the signature type should be nullable
if (($nullablePosition = \array_search('null', $returnTypes)) !== false) {
$nullable = true;
\array_splice($returnTypes, $nullablePosition, 1);
\array_splice($returnTypes, (int) $nullablePosition, 1);
}
//remove 'false' from the list to identify if the function return false on error
if (($falsablePosition = \array_search('false', $returnTypes)) !== false) {
$falsable = true;
\array_splice($returnTypes, $falsablePosition, 1);
\array_splice($returnTypes, (int) $falsablePosition, 1);
}
if (\count($returnTypes) === 0) {
throw new \RuntimeException('Error when trying to extract parameter type');
Expand Down

0 comments on commit 04e226d

Please sign in to comment.