Validate args
This commit is contained in:
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Pcm\IconBundle\Twig\Functions;
|
||||
|
||||
use Exception;
|
||||
use InvalidArgumentException;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFunction;
|
||||
@@ -18,7 +19,7 @@ final class IconExtension extends AbstractExtension
|
||||
'size' => self::DEFAULT_SIZE
|
||||
];
|
||||
|
||||
public function __construct(private array $directories)
|
||||
public function __construct(private array $directories, private array $palletes)
|
||||
{
|
||||
if (empty($this->directories))
|
||||
throw new InvalidArgumentException('Directories array must contain at least one path!');
|
||||
@@ -28,6 +29,21 @@ final class IconExtension extends AbstractExtension
|
||||
|
||||
if ($dirsContainNonString)
|
||||
throw new \TypeError('Directories array must only contain strings!');
|
||||
|
||||
if (empty($this->palletes))
|
||||
throw new InvalidArgumentException('Palletes array must contain at least one pallet!');
|
||||
|
||||
$pelletesContainNonarray = array_reduce($this->palletes,
|
||||
fn($notArray, $path) => $notArray || !is_array($path));
|
||||
|
||||
if ($pelletesContainNonarray)
|
||||
throw new \TypeError('Palletes array must only contain arrays!');
|
||||
|
||||
foreach ($this->palletes as $pallete) {
|
||||
if (!(array_key_exists('stroke', $pallete) && array_key_exists('fill', $pallete))) {
|
||||
throw new \Exception('Palletes must contain a "stroke" and "fill" key!');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user