8000 refactor: compare MAL display strings through named constants by irfan-dahir · Pull Request #606 · jikan-me/jikan · GitHub
[go: up one dir, main page]

Skip to content

refactor: compare MAL display strings through named constants - #606

Merged
irfan-dahir merged 1 commit into
feat/backend-suite-context-docsfrom
feat/display-sentinel-constants
Oct 11, 2026
Merged

irfan-dahir merged 1 commit into
feat/backend-suite-context-docsfrom
feat/display-sentinel-constants

Conversation

@irfan-dahir
Copy link
Copy Markdown
Collaborator

Stacked on #605. Resolves all 20 audit_api_consistency (load-bearing-copy) findings on jikan — the item from the gap analysis that makes the suite's "paid for itself" claim concrete.

The defect

The parsers/models compared scraped text against hand-typed display strings at 21 sites:
'Unknown', 'N/A', 'Filler', 'Recap', 'Currently Airing', 'Publishing', 'Not available', 'None', 'Synonyms' (e.g. AnimeParser.php:207, MangaParser.php:217, AnimeEpisodeParser.php:151).

These strings are upstream data from MyAnimeList, not jikan's own copy. So the failure mode is precisely the one the audit guards: if MAL renames a display string (e.g. Unknown → Not available), every hand-typed comparison silently stops matching and the API quietly starts returning null/derived values.

The fix

  • src/Helper/Constants.php: new DISPLAY_* constants, documented as upstream display strings compared by value — an upstream rename becomes a one-line change in one file.
  • 10 parser/model files: every comparison, plus the one AnimeCardParser emission of 'Unknown', now references the constant so comparison and emission cannot diverge. Missing Jikan\Helper\Constants imports added.
  • DECISIONS.md: first authored entry (still-marked stub) recording the decision, the alternatives considered (enum — rejected, reasons stated), and the impact.

Verified

Check Result
audit_api_consistency ✅ clean, exit 0 over 388 files (was 20 findings)
phpunit ✅ 394/394 (behaviour unchanged — constants carry identical strings)
php-cs-fixer ✅ 0 files need fixing
pre-commit gates ran on this commit (error-handling + network-coupling envelopes, both clean)

Decisions log first entry also starts closing the documentation debt (5 stubs).

Resolves the 20 backend-suite audit_api_consistency findings
(load-bearing-copy) on jikan. The parsers and models compared scraped text
against hand-typed display strings ('Unknown', 'N/A', 'Filler', 'Recap',
'Currently Airing', ...) at 21 sites. Those strings are upstream data from
MyAnimeList, not jikan's own copy, so the failure mode is silent drift: an
upstream rename no longer matches the sentinel, and the parser quietly
changes what the API returns.

- src/Helper/Constants.php: new DISPLAY_* constants, each with a docblock
  note that it is an upstream display string compared by value.
- 10 parser/model files: every comparison AND the one AnimeCardParser
  emission now reference the constant (so comparison and emission cannot
  diverge); adding the missing Jikan\Helper\Constants imports.
- DECISIONS.md: first authored entry recording the decision and why an enum
  was rejected.

Verified: audit_api_consistency clean (exit 0) over 388 files; phpunit
394/394 (behaviour unchanged - constants carry identical strings);
php-cs-fixer clean.
@irfan-dahir
irfan-dahir merged commit 3fc8ede into feat/backend-suite-context-docs Oct 11, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0