Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit dc7977b

Browse files
authored
Merge pull request #218 from kenjis/update-app-code
Update app code
2 parents 99c0a2c + 82d86c2 commit dc7977b

File tree

6 files changed

+21
-14
lines changed

6 files changed

+21
-14
lines changed

‎app/Controllers/DungeonController.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,43 @@
33
namespace App\Controllers;
44

55
use App\Models\DungeonModel;
6-
use App\Models\HeroModel;
6+
use CodeIgniter\HTTP\ResponseInterface;
77

88
class DungeonController extends BaseController
99
{
1010
/**
11-
* HeroModel instance.
11+
* DungeonModel instance.
1212
*/
13-
protected $heroes;
13+
protected DungeonModel$dungeons;
1414

1515
public function __construct()
1616
{
17-
// Assign the model to $this->heroes
17+
// Assign the model to $this->dungeons
1818
// so that it's available throughout this class
1919
// Use the `model()` helper method to return
2020
// a single instance of the model no matter
2121
// how many times we call it
22-
$this->heroes = model(DungeonModel::class);
22+
$this->dungeons = model(DungeonModel::class);
2323
}
2424

2525
/**
26-
* View a single hero's details.
26+
* View a single dungeon's details.
2727
*
28-
* The $id parameter is the hero's ID, and is
28+
* The $id parameter is the dungeon's ID, and is
2929
* passed in from the route definition as 1,ドル
3030
* since it is the first placeholder in the route.
31+
*
32+
* @return ResponseInterface|string
3133
*/
3234
public function show(int $id)
3335
{
34-
$dungeon = $this->heroes->find($id);
36+
$dungeon = $this->dungeons->find($id);
3537

3638
if ($dungeon === null) {
3739
return redirect()->back()->with('error', 'Dungeon not found');
3840
}
3941

40-
echo view('dungeon', [
42+
return view('dungeon', [
4143
'dungeon' => $dungeon,
4244
'monsters' => $dungeon->monsters(3),
4345
]);

‎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
}

‎app/Entities/Monster.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
*
1010
* This class represents a single row in the
1111
* `monsters` database.
12+
*
13+
* @property int $dungeon_id
1214
*/
1315
class Monster extends Entity
1416
{

‎composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"psr/container": "1.1.2",
3030
"codeigniter4/devkit": "^1.0",
3131
"tatter/patches": "^2.1",
32-
"kint-php/kint": "^5.1"
32+
"kint-php/kint": "^5.1",
33+
"codeigniter/phpstan-codeigniter": "^1.4"
3334
},
3435
"minimum-stability": "dev",
3536
"prefer-stable": true,

‎phpstan.neon.dist

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ parameters:
1111
- app/Views/*
1212
ignoreErrors:
1313
- '#Call to an undefined method CodeIgniter\\Database\\ConnectionInterface::(en|dis)ableForeignKeyChecks#'
14-
- '#Cannot access property [\$a-z_]+ on (array|object)#'
1514
universalObjectCratesClasses:
1615
- CodeIgniter\Entity
1716
- CodeIgniter\Entity\Entity

‎tests/database/FakerTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ protected function setUp(): void
3434
public function testMakesValidMonster()
3535
{
3636
// We can use make() to generate a random dataset defined in our Faker
37+
/** @var Monster $monster */
3738
$monster = $this->fabricator->make();
3839

3940
$this->assertInstanceOf(Monster::class, $monster);
@@ -43,6 +44,7 @@ public function testMakesValidMonster()
4344
// Since our Faker uses Fabricator counts for its dungeon_id we should always have a valid dungeon available
4445
public function testMakesMonsterWithDungeon()
4546
{
47+
/** @var Monster $monster */
4648
$monster = $this->fabricator->make();
4749
$dungeon = model(DungeonModel::class)->find($monster->dungeon_id);
4850

@@ -52,6 +54,7 @@ public function testMakesMonsterWithDungeon()
5254
public function testCreateAddsToDatabase()
5355
{
5456
// create() generates a random dataset just like make() but also adds it to the database for us
57+
/** @var Monster $monster */
5558
$monster = $this->fabricator->create();
5659
$this->assertIsInt($monster->id);
5760

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /