diff options
author | Fabien Potencier <fabien.potencier@gmail.com> | 2013-11-22 18:42:00 +0100 |
---|---|---|
committer | Fabien Potencier <fabien.potencier@gmail.com> | 2013-11-22 18:42:00 +0100 |
commit | 6dad5f88cf869ae3d444b9ddfe5bcaa197da2ee7 (patch) | |
tree | 01402f9d446f6934758d2c8dab2a2b975c9aaceb /Core/Authentication | |
parent | 741521fab4caa2995bb8473db832e2bd84e45816 (diff) | |
parent | 05352c24aebf6214be8e82ebf8aa1465341e4d7e (diff) | |
download | symfony-security-6dad5f88cf869ae3d444b9ddfe5bcaa197da2ee7.zip symfony-security-6dad5f88cf869ae3d444b9ddfe5bcaa197da2ee7.tar.gz symfony-security-6dad5f88cf869ae3d444b9ddfe5bcaa197da2ee7.tar.bz2 |
minor #9487 unify constructor initialization style throughout symfony (Tobion)
This PR was merged into the master branch.
Discussion
----------
unify constructor initialization style throughout symfony
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | n/a
In almost all classes symfony uses property initialization when the value is static. Constructor initialization is only used for things that actually have logic, like passed parameters or dynamic values. IMHO it makes the code much more readable because property definition, phpdoc and default value is in one place. Also one can easily see what the constructor implements for logic like overridden default value of a parent class. Otherwise the real deal is just hidden behind 10 property initializations. One more advantage is that it requires less code. As you can see, the code was almost cut in half (210 additions and 395 deletions).
I unified it accordingly across symfony. Sometimes it was [not even consistent within one class](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Config/Definition/BaseNode.php#L32). At the same time I recognized some errors like missing parent constructor call, or undefined properties or private properties that are not even used.
I then realized that a few Kernel tests were not passing because they were deeply implementation specific like modifying booted flag with a custom `KernelForTest->setIsBooted();`. I improved and refactored the kernel tests in the __second commit__.
__Third commit__ unifies short ternary operator, e.g. `$foo ?: new Foo()`. __Forth commit__ unifies missing parentheses, e.g. `new Foo()`.
Commits
-------
077a089 unify missing parentheses
2888594 unify short ternary operator
2a9daff [HttpKernel] better written kernel tests
111ac18 unify constructor initialization style throughout symfony
Diffstat (limited to 'Core/Authentication')
-rw-r--r-- | Core/Authentication/Token/AbstractToken.php | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/Core/Authentication/Token/AbstractToken.php b/Core/Authentication/Token/AbstractToken.php index c532532..e62f73c 100644 --- a/Core/Authentication/Token/AbstractToken.php +++ b/Core/Authentication/Token/AbstractToken.php @@ -26,9 +26,9 @@ use Symfony\Component\Security\Core\User\EquatableInterface; abstract class AbstractToken implements TokenInterface { private $user; - private $roles; - private $authenticated; - private $attributes; + private $roles = array(); + private $authenticated = false; + private $attributes = array(); /** * Constructor. @@ -39,10 +39,6 @@ abstract class AbstractToken implements TokenInterface */ public function __construct(array $roles = array()) { - $this->authenticated = false; - $this->attributes = array(); - - $this->roles = array(); foreach ($roles as $role) { if (is_string($role)) { $role = new Role($role); |