Problem/Motivation
This happens all the time. As Drupal changes or removes namespaces the links in @see tags get broken.
Proposed resolution
Fix all broken links.
In Drupal 9 much deprecated code is going to be removed. I expect the number of broken links will be increased significantly.
We might need an automated test for this.
Remaining tasks
Fix all found broken links.
Create a test?
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | report-v3.txt | 50.35 KB | chi |
| #10 | check-references-v3.php_.zip | 1.66 KB | chi |
Comments
Comment #2
chi commentedHere is a script that can help to find broken links. See attached report.
Basically the reported issues fall into three categories.
Comment #3
jhodgdonI'm not exactly sure what the report is telling me?
But as a note... The only real standards we have on namespaces in code docs are:
a) If you use a namespace at all, it must be the fully qualified namespace.
b) Immediately after an @tag, like @var, @see, @param @return (where we are indicating a variable type), you must use the fully-qualified namespace name.
So far, we don't actually have standards that say that in other places in API docs, we must use namespaces. So it is probably OK, for instance, in docs to reference a method on the same class as static::fooBar() or self::fooBar(), or maybe even Foo::fooBar() if the class name is Foo. But it wouldn't be good on class Bar to reference Foo::fooBar() -- in that case, you should probably include the namespace. But this is just my opinion...
There's an issue discussing the standards for this in the Coding Standards project issue queue; linking as related. Probably we should decide on standards before we go around fixing problems that are not really problems (some of the things in the report there may be legal).
Comment #4
chi commentedIt mostly tells you about broken references.
For instance, consider the first line in it.
core/modules/field_ui/src/FieldStorageConfigListBuilder.php -> \Drupal\field\Entity\FieldIt indicates that FieldStorageConfigListBuilder.php file contains a reference on
\Drupal\field\Entity\Fieldclass which do not exist.https://git.drupalcode.org/project/drupal/blob/8.8.0-alpha1/core/modules...
Comment #5
chi commentedAs CS on this is not established yet, I updated the script to exclude records caused by using "wrong" format. So that now the report is supposed to have only records on broken links.
Comment #6
jhodgdonOK, that's a bit more manageable...
I think there are still some false positives in your script though, like this line:
I think it's getting confused by the . which indicates the end of a sentence. That class exists in that namespace.
Comment #7
jhodgdonI'm also not sure what's wrong with this:
core/modules/options/options.api.php -> options_test_allowed_values_callback
That function does exist.
https://api.drupal.org/api/drupal/core%21modules%21options%21tests%21opt...
Comment #8
chi commentedIt belongs to options_test module which was not installed when I was building the report. Fixed.
Comment #9
chi commentedThere is a bunch of false positives in the report caused by referencing class methods this way.
https://git.drupalcode.org/project/drupal/blob/8.8.0-alpha1/core/modules...
It'll be hard to fix as there is no indication of whether it is a class method or some global function.
Given that #2341405: Decide on standard for referencing namespaced classes does not even consider that notation I propose we replace it with FQN or
self::methodNamefor now.Comment #10
chi commentedFixed. The number of positives in the report dropped to 518.
Comment #11
jhodgdonOK, now these are looking like actual problems.
So it looks like there are several reasons for these errors:
a) Methods being referenced without a class designator. They should probably at least say self::methodName() or ClassName::methodName() instead of the bare methodName().
b) Functions/methods/classes that have been removed or moved to different namespaces
c) Typos
Still not sure how to divide the errors up into issues to be fixed, but maybe (a) could be one issue if it just used self:: as the replacement? Those would require much less thinking/investigating than the others.
Comment #12
chi commentedUntil #2341405: Decide on standard for referencing namespaced classes is resolved I propose using
self::methodName()as it most frequently used so far.Comment #13
idebr commentedPerhaps the reference check is something we can turn into a PHPCS rule? It would help new broken references from creeping in. It does not seem very Drupal-specific either.
Comment #14
chi commentedThis would be great but I think it is hardly possible. PHPCS is a pure static analyzer. For checking PHP class existence you have to use
class_existswhich relies on class loader. And besides in Drupal some namespaces are registered automatically depending on installed extensions. That means a fully bootstrapped Drupal instance is needed to make usage ofclass_existsreliable.Comment #18
quietone commentedComment #23
joachim commentedIdeally, this shouldn't just check things explicitly linked to with @see but any mention of a qualified classname or qualified classname + method name.
E.g. #3537572: PageVariantInterface docs mention class that doesn't exist