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

__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)

Details

__construct(string $pathToJsonFile, bool $loadExisting = true)

No description

Parameters

string $pathToJsonFile
bool $loadExisting

string|null getPhpDoc(string $entityId)

Get PhpDoc by entity ID

Parameters

string $entityId

Return Value

string|null

The stored doc comment, or null when the id has none

void setPhpDoc(string $entityId, string|null $phpDoc)

Set PhpDoc for entity ID

Parameters

string $entityId
string|null $phpDoc

Return Value

void

bool hasPhpDoc(string $entityId)

Check if PhpDoc exists for entity ID

Parameters

string $entityId

Return Value

bool

array getAllPhpDocs()

Get all PhpDocs (for debugging/testing)

Return Value

array

void save()

Save PhpDocs to JSON file

Return Value

void

void load()

Load PhpDocs from JSON file

Return Value

void

void clear()

Clear all PhpDocs (for testing)

Return Value

void