Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add explicit Stringable interface to UuidInterface #491

Merged
merged 4 commits into from
Feb 7, 2023

Conversation

boesing
Copy link
Contributor

@boesing boesing commented Feb 6, 2023

Description

Even tho, the Stringable interface is implicit on all objects containing the method __toString, it is recommended by PHP to explicitly setting that interface.

From php.net documentation:

[...] Unlike most interfaces, Stringable is implicitly present on any class that has the magic __toString() method defined, although it can and should be declared explicitly.

Motivation and context

I've used Stringable notation recently in an upstream project and then realized that the UuidInterface does not explicitly implements the interface. Due to the magic PHP provides starting with PHP 8.0, it still implements Stringable and thus I was able to use it but to avoid future issues with i.e. PHP 9 where this behavior might change, I wanted to add this here.

How has this been tested?

I've added 2 new checks to the existing tests.
Please note that these tests won't fail even if we remove the interface again due to the fact that PHP adds it implicitly whenever a __toString method is available.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

PR checklist

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING.md document.
  • I have added tests to cover my changes.

Even tho, the `Stringable` interface is implicit on all objects containing the method `__toString`, it is recommended by PHP to explicitly setting that interface.

From php.net documentation:
> [...] Unlike most interfaces, **Stringable** is implicitly present on any class that has the magic `__toString()` method defined, although it can and should be declared explicitly.

Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
@boesing boesing requested a review from ramsey as a code owner February 6, 2023 15:14
…e` interface

NOTE: The test will not fail even if the interface is being removed. This is due to the fact that PHP starting with 8.0 adds the interface implicitly whenever a `__toString` method is available. This might change in the future as per the php.net documentation.
Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
@ramsey
Copy link
Owner

ramsey commented Feb 6, 2023

I'm not sure why phpcs is failing the build for warnings. That's odd. Can you break those assertions across multiple lines so they don't go over 120 characters? In the meantime, I'll figure out how to tell PHP CodeSniffer that warnings aren't failures. 😄

boesing and others added 2 commits February 7, 2023 10:55
@codecov
Copy link

codecov bot commented Feb 7, 2023

Codecov Report

Merging #491 (46d72af) into 4.x (29bb73b) will not change coverage.
The diff coverage is n/a.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##                4.x     #491   +/-   ##
=========================================
  Coverage     95.57%   95.57%           
  Complexity      584      584           
=========================================
  Files            70       70           
  Lines          1561     1561           
=========================================
  Hits           1492     1492           
  Misses           69       69           

@ramsey ramsey merged commit bf2bee2 into ramsey:4.x Feb 7, 2023
@boesing boesing deleted the qa/stringable-interface branch February 7, 2023 16:19
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