Files
moko-platform/lib/Enterprise/EnterpriseReadinessValidator.php
Jonathan Miller cbfa23c4c4
Platform: moko-platform CI / CI Summary (push) Blocked by required conditions
Generic: Repo Health / Site Health (push) Has been skipped
Generic: Repo Health / Access control (push) Successful in 1s
Generic: Repo Health / Scripts governance (push) Successful in 5s
Generic: Repo Health / Release configuration (push) Successful in 5s
Generic: Repo Health / Repository health (push) Successful in 12s
Platform: moko-platform CI / Gate 1: Code Quality (push) Successful in 45s
Platform: moko-platform CI / CI Summary (pull_request) Blocked by required conditions
Universal: PR Check / Branch Policy (pull_request) Successful in 1s
Universal: Secret Scanning / Gitleaks Secret Scan (pull_request) Successful in 4s
Universal: PR Check / Validate PR (pull_request) Successful in 5s
Universal: PR Check / Build RC Package (pull_request) Successful in 2s
Platform: moko-platform CI / Gate 2: Unit Tests (8.2) (push) Failing after 44s
Platform: moko-platform CI / Gate 3: Self-Health Check (push) Failing after 48s
Platform: moko-platform CI / Gate 2: Unit Tests (8.1) (push) Failing after 48s
Platform: moko-platform CI / Gate 4: Governance (push) Successful in 48s
Platform: moko-platform CI / Gate 2: Unit Tests (8.3) (push) Failing after 50s
Platform: moko-platform CI / Gate 5: Template Integrity (push) Failing after 12s
Platform: moko-platform CI / Gate 1: Code Quality (pull_request) Successful in 1m13s
Platform: moko-platform CI / Gate 5: Template Integrity (pull_request) Failing after 5s
Platform: moko-platform CI / Gate 3: Self-Health Check (pull_request) Failing after 42s
Platform: moko-platform CI / Gate 2: Unit Tests (8.2) (pull_request) Failing after 45s
Platform: moko-platform CI / Gate 4: Governance (pull_request) Successful in 44s
Platform: moko-platform CI / Gate 2: Unit Tests (8.1) (pull_request) Failing after 47s
Platform: moko-platform CI / Gate 2: Unit Tests (8.3) (pull_request) Failing after 49s
fix: PHPStan level 0 → 2 — fix 67 type errors across 18 files
Real bugs found and fixed:
- bulk_joomla_template: $org undefined in heredoc (missing parameter)
- RepositorySynchronizer: $root undefined (should be $repoRoot), duplicate array key
- RepositoryHealthChecker: wrong class name (UnifiedValidation → UnifiedValidator)
- scan_drift: missing $adapter property declaration
- auto_detect_platform: wrong method name (detectProjectType → detect)
- EnterpriseReadinessValidator: void return used as value
- check_client_theme: extra parameter to printSummary()
- ApiClient: unused constructor parameter now stored
- GitPlatformAdapter: added listBranches/getCloneUrl/cloneRepo to interface
- MokoGiteaAdapter/GitHubAdapter: implemented new interface methods

3 legacy CLIApp scripts excluded (need migration to CliFramework):
  repo_cleanup.php, push_files.php, joomla_release.php

Authored-by: Moko Consulting
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-25 19:29:52 -05:00

261 lines
7.6 KiB
PHP

