class PhpDocLinksCheck extends AbstractReflectionCheck (View source)

Validates that every @link URL in phpDoc comments:

  1. Uses the https scheme (always checked).

  1. 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

__construct(ReflectionProviderInterface|null $reflectionProvider = null, KnownProblemsRegistry|null $knownProblemsRegistry = null, callable|null $urlFetcher = null, bool|null $checkLiveness = null, EntityLookupService|null $entityLookup = null)

No description

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.

static int
fetchUrl(string $url)

Fetch the HTTP status code for a URL via a cURL HEAD request.

static void
resetCache()

Clear the static URL cache. Call in test tearDown() to prevent cross-test pollution.

bool
supports(string $phpVersion)

No description

run(StubDataQueryInterface $stubs, string $entityId, string $phpVersion)

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

Parameters

ReflectionProviderInterface|null $reflectionProvider
KnownProblemsRegistry|null $knownProblemsRegistry
callable|null $urlFetcher
bool|null $checkLiveness
EntityLookupService|null $entityLookup

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.

Parameters

CheckResultSet $results
string $entityType
string $entityId
string $checkName
string $phpVersion

Return Value

bool

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

Parameters

string $url

Return Value

int

static void resetCache()

Clear the static URL cache. Call in test tearDown() to prevent cross-test pollution.

Return Value

void

bool supports(string $phpVersion)

No description

Parameters

string $phpVersion

Return Value

bool

CheckResultSet run(StubDataQueryInterface $stubs, string $entityId, string $phpVersion)

No description

Parameters

StubDataQueryInterface $stubs

Parsed stubs data

string $entityId

Entity identifier to validate

string $phpVersion

PHP version string

Return Value

CheckResultSet