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 enum wrapper #375

Merged
merged 1 commit into from
Mar 21, 2017
Merged

add enum wrapper #375

merged 1 commit into from
Mar 21, 2017

Conversation

shmax
Copy link
Collaborator

@shmax shmax commented Mar 8, 2017

Adding an intermediate Enum class. This way consumers of the library can extend ConstraintError without having references to unfamiliar namespaces exposed in their code, and if we ever decide to go with a different enum implementation we don't have to worry (as much) about breaking their code.

Copy link
Contributor

@erayd erayd left a comment

Choose a reason for hiding this comment

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

Assuming your intention with this is for people adding custom code to also be able to add their own errors by creating an Enum subclass, Enum should be abstract and also require the user to define getMessage.


namespace JsonSchema;

class Enum extends \MabeEnum\Enum
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this please be abstract?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Probably. Will give it a try when I get home.

Copy link
Contributor

Choose a reason for hiding this comment

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

If this isn't intended to be extended-only (and might be used directly for something), then it doesn't need to be abstract, and probably shouldn't be. I was suggesting that based on an invalid assumption that this would always be extended for errors.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Well that's the thing--I don't think that Enum or even Mabe/Enum has any utility without being extended. In fact, the base class itself is indeed abstract:

/~https://github.com/marc-mabe/php-enum/blob/master/src/Enum.php#L16

So I think you're right on the money on this one

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha - if that's the case, then yeah, it should be abstract.

namespace JsonSchema;

class Enum extends \MabeEnum\Enum
{
Copy link
Contributor

Choose a reason for hiding this comment

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

This should declare an abstract method getMessage:

abstract public function getMessage();

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm, are you sure? Why would we assume that any other uses of Enum also have something to do with messages?

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point - I assumed based on your summary, but you do mention extending ConstraintError explicitly. Let's leave this PR as you originally had it :-).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You're right. My code makes sense, my comment doesn't. A user would extend ConstraintError, not Mabe/Enum, so my fear of the unfamiliar namespace being exposed was not correct.

Copy link
Contributor

Choose a reason for hiding this comment

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

If that's the case, what is the motivation for this PR? There's nothing that uses it other than ConstraintError, and if you aren't intending users to extend it either...

Copy link
Collaborator Author

@shmax shmax Mar 8, 2017

Choose a reason for hiding this comment

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

More for internal benefit, I guess. If someone else decides to use Enum for something they can just extend /JsonSchema/Enum instead of /Mabe/Enum, and if we ever decide to switch to some other Enum implementation we only have to change the code in one place. Just a little future-proofing.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough :-).

Copy link
Contributor

@erayd erayd left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@bighappyface bighappyface left a comment

Choose a reason for hiding this comment

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

@shmax please rebase, thanks for your patience

@shmax
Copy link
Collaborator Author

shmax commented Mar 17, 2017

Rebased. Thanks for reviewing.

@bighappyface bighappyface merged commit af14372 into jsonrainbow:6.0.0-dev Mar 21, 2017
@erayd erayd mentioned this pull request Mar 21, 2017
erayd pushed a commit to erayd/json-schema that referenced this pull request Mar 22, 2017
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