Problem/Motivation

Annotations are not checked for deprecated / changed keys and new keys required.

  1. The context key should be context_definition to define cache contexts. See https://www.drupal.org/node/3016699
  2. The config_export key was added to config entities which is required in practice currently. See https://www.drupal.org/node/2481909. It may become optional once/if #2483407: Allow configuration schema fallback in ConfigEntityType::getPropertiesToExport() to work without an ID is done.

Steps to reproduce

Context definition came up in #3160753: Drupal 9 compatibility among others. The config export key was originally reported as part of #3131063: Detect GetResponseForExceptionEvent is deprecated in favour of ExceptionEvent.

Proposed resolution

Scan annotations and find issues in them.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Grimreaper created an issue. See original summary.

gábor hojtsy’s picture

Can you copy here what exactly would need to be detected?

grimreaper’s picture

Hello,

In the following code, https://git.drupalcode.org/project/context_profile_role/-/blob/8.x-1.x/s...

/**
 * Provides a 'User Profile Role' condition.
 *
 * @Condition(
 *   id = "user_profile_role",
 *   label = @Translation("User Profile Role"),
 *   context = {
 *     "user_profile" = @ContextDefinition("entity:user", label = @Translation("User Profile Role"))
 *   },
 * );
 */

context had been changed into context_definitions:

