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

Add strict rules #7340

Merged
merged 3 commits into from
Jul 24, 2021
Merged

Conversation

VincentLanglet
Copy link
Member

@VincentLanglet VincentLanglet commented Jul 19, 2021

No description provided.

@SonataCI
Copy link
Collaborator

Could you please rebase your PR and fix merge conflicts?

@VincentLanglet
Copy link
Member Author

@jordisala1991 What do you recommend in order to solve

return $request->isXmlHttpRequest() || $request->get('_xml_http_request');

?

Changing to

return $request->isXmlHttpRequest() || true === $request->get('_xml_http_request');

could stop working if the get wasn't returning a boolean. I don't know what was returned before.

An option could be to use

$request->attributes->getBoolean('_xml_http_request')

but is it supposed to be passed as attributes, query or request ?
I dont like checking

$request->attributes->getBoolean('_xml_http_request') || $request->request->getBoolean('_xml_http_request') || $request->query->getBoolean('_xml_http_request')

cc @sonata-project/contributors

@VincentLanglet VincentLanglet marked this pull request as ready for review July 21, 2021 15:33
@jordisala1991
Copy link
Member

@jordisala1991 What do you recommend in order to solve


return $request->isXmlHttpRequest() || $request->get('_xml_http_request');

?

Changing to


return $request->isXmlHttpRequest() || true === $request->get('_xml_http_request');

could stop working if the get wasn't returning a boolean. I don't know what was returned before.

An option could be to use


$request->attributes->getBoolean('_xml_http_request')

but is it supposed to be passed as attributes, query or request ?

I dont like checking


$request->attributes->getBoolean('_xml_http_request') || $request->request->getBoolean('_xml_http_request') || $request->query->getBoolean('_xml_http_request')

cc @sonata-project/contributors

We need to check where it is passed that parameter, it will probably be query if it is a get call or request if it is a post

@VincentLanglet
Copy link
Member Author

We need to check where it is passed that parameter, it will probably be query if it is a get call or request if it is a post

In tests, we're setting the attributes, but I think it's wrong.

Here, it's POST

type: "POST",
dataType: 'html',
data: { _xml_http_request: true },

data: {_xml_http_request: true },
dataType: 'html',
type: 'POST',

Here, it rely on the form

type: form.attr('method'),
url: form.attr('action'),
dataType: 'html',
data: {_xml_http_request: true},

Here it rely on an attr.method, or can be GET

if (this.nodeName == 'FORM') {
var url = element.attr('action');
var type = element.attr('method');
} else if (this.nodeName == 'A') {
var url = element.attr('href');
var type = 'GET';
} else {
alert('unexpected element : @' + this.nodeName + '@');
return;
}
if (element.hasClass('sonata-ba-action')) {
Admin.log('[{{ id }}|field_dialog_form_action] reserved action stop catch all events');
return;
}
var data = {
_xml_http_request: true
}
var form = jQuery(this);
Admin.log('[{{ id }}|field_dialog_form_action] execute ajax call');
var oldErrorMessages = jQuery(field_dialog_content_{{ id }}).find('div.alert-danger');
// Remove old error messages.
if (oldErrorMessages.length > 0) {
oldErrorMessages.remove();
}
// the ajax post
jQuery(form).ajaxSubmit({
url: url,
type: type,
headers: {
Accept: 'application/json'
},
data: data,

So I would say, it can be either GET or POST.

Do we have to check both query and request ?
(And what is attributes ^^')

@VincentLanglet VincentLanglet requested a review from a team July 21, 2021 20:49
@VincentLanglet VincentLanglet added this to the 4.0 milestone Jul 21, 2021
- # https://github.com/phpstan/phpstan-phpunit/issues/87
message: '#^Trying to mock an undefined method [a-zA-Z]*\(\) on class stdClass\.$#'
path: tests/
- # https://github.com/phpstan/phpstan-strict-rules/issues/130
message: '#^Call to static method PHPUnit\\Framework\\Assert::.* will always evaluate to true\.$#'
Copy link
Member

Choose a reason for hiding this comment

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

Cant some of these be removed or they conflict with other errors for psalm?

Copy link
Member Author

Choose a reason for hiding this comment

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

The issue is that we checking our return type.

for instance the method

function createDate(): \DateTime {
    return new \DateTime();
}

has the following test

self::assertInstanceOf(\DateTime::class, createDate());

Phpstan is complaining about this being always true. But we might consider it's the purpose of the test to be sure it will be true in the futur.

*
* @throws \InvalidArgumentException if the menu does not exists
*/
public function get(string $name, array $options = []): ItemInterface
{
if (!isset($options['name'])) {
throw new \InvalidArgumentException('TODO');
Copy link
Member

Choose a reason for hiding this comment

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

missing message, same below

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed, I forgot ^^'

@VincentLanglet VincentLanglet requested review from jordisala1991 and a team July 22, 2021 11:54
@VincentLanglet VincentLanglet requested review from a team, phansys and franmomu July 24, 2021 08:19
@VincentLanglet VincentLanglet merged commit 32281f1 into sonata-project:master Jul 24, 2021
@VincentLanglet VincentLanglet deleted the strictRules branch July 24, 2021 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants