Thanks to visit codestin.com
Credit goes to github.com

Skip to content

unify constructor initialization style throughout symfony #9487

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

Merged
merged 4 commits into from
Nov 22, 2013

Conversation

Tobion
Copy link
Contributor

@Tobion Tobion commented Nov 10, 2013

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. 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().

*/
public function __construct()
{
$this->clear();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

useless

@@ -23,32 +23,15 @@ public function getBundleMap()

public function registerBundles()
{
}

public function init()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

deprecated

@Tobion
Copy link
Contributor Author

Tobion commented Nov 18, 2013

@fabpot I'd be happy to merge this soon so I don't have to rebase often.

@fabpot
Copy link
Member

fabpot commented Nov 22, 2013

@Tobion Thanks for the work. To avoid any "regressions" in the future, can you also make a PR on the doc to document the way new features must be implemented (probably in the coding standard section.): like always use () when instantiating an object, ...

fabpot added a commit that referenced this pull request Nov 22, 2013
… (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
@fabpot fabpot merged commit 077a089 into symfony:master Nov 22, 2013
@Tobion Tobion deleted the constructor-unify branch November 22, 2013 19:14
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