Skip to content

Conversation

@cb-alish
Copy link
Contributor

@cb-alish cb-alish commented Jan 28, 2026

🚀 Pull Request Template

📘 Description

There was a bug in the PHP SDK where enums for sub-resources were incorrectly marked as string instead of enum. This PR fixes that issue. We are introducing class based enums.

Before

    /**
    *
    * @var ?string $item_type
    */
    public ?string $item_type;

After

    /**
    *
    * @var ?\Chargebee\ClassBasedEnums\ItemType $item_type
    */
    public ?\Chargebee\ClassBasedEnums\ItemType $item_type;

Class definition

<?php

namespace Chargebee\ClassBasedEnums;

final class ItemType { 
    const PLAN = "plan";
    const ADDON = "addon";
    const CHARGE = "charge";
    const UNKNOWN = "unknown";

    private static array $choices = [ "plan","addon","charge", ];
    public final string $value;

    public static function tryFromValue(string $key): self
    {
        $instance = new self();
        $instance->value = self::isValidChoice($key) ? $key : self::UNKNOWN;

        return $instance;
    }
    public function __toString(): string
    {
        return $this->value;
    }
    private static function isValidChoice(string $key): bool
    {
        return in_array($key, self::$choices);
    }
}
?>

🧩 Related Issues / Tickets

Closes #IssueNumber

📂 Type of Change

  • ✨ Feature
  • 🐛 Bug Fix
  • 📝 Documentation
  • 🧪 Test Improvement
  • 🔧 Refactor / Code Cleanup
  • ⚙️ Build / Tooling

@snyk-io
Copy link

snyk-io bot commented Jan 28, 2026

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

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