fix: complete InvesteMoz validation and error corrections

This commit is contained in:
2026-10-29 21:47:33 +02:00
parent 63147312e2
commit daf8623441
718 changed files with 127308 additions and 20959 deletions
+48
View File
@@ -0,0 +1,48 @@
<?php
namespace App\Support;
use RuntimeException;
/** Required evidence must be readable; an I/O failure is never empty content or a matching hash. */
final class CheckedFile
{
/** @phpstan-impure */
public static function read(string $path): string
{
$bytes = @file_get_contents($path);
if ($bytes === false) {
throw new RuntimeException('Required file could not be read.');
}
return $bytes;
}
/** @phpstan-impure */
public static function sha256(string $path): string
{
$hash = @hash_file('sha256', $path);
if ($hash === false) {
throw new RuntimeException('Required file integrity could not be verified.');
}
return $hash;
}
/** @phpstan-impure */
public static function size(string $path): int
{
$size = @filesize($path);
if ($size === false) {
throw new RuntimeException('Required file size could not be verified.');
}
return $size;
}
/** @phpstan-impure */
public static function matches(string $path, string $expected): bool
{
return hash_equals($expected, self::sha256($path));
}
}
+19
View File
@@ -0,0 +1,19 @@
<?php
namespace App\Support;
use RuntimeException;
final class CheckedPattern
{
/** @return list<string> */
public static function split(string $pattern, string $value): array
{
$parts = preg_split($pattern, $value);
if ($parts === false) {
throw new RuntimeException('Text could not be split; original content has been preserved.');
}
return $parts;
}
}
+30
View File
@@ -0,0 +1,30 @@
<?php
namespace App\Support;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Collection;
use Traversable;
use UnexpectedValueException;
final class StructuredData
{
/** @return array<array-key, mixed> */
public static function collectionItems(mixed $value): array
{
if ($value instanceof Collection) {
return $value->all();
}
if ($value instanceof Traversable) {
return iterator_to_array($value);
}
if ($value instanceof Arrayable) {
return $value->toArray();
}
if (! is_array($value)) {
throw new UnexpectedValueException('Structured data must contain an array; original data has been preserved.');
}
return $value;
}
}