Browse Source

Fix up CI for deprecation alerts.

mscherer 2 years ago
parent
commit
c6a43de1c2
4 changed files with 26 additions and 19 deletions
  1. 4 2
      .github/workflows/ci.yml
  2. 20 15
      contrib/validate-deprecation-aliases.php
  3. 1 1
      src/I18n/Date.php
  4. 1 1
      src/I18n/DateTime.php

+ 4 - 2
.github/workflows/ci.yml

@@ -9,8 +9,6 @@ on:
   pull_request:
     branches:
       - '*'
-  schedule:
-    - cron: "0 0 * * *"
   workflow_dispatch:
 
 permissions:
@@ -126,6 +124,10 @@ jobs:
           CAKE_TEST_AUTOQUOTE=1 vendor/bin/phpunit --testsuite=database
         fi
 
+    - name: Run class deprecation aliasing validation script
+      if: always()
+      run: php contrib/validate-deprecation-aliases.php
+
     - name: Prefer lowest check
       if: matrix.prefer-lowest == 'prefer-lowest'
       run: composer require --dev dereuromark/composer-prefer-lowest && vendor/bin/validate-prefer-lowest -m

+ 20 - 15
contrib/validate-deprecation-aliases.php

@@ -1,42 +1,47 @@
 #!/usr/bin/php -q
 <?php
+declare(strict_types=1);
+
+/*
+ * Validate that each deprecation of a class is followed by class_alias() and class_exists()
+ * in each relevant file complementing each other.
+ */
 
 $options = [
-	__DIR__ . '/../vendor/autoload.php',
-	__DIR__ . '/vendor/autoload.php',
+    __DIR__ . '/../vendor/autoload.php',
+    __DIR__ . '/vendor/autoload.php',
 ];
 if (!empty($_SERVER['PWD'])) {
-	array_unshift($options, $_SERVER['PWD'] . '/vendor/autoload.php');
+    array_unshift($options, $_SERVER['PWD'] . '/vendor/autoload.php');
 }
 
 foreach ($options as $file) {
-	if (file_exists($file)) {
-		define('COMPOSER_INSTALL', $file);
+    if (file_exists($file)) {
+        define('COMPOSER_INSTALL', $file);
 
-		break;
-	}
+        break;
+    }
 }
 require COMPOSER_INSTALL;
 
 $path = dirname(__DIR__) . DS . 'src' . DS;
-$di = new RecursiveDirectoryIterator($path, (RecursiveDirectoryIterator::SKIP_DOTS));
-/** @var \SplFileInfo[] $iterator */
+$di = new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS);
+/** @var array<\SplFileInfo> $iterator */
 $iterator = new RecursiveIteratorIterator($di);
 
-$issues = [];
 $code = 0;
 foreach ($iterator as $file) {
-    if (pathinfo($file, PATHINFO_EXTENSION) !== 'php') {
+    if (pathinfo((string)$file, PATHINFO_EXTENSION) !== 'php') {
         continue;
     }
-    if (pathinfo($file, PATHINFO_FILENAME) === 'functions') {
+    if (pathinfo((string)$file, PATHINFO_FILENAME) === 'functions') {
         continue;
     }
     if (strpos($file->getRealPath(), '/TestSuite/')) {
         continue;
     }
 
-    $content = file_get_contents($file);
+    $content = file_get_contents((string)$file);
     if (!strpos($content, 'class_alias(')) {
         continue;
     }
@@ -53,7 +58,7 @@ foreach ($iterator as $file) {
     $filePath = str_replace('Cake/', $path, $filePath);
     $filePath .= '.php';
     if (!file_exists($filePath)) {
-        throw new RuntimeException('Cannot find path for ' . $matches[1]);
+        throw new RuntimeException('Cannot find path for `' . $matches[1] . '`');
     }
 
     $newFileContent = file_get_contents($filePath);
@@ -61,7 +66,7 @@ foreach ($iterator as $file) {
     if (strpos($newFileContent, 'class_exists(') === false && !str_contains($newFileContent, 'class_alias(')) {
         $oldPath = str_replace($path, '', $file->getRealPath());
         $newPath = str_replace($path, '', $filePath);
-        echo "\033[31m" . ' * Missing class_exists() or class_alias() on new file for ' . $oldPath . ' => ' . $newPath . "\033[0m" . PHP_EOL;
+        echo "\033[31m" . ' * Missing `class_exists()` or `class_alias()` on new file for `' . $oldPath . '` => `' . $newPath . '`' .  "\033[0m" . PHP_EOL;
         $code = 1;
     } else {
         echo ' * OK' . PHP_EOL;

+ 1 - 1
src/I18n/Date.php

@@ -327,5 +327,5 @@ class Date extends ChronosDate implements JsonSerializable, Stringable
 }
 
 // phpcs:disable
-class_alias(Date::class, 'Cake\I18n\FrozenDate');
+class_alias('Cake\I18n\Date', 'Cake\I18n\FrozenDate');
 // phpcs:enable

+ 1 - 1
src/I18n/DateTime.php

@@ -607,5 +607,5 @@ class DateTime extends Chronos implements JsonSerializable, Stringable
 }
 
 // phpcs:disable
-class_alias(DateTime::class, 'Cake\I18n\FrozenTime');
+class_alias('Cake\I18n\DateTime', 'Cake\I18n\FrozenTime');
 // phpcs:enable