Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions build/PHPStan/Build/ApiPhpDocEntrypointProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php declare(strict_types = 1);

namespace PHPStan\Build;

use PhpParser\Node\Expr\MethodCall;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\ParametersAcceptorSelector;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use ShipMonk\PHPStan\DeadCode\Provider\SimpleMethodEntrypointProvider;

final class ApiPhpDocEntrypointProvider extends SimpleMethodEntrypointProvider
{

public function isEntrypointMethod(\ReflectionMethod $method): bool
{
$reflectionClass = $method->getDeclaringClass();
$methodName = $method->getName();

if ($this->isApiClass($reflectionClass)) {
return true;
}

do {
if ($this->isApiMethod($reflectionClass, $methodName)) {
return true;
}

foreach ($reflectionClass->getInterfaces() as $interface) {
if ($this->isApiClass($interface)) {
return true;
}

if ($this->isApiMethod($interface, $methodName)) {
return true;
}
}

$reflectionClass = $reflectionClass->getParentClass();
} while ($reflectionClass !== false);

return false;
}

private function isApiClass(\ReflectionClass $reflection): bool
{
$phpDoc = $reflection->getDocComment();
if ($phpDoc !== false && str_contains($phpDoc, '@api')) {
return true;
}

return false;
}

private function isApiMethod(\ReflectionClass $reflectionClass, string $methodName): bool
{
if (!$reflectionClass->hasMethod($methodName)) {
return false;
}

$phpDoc = $reflectionClass->getMethod($methodName)->getDocComment();
if ($phpDoc !== false && str_contains($phpDoc, '@api')) {
return true;
}

return false;
}
}
9 changes: 9 additions & 0 deletions build/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ includes:
- ../vendor/phpstan/phpstan-phpunit/extension.neon
- ../vendor/phpstan/phpstan-phpunit/rules.neon
- ../vendor/phpstan/phpstan-strict-rules/rules.neon
- ../vendor/shipmonk/dead-code-detector/rules.neon
- ../conf/bleedingEdge.neon
- ../phpstan-baseline.neon
- ../phpstan-baseline.php
Expand Down Expand Up @@ -91,6 +92,10 @@ parameters:
path: ../src/Diagnose/PHPStanDiagnoseExtension.php
- '#^Parameter \#1 \$offsetType of class PHPStan\\Type\\Accessory\\HasOffsetType constructor expects PHPStan\\Type\\Constant\\ConstantIntegerType\|PHPStan\\Type\\Constant\\ConstantStringType#'
- '#^Short ternary operator is not allowed#'

- '#^Unused .*?Factory::create$#' # likely used in DIC
- '#^Unused .*?::__construct$#' # disable dead construct analysis, DIC services might not be autowired

reportStaticMethodSignatures: true
tmpDir: %rootDir%/tmp
stubFiles:
Expand All @@ -111,3 +116,7 @@ services:
class: PHPStan\Internal\ContainerDynamicReturnTypeExtension
tags:
- phpstan.broker.dynamicMethodReturnTypeExtension
-
class: PHPStan\Build\ApiPhpDocEntrypointProvider
tags:
- shipmonk.deadCode.entrypointProvider
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"phpstan/phpstan-strict-rules": "^1.6",
"phpunit/phpunit": "^9.5.4",
"shipmonk/composer-dependency-analyser": "^1.5",
"shipmonk/dead-code-detector": "dev-master",
"shipmonk/name-collision-detector": "^2.0"
},
"config": {
Expand Down
74 changes: 72 additions & 2 deletions composer.lock

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