Skip to content

Commit

Permalink
Refactor to replace WeavedInterface with SetStateInterface
Browse files Browse the repository at this point in the history
This updates the codebase to use the new SetStateInterface instead of the deprecated WeavedInterface. The changes include interface replacement in method checks, class generation, and documentation adjustments to maintain consistency. A new SetStateInterface is introduced, and relevant bindings are updated accordingly.
  • Loading branch information
koriym committed Feb 14, 2025
1 parent 6872b30 commit c60b168
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/AopCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function __construct(MethodSignatureString $methodSignature)
public function generate(ReflectionClass $sourceClass, BindInterface $bind, string $postfix): string
{
$this->parseClass($sourceClass, $postfix);
$this->implementsInterface(WeavedInterface::class);
$this->implementsInterface(SetStateInterface::class);
$this->addMethods($sourceClass, $bind);

return $this->getCodeText();
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function newInstance(string $class, array $args, BindInterface $bind): ob
$compiledClass = $this->compile($class, $bind);
assert(class_exists($compiledClass));
$instance = (new ReflectionClass($compiledClass))->newInstanceArgs($args);
if ($instance instanceof WeavedInterface) {
if ($instance instanceof SetStateInterface) {
$instance->_initState($bind->getBindings());
}

Expand Down
3 changes: 2 additions & 1 deletion src/InterceptTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ trait InterceptTrait
/**
* @param MethodBindings $bindings
*
* @see WeavedInterface::_initState()
* {@inheritDoc}
*
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
*/
public function _initState(array $bindings): void // phpcs:ignore
Expand Down
18 changes: 18 additions & 0 deletions src/SetStateInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Ray\Aop;

use Ray\Aop\MethodInterceptor as MethodBindings;

/** @psalm-import-type MethodBindings from Types */
interface SetStateInterface extends WeavedInterface

Check failure on line 10 in src/SetStateInterface.php

View workflow job for this annotation

GitHub Actions / sa / PHPStan

Type alias MethodBindings already exists as an interface in scope of Ray\Aop\SetStateInterface.

Check failure on line 10 in src/SetStateInterface.php

View workflow job for this annotation

GitHub Actions / sa / PHPStan

Type alias MethodBindings already exists as an interface in scope of Ray\Aop\SetStateInterface.
{
/**
* @param MethodBindings $bindings
*
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
*/
public function _initState(array $bindings): void; // phpcs:ignore
}
2 changes: 1 addition & 1 deletion src/Weaver.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function newInstance(string $class, array $args): object
{
$aopClass = $this->weave($class);
$instance = (new ReflectionClass($aopClass))->newInstanceArgs($args);
if (! $instance instanceof WeavedInterface) {
if (! $instance instanceof SetStateInterface) {
/** @var T $instance */
return $instance;
}
Expand Down

0 comments on commit c60b168

Please sign in to comment.