Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Pointcut namespace refactoring #500

Merged
merged 2 commits into from
Apr 13, 2024

Conversation

lisachenko
Copy link
Member

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 Pointcut interface will be used with it's main matches method:

    /**
     * Performs matching of point of code, returns true if point matches
     *
     * @param ReflectionClass<T>|ReflectionFileNamespace $context 
     * @param ReflectionMethod|ReflectionProperty|ReflectionFunction|null $reflector
     * @param null|(string&class-string<T>)|(object&T) $instanceOrScope
     * @param null|array<mixed>  $arguments
     *
     * @template T of object
     */
    public function matches(
        ReflectionClass|ReflectionFileNamespace                $context,
        ReflectionMethod|ReflectionProperty|ReflectionFunction $reflector = null,
        object|string                                          $instanceOrScope = null,
        array                                                  $arguments = null
    ): bool;

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 $context and $reflector has been switched to have more natural matching.

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.
@scrutinizer-notifier
Copy link

A new inspection was created.

*/
public function __construct(
private PointFilter $pointFilter,
private Pointcut $pointcut,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line indented incorrectly; expected 4 spaces, found 8

object|string $instanceOrScope = null,
array $arguments = null
): bool;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected 1 newline at end of file; 0 found

ReflectionMethod|ReflectionProperty|ReflectionFunction $reflector = null,
object|string $instanceOrScope = null,
array $arguments = null
): bool {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line indented incorrectly; expected 4 spaces, found 8

throw new InvalidArgumentException("Unsupported filter kind {$filterKind}");
public function __construct(
private int $pointcutKind,
private string $attributeClassName,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line indented incorrectly; expected 4 spaces, found 8

public function __construct(
private int $pointcutKind,
private string $attributeClassName,
private bool $useContextForMatching = false,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line indented incorrectly; expected 4 spaces, found 8

private int $pointcutKind,
private string $attributeClassName,
private bool $useContextForMatching = false,
) {}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closing brace must be on a line by itself

ReflectionMethod|ReflectionProperty|ReflectionFunction $reflector = null,
object|string $instanceOrScope = null,
array $arguments = null
): bool {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 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 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line indented incorrectly; expected 4 spaces, found 8

return $this->memberNamePattern;
}
public Pointcut $classFilter,
public ModifierPointcut $visibilityFilter,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line indented incorrectly; expected 4 spaces, found 8

}
public Pointcut $classFilter,
public ModifierPointcut $visibilityFilter,
public ModifierPointcut $accessTypeFilter,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line indented incorrectly; expected 4 spaces, found 8

public Pointcut $classFilter,
public ModifierPointcut $visibilityFilter,
public ModifierPointcut $accessTypeFilter,
public string $memberNamePattern

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line indented incorrectly; expected 4 spaces, found 8

public ModifierPointcut $visibilityFilter,
public ModifierPointcut $accessTypeFilter,
public string $memberNamePattern
) {}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opening brace should be on a new line

ReflectionMethod|ReflectionProperty|ReflectionFunction $reflector = null,
object|string $instanceOrScope = null,
array $arguments = null
): bool {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line indented incorrectly; expected 4 spaces, found 8

*/
public function __construct(
private int $pointcutKind,
private string $name,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line indented incorrectly; expected 4 spaces, found 8

public function __construct(
private int $pointcutKind,
private string $name,
private bool $useContextForMatching = false,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line indented incorrectly; expected 4 spaces, found 8

ReflectionMethod|ReflectionProperty|ReflectionFunction $reflector = null,
object|string $instanceOrScope = null,
array $arguments = null
): bool {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 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 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line indented incorrectly; expected 4 spaces, found 8

public function __construct(
private AspectContainer $container,
private readonly string $pointcutId
) {}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closing brace must be on a line by itself

ReflectionMethod|ReflectionProperty|ReflectionFunction $reflector = null,
object|string $instanceOrScope = null,
array $arguments = null
): bool {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There must be a single space between the closing parenthesis and the opening brace of a multi-line function declaration; found 0 spaces

*/
protected int $filterKind;
public function __construct(private int $pointcutKind = self::KIND_ALL) {}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 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 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There must be a single space between the closing parenthesis and the opening brace of a multi-line function declaration; found 0 spaces

@lisachenko lisachenko added this to the 4.0.0 milestone Apr 13, 2024
@lisachenko lisachenko merged commit e2d30bf into master Apr 13, 2024
6 of 7 checks passed
@lisachenko lisachenko deleted the feature/pointcut-namespace-refactoring branch April 13, 2024 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants