Files
rspade_system/app/RSpade/CodeQuality/Rules/Models/RequiredModels_CodeQualityRule.php
root f6fac6c4bc Fix bin/publish: copy docs.dist from project root
Fix bin/publish: use correct .env path for rspade_system
Fix bin/publish script: prevent grep exit code 1 from terminating script

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-21 02:08:33 +00:00

103 lines
3.2 KiB
PHP
Executable File

<?php
namespace App\RSpade\CodeQuality\Rules\Models;
use Exception;
use App\RSpade\CodeQuality\Rules\CodeQualityRule_Abstract;
use App\RSpade\Core\Manifest\Manifest;
class RequiredModels_CodeQualityRule extends CodeQualityRule_Abstract
{
// Core models that must exist in the system
protected $required_models = [
'File_Model',
'Ip_Address_Model',
'Session',
'Site_User_Model',
'Site_Model',
'User_Invite_Model',
'User_Verification_Model',
'User_Model',
];
public function get_id(): string
{
return 'MODEL-REQUIRED-01';
}
public function get_name(): string
{
return 'Required Core Models';
}
public function get_description(): string
{
return 'Validates that core framework models exist and extend Rsx_Model_Abstract';
}
public function get_file_patterns(): array
{
// This rule doesn't check individual files
return [];
}
public function get_default_severity(): string
{
return 'critical';
}
public function check(string $file_path, string $contents, array $metadata = []): void
{
// This rule doesn't check individual files
// It uses check_required_models() method instead
}
/**
* Check that all required models exist and are properly configured
* This is called directly by CodeQualityChecker
*/
public function check_required_models(): void
{
foreach ($this->required_models as $model_name) {
// Check if class exists in manifest
try {
$metadata = Manifest::php_get_metadata_by_class($model_name);
if (empty($metadata)) {
$this->add_violation(
'rsx/models/',
0,
"Required model class '{$model_name}' not found in manifest",
'',
'Create the model file at rsx/models/' . strtolower(str_replace('_', '_', $model_name)) . '.php',
'critical'
);
continue;
}
// Check if it extends Rsx_Model_Abstract
if (!Manifest::php_is_subclass_of($model_name, 'Rsx_Model_Abstract')) {
$file_path = $metadata['file'] ?? 'unknown';
$this->add_violation(
$file_path,
0,
"Required model '{$model_name}' does not extend Rsx_Model_Abstract",
'',
"Make sure {$model_name} extends Rsx_Model_Abstract or a subclass of it",
'critical'
);
}
} catch (Exception $e) {
$this->add_violation(
'rsx/models/',
0,
"Required model class '{$model_name}' not found in manifest",
'',
'Create the model file at rsx/models/' . strtolower(str_replace('_', '_', $model_name)) . '.php',
'critical'
);
}
}
}
}