Skip to content

Commit 94cae55

Browse files
committed
refactor: standardize FlareException method parameter usage across codebase
Aligned all `FlareException` instantiations to use the `method: __METHOD__` parameter for consistency. Updated exception messages and adjusted formatting where necessary to ensure compliance with the revised standard.
1 parent de4df3c commit 94cae55

22 files changed

Lines changed: 103 additions & 60 deletions

.audit/260719012-combined/10-architektur.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,11 @@ Doku-Drift gegen den aktuellen Code: `ListBuilderFactory` heißt `ListSpecBuilde
5555
>
5656
> **Nutzer-Antwort: Im Backend wird nun ein Fehler ausgegeben, wenn zwei Filter mit demselben Alias publiziert werden.**
5757
58-
## A-08: `FlareException`: `method` vs. `source` inkonsistent — Minor (claude)
59-
60-
Die Exception bietet beide Parameter (`src/Exception/FlareException.php:17-18`), der Code nutzt beide uneinheitlich mit demselben Inhalt (`__METHOD__`): Loader nutzen `method:` (`src/Engine/Loader/InteractiveLoader.php:52`, `AggregationLoader.php:52`), Projector/Views/Calendar-Integration `source:` (`src/Engine/Projector/AbstractProjector.php:124`, `src/Engine/View/HandlesModelsTrait.php:33,42,57,66,75`, `src/Integration/ContaoCalendar/Loader/EventsAggregationLoader.php:66`), `ValidationLoader` keins von beiden (`src/Engine/Loader/ValidationLoader.php:57,92`).
58+
> ## A-08: `FlareException`: `method` vs. `source` inkonsistent — Minor (claude)
59+
>
60+
> Die Exception bietet beide Parameter (`src/Exception/FlareException.php:17-18`), der Code nutzt beide uneinheitlich mit demselben Inhalt (`__METHOD__`): Loader nutzen `method:` (`src/Engine/Loader/InteractiveLoader.php:52`, `AggregationLoader.php:52`), Projector/Views/Calendar-Integration `source:` (`src/Engine/Projector/AbstractProjector.php:124`, `src/Engine/View/HandlesModelsTrait.php:33,42,57,66,75`, `src/Integration/ContaoCalendar/Loader/EventsAggregationLoader.php:66`), `ValidationLoader` keins von beiden (`src/Engine/Loader/ValidationLoader.php:57,92`).
61+
>
62+
> **Nutzer-Antwort: Angeglichen -- method: __METHOD__, source, wenn verfügbar: table.id -- übertragen auf gesamte Codebase**
6163
6264
## A-09: `symfony/event-dispatcher` nicht direkt deklariert — Minor (claude, reduzierter Umfang)
6365

src/Controller/ContentElement/ListViewController.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ protected function getFrontendResponse(Template $template, ContentModel $content
8181
$listModel = $contentModel->getRelated(ContentContainer::FIELD_LIST);
8282

8383
if (!$listModel instanceof ListModel) {
84-
throw new FilterException('No list model found.');
84+
throw new FilterException('No list model found.', method: __METHOD__);
8585
}
8686
}
8787
catch (\Exception $e)
@@ -109,8 +109,12 @@ protected function getFrontendResponse(Template $template, ContentModel $content
109109
}
110110
catch (FlareException $e)
111111
{
112-
$this->logger->error(\sprintf('%s (tl_content.id=%s, tl_flare_list.id=%s)', $e->getMessage(), $contentModel->id, $listModel->id),
113-
['contao' => new ContaoContext(__METHOD__, ContaoContext::ERROR), 'exception' => $e]);
112+
$this->logger->error(\sprintf(
113+
'%s (tl_content.id=%s, tl_flare_list.id=%s)',
114+
$e->getMessage(),
115+
$contentModel->id,
116+
$listModel->id
117+
), ['contao' => new ContaoContext(__METHOD__, ContaoContext::ERROR), 'exception' => $e]);
114118

115119
return $this->getErrorResponse($e);
116120
}

src/Controller/ContentElement/ReaderController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ protected function getFrontendResponse(Template $template, ContentModel $content
9595
$listModel = $contentModel->getRelated(ContentContainer::FIELD_LIST);
9696

9797
if (!$listModel instanceof ListModel) {
98-
throw new FlareException('No list model found.');
98+
throw new FlareException('No list model found.', method: __METHOD__);
9999
}
100100
}
101101
catch (\Exception $e)

src/Engine/Engine.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ public function createView(): ViewInterface
5050
['type' => $type, 'config' => $config] = $modConf;
5151

5252
$mod = $this->engineModRegistry->get($type)
53-
?? throw new FlareException(\sprintf('No FLARE engine mod registered with type "%s".', $type));
53+
?? throw new FlareException(
54+
\sprintf('No FLARE engine mod registered with type "%s".', $type),
55+
method: __METHOD__,
56+
);
5457

5558
$mod->apply($engine, $config);
5659
}

src/Engine/Loader/ValidationLoader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function fetchEntryById(int $id): ?array
7373
}
7474
catch (\Throwable $e)
7575
{
76-
throw new FlareException($e->getMessage(), $e->getCode(), $e);
76+
throw new FlareException($e->getMessage(), $e->getCode(), $e, method: __METHOD__);
7777
}
7878
}
7979

@@ -120,7 +120,7 @@ public function fetchEntryByAutoItem(string $autoItem): ?array
120120
}
121121
catch (\Throwable $e)
122122
{
123-
throw new FlareException($e->getMessage(), $e->getCode(), $e);
123+
throw new FlareException($e->getMessage(), $e->getCode(), $e, method: __METHOD__);
124124
}
125125
}
126126

src/Engine/Projector/AbstractProjector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ protected function getProjectorFor(
9696
catch (ContainerExceptionInterface $e)
9797
{
9898
throw new FlareException(\sprintf('Failed to locate service "%s"', ProjectorRegistry::class),
99-
previous: $e, source: __METHOD__);
99+
previous: $e, method: __METHOD__);
100100
}
101101
}
102102

@@ -121,7 +121,7 @@ protected function getCurrentRequest(): Request
121121
}
122122
catch (ContainerExceptionInterface $e)
123123
{
124-
throw new FlareException('Request not available', previous: $e, source: __METHOD__);
124+
throw new FlareException('Request not available', previous: $e, method: __METHOD__);
125125
}
126126

127127
return $request;

src/Engine/View/HandlesModelsTrait.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ public function fetchModel(string $table, int|string $id_or_alias, callable $get
2222
// Contao native model cache
2323
{
2424
Controller::loadDataContainer($table);
25-
25+
2626
if (!isset($GLOBALS['TL_DCA'][$table]['fields']['published']) || $model->published) {
2727
return $model;
2828
}
2929
}
3030

3131
$modelClass = Model::getClassFromTable($table);
3232
if (!\class_exists($modelClass)) {
33-
throw new FlareException(\sprintf('Model class does not exist: "%s"', $modelClass), source: __METHOD__);
33+
throw new FlareException(\sprintf('Model class does not exist: "%s"', $modelClass), method: __METHOD__);
3434
}
3535

3636
if (!$row = $getEntry($id_or_alias)) {
@@ -39,7 +39,7 @@ public function fetchModel(string $table, int|string $id_or_alias, callable $get
3939

4040
$model = new $modelClass($row);
4141
if (!$model instanceof Model) {
42-
throw new FlareException('Invalid model instance.', source: __METHOD__);
42+
throw new FlareException('Invalid model instance.', method: __METHOD__);
4343
}
4444

4545
$registry->register($model);
@@ -54,7 +54,7 @@ public function createModelsFromEntries(string $table, array $entries): array
5454
{
5555
$modelClass = Model::getClassFromTable($table);
5656
if (!\class_exists($modelClass)) {
57-
throw new FlareException(\sprintf('Model class does not exist: "%s"', $modelClass), source: __METHOD__);
57+
throw new FlareException(\sprintf('Model class does not exist: "%s"', $modelClass), method: __METHOD__);
5858
}
5959

6060
$registry = Model\Registry::getInstance();
@@ -63,7 +63,7 @@ public function createModelsFromEntries(string $table, array $entries): array
6363
foreach ($entries as $entry)
6464
{
6565
if (!$id = $entry['id'] ?? null) {
66-
throw new FlareException('Entry does not have an ID.', source: __METHOD__);
66+
throw new FlareException('Entry does not have an ID.', method: __METHOD__);
6767
}
6868

6969
if (!$model = $registry->fetch($table, $id))
@@ -72,7 +72,7 @@ public function createModelsFromEntries(string $table, array $entries): array
7272
$model = new $modelClass($entry);
7373

7474
if (!$model instanceof Model) {
75-
throw new FlareException('Invalid model instance.', source: __METHOD__);
75+
throw new FlareException('Invalid model instance.', method: __METHOD__);
7676
}
7777

7878
$registry->register($model);

src/Exception/InferenceException.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ public function __construct(
1515
protected string $translationKey = '',
1616
protected array $formatParams = [],
1717
int $code = 0,
18-
?\Throwable $previous = null
18+
?\Throwable $previous = null,
19+
?string $method = null,
1920
) {
20-
parent::__construct($message, $code, $previous);
21+
parent::__construct($message, $code, $previous, $method);
2122
}
2223

2324
public function getTranslationKey(): string
@@ -29,4 +30,4 @@ public function getFormatParams(): array
2930
{
3031
return $this->formatParams;
3132
}
32-
}
33+
}

src/Exception/ViewException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static function create(string $expectedClass, mixed $var, ?string $method
2121

2222
return new self(
2323
message: \sprintf('Expected instance of %s, got %s', $expectedClass, $type),
24-
method: $method
24+
method: $method,
2525
);
2626
}
27-
}
27+
}

src/Filter/Element/ArchiveFilterElement.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ public function buildForm(FilterFormBuilderInterface $builder, FilterContext $co
118118
$parents = $this->fetchParents($ptable, $config['whitelist_parents']);
119119

120120
if (!$parents) {
121-
throw new FilterException('No whitelisted parents defined or parent table class invalid.');
121+
throw new FilterException(
122+
'No whitelisted parents defined or parent table class invalid.',
123+
method: __METHOD__,
124+
);
122125
}
123126

124127
foreach ($parents as $parent)
@@ -132,7 +135,7 @@ public function buildForm(FilterFormBuilderInterface $builder, FilterContext $co
132135
if (!$inferrer->isDcaDynamicPtable())
133136
// no valid ptable available
134137
{
135-
throw new FilterException('No valid ptable found.');
138+
throw new FilterException('No valid ptable found.', method: __METHOD__);
136139
}
137140

138141
/**
@@ -141,7 +144,7 @@ public function buildForm(FilterFormBuilderInterface $builder, FilterContext $co
141144

142145
if (!$groups = $config['group_whitelist_parents'])
143146
{
144-
throw new FilterException('No whitelisted parents defined.');
147+
throw new FilterException('No whitelisted parents defined.', method: __METHOD__);
145148
}
146149

147150
foreach ($groups as $group)
@@ -158,7 +161,7 @@ public function buildForm(FilterFormBuilderInterface $builder, FilterContext $co
158161
}
159162

160163
if (!$choices->count()) {
161-
throw new FilterException('No valid whitelisted parents defined.');
164+
throw new FilterException('No valid whitelisted parents defined.', method: __METHOD__);
162165
}
163166

164167
$choices->setModelSuffix('(%@name%)');
@@ -190,7 +193,7 @@ public function buildFilter(FilterBuilderInterface $builder, FilterContext $cont
190193
if ($inferrer->getDcaMainPtable())
191194
{
192195
if (!$pids = \array_column($selectedModels, 'id')) {
193-
throw new FilterException('No valid parent archive ids extracted.');
196+
throw new FilterException('No valid parent archive ids extracted.', method: __METHOD__);
194197
}
195198

196199
$builder->add(ArchiveFilterType::class, [
@@ -204,7 +207,7 @@ public function buildFilter(FilterBuilderInterface $builder, FilterContext $cont
204207
if (!$inferrer->isDcaDynamicPtable())
205208
// no valid ptable available
206209
{
207-
throw new FilterException('No valid ptable found.');
210+
throw new FilterException('No valid ptable found.', method: __METHOD__);
208211
}
209212

210213
/**

0 commit comments

Comments
 (0)