Skip to content

Commit 53ea187

Browse files
committed
docs: fix the PHP samples reported by PHPStan
1 parent 1b0e1c3 commit 53ea187

64 files changed

Lines changed: 545 additions & 241 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎docs/cli/cli_controllers.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use CodeIgniter\Controller;
2020

2121
class Tools extends Controller
2222
{
23-
public function message($to = 'World')
23+
public function message(string $to = 'World'): string
2424
{
2525
return "Hello {$to}!" . PHP_EOL;
2626
}

‎docs/cli/cli_generators.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,9 @@ use CodeIgniter\Config\BaseConfig;
321321

322322
class Generators extends BaseConfig
323323
{
324+
/**
325+
* @var array<string, array<string, string>|string>
326+
*/
324327
public array $views = [
325328
// ..
326329
'make:awesome-command' => 'App\Commands\Generators\Views\awesomecommand.tpl.php',

‎docs/concepts/factories.md‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ use CodeIgniter\Config\Factories;
5858

5959
class SomeOtherClass
6060
{
61-
public function someFunction()
61+
public function someFunction(): void
6262
{
6363
$users = Factories::models('UserModel');
6464

@@ -214,7 +214,10 @@ use CodeIgniter\Filters\FilterInterface;
214214

215215
class Factory extends BaseFactory
216216
{
217-
public $filters = [
217+
/**
218+
* @var array<string, string>
219+
*/
220+
public array $filters = [
218221
'instanceOf' => FilterInterface::class,
219222
];
220223
}
@@ -239,7 +242,10 @@ use CodeIgniter\Config\Factory as BaseFactory;
239242

240243
class Factory extends BaseFactory
241244
{
242-
public $library = [
245+
/**
246+
* @var array<string, string>
247+
*/
248+
public array $library = [
243249
'path' => 'Libraries',
244250
];
245251
}

‎docs/concepts/services.md‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ class Services extends BaseService
171171
{
172172
// ...
173173

174-
public static function routes()
174+
public static function routes(): \CodeIgniter\Router\RouteCollection
175175
{
176176
return new MyRouteCollection(static::locator(), config('Modules'));
177177
}
@@ -196,9 +196,9 @@ class Services extends BaseService
196196
{
197197
// ...
198198

199-
public static function renderer($viewPath = APPPATH . 'views/')
199+
public static function renderer(string $viewPath = APPPATH . 'views/'): View
200200
{
201-
return new View($viewPath);
201+
return new View(config('View'), $viewPath);
202202
}
203203
}
204204
```
@@ -229,7 +229,7 @@ class Services extends BaseService
229229
{
230230
// ...
231231

232-
public static function routes($getShared = true)
232+
public static function routes(bool $getShared = true): \CodeIgniter\Router\RouteCollection
233233
{
234234
if ($getShared) {
235235
return static::getSharedInstance('routes');
@@ -261,9 +261,9 @@ use CodeIgniter\Config\BaseService;
261261

262262
class Services extends BaseService
263263
{
264-
public static function postManager()
264+
public static function postManager(): \Blog\Libraries\PostManager
265265
{
266-
// ...
266+
return new \Blog\Libraries\PostManager();
267267
}
268268
}
269269
```

‎docs/database/configuration.md‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ class Database extends Config
2222
{
2323
// ...
2424

25+
/**
26+
* @var array<string, mixed>
27+
*/
2528
public array $default = [
2629
'DSN' => '',
2730
'hostname' => 'localhost',
@@ -112,6 +115,9 @@ class Database extends Config
112115
{
113116
// ...
114117

118+
/**
119+
* @var array<string, mixed>
120+
*/
115121
public array $default = [
116122
// ...
117123
'failover' => [
@@ -172,6 +178,9 @@ class Database extends Config
172178
{
173179
// ...
174180

181+
/**
182+
* @var array<string, mixed>
183+
*/
175184
public array $test = [
176185
'DSN' => '',
177186
'hostname' => 'localhost',
@@ -234,9 +243,20 @@ use CodeIgniter\Database\Config;
234243
class Database extends Config
235244
{
236245
// ...
237-
public $development = [/* ... */];
238-
public $test = [/* ... */];
239-
public $production = [/* ... */];
246+
/**
247+
* @var array<string, mixed>
248+
*/
249+
public array $development = [/* ... */];
250+
251+
/**
252+
* @var array<string, mixed>
253+
*/
254+
public array $test = [/* ... */];
255+
256+
/**
257+
* @var array<string, mixed>
258+
*/
259+
public array $production = [/* ... */];
240260

241261
public function __construct()
242262
{

‎docs/database/query_builder.md‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,9 +1281,9 @@ namespace App\Libraries;
12811281

12821282
class MyClass
12831283
{
1284-
public $title = 'My Title';
1285-
public $content = 'My Content';
1286-
public $date = 'My Date';
1284+
public string $title = 'My Title';
1285+
public string $content = 'My Content';
1286+
public string $date = 'My Date';
12871287
}
12881288
```
12891289

@@ -1468,9 +1468,9 @@ namespace App\Libraries;
14681468

14691469
class MyClass
14701470
{
1471-
public $email = 'ahmadinejad@example.com';
1472-
public $name = 'Ahmadinejad';
1473-
public $country = 'Iran';
1471+
public string $email = 'ahmadinejad@example.com';
1472+
public string $name = 'Ahmadinejad';
1473+
public string $country = 'Iran';
14741474
}
14751475
```
14761476

@@ -1794,9 +1794,9 @@ namespace App\Libraries;
17941794

17951795
class MyClass
17961796
{
1797-
public $title = 'My Title';
1798-
public $content = 'My Content';
1799-
public $date = 'My Date';
1797+
public string $title = 'My Title';
1798+
public string $content = 'My Content';
1799+
public string $date = 'My Date';
18001800
}
18011801
```
18021802

@@ -1842,9 +1842,9 @@ namespace App\Libraries;
18421842

18431843
class MyClass
18441844
{
1845-
public $title = 'My Title';
1846-
public $content = 'My Content';
1847-
public $date = 'My Date';
1845+
public string $title = 'My Title';
1846+
public string $content = 'My Content';
1847+
public string $date = 'My Date';
18481848
}
18491849
```
18501850

‎docs/database/results.md‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -228,29 +228,31 @@ namespace App\Entities;
228228

229229
class User
230230
{
231-
public $id;
232-
public $email;
233-
public $username;
231+
public int $id;
232+
public string $email;
233+
public string $username;
234234

235-
protected $lastLogin;
235+
protected DateTime $lastLogin;
236236

237-
public function lastLogin($format)
237+
public function lastLogin(string $format): string
238238
{
239239
return $this->lastLogin->format($format);
240240
}
241241

242-
public function __set($name, $value)
242+
public function __set(string $name, mixed $value): void
243243
{
244244
if ($name === 'lastLogin') {
245245
$this->lastLogin = DateTime::createFromFormat('!U', $value);
246246
}
247247
}
248248

249-
public function __get($name)
249+
public function __get(string $name): mixed
250250
{
251251
if (isset($this->{$name})) {
252252
return $this->{$name};
253253
}
254+
255+
return null;
254256
}
255257
}
256258
```

‎docs/extending/basecontroller.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ abstract class BaseController extends Controller
5151
// ...
5252

5353
/**
54-
* @var \CodeIgniter\Session\Session;
54+
* @var \CodeIgniter\Session\Session
5555
*/
5656
protected $session;
5757

‎docs/extending/core_classes.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ use CodeIgniter\Config\BaseService;
8888

8989
class Services extends BaseService
9090
{
91-
public static function routes(bool $getShared = true)
91+
public static function routes(bool $getShared = true): \CodeIgniter\Router\RouteCollection
9292
{
9393
if ($getShared) {
9494
return static::getSharedInstance('routes');

‎docs/general/configuration.md‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ use CodeIgniter\Config\BaseConfig;
8989

9090
class CustomClass extends BaseConfig
9191
{
92-
public $siteName = 'My Great Site';
93-
public $siteEmail = 'webmaster@example.com';
92+
public string $siteName = 'My Great Site';
93+
public string $siteEmail = 'webmaster@example.com';
9494
// ...
9595
}
9696
```
@@ -302,6 +302,9 @@ namespace CodeIgniter\Shield\Config;
302302

303303
class Registrar
304304
{
305+
/**
306+
* @return array<string, array<string, string>>
307+
*/
305308
public static function Pager(): array
306309
{
307310
return [
@@ -326,7 +329,7 @@ A configuration file can also specify any number of registrars explicitly. This
326329

327330
namespace Config;
328331

329-
// ...
332+
use CodeIgniter\Config\BaseConfig;
330333

331334
class MyConfig extends BaseConfig
332335
{
@@ -370,6 +373,9 @@ namespace App\Models;
370373

371374
class RegionalSales
372375
{
376+
/**
377+
* @return array<string, int>
378+
*/
373379
public static function MySalesConfig(): array
374380
{
375381
return [

0 commit comments

Comments
 (0)