+++ b/src/Plugin/Condition/UserProfileRole.php
@@ -14,7 +14,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
- *   context = {
+ *   context_definitions = {

Change record: https://www.drupal.org/node/3016699
Issue: https://www.drupal.org/project/drupal/issues/3014949

gábor hojtsy’s picture

Good point, parenting to the missing coverage issue. We don't currently check annotations I believe. We could add a very basic / crude check for this specific annotations. Are you aware of other annotations that would need to be checked?

grimreaper’s picture

Hello,

Currently not aware of other deprecation in annotations, sorry.

I though it would already be handled in PHPStan or detected somewhere else. So I was surprised when the issue had been opened :)

And thanks for the update.

gábor hojtsy’s picture

Title: Not detecting deprecation in annotation » Annotation checking missing: context to context_definition and config_export
Issue summary: View changes

Updated issue summary. Brought in config_export annotation report from #3131063: Detect GetResponseForExceptionEvent is deprecated in favour of ExceptionEvent.

gábor hojtsy’s picture

Title: Annotation checking missing: context to context_definition and config_export » Annotation checking missing: context to context_definition and new config_export
mglaman’s picture

All right, I have a pull request for phpstan-drupal to add a rule that will catch this: https://github.com/mglaman/phpstan-drupal/pull/186

EDIT: this is only for `context` to `context_definitions`

mglaman’s picture

mglaman’s picture

Status: Active » Needs review
gábor hojtsy’s picture

Version: 8.x-2.x-dev » 8.x-3.x-dev

I am still puzzled by branch switching with MRs. Did the following to get a fresh upgrade status checkout so I don't break my other dev checkouts:

$ git clone git@git.drupal.org:project/upgrade_status.git

Cloning into 'upgrade_status'...
remote: Enumerating objects: 302, done.
remote: Counting objects: 100% (302/302), done.
remote: Compressing objects: 100% (154/154), done.
remote: Total 2657 (delta 155), reused 266 (delta 120), pack-reused 2355
Receiving objects: 100% (2657/2657), 594.72 KiB | 746.00 KiB/s, done.
Resolving deltas: 100% (1649/1649), done.

$ cd upgrade_status

Did the following as per the above docs:

$ git remote add upgrade_status-3161052 git@git.drupal.org:issue/upgrade_status-3161052.git

$ git fetch upgrade_status-3161052

remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 1.15 KiB | 294.00 KiB/s, done.
From git.drupal.org:issue/upgrade_status-3161052
 * [new branch]      3161052-annotation-checking-missing -> upgrade_status-3161052/3161052-annotation-checking-missing
 * [new branch]      5.x-1.x    -> upgrade_status-3161052/5.x-1.x
 * [new branch]      6.x-1.x    -> upgrade_status-3161052/6.x-1.x
 * [new branch]      7.x-1.x    -> upgrade_status-3161052/7.x-1.x
 * [new branch]      8.x-1.x    -> upgrade_status-3161052/8.x-1.x
 * [new branch]      8.x-2.x    -> upgrade_status-3161052/8.x-2.x
 * [new branch]      8.x-3.x    -> upgrade_status-3161052/8.x-3.x

Checked out 3161052-annotation-checking-missing:

$ git checkout 3161052-annotation-checking-missing
Branch '3161052-annotation-checking-missing' set up to track remote branch '3161052-annotation-checking-missing' from 'upgrade_status-3161052'.
Switched to a new branch '3161052-annotation-checking-missing'

Attempted to rebase to 8.x-3.x:

$ git rebase 8.x-3.x

Auto-merging src/DeprecationAnalyzer.php
CONFLICT (content): Merge conflict in src/DeprecationAnalyzer.php
error: could not apply 099f4e5... Issue #3151995 by Gábor Hojtsy, rohnjeynolds, siramsay, JD_1, maxilein, Arno2Mars, scrumorg, Arngrim: Log PHPStan error in project results to let people know it failed. Fix undefined errors index
Resolve all conflicts manually, mark them as resolved with
"git add/rm <conflicted_files>", then run "git rebase --continue".
You can instead skip this commit: run "git rebase --skip".
To abort and get back to the state before "git rebase", run "git rebase --abort".
Could not apply 099f4e5... Issue #3151995 by Gábor Hojtsy, rohnjeynolds, siramsay, JD_1, maxilein, Arno2Mars, scrumorg, Arngrim: Log PHPStan error in project results to let people know it failed. Fix undefined errors index

I fixed this conflict manually, then:

$ git add src/DeprecationAnalyzer.php 
$ git rebase --continue                                  

Auto-merging upgrade_status.install
Auto-merging upgrade_status.info.yml
CONFLICT (content): Merge conflict in upgrade_status.info.yml
error: could not apply c16e35b... Cannot install this module on Drupal 9: InfoParserException, undo semi-support for Drupal 9 for now
Resolve all conflicts manually, mark them as resolved with
"git add/rm <conflicted_files>", then run "git rebase --continue".
You can instead skip this commit: run "git rebase --skip".
To abort and get back to the state before "git rebase", run "git rebase --abort".
Could not apply c16e35b... Cannot install this module on Drupal 9: InfoParserException, undo semi-support for Drupal 9 for now

Then this goes on forever, I stopped after a dozen or so manual conflict resolutions with the info file, the form, the deprecation analyzer (repeatedly on the same context lines multiple times).

What am I doing absolutely wrong here? This must not be the advertised to be super-easy MR workflow :D I am trying to get this one line composer.json change to rebase on top of the current 8.x-3.x.

mglaman’s picture

@Gábor Hojtsy I skipped the rebase fanciness and just made a new branch for the change

mglaman’s picture

We probably should add some kind of test in upgrade_status, maybe?

andypost’s picture

It just need to change to 4 failures I guess

gábor hojtsy’s picture

Could be that fails are related to #3224167: Parameter excludes_analyse is deprecated. I committed that now. How do I send this MR to retest?

gábor hojtsy’s picture

StatusFileSize
new553 bytes

I did not find a way to send the MR to retest, so going to post the change in a patch.

gábor hojtsy’s picture

StatusFileSize
new2 KB

Beginning of a test.

Status: Needs review » Needs work

The last submitted patch, 20: 3161052-20.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

gábor hojtsy’s picture

Status: Needs work » Needs review
StatusFileSize
new6.6 KB
new4.85 KB

Further fixing of the tests.

Status: Needs review » Needs work

The last submitted patch, 22: 3161052-22.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

gábor hojtsy’s picture

Status: Needs work » Needs review
StatusFileSize
new6.6 KB
new1.27 KB

Contrib item shows up first alphabetically and now they have the same amount of problems.

Status: Needs review » Needs work

The last submitted patch, 24: 3161052-24.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

gábor hojtsy’s picture

Status: Needs work » Needs review
StatusFileSize
new6.6 KB
new1.27 KB

0 based indexing.

Status: Needs review » Needs work

The last submitted patch, 26: 3161052-26.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

gábor hojtsy’s picture

Status: Needs work » Needs review
StatusFileSize
new6.65 KB
new2.54 KB

Of course its a warning, not an error because there is no version number involved.

Status: Needs review » Needs work

The last submitted patch, 28: 3161052-28.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

gábor hojtsy’s picture

Status: Needs work » Needs review
StatusFileSize
new6.65 KB
new775 bytes

Missed one spot.

gábor hojtsy’s picture

Status: Needs review » Reviewed & tested by the community

In #3224393: Parameters excludes_analyse and excludePaths cannot be used at the same time, @Eric_A noted another reason to update to mglaman/phpstan-drupal: ^0.12.11. Closed that as a duplicate, even though the reason is not the same, the patch would be the same as the first hunk here. Transporting the credits here.

  • c83b85a committed on 8.x-3.x
    Issue #3161052 by Gábor Hojtsy, mglaman, Grimreaper, Eric_A: Annotation...
gábor hojtsy’s picture

Status: Reviewed & tested by the community » Fixed

Thanks all!

mglaman’s picture

Woo!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.