88use Bolt \Entity \Content ;
99use Bolt \Extension \ExtensionRegistry ;
1010use Bolt \Storage \Query ;
11+ use Pagerfanta \PagerfantaInterface ;
12+ use RuntimeException ;
1113use Symfony \Bundle \SecurityBundle \Security ;
1214use Symfony \Component \Routing \Generator \UrlGeneratorInterface ;
1315use Symfony \Component \Security \Csrf \CsrfTokenManagerInterface ;
@@ -18,7 +20,10 @@ class RedactorConfig
1820{
1921 private const CACHE_DURATION = 1800 ; // 30 minutes
2022
23+ /** @var array<string, null|bool|string|array<string, array<string, bool|string>|string>> */
2124 private ?array $ config = null ;
25+
26+ /** @var array<string, string[]> */
2227 private ?array $ plugins = null ;
2328
2429 public function __construct (
@@ -32,26 +37,32 @@ public function __construct(
3237 ) {
3338 }
3439
40+ /**
41+ * @phpstan-ignore missingType.iterableValue (complex type)
42+ */
3543 public function getConfig (): array
3644 {
3745 if ($ this ->config ) {
3846 return $ this ->config ;
3947 }
4048
41- $ extension = $ this ->registry -> getExtension (Extension::class );
49+ $ extension = $ this ->getExtension ();
4250
4351 $ this ->config = array_replace_recursive ($ this ->getDefaults (), $ extension ->getConfig ()['default ' ], $ this ->getLinks ());
4452
4553 return $ this ->config ;
4654 }
4755
56+ /**
57+ * @phpstan-ignore missingType.iterableValue (complex type)
58+ */
4859 public function getPlugins (): array
4960 {
5061 if ($ this ->plugins ) {
5162 return $ this ->plugins ;
5263 }
5364
54- $ extension = $ this ->registry -> getExtension (Extension::class );
65+ $ extension = $ this ->getExtension ();
5566
5667 $ this ->plugins = $ this ->getDefaultPlugins ();
5768
@@ -62,6 +73,9 @@ public function getPlugins(): array
6273 return $ this ->plugins ;
6374 }
6475
76+ /**
77+ * @return array<string, null|bool|string|array<string, array<string, bool|string>|string>>
78+ */
6579 public function getDefaults (): array
6680 {
6781 $ defaults = [
@@ -113,6 +127,9 @@ public function getDefaults(): array
113127 return $ defaults ;
114128 }
115129
130+ /**
131+ * @return array<string, string[]>
132+ */
116133 public function getDefaultPlugins (): array
117134 {
118135 return [
@@ -142,6 +159,9 @@ public function getDefaultPlugins(): array
142159 ];
143160 }
144161
162+ /**
163+ * @phpstan-ignore missingType.iterableValue (complex type)
164+ */
145165 private function getLinks (): array
146166 {
147167 return $ this ->cache ->get ('redactor_insert_links ' , function (ItemInterface $ item ): array {
@@ -151,6 +171,9 @@ private function getLinks(): array
151171 });
152172 }
153173
174+ /**
175+ * @phpstan-ignore missingType.iterableValue (complex type)
176+ */
154177 private function getLinksHelper (): array
155178 {
156179 $ amount = 100 ;
@@ -161,7 +184,11 @@ private function getLinksHelper(): array
161184 ];
162185 $ contentTypes = $ this ->boltConfig ->get ('contenttypes ' )->where ('viewless ' , false )->keys ()->implode (', ' );
163186
164- $ records = $ this ->query ->getContentForTwig ($ contentTypes , $ params )->setMaxPerPage ($ amount );
187+ /** @var Content[]|PagerfantaInterface<Content> $records */
188+ $ records = $ this ->query ->getContentForTwig ($ contentTypes , $ params ) ?? [];
189+ if ($ records instanceof PagerfantaInterface) {
190+ $ records ->setMaxPerPage ($ amount );
191+ }
165192
166193 $ links = [
167194 '___ ' => [
@@ -170,7 +197,6 @@ private function getLinksHelper(): array
170197 ],
171198 ];
172199
173- /** @var Content $record */
174200 foreach ($ records as $ record ) {
175201 $ extras = $ record ->getExtras ();
176202
@@ -186,4 +212,12 @@ private function getLinksHelper(): array
186212 'definedlinks ' => array_values ($ links ),
187213 ];
188214 }
215+
216+ public function getExtension (): Extension
217+ {
218+ /** @var Extension|null $extension */
219+ $ extension = $ this ->registry ->getExtension (Extension::class);
220+
221+ return $ extension ?? throw new RuntimeException ('Redactor extension not registered ' );
222+ }
189223}
0 commit comments