#!/usr/bin/env php * * 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/moko-platform * PATH: /validate/check_paths.php * 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());