mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-11 17:44:44 +08:00
Added list of roles to print after an API is generated
This commit is contained in:
@@ -14,6 +14,7 @@ use function Functional\reduce_left;
|
||||
use function is_array;
|
||||
use function print_r;
|
||||
use function sprintf;
|
||||
use function str_repeat;
|
||||
|
||||
const DEFAULT_DELETE_SHORT_URL_THRESHOLD = 15;
|
||||
const DEFAULT_SHORT_CODES_LENGTH = 5;
|
||||
@@ -79,11 +80,20 @@ function getOptionalBoolFromInputFilter(InputFilter $inputFilter, string $fieldN
|
||||
return $value !== null ? (bool) $value : null;
|
||||
}
|
||||
|
||||
function arrayToString(array $array): string
|
||||
function arrayToString(array $array, int $indentSize = 4): string
|
||||
{
|
||||
return reduce_left($array, fn ($messages, string $name, $_, string $acc) => $acc . sprintf(
|
||||
"\n '%s' => %s",
|
||||
$name,
|
||||
is_array($messages) ? print_r($messages, true) : $messages,
|
||||
), '');
|
||||
$indent = str_repeat(' ', $indentSize);
|
||||
$index = 0;
|
||||
|
||||
return reduce_left($array, static function ($messages, string $name, $_, string $acc) use (&$index, $indent) {
|
||||
$index++;
|
||||
|
||||
return $acc . sprintf(
|
||||
"%s%s'%s' => %s",
|
||||
$index === 1 ? '' : "\n",
|
||||
$indent,
|
||||
$name,
|
||||
is_array($messages) ? print_r($messages, true) : $messages,
|
||||
);
|
||||
}, '');
|
||||
}
|
||||
|
||||
@@ -53,11 +53,12 @@ class ValidationException extends InvalidArgumentException implements ProblemDet
|
||||
public function __toString(): string
|
||||
{
|
||||
return sprintf(
|
||||
'%s %s in %s:%s%s%sStack trace:%s%s',
|
||||
'%s %s in %s:%s%s%s%sStack trace:%s%s',
|
||||
__CLASS__,
|
||||
$this->getMessage(),
|
||||
$this->getFile(),
|
||||
$this->getLine(),
|
||||
PHP_EOL,
|
||||
arrayToString($this->getInvalidElements()),
|
||||
PHP_EOL,
|
||||
PHP_EOL,
|
||||
|
||||
@@ -39,7 +39,7 @@ class ValidationExceptionTest extends TestCase
|
||||
$inputFilter = $this->prophesize(InputFilterInterface::class);
|
||||
$getMessages = $inputFilter->getMessages()->willReturn($invalidData);
|
||||
|
||||
$e = ValidationException::fromInputFilter($inputFilter->reveal());
|
||||
$e = ValidationException::fromInputFilter($inputFilter->reveal(), $prev);
|
||||
|
||||
self::assertEquals($invalidData, $e->getInvalidElements());
|
||||
self::assertEquals(['invalidElements' => array_keys($invalidData)], $e->getAdditionalData());
|
||||
@@ -52,6 +52,6 @@ class ValidationExceptionTest extends TestCase
|
||||
|
||||
public function provideExceptions(): iterable
|
||||
{
|
||||
return [[null, new RuntimeException(), new LogicException()]];
|
||||
return [[null], [new RuntimeException()], [new LogicException()]];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user