Skip to content

Adds toString method to Alpha2Code, Alpha3Code, and AlphaCode classes for better string representation.#22

Merged
gustavofreze merged 1 commit into
mainfrom
feature/develop
Feb 14, 2026
Merged

Adds toString method to Alpha2Code, Alpha3Code, and AlphaCode classes for better string representation.#22
gustavofreze merged 1 commit into
mainfrom
feature/develop

Conversation

@gustavofreze
Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings February 14, 2026 16:14
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 44756e4b9f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/Timezones.php
@gustavofreze gustavofreze merged commit 1aeeed5 into main Feb 14, 2026
10 checks passed
@gustavofreze gustavofreze deleted the feature/develop branch February 14, 2026 16:17
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds toString() methods to the AlphaCode interface and its implementations (Alpha2Code, Alpha3Code), allowing for easy string representation of country codes. Additionally, it modifies the Timezones.findByIdentifier() method to return a non-nullable Timezone object (with UTC as fallback) instead of returning null when a timezone is not found.

Changes:

  • Added toString() method to AlphaCode interface and all implementations to return the alpha code value as a string
  • Changed Timezones.findByIdentifier() from nullable to non-nullable return type, falling back to UTC when a timezone is not found
  • Added comprehensive test coverage for the new toString() functionality
  • Updated existing tests to align with the new findByIdentifier behavior
  • Applied trailing comma formatting to data provider arrays for consistency

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/AlphaCode.php Added toString() method to the interface definition
src/Alpha2Code.php Implemented toString() method returning the 2-letter code value
src/Alpha3Code.php Implemented toString() method returning the 3-letter code value
src/Timezones.php Changed findByIdentifier() return type from nullable to non-nullable with UTC fallback
tests/Models/AlphaCodeXpto.php Added toString() implementation to test enum for interface compliance
tests/CountryTest.php Added new test for toString(), updated tests for findByIdentifier change, added trailing commas, reordered data providers

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

Comment thread src/Timezones.php
Comment on lines +95 to 101
public function findByIdentifier(string $iana): Timezone
{
return array_find(
$this->items,
static fn(Timezone $timezone): bool => $timezone->value === $iana
);
) ?? Timezone::utc();
}
Copy link

Copilot AI Feb 14, 2026

Choose a reason for hiding this comment

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

The signature of findByIdentifier has been changed from returning Timezone|null to returning Timezone (with UTC fallback). However, the README documentation still shows the old behavior where null is returned when a timezone is not found (line 192: $country->timezones->findByIdentifier(iana: 'Asia/Tokyo'); # null). The documentation should be updated to reflect that UTC is now returned instead of null in this case.

Copilot uses AI. Check for mistakes.
Comment thread src/Timezones.php
Comment on lines +95 to 101
public function findByIdentifier(string $iana): Timezone
{
return array_find(
$this->items,
static fn(Timezone $timezone): bool => $timezone->value === $iana
);
) ?? Timezone::utc();
}
Copy link

Copilot AI Feb 14, 2026

Choose a reason for hiding this comment

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

This is a breaking API change. Code that previously relied on checking for null when a timezone is not found will no longer work as expected. Consider whether this breaking change is intentional and properly communicated. If the behavior is changed, consumers who were checking for null (if ($timezone === null)) will now always receive a Timezone object (UTC), which could lead to silent bugs in existing code that expects to handle the null case differently.

Copilot uses AI. Check for mistakes.
Comment thread src/Timezones.php
Comment on lines +95 to 101
public function findByIdentifier(string $iana): Timezone
{
return array_find(
$this->items,
static fn(Timezone $timezone): bool => $timezone->value === $iana
);
) ?? Timezone::utc();
}
Copy link

Copilot AI Feb 14, 2026

Choose a reason for hiding this comment

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

The PR title only mentions adding toString methods, but this PR also includes a significant breaking change to the Timezones.findByIdentifier method (changing from returning null to returning UTC when a timezone is not found). This breaking change should be prominently mentioned in the PR description to ensure reviewers and users are aware of the behavioral change and its implications.

Copilot uses AI. Check for mistakes.
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