Skip to content

Commit 02a4166

Browse files
committed
Improve exception message
1 parent 6f05243 commit 02a4166

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

system/View/Cells/Cell.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
namespace CodeIgniter\View\Cells;
1313

1414
use CodeIgniter\Traits\PropertiesTrait;
15+
use LogicException;
1516
use ReflectionClass;
16-
use RuntimeException;
1717

1818
/**
1919
* Class Cell
@@ -66,7 +66,7 @@ public function setView(string $view)
6666
* current scope and captures the output buffer instead of
6767
* relying on the view service.
6868
*
69-
* @throws RuntimeException
69+
* @throws LogicException
7070
*/
7171
final protected function view(?string $view, array $data = []): string
7272
{
@@ -90,17 +90,20 @@ final protected function view(?string $view, array $data = []): string
9090
$view = $directory . $view . '.php';
9191
}
9292

93-
foreach ([$view, $possibleView1 ?? '', $possibleView2 ?? ''] as $candidateView) {
94-
if (is_file($candidateView)) {
95-
$foundView = $candidateView;
96-
break;
97-
}
98-
}
93+
$candidateViews = array_filter(
94+
[$view, $possibleView1 ?? '', $possibleView2 ?? ''],
95+
static fn (string $path): bool => $path !== '' && is_file($path)
96+
);
9997

100-
if (! isset($foundView)) {
101-
throw new RuntimeException('Cannot locate the view file for the cell.');
98+
if ($candidateViews === []) {
99+
throw new LogicException(sprintf(
100+
'Cannot locate the view file for the "%s" cell.',
101+
static::class
102+
));
102103
}
103104

105+
$foundView = $candidateViews[0];
106+
104107
return (function () use ($properties, $foundView): string {
105108
extract($properties);
106109
ob_start();

0 commit comments

Comments
 (0)