Skip to content

Commit

Permalink
support reporting of native type coverage percentages in summary (#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm authored Nov 12, 2022
1 parent 99fae36 commit 2bf0e81
Show file tree
Hide file tree
Showing 31 changed files with 553 additions and 83 deletions.
27 changes: 14 additions & 13 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions config/native-type-coverage.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
services:
-
class: Symplify\PHPStanRules\Rules\Explicit\PropertyTypeDeclarationSeaLevelRule
tags: [phpstan.rules.rule]
arguments:
minimalLevel: 0.99
printSuggestions: false

-
class: Symplify\PHPStanRules\Rules\Explicit\ParamTypeDeclarationSeaLevelRule
tags: [phpstan.rules.rule]
arguments:
minimalLevel: 0.99
printSuggestions: false

-
class: Symplify\PHPStanRules\Rules\Explicit\ReturnTypeDeclarationSeaLevelRule
tags: [phpstan.rules.rule]
arguments:
minimalLevel: 0.99
printSuggestions: false

# for "type declaration sea level"
-
class: Symplify\PHPStanRules\Collector\FunctionLike\ParamTypeSeaLevelCollector
tags: [phpstan.collector]

-
class: Symplify\PHPStanRules\Collector\FunctionLike\ReturnTypeSeaLevelCollector
tags: [phpstan.collector]

-
class: Symplify\PHPStanRules\Collector\ClassLike\PropertyTypeSeaLevelCollector
tags: [phpstan.collector]
4 changes: 3 additions & 1 deletion default-config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

includes:
- vendor/spaze/phpstan-disallowed-calls/extension.neon
# required for dead-code.neon and code-complexity.neon
# required for dead-code.neon, code-complexity.neon, native-type-coverage.neon
- vendor/symplify/phpstan-rules/config/services/services.neon
# enable native type coverage per default.
- config/native-type-coverage.neon

parameters:
level: 5
Expand Down
7 changes: 6 additions & 1 deletion lib/RexStanUserConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

final class RexStanUserConfig
{
/**
* Cache key to invalidate the summary signature in case of default-config.neon changes.
*/
const DEFAULT_SETTINGS_VERSION = 'v1-native-type-coverage';

/**
* @param list<string> $paths
* @param list<string> $includes
Expand Down Expand Up @@ -66,7 +71,7 @@ public static function getSignature(): string
if (!$md5) {
throw new \PHPStan\ShouldNotHappenException();
}
return $md5;
return self::DEFAULT_SETTINGS_VERSION.'|'.$md5;
}

/**
Expand Down
5 changes: 5 additions & 0 deletions pages/analysis.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ function randomInRange(min, max) {
$section->setVar('sectionAttributes', ['class' => 'rexstan'], false);

foreach ($phpstanResult['files'] as $file => $fileResult) {
// skip project wide errors, which don't relate to a single file
if ($file === 'N/A') {
continue;
}

$shortFile = str_replace($basePath, '', $file);
$linkFile = preg_replace('/\s\(in context.*?$/', '', $file);
$title = '<i class="rexstan-open fa fa-folder-o"></i>'.
Expand Down
22 changes: 20 additions & 2 deletions pages/summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
<table class="table table-striped table-hover" style="width: auto;">
<tbody>
<tr>
<th class="info">Fehlerklasse</th>
<td>Errors</td>
<th class="info" style="width: 200px">Fehlerklasse</th>
<td>Overall-Errors</td>
<td>Cognitive-Complexity</td>
<td>Deprecations</td>
<td>Invalide PHPDocs</td>
Expand All @@ -36,4 +36,22 @@
</tr>
</tbody>
</table>

<table class="table table-striped table-hover" style="width: auto;">
<tbody>
<tr>
<th class="info" style="width: 200px">Native Type Coverage</th>
<td>Class Property Types</td>
<td>Parameter Types</td>
<td>Return Types</td>
</tr>
<tr>
<th class="info">Fortschritt in %</th>
<td><?= $result[ResultPrinter::KEY_PROPERTY_TYPE_COVERAGE] ?></td>
<td><?= $result[ResultPrinter::KEY_PARAM_TYPE_COVERAGE] ?></td>
<td><?= $result[ResultPrinter::KEY_RETURN_TYPE_COVERAGE] ?></td>
</tr>
</tbody>
</table>

<p>Die Zusammenfassung ist abhängig von den in den <a href="<?= $settingsUrl ?>">Einstellungen</a> definierten PHPStan-Extensions</p>
31 changes: 16 additions & 15 deletions vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -245,17 +245,17 @@
},
{
"name": "nikic/php-parser",
"version": "v4.15.1",
"version_normalized": "4.15.1.0",
"version": "v4.15.2",
"version_normalized": "4.15.2.0",
"source": {
"type": "git",
"url": "https://github.com/nikic/PHP-Parser.git",
"reference": "0ef6c55a3f47f89d7a374e6f835197a0b5fcf900"
"reference": "f59bbe44bf7d96f24f3e2b4ddc21cd52c1d2adbc"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/0ef6c55a3f47f89d7a374e6f835197a0b5fcf900",
"reference": "0ef6c55a3f47f89d7a374e6f835197a0b5fcf900",
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/f59bbe44bf7d96f24f3e2b4ddc21cd52c1d2adbc",
"reference": "f59bbe44bf7d96f24f3e2b4ddc21cd52c1d2adbc",
"shasum": ""
},
"require": {
Expand All @@ -266,7 +266,7 @@
"ircmaxell/php-yacc": "^0.0.7",
"phpunit/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0"
},
"time": "2022-09-04T07:30:47+00:00",
"time": "2022-11-12T15:38:23+00:00",
"bin": [
"bin/php-parse"
],
Expand Down Expand Up @@ -298,7 +298,7 @@
],
"support": {
"issues": "https://github.com/nikic/PHP-Parser/issues",
"source": "https://github.com/nikic/PHP-Parser/tree/v4.15.1"
"source": "https://github.com/nikic/PHP-Parser/tree/v4.15.2"
},
"install-path": "../nikic/php-parser"
},
Expand Down Expand Up @@ -710,17 +710,17 @@
},
{
"name": "staabm/phpstan-baseline-analysis",
"version": "0.9",
"version_normalized": "0.9.0.0",
"version": "0.9.1",
"version_normalized": "0.9.1.0",
"source": {
"type": "git",
"url": "https://github.com/staabm/phpstan-baseline-analysis.git",
"reference": "8116766e5595d34251a6e4e7c5084c1e0681e9d3"
"reference": "a8d992891f69b9abd1eee89efb642b9b1caf4204"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/staabm/phpstan-baseline-analysis/zipball/8116766e5595d34251a6e4e7c5084c1e0681e9d3",
"reference": "8116766e5595d34251a6e4e7c5084c1e0681e9d3",
"url": "https://api.github.com/repos/staabm/phpstan-baseline-analysis/zipball/a8d992891f69b9abd1eee89efb642b9b1caf4204",
"reference": "a8d992891f69b9abd1eee89efb642b9b1caf4204",
"shasum": ""
},
"require": {
Expand All @@ -730,12 +730,13 @@
"thecodingmachine/safe": "^1.3 || ^2.0"
},
"require-dev": {
"phpstan/phpstan": "^1.8",
"phpstan/phpstan": "^1.9",
"phpunit/phpunit": "^9.5",
"symfony/var-dumper": "^5.3",
"symplify/phpstan-rules": "^11.0",
"thecodingmachine/phpstan-safe-rule": "^1.2"
},
"time": "2022-10-13T15:17:23+00:00",
"time": "2022-11-12T21:39:56+00:00",
"bin": [
"bin/phpstan-baseline-analyze",
"bin/phpstan-baseline-trend",
Expand All @@ -754,7 +755,7 @@
],
"support": {
"issues": "https://github.com/staabm/phpstan-baseline-analysis/issues",
"source": "https://github.com/staabm/phpstan-baseline-analysis/tree/0.9"
"source": "https://github.com/staabm/phpstan-baseline-analysis/tree/0.9.1"
},
"funding": [
{
Expand Down
16 changes: 8 additions & 8 deletions vendor/composer/installed.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'name' => '__root__',
'pretty_version' => 'dev-main',
'version' => 'dev-main',
'reference' => '8f2496604468100163a9aadd129f5a72ddc7f7d4',
'reference' => 'dbc33b35c458e338531bdf284f9ac157d9ee02ee',
'type' => 'library',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
Expand All @@ -13,7 +13,7 @@
'__root__' => array(
'pretty_version' => 'dev-main',
'version' => 'dev-main',
'reference' => '8f2496604468100163a9aadd129f5a72ddc7f7d4',
'reference' => 'dbc33b35c458e338531bdf284f9ac157d9ee02ee',
'type' => 'library',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
Expand Down Expand Up @@ -47,9 +47,9 @@
'dev_requirement' => false,
),
'nikic/php-parser' => array(
'pretty_version' => 'v4.15.1',
'version' => '4.15.1.0',
'reference' => '0ef6c55a3f47f89d7a374e6f835197a0b5fcf900',
'pretty_version' => 'v4.15.2',
'version' => '4.15.2.0',
'reference' => 'f59bbe44bf7d96f24f3e2b4ddc21cd52c1d2adbc',
'type' => 'library',
'install_path' => __DIR__ . '/../nikic/php-parser',
'aliases' => array(),
Expand Down Expand Up @@ -119,9 +119,9 @@
'dev_requirement' => false,
),
'staabm/phpstan-baseline-analysis' => array(
'pretty_version' => '0.9',
'version' => '0.9.0.0',
'reference' => '8116766e5595d34251a6e4e7c5084c1e0681e9d3',
'pretty_version' => '0.9.1',
'version' => '0.9.1.0',
'reference' => 'a8d992891f69b9abd1eee89efb642b9b1caf4204',
'type' => 'library',
'install_path' => __DIR__ . '/../staabm/phpstan-baseline-analysis',
'aliases' => array(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ public function haveBracesInRange(int $startPos, int $endPos) {
|| $this->haveTokenInRange($startPos, $endPos, '}');
}

public function haveTagInRange(int $startPos, int $endPos): bool {
return $this->haveTokenInRange($startPos, $endPos, \T_OPEN_TAG)
|| $this->haveTokenInRange($startPos, $endPos, \T_CLOSE_TAG);
}

/**
* Get indentation before token position.
*
Expand Down
18 changes: 7 additions & 11 deletions vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/DNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,7 @@ public static function fromString(string $str, array $attributes = []): DNumber
public static function parse(string $str) : float {
$str = str_replace('_', '', $str);

// if string contains any of .eE just cast it to float
if (false !== strpbrk($str, '.eE')) {
return (float) $str;
}

// otherwise it's an integer notation that overflowed into a float
// if it starts with 0 it's one of the special integer notations
// Check whether this is one of the special integer notations.
if ('0' === $str[0]) {
// hex
if ('x' === $str[1] || 'X' === $str[1]) {
Expand All @@ -65,10 +59,12 @@ public static function parse(string $str) : float {
return bindec($str);
}

// oct
// substr($str, 0, strcspn($str, '89')) cuts the string at the first invalid digit (8 or 9)
// so that only the digits before that are used
return octdec(substr($str, 0, strcspn($str, '89')));
// oct, but only if the string does not contain any of '.eE'.
if (false === strpbrk($str, '.eE')) {
// substr($str, 0, strcspn($str, '89')) cuts the string at the first invalid digit
// (8 or 9) so that only the digits before that are used.
return octdec(substr($str, 0, strcspn($str, '89')));
}
}

// dec
Expand Down
2 changes: 1 addition & 1 deletion vendor/nikic/php-parser/lib/PhpParser/Node/UnionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class UnionType extends ComplexType
{
/** @var (Identifier|Name)[] Types */
/** @var (Identifier|Name|IntersectionType)[] Types */
public $types;

/**
Expand Down
Loading

0 comments on commit 2bf0e81

Please sign in to comment.