<?php
$dir = 'c:\xampp\htdocs\inveetaire\app\views\public\identity\sections';
$partials = 'c:\xampp\htdocs\inveetaire\app\views\public\identity\partials';

$files = array_merge(glob("$dir/*.php"), glob("$partials/*.php"));

foreach ($files as $f) {
    $content = file_get_contents($f);
    
    // Count PHP control structures
    $if = substr_count($content, '<?php if');
    $endif = substr_count($content, '<?php endif;');
    $foreach = substr_count($content, '<?php foreach');
    $endforeach = substr_count($content, '<?php endforeach;');
    
    // Count main HTML tags
    $divOpen = substr_count($content, '<div');
    $divClose = substr_count($content, '</div');
    
    $sectionOpen = substr_count($content, '<section');
    $sectionClose = substr_count($content, '</section>');
    
    echo basename($f) . ":\n";
    if ($if !== $endif) echo "  [WARNING] Mismatched if ($if) / endif ($endif)\n";
    if ($foreach !== $endforeach) echo "  [WARNING] Mismatched foreach ($foreach) / endforeach ($endforeach)\n";
    if ($divOpen !== $divClose) echo "  [WARNING] Mismatched div (<div: $divOpen, </div: $divClose)\n";
    if ($sectionOpen !== $sectionClose) echo "  [WARNING] Mismatched section (<section: $sectionOpen, </section>: $sectionClose)\n";
}
