Skip to content

Commit 473d9e2

Browse files
committed
refactor: use return instead of echo
1 parent 99c0a2c commit 473d9e2

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

app/Controllers/DungeonController.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Models\DungeonModel;
66
use App\Models\HeroModel;
7+
use CodeIgniter\HTTP\ResponseInterface;
78

89
class DungeonController extends BaseController
910
{
@@ -28,6 +29,8 @@ public function __construct()
2829
* The $id parameter is the hero's ID, and is
2930
* passed in from the route definition as $1,
3031
* since it is the first placeholder in the route.
32+
*
33+
* @return ResponseInterface|string
3134
*/
3235
public function show(int $id)
3336
{
@@ -37,7 +40,7 @@ public function show(int $id)
3740
return redirect()->back()->with('error', 'Dungeon not found');
3841
}
3942

40-
echo view('dungeon', [
43+
return view('dungeon', [
4144
'dungeon' => $dungeon,
4245
'monsters' => $dungeon->monsters(3),
4346
]);

app/Controllers/HeroController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class HeroController extends BaseController
1414
* passed in from the route definition as $1,
1515
* since it is the first placeholder in the route.
1616
*/
17-
public function show(int $id)
17+
public function show(int $id): string
1818
{
1919
// When you only need to use a model in a single place,
2020
// you can simply get a new instance here. It will use
@@ -30,10 +30,10 @@ public function show(int $id)
3030
throw new PageNotFoundException('Hero not found');
3131
}
3232

33-
// Display a view file, passing the variables
33+
// Return a view, passing the variables
3434
// you want to access in the view within the
3535
// second parameter.
36-
echo view('hero', [
36+
return view('hero', [
3737
'hero' => $hero,
3838
]);
3939
}

0 commit comments

Comments
 (0)