packages/ztd-query-mysql/fuzz/Robustness/Invariant/ShadowStoreConsistencyChecker.php

1<?php
2
3declare(strict_types=1);
4
5namespace Fuzz\Robustness\Invariant;
6
7use ZtdQuery\Shadow\ShadowStore;
8
9/**
10 * Implements the Shadow Store Consistency Checker contract for MySQL.
11 */
12final class ShadowStoreConsistencyChecker
13{
14    private ShadowStore $store;
15
16    /**
17     * Configure the dependencies used by this operation.
18     */
19    public function __construct(ShadowStore $store)
20    {
21        $this->store = $store;
22    }
23
24    /**
25     * Check that all shadow store tables maintain non-empty key structure.
26     */
27    public function check(string $sql): ?InvariantViolation
28    {
29        foreach ($this->store->getAll() as $tableName => $rows) {
30            if ($tableName === '') {
31                return new InvariantViolation('SHADOW_EMPTY_KEY', 'ShadowStore contains an empty table name key', $sql);
32            }
33        }
34
35        return null;
36    }
37}
38