PhpDocLinksCheck
class PhpDocLinksCheck extends AbstractReflectionCheck (View source)
Validates that every @link URL in phpDoc comments:
- Uses the https scheme (always checked).
- Is reachable and not dead (checked only when the CHECK_LINKS environment variable is set to "true").
For class-like entities (classes, interfaces, enums) the check examines:
- the entity-level phpDoc
- the phpDoc of every declared method
For functions the check examines the function-level phpDoc only.
Non-URL values after @link (e.g. cross-references like "ClassName::method") are silently ignored — only entries starting with "http://" or "https://" are validated.
Dead-link detection uses an in-process static cache so that the same URL is fetched at most once per test run. Only HTTP 404 / 410 and connection failures are reported; other non-200 responses (403, 429, 5xx …) are treated as alive.
To enable liveness checking, export CHECK_LINKS=true before running PHPUnit: CHECK_LINKS=true php vendor/bin/phpunit tests/PhpDocValidatorTest.php
Known problems are supported at entity level:
- entityType + entityId + 'PhpDocLinksCheck' → skips all link checks for that entity.
Constants
| private LINK_PATTERN |
Matches "@link http://..." or "@link https://..." in a phpDoc block. Capture group 1 is the full URL (no whitespace). |
Properties
| protected ReflectionProviderInterface | $reflectionProvider | from AbstractReflectionCheck | |
| protected KnownProblemsRegistry | $knownProblemsRegistry | from AbstractReflectionCheck |
Methods
No description
Records a skipped-success result if a known problem covers this entity, and returns true.
Fetch the HTTP status code for a URL via a cURL HEAD request.
Clear the static URL cache. Call in test tearDown() to prevent cross-test pollution.
No description
Details
__construct(ReflectionProviderInterface|null $reflectionProvider = null, KnownProblemsRegistry|null $knownProblemsRegistry = null, callable|null $urlFetcher = null, bool|null $checkLiveness = null, EntityLookupService|null $entityLookup = null)
No description
protected bool
skipWithKnownProblem(CheckResultSet $results, string $entityType, string $entityId, string $checkName, string $phpVersion)
Records a skipped-success result if a known problem covers this entity, and returns true.
Returns false if validation should proceed normally.
static int
fetchUrl(string $url)
Fetch the HTTP status code for a URL via a cURL HEAD request.
Follows redirects (up to 5). Returns 0 on connection / SSL failure.
Results are cached in a static map so the same URL is requested only once per PHP process (i.e. per PHPUnit test run).
static void
resetCache()
Clear the static URL cache. Call in test tearDown() to prevent cross-test pollution.
bool
supports(string $phpVersion)
No description
CheckResultSet
run(StubDataQueryInterface $stubs, string $entityId, string $phpVersion)
No description