From ff99cac9b1d708bb799f315b5f9502846e04d066 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mor=C3=A1vek?= Date: Wed, 27 Jun 2018 22:55:55 +0200 Subject: [PATCH] Refactoring exception hierarchy (possible BC break) --- composer.json | 5 +---- src/Bridges/TexyDI/TexyExtension.php | 4 ++-- src/Bridges/TexyLatte/TexyModeMacro.php | 8 +------- src/Texy/TexyMultiplier.php | 2 +- src/Texy/exceptions.php | 24 ------------------------ tests/Texy/TexyMultiplierTest.phpt | 3 +-- 6 files changed, 6 insertions(+), 40 deletions(-) delete mode 100644 src/Texy/exceptions.php diff --git a/composer.json b/composer.json index c625529..85a2e74 100644 --- a/composer.json +++ b/composer.json @@ -48,10 +48,7 @@ "psr-4": { "Nepada\\Bridges\\": "src/Bridges/", "Nepada\\Texy\\": "src/Texy/" - }, - "classmap": [ - "src/Texy/exceptions.php" - ] + } }, "extra": { "branch-alias": { diff --git a/src/Bridges/TexyDI/TexyExtension.php b/src/Bridges/TexyDI/TexyExtension.php index 258f65a..0510149 100644 --- a/src/Bridges/TexyDI/TexyExtension.php +++ b/src/Bridges/TexyDI/TexyExtension.php @@ -49,7 +49,7 @@ public function beforeCompile(): void } $latteExtension = $this->compiler->getExtensions(Nette\Bridges\ApplicationDI\LatteExtension::class); if ($latteExtension === []) { - throw new Texy\InvalidStateException('LatteExtension not found, did you register it in your configuration?'); + throw new \LogicException('LatteExtension not found, did you register it in your configuration?'); } reset($latteExtension)->addMacro(Nepada\Bridges\TexyLatte\TexyModeMacro::class . '::install'); @@ -58,7 +58,7 @@ public function beforeCompile(): void } $templateConfigurator = $container->getByType(Nepada\TemplateFactory\TemplateConfigurator::class); if ($templateConfigurator === null) { - throw new Texy\InvalidStateException('Could not find TemplateConfigurator service, did you register TemplateFactoryExtension in your configuration?'); + throw new \LogicException('Could not find TemplateConfigurator service, did you register TemplateFactoryExtension in your configuration?'); } $container->getDefinition($templateConfigurator) ->addSetup('addFilter', ['texy', [$this->prefix('@latteFilters'), 'process']]) diff --git a/src/Bridges/TexyLatte/TexyModeMacro.php b/src/Bridges/TexyLatte/TexyModeMacro.php index d8f991b..38407db 100644 --- a/src/Bridges/TexyLatte/TexyModeMacro.php +++ b/src/Bridges/TexyLatte/TexyModeMacro.php @@ -5,7 +5,6 @@ use Latte; use Latte\MacroNode; -use Nepada; use Nepada\Texy\TexyMultiplier; use Nette; @@ -55,7 +54,6 @@ public function finalize() * @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint * @param MacroNode $node * @return void - * @throws Latte\CompileException */ public function nodeOpened(MacroNode $node) { @@ -92,10 +90,6 @@ public function nodeClosed(MacroNode $node): void $node->closingCode = 'global->texy->setMode(array_pop($this->global->texyModeStack)); ?>'; } - /** - * @param Latte\Runtime\Template $template - * @throws Nepada\Texy\InvalidStateException - */ public static function validateTemplate(Latte\Runtime\Template $template): void { if (!isset($template->global->texy) || !$template->global->texy instanceof TexyMultiplier) { @@ -103,7 +97,7 @@ public static function validateTemplate(Latte\Runtime\Template $template): void ? ' in component ' . get_class($template->global->control) . '(' . $template->global->control->getName() . ')' : null; - throw new Nepada\Texy\InvalidStateException("TexyMultiplier instance not found{$where}."); + throw new \LogicException("TexyMultiplier instance not found{$where}."); } } diff --git a/src/Texy/TexyMultiplier.php b/src/Texy/TexyMultiplier.php index 0d05752..460ebce 100644 --- a/src/Texy/TexyMultiplier.php +++ b/src/Texy/TexyMultiplier.php @@ -56,7 +56,7 @@ public function getTexy(?string $mode = null): Texy\Texy if (!isset($this->texy[$mode])) { if (!isset($this->factories[$mode])) { - throw new InvalidStateException("Missing Texy! factory for mode '{$mode}'."); + throw new \InvalidArgumentException("Missing Texy! factory for mode '{$mode}'."); } $this->texy[$mode] = $this->factories[$mode]->create(); } diff --git a/src/Texy/exceptions.php b/src/Texy/exceptions.php deleted file mode 100644 index c261a17..0000000 --- a/src/Texy/exceptions.php +++ /dev/null @@ -1,24 +0,0 @@ -getTexy(); }, - InvalidStateException::class, + \InvalidArgumentException::class, "Missing Texy! factory for mode 'test'." );