diff --git a/composer.json b/composer.json
index 88fd66a805..638e0e424f 100644
--- a/composer.json
+++ b/composer.json
@@ -36,7 +36,8 @@
         "symfony/finder": "^6.1",
         "symfony/lock": "^6.1",
         "symfony/browser-kit": "^6.1",
-        "symfony/dom-crawler": "^6.1"
+        "symfony/dom-crawler": "^6.1",
+        "phpstan/phpstan-deprecation-rules": "^1.0"
     },
     "replace": {
         "symfony/polyfill-php72": "*",
diff --git a/composer.lock b/composer.lock
index 9d1a73887a..8d6dc84bce 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "9286c042bc6a3f1a14f3ad64eadf064a",
+    "content-hash": "1a24c4ac52165a571e7f9160fc20bb07",
     "packages": [
         {
             "name": "asm89/stack-cors",
@@ -5828,6 +5828,56 @@
             ],
             "time": "2022-09-07T16:05:32+00:00"
         },
+        {
+            "name": "phpstan/phpstan-deprecation-rules",
+            "version": "1.0.0",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/phpstan/phpstan-deprecation-rules.git",
+                "reference": "e5ccafb0dd8d835dd65d8d7a1a0d2b1b75414682"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/phpstan/phpstan-deprecation-rules/zipball/e5ccafb0dd8d835dd65d8d7a1a0d2b1b75414682",
+                "reference": "e5ccafb0dd8d835dd65d8d7a1a0d2b1b75414682",
+                "shasum": ""
+            },
+            "require": {
+                "php": "^7.1 || ^8.0",
+                "phpstan/phpstan": "^1.0"
+            },
+            "require-dev": {
+                "php-parallel-lint/php-parallel-lint": "^1.2",
+                "phpstan/phpstan-phpunit": "^1.0",
+                "phpunit/phpunit": "^9.5"
+            },
+            "type": "phpstan-extension",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "1.0-dev"
+                },
+                "phpstan": {
+                    "includes": [
+                        "rules.neon"
+                    ]
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "PHPStan\\": "src/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "description": "PHPStan rules for detecting usage of deprecated classes, methods, properties, constants and traits.",
+            "support": {
+                "issues": "https://github.com/phpstan/phpstan-deprecation-rules/issues",
+                "source": "https://github.com/phpstan/phpstan-deprecation-rules/tree/1.0.0"
+            },
+            "time": "2021-09-23T11:02:21+00:00"
+        },
         {
             "name": "phpunit/php-code-coverage",
             "version": "9.2.17",
diff --git a/composer/Metapackage/DevDependencies/composer.json b/composer/Metapackage/DevDependencies/composer.json
index 2f715682a2..e80b10fd27 100644
--- a/composer/Metapackage/DevDependencies/composer.json
+++ b/composer/Metapackage/DevDependencies/composer.json
@@ -19,6 +19,7 @@
         "phpspec/prophecy-phpunit": "^2",
         "phpstan/extension-installer": "^1.1",
         "phpstan/phpstan": "^1.8.5",
+        "phpstan/phpstan-deprecation-rules": "^1.0",
         "phpunit/phpunit": "^9.5",
         "symfony/browser-kit": "^6.1",
         "symfony/css-selector": "^6.1",
diff --git a/composer/Metapackage/PinnedDevDependencies/composer.json b/composer/Metapackage/PinnedDevDependencies/composer.json
index 0f40370a0c..d878ff150b 100644
--- a/composer/Metapackage/PinnedDevDependencies/composer.json
+++ b/composer/Metapackage/PinnedDevDependencies/composer.json
@@ -37,6 +37,7 @@
         "phpstan/extension-installer": "1.1.0",
         "phpstan/phpdoc-parser": "1.7.0",
         "phpstan/phpstan": "1.8.5",
+        "phpstan/phpstan-deprecation-rules": "1.0.0",
         "phpunit/php-code-coverage": "9.2.17",
         "phpunit/php-file-iterator": "3.0.6",
         "phpunit/php-invoker": "3.1.1",
diff --git a/core/scripts/dev/commit-code-check.sh b/core/scripts/dev/commit-code-check.sh
index 9b50666f6d..68105bf6f3 100755
--- a/core/scripts/dev/commit-code-check.sh
+++ b/core/scripts/dev/commit-code-check.sh
@@ -217,7 +217,26 @@
 
 # Run PHPStan on all files on DrupalCI or when phpstan files are changed.
 # APCu is disabled to ensure that the composer classmap is not corrupted.
-if [[ $PHPSTAN_DIST_FILE_CHANGED == "1" ]] || [[ "$DRUPALCI" == "1" ]]; then
+
+# Set *manually* this variable to '1' to (re)generate the PHPStan baseline in
+# DrupalCI runs.
+# The new baseline will be available in the Jenkins test run artifacts under
+# the artifacts/phpstan directory. The DrupalCI test run will be interrupted.
+PHPSTAN_GENERATE_BASELINE=1
+
+if [[ "$DRUPALCI" == "1" ]] && [[ $PHPSTAN_GENERATE_BASELINE == "1" ]]; then
+  printf "\nGenerating PHPStan baseline.\n"
+  printf "\n"
+  printf "Upon success, replace core/phpstan-baseline.neon with the file that\n"
+  printf "can be found in the test result artifacts.\n"
+  printf "\n"
+  cd core
+  php -d apc.enabled=0 -d apc.enable_cli=0 ../vendor/bin/phpstan analyze --generate-baseline --no-progress --configuration="$TOP_LEVEL/core/phpstan.neon.dist"
+  mkdir /var/lib/drupalci/artifacts/phpstan
+  cp phpstan-baseline.neon /var/lib/drupalci/artifacts/phpstan
+  cd ..
+  FINAL_STATUS=1
+elif [[ $PHPSTAN_DIST_FILE_CHANGED == "1" ]] || [[ "$DRUPALCI" == "1" ]]; then
   printf "\nRunning PHPStan on *all* files.\n"
   php -d apc.enabled=0 -d apc.enable_cli=0 vendor/bin/phpstan analyze --no-progress --configuration="$TOP_LEVEL/core/phpstan.neon.dist"
 else
