Files
moko-platform/validate/check_paths.php
T
Jonathan Miller b0cc468155 feat: migrate to Gitea-only workflows and API
- RepositorySynchronizer defaults to GiteaAdapter
- PlatformAdapterFactory points to git.mokoconsulting.tech
- All plugins reference .gitea/workflows instead of .github/workflows
- push_files.php uses Gitea API
- Common.php REPO URLs updated to Gitea
- sync_dolibarr_readmes.php updated to Gitea URLs

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 17:40:18 -05:00

86 lines
2.5 KiB
PHP

#!/usr/bin/env 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.Scripts.Validate
* INGROUP: MokoStandards
* REPO: https://git.mokoconsulting.tech/MokoConsulting/MokoStandards-API
* PATH: /validate/check_paths.php
* VERSION: 04.06.00
* BRIEF: Validates that path separators use forward slashes (advisory)
*/
declare(strict_types=1);
require_once __DIR__ . '/../../vendor/autoload.php';
use MokoEnterprise\CliFramework;
/**
* Warns when backslash characters that look like Windows path separators appear
* in XML, JSON, YAML and Markdown tracked files (advisory — always exits 0).
*/
class CheckPaths extends CliFramework
{
/**
* Configure available arguments.
*/
protected function configure(): void
{
$this->setDescription('Validates that path separators use forward slashes (advisory)');
$this->addArgument('--path', 'Repository path to check', '.');
}
/**
* Scan for backslash path separators (advisory — always exits 0).
*
* @return int Exit code: always 0.
*/
protected function run(): int
{
$path = $this->getArgument('--path');
$patterns = ['*.xml', '*.json', '*.yml', '*.yaml', '*.md'];
$quoted = implode(' ', array_map('escapeshellarg', $patterns));
$output = shell_exec('git -C ' . escapeshellarg($path) . " ls-files {$quoted} 2>/dev/null") ?? '';
$files = array_values(array_filter(explode("\n", $output)));
$total = count($files);
$found = 0;
$this->section('Scanning for backslash path separators');
foreach ($files as $i => $file) {
$this->progress($i + 1, $total, $file);
$fullPath = $path . '/' . $file;
if (!is_file($fullPath)) {
continue;
}
$content = (string) file_get_contents($fullPath);
if (preg_match('/\\\\\\\\/', $content)) {
$stripped = preg_replace('/\\\\(n|t|r|"|\\\\|namespace)/', '', $content);
if (preg_match('/\\\\\\\\/', (string) $stripped)) {
$this->progress($i + 1, $total, '', true);
$this->status(false, $file, 'backslash path separator detected');
$found++;
}
}
}
$this->progress($total, $total, '', true);
$this->printSummary($total - $found, $found, $this->elapsed());
if ($found > 0) {
$this->log('WARNING', 'Advisory — use forward slashes in path strings');
}
return 0;
}
}
$script = new CheckPaths('check_paths', 'Validates that path separators use forward slashes');
exit($script->execute());