-
Notifications
You must be signed in to change notification settings - Fork 348
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
Remove setters from UserInterface #367
Remove setters from UserInterface #367
Conversation
👎 |
Wrong. By defining a method in an interface, you're limiting the implementation. Remove the definition to add flexibility and extensibility.
|
👍 |
@@ -4,6 +4,7 @@ | |||
|
|||
interface UserInterface | |||
{ | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this line.
👎 But perhaps this is a alternativ for you. Defined a separate method like |
It seems that you have not bothered to test this change and are operating from a false pretense. Removing a formal declaration from an interface does not prevent you from breaking encapsulation. You're free to continue the mistake of global mutability without the interface imposing it upon you, therefore preserving BC.
|
👎 PS: If you want to enforce immutability - throw exception in setter if value has changed. |
Yep, let's just avoid all the clutter and just implement |
The setters are indeed not required by the interface, but this is a major BC break (to be marked for 1.x) How the object is populated is entirely up to the mapper and eventually to the hydrator that is used internally in ZfcUser (through the form), but AFAIK, no other API internal to ZfcUser requires the setters. I fully agree with @texdc here. If somebody wants to interact with the identity to "write" to it then he should be aware of the specific implementation of the identity itself, and not rely on an interface that was not designed for it and isn't able to handle custom use-cases either (additional fields). Assuming that the identity is anemic is indeed a mistake of ZfcUser, since it tries to provide a generic implementation, and enforcing an anemic identity is not generic enough. |
@Danielss89 just listed me some methods that are indeed required within ZfcUser... this is indeed annoying :-( |
@texdc After discussing with a few people i've come to the following conclusion: |
@Danielss89 OK, but finish #379 first. |
Thanks! I'll start ASAP.
|
Setters are potentially unnecessary and may vary per implementation due to PHP's limitations on type-casting and method signatures.
@Danielss89 @Ocramius This should be ready for review/merge. It looks like the build failed because the mocks were not generated properly. |
Please fix tests, and i will review afterwords. |
It seems to be a 5.3.3 issue only. |
I checked the tests. They appear fine. As I said, the mocks were not generated properly by phpunit - their definitions are accurate. If 5.3 passes, 5.3.3 should as well.
|
I just reran them on travis, they still seem to fail |
I have no control over the failures - they are caused by composer's unreliable loading. No changes have been made to the $ composer install --dev --prefer-source
Loading composer repositories with package information
Installing dependencies (including require-dev)
- Installing zendframework/zendxml (1.0.0)
Cloning 559b34f426d33a11c3db118e00ce14bb8dc64e5f
- Installing zendframework/zendframework (2.3.1)
Cloning 055eac4314425c291f3ef0e104a6196a8fc24cd5
- Installing zendframework/zend-stdlib (2.3.0)
Cloning d1c481b8a43f2f079b16d3567960ba539e9dacaa
- Installing zendframework/zend-eventmanager (2.3.0)
Cloning 048164ee81854942667ffdda3030ce06caa79bb5
- Installing zendframework/zend-db (2.3.0)
Cloning 37d573ea83b9573e2247c36fac7b370283ca673e
- Installing zf-commons/zfc-base (v0.1.2)
Cloning fc68a49b58ba68584a9a4c44a1ca9df12b30d1bf
- Installing pdepend/pdepend (1.1.3)
Cloning 1537f19d62d7b30c13ac173270106df7c6b9c459
- Installing phpmd/phpmd (1.4.1)
Cloning 7d03a50e937811970751697ad1aea33a1089d66f
- Installing symfony/yaml (v2.4.4)
Cloning 65539ecde838f9c0d18b006b2101e3deb4b5c9ff
- Installing phpunit/php-text-template (1.2.0)
Cloning 206dfefc0ffe9cebf65c413e3d0e809c82fbf00a
- Installing phpunit/phpunit-mock-objects (1.2.3)
Cloning 5794e3c5c5ba0fb037b11d8151add2a07fa82875
- Installing phpunit/php-timer (1.0.5)
Cloning 19689d4354b295ee3d8c54b4f42c3efb69cbc17c
- Installing phpunit/php-token-stream (1.2.2)
Cloning ad4e1e23ae01b483c16f600ff1bebec184588e32
- Installing phpunit/php-file-iterator (1.3.4)
Cloning acd690379117b042d1c8af1fafd61bde001bf6bb
- Installing phpunit/php-code-coverage (1.2.17)
Cloning 6ef2bf3a1c47eca07ea95f0d8a902a6340390b34
- Installing phpunit/phpunit (3.7.37)
Cloning ae6cefd7cc84586a5ef27e04bae11ee940ec63dc
- Installing squizlabs/php_codesniffer (1.4.8)
Cloning d26daa8096ad2c8758677f0352597f8cda4722e0
zendframework/zendframework suggests installing doctrine/annotations (Doctrine Annotations >=1.0 for annotation features)
zendframework/zendframework suggests installing ircmaxell/random-lib (Fallback random byte generator for Zend\Math\Rand if OpenSSL/Mcrypt extensions are unavailable)
zendframework/zendframework suggests installing ocramius/proxy-manager (ProxyManager 0.5.* to handle lazy initialization of services)
zendframework/zendframework suggests installing zendframework/zendpdf (ZendPdf for creating PDF representations of barcodes)
zendframework/zendframework suggests installing zendframework/zendservice-recaptcha (ZendService\ReCaptcha for rendering ReCaptchas in Zend\Captcha and/or Zend\Form)
phpunit/phpunit suggests installing phpunit/php-invoker (~1.1)
Writing lock file
Generating autoload files $ ls -l vendor/zendframework/
total 0
drwxr-xr-x 3 george wheel 102 May 2 02:56 zend-db
drwxr-xr-x 3 george wheel 102 May 2 02:56 zend-eventmanager
drwxr-xr-x 3 george wheel 102 May 2 02:56 zend-stdlib
drwxr-xr-x 21 george wheel 714 May 2 02:56 zendframework
drwxr-xr-x 10 george wheel 340 May 2 02:54 zendxml $ ls -l vendor/zendframework/zendframework/library/Zend/Authentication/
total 40
drwxr-xr-x 12 george wheel 408 May 2 02:56 Adapter
-rw-r--r-- 1 george wheel 4016 May 2 02:56 AuthenticationService.php
-rw-r--r-- 1 george wheel 1007 May 2 02:56 AuthenticationServiceInterface.php
drwxr-xr-x 6 george wheel 204 May 2 02:56 Exception
-rw-r--r-- 1 george wheel 459 May 2 02:56 README.md
-rw-r--r-- 1 george wheel 2703 May 2 02:56 Result.php
drwxr-xr-x 6 george wheel 204 May 2 02:56 Storage
drwxr-xr-x 3 george wheel 102 May 2 02:56 Validator
-rw-r--r-- 1 george wheel 1490 May 2 02:56 composer.json
$ php -v
PHP 5.3.28 (cli) (built: May 2 2014 00:54:57) (DEBUG)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies
with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans Clone the repo/PR and run the tests under |
@Danielss89 do we really need 5.3.3 after this refactoring? We could just bump like ZF2 did... |
Setter methods are potentially unnecessary and may vary per implementation due to PHP's limitations on type-hinting and method signatures. For instance, if I have an
EmailAddress
value object, I'll want to construct my user entity like so:A fatal error occurs:
Also, if visibility is changed on the setters, fatal errors occur. In DDD entities, the
$id
is immutable: