PhpDocStorage
class PhpDocStorage implements PhpDocRepository (View source)
Storage for raw PhpDoc comments, separated from main entity data.
Provides lazy loading and efficient access to PhpDoc by entity ID.
Invariant: any code path that will call save() must construct this with $loadExisting = false.
setPhpDoc() only unsets an id when that same id is re-serialized with an empty doc, so a writer that pre-loaded the file would carry forward entries for entities that have since been renamed or deleted, and StubsPhpDoc.json would grow monotonically while serving docs for ids that no longer exist.
Both writers honour this today — run-stubs-parser.php and the cache-incomplete branch of Runner::getStubs() pass false — and the only $loadExisting = true construction (the cache-complete branch of Runner::getStubs()) is a pure reader that never saves. That is why the file currently has zero orphaned ids. Preserve the split when adding a writer.
Serializers see only the two-method {\StubTests\Framework\Serialization\PhpDocRepository} slice of this class, so they cannot reach save()/load()/clear() and cannot break the invariant above. Keep depending on the concrete class wherever the file lifecycle actually matters.
Methods
No description
Get PhpDoc by entity ID
Set PhpDoc for entity ID
Check if PhpDoc exists for entity ID
Get all PhpDocs (for debugging/testing)
Save PhpDocs to JSON file
Load PhpDocs from JSON file
Clear all PhpDocs (for testing)
Details
__construct(string $pathToJsonFile, bool $loadExisting = true)
No description
string|null
getPhpDoc(string $entityId)
Get PhpDoc by entity ID
void
setPhpDoc(string $entityId, string|null $phpDoc)
Set PhpDoc for entity ID
bool
hasPhpDoc(string $entityId)
Check if PhpDoc exists for entity ID
array
getAllPhpDocs()
Get all PhpDocs (for debugging/testing)
void
save()
Save PhpDocs to JSON file
void
load()
Load PhpDocs from JSON file
void
clear()
Clear all PhpDocs (for testing)