Skip to content
PHP Ecosystem
Explore

AbstractAuditParser

API reference › Foxy › Audit › Parser › AbstractAuditParser

abstract classFoxy\Audit\Parser\AbstractAuditParser
Sourcesrc/Audit/Parser/AbstractAuditParser.php
5 subclasses

Provides strict validation and normalization helpers for audit output parsers.

MethodDescriptionDefined by
assertNotErrorDocument() protected finalRejects a JSON document that represents a package manager error.AbstractAuditParser
assertOutputSize() protected finalRejects audit output that exceeds the parser’s size limit.AbstractAuditParser
decodeObject() protected finalDecodes an audit JSON object after validating its size and shape.AbstractAuditParser
getAdvisoryId() protected finalSelects a GHSA identifier from the candidate or URL, falling back to the source identifier.AbstractAuditParser
getBoolean() protected finalReturns a required boolean field.AbstractAuditParser
getCves() protected finalReturns validated, normalized CVE identifiers.AbstractAuditParser
getGhsaId() protected finalExtracts and normalizes a GHSA identifier from a value or URL.AbstractAuditParser
getManagerName() protected abstractReturns the package manager name used in malformed-output errors.AbstractAuditParser
getNonNegativeInteger() protected finalReturns a required non-negative integer field.AbstractAuditParser
getObject() protected finalConverts a decoded JSON object into its property map.AbstractAuditParser
getOptionalString() protected finalReturns a sanitized optional string field, or null when absent or empty.AbstractAuditParser
getSeverity() protected finalReturns a supported normalized severity value.AbstractAuditParser
getSeverityCount() protected finalReturns the sum of severity counts and optionally validates the reported total.AbstractAuditParser
getSourceId() protected finalReturns a non-empty source identifier from a string or integer value.AbstractAuditParser
getString() protected finalReturns a required sanitized string field.AbstractAuditParser
getStringList() protected finalReturns a normalized list containing only strings.AbstractAuditParser
malformed() protected finalCreates a package-manager-specific malformed-output exception.AbstractAuditParser
sanitizeString() protected finalReplaces control characters and trims surrounding whitespace.AbstractAuditParser
uniqueStrings() protected finalReturns unique strings in deterministic order.AbstractAuditParser
final protected function assertNotErrorDocument(mixed[] $data): void

Rejects a JSON document that represents a package manager error.

Parameters

ParameterTypeDescription
$datamixed[]
final protected function assertOutputSize(string $output): void

Rejects audit output that exceeds the parser’s size limit.

Parameters

ParameterTypeDescription
$outputstring
final protected function decodeObject(string $output): mixed[]

Decodes an audit JSON object after validating its size and shape.

Parameters

ParameterTypeDescription
$outputstring

Returns

mixed[]

final protected function getAdvisoryId(string $sourceId, string|null $candidate, string|null $url): string

Selects a GHSA identifier from the candidate or URL, falling back to the source identifier.

Parameters

ParameterTypeDescription
$sourceIdstring
$candidatestring|null
$urlstring|null

Returns

string

final protected function getBoolean(array $data, string $key, string $context): bool

Returns a required boolean field.

Parameters

ParameterTypeDescription
$dataarray
$keystring
$contextstring

Returns

bool

final protected function getCves(mixed $value, string $context): list<string>

Returns validated, normalized CVE identifiers.

Parameters

ParameterTypeDescription
$valuemixed
$contextstring

Returns

list<string>

final protected function getGhsaId(string|null $value): string|null

Extracts and normalizes a GHSA identifier from a value or URL.

Parameters

ParameterTypeDescription
$valuestring|null

Returns

string|null

abstract protected function getManagerName(): string

Returns the package manager name used in malformed-output errors.

Returns

string

final protected function getNonNegativeInteger(array $data, string $key, string $context): int

Returns a required non-negative integer field.

Parameters

ParameterTypeDescription
$dataarray
$keystring
$contextstring

Returns

int

final protected function getObject(mixed $value, string $context): mixed[]

Converts a decoded JSON object into its property map.

Parameters

ParameterTypeDescription
$valuemixed
$contextstring

Returns

mixed[]

final protected function getOptionalString(array $data, string $key, string $context): string|null

Returns a sanitized optional string field, or null when absent or empty.

Parameters

ParameterTypeDescription
$dataarray
$keystring
$contextstring

Returns

string|null

final protected function getSeverity(mixed $value, string $context): Foxy\Audit\Severity

Returns a supported normalized severity value.

Parameters

ParameterTypeDescription
$valuemixed
$contextstring

Returns

Foxy\Audit\Severity

final protected function getSeverityCount(array $metadata, string $context, bool $requireTotal): int

Returns the sum of severity counts and optionally validates the reported total.

Parameters

ParameterTypeDescription
$metadataarray
$contextstring
$requireTotalbool

Returns

int

final protected function getSourceId(mixed $value, string $context): string

Returns a non-empty source identifier from a string or integer value.

Parameters

ParameterTypeDescription
$valuemixed
$contextstring

Returns

string

final protected function getString(array $data, string $key, string $context, bool $allowEmpty = false): string

Returns a required sanitized string field.

Parameters

ParameterTypeDescription
$dataarray
$keystring
$contextstring
$allowEmptybool

Returns

string

final protected function getStringList(mixed $value, string $context): list<string>

Returns a normalized list containing only strings.

Parameters

ParameterTypeDescription
$valuemixed
$contextstring

Returns

list<string>

final protected function malformed(string $reason, Throwable|null $previous = null): Foxy\Exception\RuntimeException

Creates a package-manager-specific malformed-output exception.

Parameters

ParameterTypeDescription
$reasonstring
$previousThrowable|null

Returns

Foxy\Exception\RuntimeException

final protected function sanitizeString(string $value): string

Replaces control characters and trims surrounding whitespace.

Parameters

ParameterTypeDescription
$valuestring

Returns

string

final protected function uniqueStrings(list<string> $values): list<string>

Returns unique strings in deterministic order.

Parameters

ParameterTypeDescription
$valueslist<string>

Returns

list<string>