classBadges
final class Badges
Reads and writes the badge rows that carry a card's kind, status, origin, category and labels.
A badge is an image whose alt text is the value. Its role comes from the image title, or from the path of a static shields.io badge, and is a label otherwise.
Properties§
public array<string, array<string, array{url: string, title: ?string}>> $images = []Methods§
public static function isParagraph(Node $node): boolTells whether a block is a badge row.
Parameters
$node | Node | The block |
Returns
bool True for a paragraph starting with an imageTest cases 1
Called from 1
Calls 1
- method-call
Node::firstChild()line 37
public function read(Node $node, stdClass $item): voidReads a badge row into the item.
Parameters
$node | Node | The badge row |
$item | stdClass | The item being read |
Throws
InvalidInputException When the row holds anything but images, a value is empty, repeated or contradicts its static imageTest cases 6
BadgesTest::testReadAppendsToTheLabelsAlreadyReadcallsBadgesTest::testReadReadsTheTextOfEmphasisInTheAltTextcallsBadgesTest::testReadRejectsAFieldTheItemAlreadyHascallsBadgesTest::testReadRejectsLabelsThatAreNotAListcallsBadgesTest::testReadRejectsMalformedRowscallsBadgesTest::testReadSetsTheFieldsAndLabelsOfARowcalls
Called from 1
Calls 9
- method-call
Node::children()line 50 - function-call
trimline 51 - new InvalidInputException line 55
- static-call Nodes::text() line 57
- static-call Badges::field() line 61
- static-call StaticBadge::validate() line 62
- function-call
is_arrayline 65 - function-call
in_arrayline 65 - function-call
property_existsline 70
public static function field(string $url, string|null $title): stringDecides which field a badge sets.
Parameters
$url | string | The image URL |
$title | string|null | The image title |
Returns
string kind, status, origin, category or labelThrows
InvalidInputException When the title names another fieldTest cases 2
Called from 1
Calls 4
- function-call
in_arrayline 92 - new InvalidInputException line 93
- function-call
parse_urlline 97 - function-call
preg_matchline 97
public static function render(
string $field,
string $value,
array{url: string, title: ?string}|null $image,
): stringWrites a badge.
Parameters
$field | string | The field the badge sets |
$value | string | The value |
$image | array{url: string, title: ?string}|null | The image read for this value, or null for a new static badge |
Returns
string The Markdown imageTest cases 1
Called from 2
Calls 4
- function-call
rawurlencodeline 115 - function-call
str_replaceline 115 - static-call Nodes::escape() line 117
- static-call Nodes::destination() line 117
Test cases 18§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 10
BadgesTest::testFieldDecidesTheFieldABadgeSetscallsBadgesTest::testFieldRejectsATitleNamingAnotherFieldcallsBadgesTest::testIsParagraphTellsWhetherABlockIsABadgeRowcallsBadgesTest::testReadAppendsToTheLabelsAlreadyReadcallsBadgesTest::testReadReadsTheTextOfEmphasisInTheAltTextcallsBadgesTest::testReadRejectsAFieldTheItemAlreadyHascallsBadgesTest::testReadRejectsLabelsThatAreNotAListcallsBadgesTest::testReadRejectsMalformedRowscallsBadgesTest::testReadSetsTheFieldsAndLabelsOfARowcallsBadgesTest::testRenderWritesAMarkdownImagecalls
Other tests reaching this symbol 8
DefinitionReaderTestcallsDocumentReaderTestcallsLoaderTestcallsCardReaderTestcallsReferenceTestcallsCardWriterTestcallsMarkdownDocumentTestcallsFormatterTestcalls
Relations§
Instantiated in 1
Static calls 3
- static-call Requirements\Config\Markdown\CardReader::card() packages/requirements/src/Config/Markdown/CardReader.php:84
- static-call Requirements\Config\Markdown\Render\CardWriter::render() packages/requirements/src/Config/Markdown/Render/CardWriter.php:53
- static-call Requirements\Config\Markdown\Render\CardWriter::render() packages/requirements/src/Config/Markdown/Render/CardWriter.php:57