classMetadataReader
final class MetadataReader
Reads the metadata field: nested lists of "**key:** value" entries or plain values.
A value is decoded as JSON when it is valid JSON and kept as text otherwise; a parent entry with an empty value (or [] in a sequence) holds one nested list.
Methods§
public function read(Node $node): stdClassReads the metadata mapping.
Parameters
$node | Node | A paragraph holding a JSON object, or a bullet list of keys |
Returns
stdClass The metadataThrows
InvalidInputException When the value is not a mapping or the lists are malformedTest cases 4
Called from 1
Calls 4
- method-call MetadataReader::scalar() line 32
- static-call Nodes::text() line 32
- method-call MetadataReader::nested() line 32
- new InvalidInputException line 34
public function nested(Node $node): stdClass|list<mixed>Reads one level of nested metadata.
Parameters
$node | Node | The bullet list |
Returns
stdClass|list<mixed> A mapping for bold keys, a sequence for plain valuesThrows
InvalidInputException When keys and values are mixed, a key repeats or a nested list is misplacedTest cases 5
Called from 2
Calls 8
- new
stdClassline 50 - static-call Nodes::items() line 53
- new InvalidInputException line 56
- static-call Nodes::pair() line 63
- static-call Nodes::text() line 63
- method-call MetadataReader::nested() line 69
- method-call MetadataReader::scalar() line 71
- function-call
property_existsline 74
public function scalar(string $text): mixedReads a scalar value.
Parameters
$text | string | The written value |
Returns
mixed The decoded JSON value, or the text when it is not JSONThrows
InvalidInputException When the value is emptyTest cases 2
Called from 2
Calls 3
- new InvalidInputException line 97
- function-call
json_decodeline 99 - function-call
json_last_errorline 100
Test cases 14§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 11
MetadataReaderTest::testNestedReadsAMappingcallsMetadataReaderTest::testNestedReadsASequencecallsMetadataReaderTest::testNestedReadsNestedMappingscallsMetadataReaderTest::testNestedReadsNestedSequencesUnderAnEmptyListValuecallsMetadataReaderTest::testNestedRejectsMalformedListscallsMetadataReaderTest::testReadReadsAJsonObjectParagraphcallsMetadataReaderTest::testReadReadsAListOfKeysAndValuescallsMetadataReaderTest::testReadReadsAnEmptyJsonObjectParagraphcallsMetadataReaderTest::testReadRejectsAValueThatIsNotAMappingcallsMetadataReaderTest::testScalarDecodesJsonOrKeepsTextcallsMetadataReaderTest::testScalarRejectsAnEmptyValuecalls
Other tests reaching this symbol 3
FieldReaderTestcallsFieldSectionsTestcallsMarkdownDocumentTestcalls