Skip to content

Commit

Permalink
Merge pull request #229 from ray-di/types
Browse files Browse the repository at this point in the history
Add centralized type definitions in Types.php
  • Loading branch information
koriym authored Dec 15, 2024
2 parents ba45ba8 + d176d21 commit b3ebb85
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 173 deletions.
135 changes: 0 additions & 135 deletions .github/workflows/continuous-integration-pecl.yml

This file was deleted.

4 changes: 2 additions & 2 deletions src/AbstractMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
/**
* Abstract matcher base class
*
* @psalm-type MatcherArguments = array<array-key, mixed>
* @psalm-type Arguments = array<array-key, mixed>
* @psalm-import-type MatcherArguments from Types
* @psalm-import-type Arguments from Types
*/
abstract class AbstractMatcher
{
Expand Down
21 changes: 10 additions & 11 deletions src/Aspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@
/**
* Aspect class manages aspect weaving and method interception
*
* @psalm-type MethodInterceptors = array<array-key, MethodInterceptor>
* @psalm-type MethodBindings = array<string, MethodInterceptors>
* @psalm-type ClassBindings = array<class-string, MethodBindings>
* @psalm-type MatcherConfig = array{
* classMatcher: AbstractMatcher,
* methodMatcher: AbstractMatcher,
* interceptors: MethodInterceptors
* }
* @psalm-type MatcherConfigList = array<array-key, MatcherConfig>
* @psalm-type Arguments = array<array-key, mixed>
* @psalm-import-type MethodInterceptors from Types
* @psalm-import-type MethodBindings from Types
* @psalm-import-type ClassBindings from Types
* @psalm-import-type MatcherConfig from Types
* @psalm-import-type MatcherConfigList from Types
* @psalm-import-type Arguments from Types
* @psalm-import-type MethodName from Types
*/
final class Aspect
{
Expand Down Expand Up @@ -135,7 +132,9 @@ private function createBind(string $className): Bind
continue; // @codeCoverageIgnore
}

$bind->bindInterceptors($method->getName(), $matcher['interceptors']);
/** @var MethodName $methodName */
$methodName = $method->getName();
$bind->bindInterceptors($methodName, $matcher['interceptors']);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/AspectPecl.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
use function method_intercept;

/**
* @psalm-type MethodBoundInterceptors = array<non-empty-string, MethodInterceptors>
* @psalm-type ClassBoundInterceptors = array<class-string, MethodBoundInterceptors>
* @psalm-import-type MatcherConfigList from Aspect
* @psalm-import-type MethodInterceptors from Aspect
* @psalm-import-type MethodBoundInterceptors from Types
* @psalm-import-type ClassBoundInterceptors from Types
* @psalm-import-type MatcherConfigList from Types
* @psalm-import-type MethodInterceptors from Types
* @codeCoverageIgnore
*/
final class AspectPecl
Expand Down
9 changes: 5 additions & 4 deletions src/Bind.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
/**
* Bind class manages method interception bindings
*
* @psalm-import-type MethodInterceptors from Aspect
* @psalm-import-type MethodBindings from Aspect
* @psalm-type Pointcuts = array<Pointcut>
* @psalm-import-type MethodInterceptors from Types
* @psalm-import-type MethodBindings from Types
* @psalm-import-type Pointcuts from Types
* @psalm-import-type MethodName from Types
*/
final class Bind implements BindInterface
{
Expand Down Expand Up @@ -69,7 +70,7 @@ public function bind(string $class, array $pointcuts): BindInterface
/**
* Bind interceptors to a method
*
* @param string $method Method name
* @param MethodName $method Method name
* @param MethodInterceptors $interceptors List of interceptors
*/
public function bindInterceptors(string $method, array $interceptors): BindInterface
Expand Down
2 changes: 2 additions & 0 deletions src/BindInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Ray\Aop;

/** @psalm-import-type MethodName from Types */
interface BindInterface
{
/**
Expand All @@ -17,6 +18,7 @@ public function bind(string $class, array $pointcuts): self;
/**
* Bind interceptors to method
*
* @param MethodName $method
* @param MethodInterceptor[] $interceptors
*/
public function bindInterceptors(string $method, array $interceptors): self;
Expand Down
2 changes: 1 addition & 1 deletion src/BuiltinMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

/**
* @psalm-suppress PropertyNotSetInConstructor
* @psalm-import-type MatcherArguments from AbstractMatcher
* @psalm-import-type MatcherArguments from Types
*/
class BuiltinMatcher extends AbstractMatcher
{
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* AOP (Aspect-Oriented Programming) classes. Handles the binding of
* methods and ensures the classes are writable.
*
* @psalm-import-type ConstructorArguments from CompilerInterface
* @psalm-import-type ConstructorArguments from Types
*/
final class Compiler implements CompilerInterface
{
Expand Down
10 changes: 5 additions & 5 deletions src/CompilerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
namespace Ray\Aop;

/**
* @psalm-import-type MethodInterceptors from Aspect
* @psalm-import-type MethodBindings from Aspect
* @psalm-import-type ClassBindings from Aspect
* @psalm-import-type MatcherConfig from Aspect
* @psalm-type ConstructorArguments = list<mixed>
* @psalm-import-type MethodInterceptors from Types
* @psalm-import-type MethodBindings from Types
* @psalm-import-type ClassBindings from Types
* @psalm-import-type MatcherConfig from Types
* @psalm-import-type ConstructorArguments from Types
*/
interface CompilerInterface
{
Expand Down
10 changes: 9 additions & 1 deletion src/Matcher/AnyMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,23 @@

use ArrayObject;
use Ray\Aop\AbstractMatcher;
use Ray\Aop\Types;
use ReflectionClass;
use ReflectionMethod;

use function in_array;
use function strpos;

/**
* @psalm-import-type Arguments from Types
* @psalm-import-type BuiltinMethodsNames from Types
*/
final class AnyMatcher extends AbstractMatcher
{
/** @var string[] */
/**
* @var BuiltinMethodsNames
* @readonly
*/
private static $builtinMethods = [];

public function __construct()
Expand Down
12 changes: 6 additions & 6 deletions src/MethodMatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
use function get_class;

/**
* @psalm-import-type MethodInterceptors from Aspect
* @psalm-import-type MethodBindings from Aspect
* @psalm-import-type ClassBindings from Aspect
* @psalm-import-type MatcherConfig from Aspect
* @psalm-import-type Arguments from Aspect
* @psalm-import-type Pointcuts from Bind
* @psalm-import-type MethodInterceptors from Types
* @psalm-import-type MethodBindings from Types
* @psalm-import-type ClassBindings from Types
* @psalm-import-type MatcherConfig from Types
* @psalm-import-type Arguments from Types
* @psalm-import-type Pointcuts from Types
*/
final class MethodMatch
{
Expand Down
6 changes: 3 additions & 3 deletions src/ReflectiveMethodInvocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
use function is_callable;

/**
* @psalm-import-type ArgumentList from Types
* @psalm-import-type NamedArguments from Types
* @psalm-import-type InterceptorList from Types
* @template T of object
* @psalm-type ArgumentList = ArrayObject<int, mixed>
* @psalm-type NamedArguments = ArrayObject<non-empty-string, mixed>
* @psalm-type InterceptorList = array<MethodInterceptor>
* @implements MethodInvocation<T>
*/
final class ReflectiveMethodInvocation implements MethodInvocation
Expand Down
58 changes: 58 additions & 0 deletions src/Types.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

declare(strict_types=1);

namespace Ray\Aop;

use ArrayObject;

/**
* Type definitions for Ray.Aop
*
* @phpcs:disable SlevomatCodingStandard.Commenting.DocCommentSpacing
* @template T of object
*
* Domain Types
* @psalm-type ScriptDir = non-empty-string
* @psalm-type ClassName = class-string
* @psalm-type MethodName = non-empty-string
* @psalm-type AspectClassName = non-empty-string
* @psalm-type BindingName = non-empty-string
* @psalm-type MatcherName = non-empty-string
*
* Base Types
* @psalm-type ArgumentList = ArrayObject<int, mixed>
* @psalm-type NamedArguments = ArrayObject<MethodName, mixed>
* @psalm-type InterceptorList = array<MethodInterceptor>
* @psalm-type ConstructorArguments = list<mixed>
* @psalm-type ReflectionClassTemplate = ReflectionClass<T>
*
* Matcher Types
* @psalm-type MatcherArguments = array<array-key, mixed>
* @psalm-type MethodInterceptors = array<array-key, MethodInterceptor>
* @psalm-type MatcherConfig = array{
* classMatcher: AbstractMatcher,
* methodMatcher: AbstractMatcher,
* interceptors: MethodInterceptors
* }
* @psalm-type Arguments = array<array-key, mixed>
* @psalm-type BuiltinMethodsNames = list<non-empty-string>
*
* Method and Binding Types
* @psalm-type MethodBindings = array<MethodName, MethodInterceptors>
* @psalm-type ClassBindings = array<ClassName, MethodBindings>
* @psalm-type MatcherConfigList = array<array-key, MatcherConfig>
* @psalm-type MethodBoundInterceptors = array<MethodName, MethodInterceptors>
* @psalm-type ClassBoundInterceptors = array<ClassName, MethodBoundInterceptors>
*
* PointCut Types
* @psalm-type Pointcuts = array<Pointcut>
* @phpcs:enable
*/
final class Types
{
/** @codeCoverageIgnore */
private function __construct()
{
}
}

0 comments on commit b3ebb85

Please sign in to comment.