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

[Addressing] Country name to code converter extraction #4252

Merged

Conversation

lchrusciel
Copy link
Member

Q A
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
License MIT

*
* @return string
*
* @throws \InvalidArgumentException If name is not found in country code registry.
Copy link
Member

Choose a reason for hiding this comment

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

Should the @throws docblock be in interface? I think it's an implementation detail.

Copy link
Contributor

Choose a reason for hiding this comment

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

IMHO the interface is right place for it, but I'd comment it with "If conversion fails"

Copy link
Member

Choose a reason for hiding this comment

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

👍

Copy link
Member Author

Choose a reason for hiding this comment

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

I think, that @Zales0123 is right. As far, as we don't depend on this exception it is an implementation detail. It should be placed in class.

Copy link
Contributor

Choose a reason for hiding this comment

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

So what's the other way to tell the user that given country name cannot be transformed? It's one of the obvious cases that should be a part of a contract, otherwise there is no way to handle an transformation error.

Copy link
Contributor

Choose a reason for hiding this comment

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

The interface know nothing about the exceptions since it's only abstraction layer. The exceptions are dependent on implementation and should be declared there.

Copy link
Contributor

Choose a reason for hiding this comment

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

It knows nothing, but we can declare, that implementations will throw given type of exception if something bad happens, so the interface consumer can catch it and handle it. Throwing an exception is one of the ways to communicate between objects just like returning a value.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that while defining contract we can specify which exception should be thrown (it's a pity that PHP doesn't enforce it on implementations...). In that particular case it is totally valid to specify the exception 👍

@michalmarcinkowski
Copy link
Contributor

👍 for extracting, after this is merged we can reuse it in contexts, fixtures and few other places in Sylius also :)

@michalmarcinkowski michalmarcinkowski added Enhancement Minor issues and PRs improving the current solutions (optimizations, typo fixes, etc.). DX Issues and PRs aimed at improving Developer eXperience. labels Feb 22, 2016
@lchrusciel lchrusciel force-pushed the country-name-to-code-converter branch from 08f4b7e to 59951a8 Compare February 22, 2016 14:10
@lchrusciel lchrusciel changed the title [Behat] Country name to code converter extraction [Addressing] Country name to code converter extraction Feb 22, 2016
@@ -17,6 +17,7 @@
<import resource="services/pages.xml"/>
</imports>
<parameters>
<parameter key="sylius.behat.converter.country_name_to_code.class">Sylius\Behat\CountryNameToCodeConverter</parameter>
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 be removed

@lchrusciel lchrusciel force-pushed the country-name-to-code-converter branch from 59951a8 to 476189b Compare February 22, 2016 14:33
*
* @throws \InvalidArgumentException If name is not found in country code registry.
*/
public function convertToCode($name, $locale = 'en');
Copy link
Contributor

Choose a reason for hiding this comment

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

We should not define defaults on interface.

@lchrusciel
Copy link
Member Author

It is ready to merge

michalmarcinkowski added a commit that referenced this pull request Feb 22, 2016
[Addressing] Country name to code converter extraction
@michalmarcinkowski michalmarcinkowski merged commit 588daf9 into Sylius:master Feb 22, 2016
@michalmarcinkowski
Copy link
Contributor

Thanks Łukasz! 👍

@lchrusciel lchrusciel deleted the country-name-to-code-converter branch February 26, 2016 13:42
pamil pushed a commit to pamil/Sylius that referenced this pull request May 7, 2019
…onverter

[Addressing] Country name to code converter extraction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DX Issues and PRs aimed at improving Developer eXperience. Enhancement Minor issues and PRs improving the current solutions (optimizations, typo fixes, etc.).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants