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] Added support for class initializations asserts. #354

Conversation

TheCelavi
Copy link
Contributor

Added support for class initializations asserts. Fixed documentation. Minor code improvements.

No BC breaks.

@TheCelavi
Copy link
Contributor Author

Sorry, today is not my day...

@lisachenko
Copy link
Member

Sorry, today is not my day...

Hey, mate, everything is ok ) 👍 😄

/**
* Before class instance initialization.
*
* @Pointcut\Before("initialization(Go\Tests\TestProject\Application\Main)")
Copy link
Member

Choose a reason for hiding this comment

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

It's fragile joinpoint, maybe we shouldn't use it in framework at all? And just leave it as experimental feature with special configuration?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do not know about that, however, I know that if we have it in code, we should have way to test it. Right?

/**
* After class initialization.
*
* @Pointcut\Before("staticinitialization(Go\Tests\TestProject\Application\Main)")
Copy link
Member

Choose a reason for hiding this comment

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

Comment name and method name "After" differs from the actual pointcut type, which is "Before"

@@ -41,9 +37,13 @@ public function matches($other)
throw new \InvalidArgumentException(sprintf('Expected instance of "%s", got "%s".', ClassAdvisorIdentifier::class, is_object($other) ? get_class($other) : gettype($other)));
}

$wovenAdvisorIdentifiers = $this->getWovenAdvisorIdentifiers($other->getClass());
$reflectionClass = ReflectionClass::create($other->getClass(), $this->configuration);
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, what is this? I can't remember ::create() method in the ReflectionClass.

UPD1 Ah, ok, you have introduced new helper class for that. Maybe rename it to more meaningful name to prevent collision with native ReflectionClass and same class from goaop/parser-reflection? I would vote for ProxyClassReflectionHelper or similar.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree, lets make it util class/factory class, that is its purpose.

use Go\ParserReflection\ReflectionEngine;
use Go\ParserReflection\ReflectionFile;

final class ReflectionClass extends BaseReflectionClass
Copy link
Member

Choose a reason for hiding this comment

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

Maybe rename it to the ProxyReflectionClass? To prevent collision in names with original ReflectionClass

$advisorIdentifier,
$index
);
$constraint = new ClassMemberWovenConstraint($this->configuration);
Copy link
Member

Choose a reason for hiding this comment

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

👍 I like how one single constraint class now handles every assertion.

*
* @Pointcut\Before("staticinitialization(Go\Tests\TestProject\Application\Main)")
*/
public function afterClassStaticInitialization()
Copy link
Member

Choose a reason for hiding this comment

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

What about method name itself and method body? ) It's unmatched with doc block and pointcut

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Something is seriously wrong with my brain today... sorry. I am going to close up for today, no use for me to keep working... :D

Copy link
Member

Choose a reason for hiding this comment

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

Yes, it's always cool to have some time for relax 👍 Don't hurry, this project is maintained for 6 years ) Just keep going slowly

// noop
}

public static function createReflectionClass($className, array $configuration)
Copy link
Member

Choose a reason for hiding this comment

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

Doc block for typehint and IDE?

use Go\ParserReflection\ReflectionEngine;
use Go\ParserReflection\ReflectionFile;

final class ProxyClassReflectionHelper
Copy link
Member

Choose a reason for hiding this comment

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

Missing doc block?

@lisachenko
Copy link
Member

Looks good!

@lisachenko lisachenko merged commit 96afb72 into goaop:2.x Aug 22, 2017
@lisachenko lisachenko changed the title [FEATURE] Added support for class initializations asserts. [Feature] Added support for class initializations asserts. Aug 22, 2017
@lisachenko lisachenko added this to the 2.x milestone Aug 22, 2017
@lisachenko
Copy link
Member

BTW,
This block:

        if (null === $wovenAdvisorIdentifiers) { // there are no advisor identifiers
            return true;
        }

        if (!isset($wovenAdvisorIdentifiers[$target])) {
            return true;
        }

        if (!isset($wovenAdvisorIdentifiers[$target][$other->getSubject()])) {
            return true;
        }

can be replaced with one single check

        if (!isset($wovenAdvisorIdentifiers[$target][$other->getSubject()])) {
            return true;
        }

Need to clean this block later in future PR.

lisachenko added a commit that referenced this pull request Aug 22, 2017
* origin/2.x:
  [Feature] Add support for class initializations asserts. (#354)
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.

2 participants