[Feature] Pointcut namespace refactoring#500
Conversation
This major refactoring removed the duplication around PointFilter and Pointcut. PHP8 features and types have been applied to the namespace for strong typing. Now only one Pointcut interface is responsible for matching of joinpoint. New tests were added, PhpStan level 9 check achieved for the Pointcut namespace now. Signature of Pointcut has been changed to highlight logic of 3-stage matching. Now first element of Pointcut->matches() is always context to streamline optimizations. IntroductionAdvisor has been removed too to unify logic inside GenericPointcutAdvisor. All filters from the Support namespace have been removed or refactored/renamed into pointcuts.
|
A new inspection was created. |
| */ | ||
| public function __construct( | ||
| private PointFilter $pointFilter, | ||
| private Pointcut $pointcut, |
There was a problem hiding this comment.
Line indented incorrectly; expected 4 spaces, found 8
| object|string $instanceOrScope = null, | ||
| array $arguments = null | ||
| ): bool; | ||
| } No newline at end of file |
There was a problem hiding this comment.
Expected 1 newline at end of file; 0 found
| ReflectionMethod|ReflectionProperty|ReflectionFunction $reflector = null, | ||
| object|string $instanceOrScope = null, | ||
| array $arguments = null | ||
| ): bool { |
There was a problem hiding this comment.
There must be a single space between the closing parenthesis and the opening brace of a multi-line function declaration; found 0 spaces
| if (!isset(self::$mappings[$filterKind])) { | ||
| throw new InvalidArgumentException("Unsupported filter kind {$filterKind}"); | ||
| public function __construct( | ||
| private int $pointcutKind, |
There was a problem hiding this comment.
Line indented incorrectly; expected 4 spaces, found 8
| throw new InvalidArgumentException("Unsupported filter kind {$filterKind}"); | ||
| public function __construct( | ||
| private int $pointcutKind, | ||
| private string $attributeClassName, |
There was a problem hiding this comment.
Line indented incorrectly; expected 4 spaces, found 8
| public function __construct( | ||
| private int $pointcutKind, | ||
| private string $attributeClassName, | ||
| private bool $useContextForMatching = false, |
There was a problem hiding this comment.
Line indented incorrectly; expected 4 spaces, found 8
| private int $pointcutKind, | ||
| private string $attributeClassName, | ||
| private bool $useContextForMatching = false, | ||
| ) {} |
There was a problem hiding this comment.
Closing brace must be on a line by itself
| ReflectionMethod|ReflectionProperty|ReflectionFunction $reflector = null, | ||
| object|string $instanceOrScope = null, | ||
| array $arguments = null | ||
| ): bool { |
There was a problem hiding this comment.
There must be a single space between the closing parenthesis and the opening brace of a multi-line function declaration; found 0 spaces
| * Inheritance class matcher constructor | ||
| * @param (string&class-string) $parentClassOrInterfaceName Parent class or interface name to match in hierarchy | ||
| */ | ||
| public function __construct(private string $parentClassOrInterfaceName) {} |
There was a problem hiding this comment.
- Opening brace should be on a new line
- Closing brace must be on a line by itself
| ReflectionMethod|ReflectionProperty|ReflectionFunction $reflector = null, | ||
| object|string $instanceOrScope = null, | ||
| array $arguments = null | ||
| ): bool { |
There was a problem hiding this comment.
There must be a single space between the closing parenthesis and the opening brace of a multi-line function declaration; found 0 spaces
| { | ||
| return $this->memberNamePattern; | ||
| } | ||
| public Pointcut $classFilter, |
There was a problem hiding this comment.
Line indented incorrectly; expected 4 spaces, found 8
| return $this->memberNamePattern; | ||
| } | ||
| public Pointcut $classFilter, | ||
| public ModifierPointcut $visibilityFilter, |
There was a problem hiding this comment.
Line indented incorrectly; expected 4 spaces, found 8
| } | ||
| public Pointcut $classFilter, | ||
| public ModifierPointcut $visibilityFilter, | ||
| public ModifierPointcut $accessTypeFilter, |
There was a problem hiding this comment.
Line indented incorrectly; expected 4 spaces, found 8
| public Pointcut $classFilter, | ||
| public ModifierPointcut $visibilityFilter, | ||
| public ModifierPointcut $accessTypeFilter, | ||
| public string $memberNamePattern |
There was a problem hiding this comment.
Line indented incorrectly; expected 4 spaces, found 8
| public ModifierPointcut $visibilityFilter, | ||
| public ModifierPointcut $accessTypeFilter, | ||
| public string $memberNamePattern | ||
| ) {} |
There was a problem hiding this comment.
Closing brace must be on a line by itself
| * | ||
| * @param string $methodName Method name to match, can contain wildcards "*","?" or "|" | ||
| */ | ||
| public function __construct(private string $methodName) { |
There was a problem hiding this comment.
Opening brace should be on a new line
| ReflectionMethod|ReflectionProperty|ReflectionFunction $reflector = null, | ||
| object|string $instanceOrScope = null, | ||
| array $arguments = null | ||
| ): bool { |
There was a problem hiding this comment.
There must be a single space between the closing parenthesis and the opening brace of a multi-line function declaration; found 0 spaces
| ReflectionMethod|ReflectionProperty|ReflectionFunction $reflector = null, | ||
| object|string $instanceOrScope = null, | ||
| array $arguments = null | ||
| ): bool { |
There was a problem hiding this comment.
There must be a single space between the closing parenthesis and the opening brace of a multi-line function declaration; found 0 spaces
| ReflectionMethod|ReflectionProperty|ReflectionFunction $reflector = null, | ||
| object|string $instanceOrScope = null, | ||
| array $arguments = null | ||
| ): bool { |
There was a problem hiding this comment.
There must be a single space between the closing parenthesis and the opening brace of a multi-line function declaration; found 0 spaces
| * @param bool $useContextForMatching Switch to matching context name instead of reflector | ||
| */ | ||
| public function __construct( | ||
| private int $pointcutKind, |
There was a problem hiding this comment.
Line indented incorrectly; expected 4 spaces, found 8
| */ | ||
| public function __construct( | ||
| private int $pointcutKind, | ||
| private string $name, |
There was a problem hiding this comment.
Line indented incorrectly; expected 4 spaces, found 8
| public function __construct( | ||
| private int $pointcutKind, | ||
| private string $name, | ||
| private bool $useContextForMatching = false, |
There was a problem hiding this comment.
Line indented incorrectly; expected 4 spaces, found 8
| ReflectionMethod|ReflectionProperty|ReflectionFunction $reflector = null, | ||
| object|string $instanceOrScope = null, | ||
| array $arguments = null | ||
| ): bool { |
There was a problem hiding this comment.
There must be a single space between the closing parenthesis and the opening brace of a multi-line function declaration; found 0 spaces
| $this->pointcut = $pointcut; | ||
| $this->kind = $pointcut->getKind(); | ||
| } | ||
| public function __construct(private Pointcut $pointcut) {} |
There was a problem hiding this comment.
- Opening brace should be on a new line
- Closing brace must be on a line by itself
| ReflectionMethod|ReflectionProperty|ReflectionFunction $reflector = null, | ||
| object|string $instanceOrScope = null, | ||
| array $arguments = null | ||
| ): bool { |
There was a problem hiding this comment.
There must be a single space between the closing parenthesis and the opening brace of a multi-line function declaration; found 0 spaces
| ReflectionMethod|ReflectionProperty|ReflectionFunction $reflector = null, | ||
| object|string $instanceOrScope = null, | ||
| array $arguments = null | ||
| ): bool { |
There was a problem hiding this comment.
There must be a single space between the closing parenthesis and the opening brace of a multi-line function declaration; found 0 spaces
| { | ||
| return $this->getPointcut()->matches($point, $context, $instance, $arguments); | ||
| public function __construct( | ||
| private AspectContainer $container, |
There was a problem hiding this comment.
Line indented incorrectly; expected 4 spaces, found 8
| return $this->getPointcut()->matches($point, $context, $instance, $arguments); | ||
| public function __construct( | ||
| private AspectContainer $container, | ||
| private readonly string $pointcutId |
There was a problem hiding this comment.
Line indented incorrectly; expected 4 spaces, found 8
| public function __construct( | ||
| private AspectContainer $container, | ||
| private readonly string $pointcutId | ||
| ) {} |
There was a problem hiding this comment.
Closing brace must be on a line by itself
| ReflectionMethod|ReflectionProperty|ReflectionFunction $reflector = null, | ||
| object|string $instanceOrScope = null, | ||
| array $arguments = null | ||
| ): bool { |
There was a problem hiding this comment.
There must be a single space between the closing parenthesis and the opening brace of a multi-line function declaration; found 0 spaces
| ReflectionMethod|ReflectionProperty|ReflectionFunction $reflector = null, | ||
| object|string $instanceOrScope = null, | ||
| array $arguments = null | ||
| ): bool { |
There was a problem hiding this comment.
There must be a single space between the closing parenthesis and the opening brace of a multi-line function declaration; found 0 spaces
| * Default constructor can be used to specify concrete pointcut kind | ||
| */ | ||
| protected int $filterKind; | ||
| public function __construct(private int $pointcutKind = self::KIND_ALL) {} |
There was a problem hiding this comment.
- Opening brace should be on a new line
- Closing brace must be on a line by itself
| ReflectionMethod|ReflectionProperty|ReflectionFunction $reflector = null, | ||
| object|string $instanceOrScope = null, | ||
| array $arguments = null | ||
| ): true { |
There was a problem hiding this comment.
There must be a single space between the closing parenthesis and the opening brace of a multi-line function declaration; found 0 spaces
Previous Pointcut system wasn't type-safe, consisted of mix of different PointFilters and Poincuts, which resulted in extra code duplication, tricky checks and absence of strict typing of arguments.
For version 4 of framework, following major
Pointcutinterface will be used with it's mainmatchesmethod:Pointcut matching is now always performed via single interface by checking first context, then context + reflector and finally, for dynamic pointcuts it checks context + reflector + instance + arguments of invocation.
Pay an attention, that in current version of framework, position of
$contextand$reflectorhas been switched to have more natural matching.