Skip to content

Modernise package for PHP 8.2+#150

Merged
bytestream merged 35 commits into
Gregwar:masterfrom
lachlan-00:php8
Jun 8, 2026
Merged

Modernise package for PHP 8.2+#150
bytestream merged 35 commits into
Gregwar:masterfrom
lachlan-00:php8

Conversation

@lachlan-00

@lachlan-00 lachlan-00 commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

The current code is referencing php8.0 GdImage so I've raised it from 5.3 -> 8.2

static analysis and tests complete successfully.

  • Increased the minimum required PHP version to 8.2 in composer.json, and added phpstan/phpstan as a dev dependency for static analysis.
  • Added new package specific exceptions
  • Removed unused ImageFileHandler class
  • Updated phpstan.neon.dist configuration with higher analysis level
  • Updated phpunit.xml.dist to use the latest schema and improved code coverage configuration.
  • Refactored CaptchaBuilder to use strict property and method typing, PHP 8+ features (union types, constructor property promotion), and improved null safety.
  • Updated method signatures for better type safety and static analysis compatibility, including stricter parameter and return types throughout the class.
  • Improved error handling in OCR-related methods, making failures explicit and safer.
  • Updated README.md.
  • Added type hints and PHP 8+ features, and updated method implementations to improve compatibility with static analyzers like PHPStan.

Copilot AI review requested due to automatic review settings June 4, 2026 04:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Modernizes the library for PHP 8 by adding strict typing across the codebase, updating tooling/configuration, and adjusting tests/documentation accordingly.

Changes:

  • Raised minimum PHP version to 8.0 and added PHPStan config/baseline wiring.
  • Added type declarations and return types across Captcha/Phrase builders and image handling.
  • Updated PHPUnit config and adjusted tests/docs plus ignored generated artifacts.

Reviewed changes

Copilot reviewed 11 out of 13 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
tests/CaptchaBuilderTest.php Updates tests for typed properties/return types; adjusts output file assertions.
src/Gregwar/Captcha/PhraseBuilderInterface.php Adds strict parameter/return types to the phrase builder contract.
src/Gregwar/Captcha/PhraseBuilder.php Implements typed properties and typed method signatures.
src/Gregwar/Captcha/ImageFileHandler.php Adds typed properties/methods and GD image typing; changes GC logic.
src/Gregwar/Captcha/CaptchaBuilderInterface.php Adds typed, modern method signatures and doc annotations.
src/Gregwar/Captcha/CaptchaBuilder.php Broad typing refactor; adds temp dir usage and OCR helper changes.
phpunit.xml.dist Updates PHPUnit config to modern schema/coverage config.
phpstan.neon.dist Removes old distributed PHPStan config.
phpstan.neon Adds new PHPStan config (level 8 + baseline include).
composer.json Raises PHP requirement and adds PHPStan dev dependency.
README.md Updates examples/wording to match modern PHP syntax.
.gitignore Ignores test-generated image outputs and tool caches/lockfile.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Gregwar/Captcha/ImageFileHandler.php Outdated
Comment thread src/Gregwar/Captcha/CaptchaBuilder.php Outdated
Comment thread src/Gregwar/Captcha/CaptchaBuilder.php Outdated
Comment thread src/Gregwar/Captcha/CaptchaBuilder.php Outdated
Comment thread src/Gregwar/Captcha/CaptchaBuilder.php Outdated
Comment thread src/Gregwar/Captcha/CaptchaBuilder.php Outdated
Comment thread src/Gregwar/Captcha/CaptchaBuilder.php Outdated
Comment thread src/Gregwar/Captcha/CaptchaBuilderInterface.php Outdated
Comment thread src/Gregwar/Captcha/CaptchaBuilderInterface.php Outdated
Comment thread src/Gregwar/Captcha/CaptchaBuilderInterface.php Outdated
@bytestream

Copy link
Copy Markdown
Collaborator

The current code is referencing php8.0 GdImage

What do you mean? Link?

@lachlan-00

Copy link
Copy Markdown
Contributor Author

The current code is referencing php8.0 GdImage

What do you mean? Link?

In phpstorm it mentioned php 8.0 when i was updating the code, i'll need to look it up again, but will confirm

@lachlan-00

Copy link
Copy Markdown
Contributor Author

The current code is referencing php8.0 GdImage

What do you mean? Link?

https://php.watch/versions/8.0/gdimage

Here we go, what i mean is that gdimage replaces the resource type.

@bytestream bytestream left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for your efforts.

Comment thread phpunit.xml.dist Outdated
Comment thread composer.json Outdated
Comment thread composer.json
Comment thread composer.json Outdated
Comment thread .gitignore Outdated
Comment thread src/Gregwar/Captcha/ImageFileHandler.php Outdated
Comment thread src/Gregwar/Captcha/CaptchaBuilderInterface.php
Comment thread src/Gregwar/Captcha/CaptchaBuilder.php Outdated
Comment thread .github/workflows/ci.yml Outdated
Comment thread src/Gregwar/Captcha/CaptchaBuilder.php Outdated
@bytestream bytestream changed the title raise minimum php to 8.0, add strict typing and add phpstan Modernise package for PHP 8.2+ Jun 7, 2026
@bytestream

Copy link
Copy Markdown
Collaborator

@lachlan-00 just need to fix those PHPstan errors then I'm happy to merge 👍🏼

* read function value min max checking
* Distort width and height check
explicit int<> typing
@lachlan-00

Copy link
Copy Markdown
Contributor Author

@lachlan-00 just need to fix those PHPstan errors then I'm happy to merge 👍🏼

No problem @bytestream last commit 9d4bd7e addresses 8.5 issues.

  • Explicit int typing on properties and functions
  • swap logic for line 316 if ($this->lineColor !== null) {
  • add width and height check on line 570 for distort call
  • min, max checking on rand function to make sure values are between 0 and 255

Let me know if you need anything else!

@lachlan-00 lachlan-00 requested a review from bytestream June 7, 2026 23:48
@bytestream bytestream merged commit cc91144 into Gregwar:master Jun 8, 2026
4 checks passed
@bytestream

Copy link
Copy Markdown
Collaborator

Thanks for persevering with this @lachlan-00. Your efforts are greatly appreciated 👍🏼

@lachlan-00

Copy link
Copy Markdown
Contributor Author

no problem again!

I wasn't expecting to do much but i think it's a useful library to keep updated and Ampache will start using it to replace our archaic captcha that is VERY machine readable.

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.

3 participants