Skip to content

feat!: replace dasprid/enum with native PHP enums#230

Open
DASPRiD wants to merge 1 commit into
mainfrom
feat/native-enums
Open

feat!: replace dasprid/enum with native PHP enums#230
DASPRiD wants to merge 1 commit into
mainfrom
feat/native-enums

Conversation

@DASPRiD

@DASPRiD DASPRiD commented Apr 5, 2026

Copy link
Copy Markdown
Member

BREAKING CHANGE: All enum classes (ErrorCorrectionLevel, Mode, CharacterSetEci, GradientType) are now native PHP enums. Static method access like ErrorCorrectionLevel::L() must be changed to ErrorCorrectionLevel::L (without parentheses).

Closes #198

BREAKING CHANGE: All enum classes (ErrorCorrectionLevel, Mode,
CharacterSetEci, GradientType) are now native PHP enums. Static
method access like ErrorCorrectionLevel::L() must be changed to
ErrorCorrectionLevel::L (without parentheses).

Closes #198

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@codecov

codecov Bot commented Apr 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 63.13364% with 80 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.72%. Comparing base (bf7d67c) to head (c95e730).
⚠️ Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
src/Renderer/Image/EpsImageBackEnd.php 0.00% 46 Missing ⚠️
src/Common/CharacterSetEci.php 85.00% 12 Missing ⚠️
src/Renderer/Image/SvgImageBackEnd.php 57.14% 12 Missing ⚠️
src/Renderer/Image/ImagickImageBackEnd.php 16.66% 5 Missing ⚠️
src/Common/ErrorCorrectionLevel.php 85.00% 3 Missing ⚠️
src/Common/Mode.php 95.00% 1 Missing ⚠️
src/Encoder/Encoder.php 92.85% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main     #230      +/-   ##
============================================
+ Coverage     71.81%   72.72%   +0.90%     
- Complexity      995     1075      +80     
============================================
  Files            49       49              
  Lines          3151     3226      +75     
============================================
+ Hits           2263     2346      +83     
+ Misses          888      880       -8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@vlakoff

vlakoff commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

You may also want to update in CLAUDE.md, changing:

   - `Version`, `ErrorCorrectionLevel`, `Mode`, `CharacterSetEci` - QR spec enums (using `dasprid/enum`)

to:

   - `Version`, `ErrorCorrectionLevel`, `Mode`, `CharacterSetEci` - QR spec enums

@DASPRiD

DASPRiD commented Apr 7, 2026

Copy link
Copy Markdown
Member Author

@vlakoff good point. the rest of the implementation looks fine to you?

round($centerY, self::PRECISION),
round(max($width, $height) / 2, self::PRECISION)
),
};

@vlakoff vlakoff Apr 13, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The sprintf() may be factorized:

$coords = match ($gradient->getType()) {
    GradientType::HORIZONTAL => [
        round($x, self::PRECISION),
        round($y, self::PRECISION),
        round($x + $width, self::PRECISION),
        round($y, self::PRECISION),
    ],

    // ...

    GradientType::RADIAL => [
        round($centerX, self::PRECISION),
        round($centerY, self::PRECISION),
        0,
        round($centerX, self::PRECISION),
        round($centerY, self::PRECISION),
        round(max($width, $height) / 2, self::PRECISION),
    ],
};

$this->eps .= sprintf(
    " /Coords [ %s ]\n",
    implode(' ', $coords)
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We may even go further:

$coords = match ($gradient->getType()) {
    GradientType::HORIZONTAL => [
        $x,
        $y,
        $x + $width,
        $y,
    ],

    // ...

    GradientType::RADIAL => [
        $centerX,
        $centerY,
        0,
        $centerX,
        $centerY,
        max($width, $height) / 2,
    ],
};

$coords = array_map(
    fn ($v) => round($v, self::PRECISION),
    $coords
);

$this->eps .= sprintf(
    " /Coords [ %s ]\n",
    implode(' ', $coords)
);

'cx' => ($x + $width) / 2, 'cy' => ($y + $height) / 2,
'r' => max($width, $height) / 2,
],
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It may be more readable if each item is placed on its own line.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

+1, and I think the same can be said for some match statement branches in this diff as well

@vlakoff

vlakoff commented May 17, 2026

Copy link
Copy Markdown
Contributor

I went through the code again with Claude's help and have nothing more to flag. The implementation looks good overall — my suggestions above are the only things I'd want to see addressed first.

@DASPRiD

DASPRiD commented May 19, 2026

Copy link
Copy Markdown
Member Author

I'll look into that once I have proper internet again - my ISP has… issues right now…

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.

Native PHP enums for 3.0

3 participants