refactor(RichObjectStrings): Only log error if key or value is not string in validator

Signed-off-by: provokateurin <kate@provokateurin.de>
pull/52035/head
provokateurin 2025-04-08 11:38:25 +07:00
parent 59444784f2
commit fd156d3408
No known key found for this signature in database
2 changed files with 4 additions and 7 deletions

@ -10,6 +10,8 @@ namespace OC\RichObjectStrings;
use OCP\RichObjectStrings\Definitions; use OCP\RichObjectStrings\Definitions;
use OCP\RichObjectStrings\InvalidObjectExeption; use OCP\RichObjectStrings\InvalidObjectExeption;
use OCP\RichObjectStrings\IValidator; use OCP\RichObjectStrings\IValidator;
use OCP\Server;
use Psr\Log\LoggerInterface;
/** /**
* Class Validator * Class Validator
@ -79,10 +81,10 @@ class Validator implements IValidator {
foreach ($parameter as $key => $value) { foreach ($parameter as $key => $value) {
if (!is_string($key)) { if (!is_string($key)) {
throw new InvalidObjectExeption('Object for placeholder ' . $placeholder . ' is invalid, key ' . $key . ' is not a string'); Server::get(LoggerInterface::class)->error('Object for placeholder ' . $placeholder . ' is invalid, key ' . $key . ' is not a string');
} }
if (!is_string($value)) { if (!is_string($value)) {
throw new InvalidObjectExeption('Object for placeholder ' . $placeholder . ' is invalid, value ' . $value . ' for key ' . $key . ' is not a string'); Server::get(LoggerInterface::class)->error('Object for placeholder ' . $placeholder . ' is invalid, value ' . $value . ' for key ' . $key . ' is not a string');
} }
} }
} }

@ -10,7 +10,6 @@ namespace Test\RichObjectStrings;
use OC\RichObjectStrings\Validator; use OC\RichObjectStrings\Validator;
use OCP\RichObjectStrings\Definitions; use OCP\RichObjectStrings\Definitions;
use OCP\RichObjectStrings\InvalidObjectExeption;
use Test\TestCase; use Test\TestCase;
class ValidatorTest extends TestCase { class ValidatorTest extends TestCase {
@ -37,9 +36,6 @@ class ValidatorTest extends TestCase {
]); ]);
$this->addToAssertionCount(2); $this->addToAssertionCount(2);
$this->expectException(InvalidObjectExeption::class);
$this->expectExceptionMessage('Object for placeholder string1 is invalid, value 123 for key key is not a string');
$v->validate('test {string1} test.', [ $v->validate('test {string1} test.', [
'string1' => [ 'string1' => [
'type' => 'user', 'type' => 'user',
@ -49,7 +45,6 @@ class ValidatorTest extends TestCase {
], ],
]); ]);
$this->expectExceptionMessage('Object for placeholder string1 is invalid, key 456 is not a string');
$v->validate('test {string1} test.', [ $v->validate('test {string1} test.', [
'string1' => [ 'string1' => [
'type' => 'user', 'type' => 'user',