<?php
/**
* Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
*
* This file is part of a Moko Consulting project.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
* FILE INFORMATION
* DEFGROUP: MokoStandards.Enterprise
* INGROUP: MokoStandards
* REPO: https://git.mokoconsulting.tech/MokoConsulting/moko-platform
* PATH: /lib/Enterprise/EnterpriseReadinessValidator.php
* BRIEF: Enterprise readiness validation library
*/
declare(strict_types=1);
namespace MokoEnterprise;
/**
* Enterprise Readiness Validator
*
* Enterprise library for validating repository compliance with
* enterprise standards including libraries, monitoring, security, and documentation.
*/
class EnterpriseReadinessValidator
{
private AuditLogger $logger;
private SecurityValidator $securityValidator;
private array $results = [];
/**
* Constructor
*/
public function __construct(
?AuditLogger $logger = null,
?SecurityValidator $securityValidator = null
) {
$this->logger = $logger ?? new AuditLogger('enterprise_readiness');
$this->securityValidator = $securityValidator ?? new SecurityValidator();
}
/**
* Validate enterprise readiness
*
* @param string $path Repository path to validate
* @return array Validation results
*/
public function validate(string $path): array
{
$this->logger->logInfo("Starting enterprise readiness validation for: {$path}");
$this->results = [];
// Run all validation checks
$this->checkEnterpriseLibraries($path);
$this->checkMonitoring($path);
$this->checkAuditLogging($path);
$this->checkSecurityCompliance($path);
$this->checkDocumentation($path);
$passed = count(array_filter($this->results, fn($r) => $r['passed']));
$total = count($this->results);
$percentage = $total > 0 ? ($passed / $total * 100) : 0;
$this->logger->logInfo("Enterprise readiness validation complete: {$passed}/{$total} checks passed ({$percentage}%)");
return [
'results' => $this->results,
'passed' => $passed,
'failed' => $total - $passed,
'total' => $total,
'percentage' => $percentage,
'compliant' => $passed === $total,
];
}
/**
* Check for required enterprise libraries
*/
private function checkEnterpriseLibraries(string $path): void
{
$required = [
'ApiClient',
'AuditLogger',
'Config',
'ErrorRecovery',
'MetricsCollector'
];
foreach ($required as $library) {
$phpFile = "{$path}/lib/Enterprise/{$library}.php";
$this->addResult(
"Enterprise library: {$library}",
file_exists($phpFile),
file_exists($phpFile) ? "Found at {$phpFile}" : "Missing required enterprise library"
);
}
}
/**
* Check monitoring configuration
*/
private function checkMonitoring(string $path): void
{
// Check for metrics collection
$metricsDir = "{$path}/var/logs/metrics";
$hasMetricsDir = is_dir($metricsDir);
$hasComposer = file_exists($path . '/composer.json');
$this->addResult(
'Metrics directory configured',
$hasMetricsDir || !$hasComposer,
$hasMetricsDir ? "Metrics directory exists at {$metricsDir}" : 'Metrics logging not configured'
);
// Check for monitoring documentation
$monitoringDocs = "{$path}/docs/monitoring";
$hasMonitoringDocs = is_dir($monitoringDocs) || file_exists("{$path}/docs/monitoring.md");
$this->addResult(
'Monitoring documentation exists',
$hasMonitoringDocs,
$hasMonitoringDocs ? "Monitoring documentation found" : 'Monitoring documentation not found'
);
}
/**
* Check audit logging configuration
*/
private function checkAuditLogging(string $path): void
{
$auditDir = "{$path}/var/logs/audit";
$hasAuditDir = is_dir($auditDir);
$hasComposer = file_exists($path . '/composer.json');
$this->addResult(
'Audit logging directory configured',
$hasAuditDir || !$hasComposer,
$hasAuditDir ? "Audit directory exists at {$auditDir}" : 'Audit logging not configured'
);
}
/**
* Check security compliance
*/
private function checkSecurityCompliance(string $path): void
{
// Check for security policy
$hasSecurity = file_exists("{$path}/SECURITY.md") || file_exists("{$path}/.github/SECURITY.md");
$this->addResult(
'Security policy exists',
$hasSecurity,
$hasSecurity ? "SECURITY.md found" : 'SECURITY.md not found'
);
// Check for CodeQL configuration
$codeqlConfig = "{$path}/.github/codeql";
$hasCodeQL = is_dir($codeqlConfig) || file_exists("{$path}/.github/codeql/codeql-config.yml");
$this->addResult(
'CodeQL configured',
$hasCodeQL,
$hasCodeQL ? "CodeQL configuration found" : 'CodeQL not configured'
);
// Run security scan on PHP files
if (is_dir("{$path}/src")) {
$this->securityValidator->scanDirectory("{$path}/src", ['.php']);
$issues = $this->securityValidator->getFindings();
$issueCount = count($issues);
$this->addResult(
'No security vulnerabilities in source code',
$issueCount === 0,
$issueCount === 0 ? "No security issues found" : "{$issueCount} security issues found"
);
}
}
/**
* Check documentation requirements
*/
private function checkDocumentation(string $path): void
{
// Check for architecture documentation
$hasArchitecture = file_exists("{$path}/docs/architecture.md") ||
file_exists("{$path}/docs/guide/architecture.md");
$this->addResult(
'Architecture documentation exists',
$hasArchitecture,
$hasArchitecture ? "Architecture documentation found" : 'Architecture documentation not found'
);
// Check for API documentation
$hasAPI = file_exists("{$path}/docs/api.md") || is_dir("{$path}/docs/api");
$this->addResult(
'API documentation exists',
$hasAPI,
$hasAPI ? "API documentation found" : 'API documentation not found'
);
}
/**
* Add a validation result
*/
private function addResult(string $check, bool $passed, string $message): void
{
$this->results[] = [
'check' => $check,
'passed' => $passed,
'message' => $message,
];
}
/**
* Get all results
*
* @return array All validation results
*/
public function getResults(): array
{
return $this->results;
}
/**
* Get failed checks
*
* @return array Array of failed checks
*/
public function getFailedChecks(): array
{
return array_filter($this->results, fn($r) => !$r['passed']);
}
/**
* Get passed checks
*
* @return array Array of passed checks
*/
public function getPassedChecks(): array
{
return array_filter($this->results, fn($r) => $r['passed']);
}
/**
* Check if fully compliant
*
* @return bool True if all checks passed
*/
public function isCompliant(): bool
{
return empty($this->getFailedChecks());
}
}