Skip to content

Commit

Permalink
Merge pull request #24348 from totten/master-class-err
Browse files Browse the repository at this point in the history
ClassScanner - Throw an exception if a class-file doesn't have the expected class
  • Loading branch information
demeritcowboy authored Aug 23, 2022
2 parents 5820d17 + 4cd22a3 commit 0ea48af
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Civi/Core/ClassScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@ private static function scanCoreClasses(): array {
static::scanFolders($classes, $civicrmRoot, 'Civi/WorkflowMessage', '\\');
static::scanFolders($classes, $civicrmRoot, 'CRM/*/Import', '_');
if (\CRM_Utils_Constant::value('CIVICRM_UF') === 'UnitTests') {
static::scanFolders($classes, $civicrmRoot . 'tests/phpunit', 'CRM/*/WorkflowMessage', '_');
static::scanFolders($classes, $civicrmRoot . 'tests/phpunit', 'Civi/*/WorkflowMessage', '\\');
if (strpos(get_include_path(), $civicrmRoot . 'tests/phpunit') !== FALSE) {
static::scanFolders($classes, $civicrmRoot . 'tests/phpunit', 'CRM/*/WorkflowMessage', '_');
static::scanFolders($classes, $civicrmRoot . 'tests/phpunit', 'Civi/*/WorkflowMessage', '\\');
}
}

$cache->set($cacheKey, $classes, static::TTL);
Expand Down Expand Up @@ -198,6 +200,10 @@ public static function scanFolders(array &$classes, string $classRoot, string $c
$classes[] = $class;
}
}
elseif (!interface_exists($class) && !trait_exists($class)) {
// If you get this error, then perhaps (a) you need to fix the name of file/class/namespace or (b) you should disable class-scanning.
throw new \RuntimeException("Scanned file {$relFile} for class {$class}, but it was not found.");
}
}
}
}
Expand Down

0 comments on commit 0ea48af

Please sign in to comment.