Skip to content

Commit

Permalink
Refactoring exception hierarchy (possible BC break)
Browse files Browse the repository at this point in the history
  • Loading branch information
xificurk committed Jun 27, 2018
1 parent cfd268f commit ff99cac
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 40 deletions.
5 changes: 1 addition & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@
"psr-4": {
"Nepada\\Bridges\\": "src/Bridges/",
"Nepada\\Texy\\": "src/Texy/"
},
"classmap": [
"src/Texy/exceptions.php"
]
}
},
"extra": {
"branch-alias": {
Expand Down
4 changes: 2 additions & 2 deletions src/Bridges/TexyDI/TexyExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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']])
Expand Down
8 changes: 1 addition & 7 deletions src/Bridges/TexyLatte/TexyModeMacro.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

use Latte;
use Latte\MacroNode;
use Nepada;
use Nepada\Texy\TexyMultiplier;
use Nette;

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -92,18 +90,14 @@ public function nodeClosed(MacroNode $node): void
$node->closingCode = '<?php $this->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) {
$where = isset($template->global->control) && $template->global->control instanceof Nette\ComponentModel\IComponent
? ' 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}.");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Texy/TexyMultiplier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
24 changes: 0 additions & 24 deletions src/Texy/exceptions.php

This file was deleted.

3 changes: 1 addition & 2 deletions tests/Texy/TexyMultiplierTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ declare(strict_types = 1);

namespace NepadaTests\Texy;

use Nepada\Texy\InvalidStateException;
use Nepada\Texy\TexyFactory;
use Nepada\Texy\TexyMultiplier;
use Tester;
Expand Down Expand Up @@ -31,7 +30,7 @@ class TexyMultiplierTest extends Tester\TestCase
function () use ($multiplier): void {
$multiplier->getTexy();
},
InvalidStateException::class,
\InvalidArgumentException::class,
"Missing Texy! factory for mode 'test'."
);

Expand Down

0 comments on commit ff99cac

Please sign in to comment.