feat: Add support for Traits#21
Merged
Merged
Conversation
Member
|
I tested it, this looks good! |
This was referenced Apr 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add Trait Documentation Support
Summary
This PR adds comprehensive support for documenting PHP traits in Teak, including standalone trait documentation and trait method/property inheritance in classes that use them.
Changes
Core Trait Support
1. Trait Documentation as Standalone Entities
Modified:
lib/Console/ClassReferenceHandler.php$traitMapto index all available traitsgenerateClassList()to document traits alongside classesModified:
lib/Compiler/ClassLinkList.phpgenerate()method to process traits for cross-linking in documentation2. Class Support for Trait Methods and Properties
Modified:
lib/Reflection/ClassReflection.php$traitMethodsand$traitPropertiesarrays to track inherited trait membersClass_andTrait_objectsaddTraitInformation()method to collect trait membersgetMethods()to include trait methods with proper override priority (class methods > trait methods > parent methods)getProperties()to include trait propertiesgetUsedTraits()method to expose which traits a class usesmethod_exists()checks for trait compatibility ingetParent()andgetInterfaces()Modified:
lib/Reflection/Reflection.phpTrait_alongsideClass_,Method, andPropertyModified:
lib/Console/ClassReferenceHandler.phpTrait_importgenerateClassList()to detect and process trait usage viagetUsedTraits()3. Trait Usage Display
Created:
lib/Compiler/Class_/TraitList.phpParentListandInterfaceListTraitName" for single traitsTrait1,Trait2" for multiple traitsModified:
lib/Compiler/Class_/ApiTable.phpTraitListalongsideParentListandInterfaceListTesting Infrastructure
PHPUnit Setup
Modified:
composer.jsonphpunit/phpunit: ^10.0as a dev dependencyModified:
phpunit.xmlModified:
.gitignore.phpunit.cachedirectoryTest Coverage
Created:
tests/testclasses/TestTrait.phpModified:
tests/testclasses/TestClass.phpTestTraitfor integration testingModified:
tests/ClassCompilerTest.phptestTraitDocumentation()- verifies standalone trait documentationtestClassWithTraitShowsTraitMethods()- verifies trait members appear in class documentation and trait usage statement is displayedDocumentation Output
When a class uses a trait, the generated documentation now includes:
Benefits
Test Results
All tests pass successfully.
Breaking Changes
None. This is a backward-compatible addition that extends existing functionality.