Prevent exception when dynamically extending a class to add behaviors.#225
Prevent exception when dynamically extending a class to add behaviors.#225LukeTowers merged 3 commits intodevelopfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 WalkthroughDeduplicates the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/Extension/ExtendableTrait.php (1)
492-502: Consider applying the samearray_unique()treatment here for consistency.The static method flow has a similar loop processing
$useswithout deduplication. While this won't throw an exception (it just overwritesself::$extendableStaticMethodsentries), applyingarray_unique()here would maintain consistency with the fix at line 87 and avoid redundant processing.Suggested fix
- foreach ($uses as $use) { + foreach (array_unique($uses) as $use) {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/Extension/ExtendableTrait.php` around lines 492 - 502, The static-methods loop processes $uses without deduplication causing redundant work and overwrites in self::$extendableStaticMethods; modify the loop that builds $useClassName and iterates ReflectionClass->getMethods(ReflectionMethod::IS_STATIC) to first apply array_unique() to $uses (the same way used earlier) so each $use is handled once before creating $useClassName and populating self::$extendableStaticMethods[$className][$method->getName()] = $useClassName.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/Extension/ExtendableTrait.php`:
- Around line 492-502: The static-methods loop processes $uses without
deduplication causing redundant work and overwrites in
self::$extendableStaticMethods; modify the loop that builds $useClassName and
iterates ReflectionClass->getMethods(ReflectionMethod::IS_STATIC) to first apply
array_unique() to $uses (the same way used earlier) so each $use is handled once
before creating $useClassName and populating
self::$extendableStaticMethods[$className][$method->getName()] = $useClassName.
Fixes wintercms/winter#1460
Summary by CodeRabbit