Skip to content

Commit 42ad5bd

Browse files
committed
fix: make <code> tags use fences
1 parent e0f4930 commit 42ad5bd

File tree

3 files changed

+79
-8
lines changed

3 files changed

+79
-8
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2235,11 +2235,6 @@ parameters:
22352235
count: 1
22362236
path: src/Renderer/TwigExtension.php
22372237

2238-
-
2239-
message: "#^Method Doctum\\\\Renderer\\\\TwigExtension\\:\\:parseDesc\\(\\) has parameter \\$desc with no typehint specified\\.$#"
2240-
count: 1
2241-
path: src/Renderer/TwigExtension.php
2242-
22432238
-
22442239
message: "#^Method Doctum\\\\Renderer\\\\TwigExtension\\:\\:pathForClass\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
22452240
count: 1

src/Renderer/TwigExtension.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,18 @@ public static function abbrClass($class, bool $absolute = false): string
138138
return sprintf('<abbr title="%s">%s</abbr>', htmlentities($class, ENT_QUOTES), htmlspecialchars($short));
139139
}
140140

141-
public function parseDesc(array $context, $desc, Reflection $classOrFunctionRefl)
141+
public function parseDesc(array $context, ?string $desc, Reflection $classOrFunctionRefl)
142142
{
143-
if (!$desc) {
143+
if ($desc === null || $desc === '') {
144144
return $desc;
145145
}
146146

147147
if (null === $this->markdown) {
148148
$this->markdown = new Parsedown();
149149
}
150150

151+
$desc = str_replace(['<code>', '</code>'], ['```', '```'], $desc);
152+
151153
// FIXME: the @see argument is more complex than just a class (Class::Method, local method directly, ...)
152154
$desc = preg_replace_callback(
153155
'/@see ([^ ]+)/',

tests/Renderer/TwigExtensionTest.php

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,81 @@ public function dataProviderParseDesc(): array
7878
. '<p>' . "\n"
7979
. 'Emulated prepared statements does not communicate with the database server' . "\n"
8080
. 'so <b>PDO::prepare</b> does not check the statement.'
81-
]
81+
],
82+
[
83+
'Collects rows for insert into a database until the buffer size is reached.' . "\n"
84+
. ' Then flushes the buffer to the database and starts over again.' . "\n"
85+
. '' . "\n"
86+
. ' Benefits over collecting a (possibly huge) insert array and then using' . "\n"
87+
. ' $db->sql_multi_insert() include:' . "\n"
88+
. '' . "\n"
89+
. ' - Going over max packet size of the database connection is usually prevented' . "\n"
90+
. ' because the data is submitted in batches.' . "\n"
91+
. '' . "\n"
92+
. ' - Reaching database connection timeout is usually prevented because' . "\n"
93+
. ' submission of batches talks to the database every now and then.' . "\n"
94+
. '' . "\n"
95+
. ' - Usage of less PHP memory because data no longer needed is discarded on' . "\n"
96+
. ' buffer flush.' . "\n"
97+
. '' . "\n"
98+
. ' Attention:' . "\n"
99+
. ' Please note that users of this class have to call flush() to flush the' . "\n"
100+
. ' remaining rows to the database after their batch insert operation is' . "\n"
101+
. ' finished.' . "\n"
102+
. '' . "\n"
103+
. ' Usage:' . "\n"
104+
. ' <code>' . "\n"
105+
. ' $buffer = new \phpbb\db\sql_insert_buffer($db, \'test_table\', 1234);' . "\n"
106+
. '' . "\n"
107+
. ' while (do_stuff())' . "\n"
108+
. ' {' . "\n"
109+
. ' $buffer->insert(array(' . "\n"
110+
. ' \'column1\' => \'value1\',' . "\n"
111+
. ' \'column2\' => \'value2\',' . "\n"
112+
. ' ));' . "\n"
113+
. ' }' . "\n"
114+
. '' . "\n"
115+
. ' $buffer->flush();' . "\n"
116+
. ' </code>' . "\n",
117+
'<p>Collects rows for insert into a database until the buffer size is reached.' . "\n"
118+
. 'Then flushes the buffer to the database and starts over again.</p>' . "\n"
119+
. ''
120+
. '<p>Benefits over collecting a (possibly huge) insert array and then using' . "\n"
121+
. '$db-&gt;sql_multi_insert() include:</p>' . "\n"
122+
. '<ul>' . "\n"
123+
. '<li>' . "\n"
124+
. '<p>Going over max packet size of the database connection is usually prevented' . "\n"
125+
. 'because the data is submitted in batches.</p>' . "\n"
126+
. '</li>' . "\n"
127+
. '<li>' . "\n"
128+
. '<p>Reaching database connection timeout is usually prevented because' . "\n"
129+
. 'submission of batches talks to the database every now and then.</p>' . "\n"
130+
. '</li>' . "\n"
131+
. '<li>' . "\n"
132+
. '<p>Usage of less PHP memory because data no longer needed is discarded on' . "\n"
133+
. 'buffer flush.</p>' . "\n"
134+
. ''
135+
. '<p>Attention:' . "\n"
136+
. 'Please note that users of this class have to call flush() to flush the' . "\n"
137+
. 'remaining rows to the database after their batch insert operation is' . "\n"
138+
. 'finished.</p>' . "\n"
139+
. ''
140+
. '<p>Usage:</p>' . "\n"
141+
. '<pre><code>'
142+
. '$buffer = new \phpbb\db\sql_insert_buffer($db, \'test_table\', 1234);' . "\n"
143+
. '' . "\n"
144+
. 'while (do_stuff())' . "\n"
145+
. '{' . "\n"
146+
. ' $buffer-&gt;insert(array(' . "\n"
147+
. ' \'column1\' =&gt; \'value1\',' . "\n"
148+
. ' \'column2\' =&gt; \'value2\',' . "\n"
149+
. ' ));' . "\n"
150+
. '}' . "\n"
151+
. '' . "\n"
152+
. '$buffer-&gt;flush();</code></pre>' . "\n"
153+
. '</li>' . "\n"
154+
. '</ul>'
155+
],
82156
];
83157
}
84158

0 commit comments

Comments
 (0)