Skip to content

Commit 7400c89

Browse files
committed
Bard added
1 parent 5e5d6a8 commit 7400c89

File tree

2 files changed

+101
-1
lines changed

2 files changed

+101
-1
lines changed

src/Archetype/Bard.php

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
3+
namespace Calvert\DndErrors\Archetype;
4+
5+
use Calvert\DndErrors\ErrorContext;
6+
7+
final class Bard implements ArchetypeInterface
8+
{
9+
public function getSlug(): string
10+
{
11+
return 'bard';
12+
}
13+
14+
public function render(ErrorContext $context): string
15+
{
16+
$location = 'Unknown location';
17+
if (is_string($context->file) && is_int($context->line)) {
18+
$location = $context->file . ':' . $context->line;
19+
}
20+
21+
$header = $this->pickHeader($context);
22+
$flavour = $this->pickFlavourLine($context);
23+
24+
$body = array(
25+
$header,
26+
'',
27+
$flavour,
28+
'',
29+
'Message: ' . $context->message,
30+
'Location: ' . $location,
31+
);
32+
33+
return implode("\n", $body) . "\n";
34+
}
35+
36+
private function pickHeader(ErrorContext $context): string
37+
{
38+
$headers = array(
39+
"🎻 A BARD hears a discordant note in the runtime. 🎻",
40+
"🎭 TRAGICOMEDY: An exception takes centre stage. 🎭",
41+
"🎶 The BARD strikes a chord… and the stack trace harmonises back. 🎶",
42+
"🍷 TALE OF WOES: The script falters mid-verse. 🍷",
43+
"🪕 The BARD tunes the lute—something’s off in the code. 🪕",
44+
);
45+
46+
if ($context->type === 'fatal') {
47+
$headers[] = "💀 FINAL VERSE: Fatal error—curtain down, no encore. 💀";
48+
$headers[] = "🩸 TRAGEDY: The runtime collapses to thunderous silence. 🩸";
49+
}
50+
51+
return $headers[random_int(0, count($headers) - 1)];
52+
}
53+
54+
private function pickFlavourLine(ErrorContext $context): string
55+
{
56+
$lines = array(
57+
'The bard winks: “Every bug is a plot twist, darling.”',
58+
'The bard sighs dramatically: “Alas, our hero has failed their saving throw.”',
59+
'The bard narrates: “And lo—upon line and file, betrayal was revealed.”',
60+
'The bard strums softly: “We can fix this… with a little rhythm and discipline.”',
61+
'The bard raises a glass: “To the brave debugger, and the doomed deploy.”',
62+
'The bard declares: “Let us rewrite this scene before the audience notices.”',
63+
);
64+
65+
if (stripos($context->message, 'undefined') !== false) {
66+
$lines[] = 'The bard sings: “A name without a chorus… undefined, unheard, unseen.”';
67+
$lines[] = 'The bard mutters: “You introduced a character that never appears in Act One.”';
68+
}
69+
70+
if (stripos($context->message, 'null') !== false) {
71+
$lines[] = 'The bard gasps: “You handed the stage… nothingness.”';
72+
$lines[] = 'The bard whispers: “Null entered the tavern, and the whole story fell quiet.”';
73+
}
74+
75+
if (stripos($context->message, 'argument') !== false || stripos($context->message, 'type') !== false) {
76+
$lines[] = 'The bard scolds: “Your cast is mismatched—wrong role, wrong type, wrong timing.”';
77+
$lines[] = 'The bard sighs: “That argument simply doesn’t fit the metre.”';
78+
}
79+
80+
if ($context->type === 'fatal') {
81+
$lines[] = 'The bard bows: “No rewrite can save a stage that has already burned.”';
82+
$lines[] = 'The bard murmurs: “The final line was spoken… and the process exited.”';
83+
$lines[] = 'The bard lowers their voice: “Silence. The realm has crashed.”';
84+
}
85+
86+
if (stripos($context->message, 'parse') !== false || stripos($context->message, 'syntax') !== false) {
87+
$lines[] = 'The bard winces: “Those lines don’t scan. The syntax breaks the song.”';
88+
$lines[] = 'The bard taps the parchment: “Your verse is malformed. The interpreter refuses to read it.”';
89+
}
90+
91+
if (stripos($context->message, 'memory') !== false) {
92+
$lines[] = 'The bard warns: “We’ve spent the last of our inspiration… memory is gone.”';
93+
$lines[] = 'The bard declares: “Too many verses, not enough breath—resources exhausted.”';
94+
}
95+
96+
return $lines[random_int(0, count($lines) - 1)];
97+
}
98+
}

src/DndErrors.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Calvert\DndErrors\Archetype\Paladin;
77
use Calvert\DndErrors\Archetype\Wizard;
88
use Calvert\DndErrors\Archetype\Ranger;
9+
use Calvert\DndErrors\Archetype\Bard;
910
use ErrorException;
1011
use Throwable;
1112

@@ -15,7 +16,7 @@ final class DndErrors
1516

1617
/**
1718
* @param array $options {
18-
* @type string $archetype 'paladin'|'ranger'|'wizard'|'random'
19+
* @type string $archetype 'paladin'|'ranger'|'wizard'|'bard'|'random'
1920
* @type bool $exit Whether to exit after rendering uncaught errors. Default true.
2021
* }
2122
*/
@@ -110,6 +111,7 @@ private static function resolveArchetype(string $slug): ArchetypeInterface
110111
'paladin' => new Paladin(),
111112
'wizard' => new Wizard(),
112113
'ranger' => new Ranger(),
114+
'bard' => new Bard(),
113115
);
114116

115117
if ($slug === 'random') {

0 commit comments

Comments
 (0)