Skip to content

[WebProfilerBundle] fixed getSession when no session has been set deprecation warnings #27458

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 1 commit into from
Jun 4, 2018

Conversation

GregOriol
Copy link
Contributor

@GregOriol GregOriol commented May 31, 2018

Q A
Branch? 4.1
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets none but see comment
License MIT

Symfony 4.1 adds deprecation warnings when getSession is called and a session has not been set.
Some code in the WebProfiler was not up-to-date to use hasSession before.

(this actually caused Silex-WebProfiler's tests to fail)

@nicolas-grekas nicolas-grekas added this to the 4.1 milestone Jun 1, 2018
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

minor CS comment (we don't use brackets usually when not needed, like here)

@@ -180,7 +180,7 @@ public function searchBarAction(Request $request)
$this->cspHandler->disableCsp();
}

if (null === $session = $request->getSession()) {
if (!$request->hasSession() || null === ($session = $request->getSession())) {
Copy link
Member

Choose a reason for hiding this comment

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

I'd suggest to use if (!$request->hasSession() || !$session = $request->getSession()) {

@@ -289,7 +289,7 @@ public function searchAction(Request $request)
$limit = $request->query->get('limit');
$token = $request->query->get('token');

if (null !== $session = $request->getSession()) {
if ($request->hasSession() && ($session = $request->getSession())) {
Copy link
Member

Choose a reason for hiding this comment

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

if ($request->hasSession() && $session = $request->getSession()) {

@@ -1,7 +1,7 @@
{% extends '@WebProfiler/Profiler/layout.html.twig' %}

{% macro profile_search_filter(request, result, property) %}
{%- if request.session is not null -%}
{%- if request.hasSession and request.session is not null -%}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not only {%- if request.hasSession -%} ?

@@ -180,7 +180,7 @@ public function searchBarAction(Request $request)
$this->cspHandler->disableCsp();
}

if (null === $session = $request->getSession()) {
if (!$request->hasSession() || !$session = $request->getSession()) {
Copy link
Member

Choose a reason for hiding this comment

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

if (!$request->hasSession()) is enough

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you sure? I think we need $session in the else part.
We could move $session = $request->getSession() into the else though.

Copy link
Member

Choose a reason for hiding this comment

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

moving it to the else seems reasonable to me

@nicolas-grekas nicolas-grekas changed the base branch from master to 4.1 June 4, 2018 20:59
@nicolas-grekas
Copy link
Member

Thank you @GregOriol.

@nicolas-grekas nicolas-grekas merged commit 0f3ba5a into symfony:4.1 Jun 4, 2018
nicolas-grekas added a commit that referenced this pull request Jun 4, 2018
…een set deprecation warnings (GregOriol)

This PR was submitted for the master branch but it was squashed and merged into the 4.1 branch instead (closes #27458).

Discussion
----------

[WebProfilerBundle] fixed getSession when no session has been set deprecation warnings

| Q             | A
| ------------- | ---
| Branch?       | 4.1
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | none but see comment
| License       | MIT

Symfony 4.1 adds deprecation warnings when getSession is called and a session has not been set.
Some code in the WebProfiler was not up-to-date to use hasSession before.

(this actually caused [Silex-WebProfiler](https://github.com/silexphp/Silex-WebProfiler)'s tests to fail)

Commits
-------

0f3ba5a [WebProfilerBundle] fixed getSession when no session has been set deprecation warnings
@fabpot fabpot mentioned this pull request Jun 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants