Skip to content

Commit

Permalink
Improve exception message
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbalandan committed May 20, 2023
1 parent 6f05243 commit 02a4166
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions system/View/Cells/Cell.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
namespace CodeIgniter\View\Cells;

use CodeIgniter\Traits\PropertiesTrait;
use LogicException;
use ReflectionClass;
use RuntimeException;

/**
* Class Cell
Expand Down Expand Up @@ -66,7 +66,7 @@ public function setView(string $view)
* current scope and captures the output buffer instead of
* relying on the view service.
*
* @throws RuntimeException
* @throws LogicException
*/
final protected function view(?string $view, array $data = []): string
{
Expand All @@ -90,17 +90,20 @@ final protected function view(?string $view, array $data = []): string
$view = $directory . $view . '.php';
}

foreach ([$view, $possibleView1 ?? '', $possibleView2 ?? ''] as $candidateView) {
if (is_file($candidateView)) {
$foundView = $candidateView;
break;
}
}
$candidateViews = array_filter(
[$view, $possibleView1 ?? '', $possibleView2 ?? ''],
static fn (string $path): bool => $path !== '' && is_file($path)
);

if (! isset($foundView)) {
throw new RuntimeException('Cannot locate the view file for the cell.');
if ($candidateViews === []) {
throw new LogicException(sprintf(
'Cannot locate the view file for the "%s" cell.',
static::class
));
}

$foundView = $candidateViews[0];

return (function () use ($properties, $foundView): string {
extract($properties);
ob_start();
Expand Down

0 comments on commit 02a4166

Please sign in to comment.