Remove directory arg checks, add braces where missing on conditionals
This commit is contained in:
@@ -22,23 +22,16 @@ final class IconExtension extends AbstractExtension
|
||||
|
||||
public function __construct(private array $directories, private array $palletes)
|
||||
{
|
||||
if (empty($this->directories))
|
||||
throw new \InvalidArgumentException('Directories array must contain at least one path!');
|
||||
|
||||
$dirsContainNonString = array_reduce($this->directories,
|
||||
fn($notString, $path) => $notString || !is_string($path));
|
||||
|
||||
if ($dirsContainNonString)
|
||||
throw new \TypeError('Directories array must only contain strings!');
|
||||
|
||||
if (empty($this->palletes))
|
||||
if (empty($this->palletes)) {
|
||||
throw new \InvalidArgumentException('Palletes array must contain at least one pallet!');
|
||||
}
|
||||
|
||||
$palletesContainNonarray = array_reduce($this->palletes,
|
||||
fn($notArray, $path) => $notArray || !is_array($path));
|
||||
|
||||
if ($palletesContainNonarray)
|
||||
if ($palletesContainNonarray) {
|
||||
throw new \TypeError('Palletes array must only contain arrays!');
|
||||
}
|
||||
|
||||
foreach ($this->palletes as $pallete) {
|
||||
if (!(
|
||||
@@ -115,10 +108,11 @@ final class IconExtension extends AbstractExtension
|
||||
private function throwIfUnrecognisedOptionExists(array $options): void
|
||||
{
|
||||
foreach (array_keys($options) as $key) {
|
||||
if (!key_exists($key, self::DEFAULT_OPTIONS))
|
||||
if (!key_exists($key, self::DEFAULT_OPTIONS)) {
|
||||
throw new \InvalidArgumentException("Unrecognised option '{$key}'!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getSanitisedIconSvg(string $iconName): string
|
||||
{
|
||||
@@ -126,6 +120,7 @@ final class IconExtension extends AbstractExtension
|
||||
$rawSvgMarkup = $this->getSvgMarkup($iconFilepath);
|
||||
$cleanSvgMarkup = $this->removeExistingTitleElement($rawSvgMarkup);
|
||||
$cleanSvgMarkup = $this->removeBlackStrokeAttributes($cleanSvgMarkup);
|
||||
|
||||
return $this->removeBlackFillAttributes($cleanSvgMarkup);
|
||||
}
|
||||
|
||||
@@ -134,9 +129,10 @@ final class IconExtension extends AbstractExtension
|
||||
foreach ($this->directories as $directory) {
|
||||
$potentialFilepath = sprintf('%s/%s.svg', $directory, $iconName);
|
||||
|
||||
if (file_exists($potentialFilepath))
|
||||
if (file_exists($potentialFilepath)) {
|
||||
return $potentialFilepath;
|
||||
}
|
||||
}
|
||||
|
||||
throw new IconNotFound(sprintf('File "%s.svg" not found in %s', $iconName, implode(', ', $this->directories)));
|
||||
}
|
||||
@@ -176,8 +172,9 @@ final class IconExtension extends AbstractExtension
|
||||
|
||||
private function getPallete(string $palleteName): array
|
||||
{
|
||||
if (array_key_exists($palleteName, $this->palletes))
|
||||
if (array_key_exists($palleteName, $this->palletes)) {
|
||||
return $this->palletes[$palleteName];
|
||||
}
|
||||
|
||||
throw new PalleteNotFound("The pallete '$palleteName' was not found!");
|
||||
}
|
||||
@@ -191,7 +188,10 @@ final class IconExtension extends AbstractExtension
|
||||
|
||||
private function addTitleToSvgIfNotNull(string $svg, ?string $title): string
|
||||
{
|
||||
if (null === $title) return $svg;
|
||||
if (null === $title) {
|
||||
return $svg;
|
||||
}
|
||||
|
||||
$this->throwIfTitleIsEmpty($title);
|
||||
|
||||
return preg_replace('/(<svg(.|\n)*?>\n?)/', "$1<title>$title</title>", $svg);
|
||||
@@ -215,9 +215,10 @@ final class IconExtension extends AbstractExtension
|
||||
|
||||
private function throwIfTitleIsEmpty(string $title): void
|
||||
{
|
||||
if ('' === $title)
|
||||
if ('' === $title) {
|
||||
throw new \InvalidArgumentException('Title string must not be empty!');
|
||||
}
|
||||
}
|
||||
|
||||
private function setSvgHeightAndWidth(string $content, int $size): string
|
||||
{
|
||||
@@ -230,9 +231,10 @@ final class IconExtension extends AbstractExtension
|
||||
|
||||
private function throwIfSizeIsNegative(int $size): void
|
||||
{
|
||||
if ($size < 0)
|
||||
if ($size < 0) {
|
||||
throw new \InvalidArgumentException('Size must not be negative');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class IconNotFound extends \Exception {};
|
||||
|
||||
Reference in New Issue
Block a user