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

Skip to content

False positives in DebugClassLoader when @param documentation mentions another $variable #43936

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

Closed
longwave opened this issue Nov 4, 2021 · 2 comments · Fixed by #44013
Closed

Comments

@longwave
Copy link
Contributor

longwave commented Nov 4, 2021

Symfony version(s) affected

5.4

Description

When running Drupal core tests against Symfony 5.4, the DebugClassLoader is reporting false positives when an @param tag contains documentation that mentions another $variable.

How to reproduce

Sample test output from Drupal 9.4 patched for Symfony 5.4 (with patch from e.g. https://www.drupal.org/project/drupal/issues/3161889#comment-14281559)

Remaining self deprecation notices (2)

  1x: The "Drupal\Core\Database\Query\Select::havingCondition()" method will require a new "$value The value to test the field against. In most cases, this is a scalar. For more complex options, it is an array. The meaning of each element in the array is dependent on the $operator." argument in the next major version of its interface "Drupal\Core\Database\Query\SelectInterface", not defining it is deprecated.
    1x in OrderByTest::setUp from Drupal\Tests\Core\Database

  1x: The "Drupal\Core\Database\Query\Select::fields()" method will require a new "$fields An indexed array of fields present in the specified table that should be included in this query. If not specified, $table_alias.*" argument in the next major version of its interface "Drupal\Core\Database\Query\SelectInterface", not defining it is deprecated.
    1x in OrderByTest::setUp from Drupal\Tests\Core\Database

SelectInterface has these docblocks:

  /**
   * Helper function to build most common HAVING conditional clauses.
   *
   * This method can take a variable number of parameters. If called with two
   * parameters, they are taken as $field and $value with $operator having a value
   * of IN if $value is an array and = otherwise.
   *
   * @param $field
   *   The name of the field to check. If you would like to add a more complex
   *   condition involving operators or functions, use having().
   * @param $value
   *   The value to test the field against. In most cases, this is a scalar. For more
   *   complex options, it is an array. The meaning of each element in the array is
   *   dependent on the $operator.
   * @param $operator
   *   The comparison operator, such as =, <, or >=. It also accepts more complex
   *   options such as IN, LIKE, or BETWEEN. Defaults to IN if $value is an array
   *   = otherwise.
   *
   * @return \Drupal\Core\Database\Query\ConditionInterface
   *   The called object.
   */
  public function havingCondition($field, $value = NULL, $operator = NULL);

  /**
   * Add multiple fields from the same table to be SELECTed.
   *
   * This method does not return the aliases set for the passed fields. In the
   * majority of cases that is not a problem, as the alias will be the field
   * name. However, if you do need to know the alias you can call getFields()
   * and examine the result to determine what alias was created. Alternatively,
   * simply use addField() for the few fields you care about and this method for
   * the rest.
   *
   * @param $table_alias
   *   The name of the table from which the field comes, as an alias. Generally
   *   you will want to use the return value of join() here to ensure that it is
   *   valid.
   * @param $fields
   *   An indexed array of fields present in the specified table that should be
   *   included in this query. If not specified, $table_alias.* will be generated
   *   without any aliases.
   *
   * @return $this
   *   The called object.
   */
  public function fields($table_alias, array $fields = []);

Select defines these interfaces correctly:

  /**
   * {@inheritdoc}
   */
  public function havingCondition($field, $value = NULL, $operator = NULL) {

  /**
   * {@inheritdoc}
   */
  public function fields($table_alias, array $fields = []) {

Possible Solution

There are a few more similar cases; in all cases that I have found, the @param tag happens to mention a variable so this looks like a parsing issue with docblocks.

Additional Context

No response

@nicolas-grekas
Copy link
Member

I suppose DebugClassLoader::parsePhpDoc() is at fault.
Would you like to have a look for a fix?

@stof
Copy link
Member

stof commented Nov 5, 2021

@longwave does it also happen if your phpdoc properly define the type of the argument between the @param and the argument name ?

@fabpot fabpot closed this as completed Nov 13, 2021
fabpot added a commit that referenced this issue Nov 13, 2021
…description (nicolas-grekas)

This PR was merged into the 5.4 branch.

Discussion
----------

[ErrorHandler] fix parsing ``@param`` with dollars in the description

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #43936
| License       | MIT
| Doc PR        | -

Commits
-------

8046b3b [ErrorHandler] fix parsing ``@param`` with dollars in the description
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants