Skip to content

Conversation

@sasezaki
Copy link
Contributor

Sadly, PR #562 introduces some inline @var
Using inline var is not encouraged.
https://phpstan.org/writing-php-code/phpdocs-basics#inline-%40var

Summary

This PR enhances type safety and code quality by adding PHPStan generic type annotations throughout the codebase and refactoring detector implementations to be more concise.

  • Add @extends and @template-extends generic type annotations to all Extractor and Detector classes across all adapters (Archive, Gist, ImageShack, Twitter, Wikipedia, Facebook, Github, Flickr, etc.)
  • Remove redundant intermediate $extractor variables in detector classes, accessing API directly via $this->extractor->getApi()
  • Simplify createCustomDetectors() return type annotations by leveraging generics

Benefits

  • Improved type safety: PHPStan can now properly infer types through the generic inheritance chain
  • Better IDE support: Autocomplete and type hints work correctly with properly typed generics
  • Cleaner code: Eliminated unnecessary intermediate variables that added no value

…ctors

      Added PHPDoc template annotations to improve type safety and PHPStan compatibility across all adapter classes. This change removes the need for inline @var annotations by properly declaring generic type
      relationships between Extractors and Detectors.
  Simplify code by directly accessing API from extractor property instead of
  using intermediate  variable across multiple adapter detectors
@oscarotero oscarotero requested a review from Vitorinox October 22, 2025 08:36
Copy link
Collaborator

@Vitorinox Vitorinox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! The added generics and refactors make the code cleaner and more maintainable without introducing any regressions. Approving this

@Vitorinox Vitorinox merged commit b87a812 into php-embed:master Oct 22, 2025
7 checks passed
@sasezaki sasezaki deleted the generics branch October 25, 2025 02:47
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.

2 participants