-
Notifications
You must be signed in to change notification settings - Fork 426
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e0d63b0
commit 030bd55
Showing
8 changed files
with
131 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Rules\Methods; | ||
|
||
use PHPStan\Reflection\MethodReflection; | ||
|
||
/** | ||
* This is the extension interface to implement if you want to describe an always-used class method. | ||
* | ||
* To register it in the configuration file use the `phpstan.methods.alwaysUsedMethodExtension` service tag: | ||
* | ||
* ``` | ||
* services: | ||
* - | ||
* class: App\PHPStan\MyExtension | ||
* tags: | ||
* - phpstan.methods.alwaysUsedMethodExtension | ||
* ``` | ||
* | ||
* @api | ||
*/ | ||
interface AlwaysUsedMethodExtension | ||
{ | ||
|
||
public function isAlwaysUsed(MethodReflection $methodReflection): bool; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Rules\Methods; | ||
|
||
interface AlwaysUsedMethodExtensionProvider | ||
{ | ||
|
||
public const EXTENSION_TAG = 'phpstan.methods.alwaysUsedMethodExtension'; | ||
|
||
/** | ||
* @return AlwaysUsedMethodExtension[] | ||
*/ | ||
public function getExtensions(): array; | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
src/Rules/Methods/DirectAlwaysUsedMethodExtensionProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Rules\Methods; | ||
|
||
class DirectAlwaysUsedMethodExtensionProvider implements AlwaysUsedMethodExtensionProvider | ||
{ | ||
|
||
/** | ||
* @param AlwaysUsedMethodExtension[] $extensions | ||
*/ | ||
public function __construct(private array $extensions) | ||
{ | ||
} | ||
|
||
public function getExtensions(): array | ||
{ | ||
return $this->extensions; | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
src/Rules/Methods/LazyAlwaysUsedMethodExtensionProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Rules\Methods; | ||
|
||
use PHPStan\DependencyInjection\Container; | ||
|
||
class LazyAlwaysUsedMethodExtensionProvider implements AlwaysUsedMethodExtensionProvider | ||
{ | ||
|
||
/** @var AlwaysUsedMethodExtension[]|null */ | ||
private ?array $extensions = null; | ||
|
||
public function __construct(private Container $container) | ||
{ | ||
} | ||
|
||
public function getExtensions(): array | ||
{ | ||
return $this->extensions ??= $this->container->getServicesByTag(static::EXTENSION_TAG); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters