Skip to content

Commit 394be30

Browse files
committed
docs: fix the PHP samples reported by PHPStan
1 parent c3379fb commit 394be30

64 files changed

Lines changed: 545 additions & 240 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

@@ -210,7 +210,10 @@ use CodeIgniter\Filters\FilterInterface;
210210

211211
class Factory extends BaseFactory
212212
{
213-
public $filters = [
213+
/**
214+
* @var array<string, string>
215+
*/
216+
public array $filters = [
214217
'instanceOf' => FilterInterface::class,
215218
];
216219
}
@@ -235,7 +238,10 @@ use CodeIgniter\Config\Factory as BaseFactory;
235238

236239
class Factory extends BaseFactory
237240
{
238-
public $library = [
241+
/**
242+
* @var array<string, string>
243+
*/
244+
public array $library = [
239245
'path' => 'Libraries',
240246
];
241247
}

‎docs/concepts/services.md‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class Services extends BaseService
158158
{
159159
// ...
160160

161-
public static function routes()
161+
public static function routes(): \CodeIgniter\Router\RouteCollection
162162
{
163163
return new \App\Router\MyRouteCollection(static::locator(), config('Modules'));
164164
}
@@ -182,9 +182,9 @@ class Services extends BaseService
182182
{
183183
// ...
184184

185-
public static function renderer($viewPath = APPPATH . 'views/')
185+
public static function renderer(string $viewPath = APPPATH . 'views/'): \CodeIgniter\View\View
186186
{
187-
return new \CodeIgniter\View\View($viewPath);
187+
return new \CodeIgniter\View\View(config('View'), $viewPath);
188188
}
189189
}
190190
```
@@ -212,7 +212,7 @@ class Services extends BaseService
212212
{
213213
// ...
214214

215-
public static function routes($getShared = true)
215+
public static function routes(bool $getShared = true): \CodeIgniter\Router\RouteCollection
216216
{
217217
if ($getShared) {
218218
return static::getSharedInstance('routes');
@@ -244,9 +244,9 @@ use CodeIgniter\Config\BaseService;
244244

245245
class Services extends BaseService
246246
{
247-
public static function postManager()
247+
public static function postManager(): \Blog\Libraries\PostManager
248248
{
249-
// ...
249+
return new \Blog\Libraries\PostManager();
250250
}
251251
}
252252
```

‎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
@@ -1279,9 +1279,9 @@ namespace App\Libraries;
12791279

12801280
class MyClass
12811281
{
1282-
public $title = 'My Title';
1283-
public $content = 'My Content';
1284-
public $date = 'My Date';
1282+
public string $title = 'My Title';
1283+
public string $content = 'My Content';
1284+
public string $date = 'My Date';
12851285
}
12861286
```
12871287

@@ -1466,9 +1466,9 @@ namespace App\Libraries;
14661466

14671467
class MyClass
14681468
{
1469-
public $email = 'ahmadinejad@example.com';
1470-
public $name = 'Ahmadinejad';
1471-
public $country = 'Iran';
1469+
public string $email = 'ahmadinejad@example.com';
1470+
public string $name = 'Ahmadinejad';
1471+
public string $country = 'Iran';
14721472
}
14731473
```
14741474

@@ -1792,9 +1792,9 @@ namespace App\Libraries;
17921792

17931793
class MyClass
17941794
{
1795-
public $title = 'My Title';
1796-
public $content = 'My Content';
1797-
public $date = 'My Date';
1795+
public string $title = 'My Title';
1796+
public string $content = 'My Content';
1797+
public string $date = 'My Date';
17981798
}
17991799
```
18001800

@@ -1840,9 +1840,9 @@ namespace App\Libraries;
18401840

18411841
class MyClass
18421842
{
1843-
public $title = 'My Title';
1844-
public $content = 'My Content';
1845-
public $date = 'My Date';
1843+
public string $title = 'My Title';
1844+
public string $content = 'My Content';
1845+
public string $date = 'My Date';
18461846
}
18471847
```
18481848

‎docs/database/results.md‎

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

223223
class User
224224
{
225-
public $id;
226-
public $email;
227-
public $username;
225+
public int $id;
226+
public string $email;
227+
public string $username;
228228

229-
protected $lastLogin;
229+
protected DateTime $lastLogin;
230230

231-
public function lastLogin($format)
231+
public function lastLogin(string $format): string
232232
{
233233
return $this->lastLogin->format($format);
234234
}
235235

236-
public function __set($name, $value)
236+
public function __set(string $name, mixed $value): void
237237
{
238238
if ($name === 'lastLogin') {
239239
$this->lastLogin = DateTime::createFromFormat('!U', $value);
240240
}
241241
}
242242

243-
public function __get($name)
243+
public function __get(string $name): mixed
244244
{
245245
if (isset($this->{$name})) {
246246
return $this->{$name};
247247
}
248+
249+
return null;
248250
}
249251
}
250252
```

‎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
@@ -87,7 +87,7 @@ use CodeIgniter\Config\BaseService;
8787

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

‎docs/general/configuration.md‎

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

8686
class CustomClass extends BaseConfig
8787
{
88-
public $siteName = 'My Great Site';
89-
public $siteEmail = 'webmaster@example.com';
88+
public string $siteName = 'My Great Site';
89+
public string $siteEmail = 'webmaster@example.com';
9090
// ...
9191
}
9292
```
@@ -298,6 +298,9 @@ namespace CodeIgniter\Shield\Config;
298298

299299
class Registrar
300300
{
301+
/**
302+
* @return array<string, array<string, string>>
303+
*/
301304
public static function Pager(): array
302305
{
303306
return [
@@ -322,7 +325,7 @@ A configuration file can also specify any number of registrars explicitly. This
322325

323326
namespace Config;
324327

325-
// ...
328+
use CodeIgniter\Config\BaseConfig;
326329

327330
class MyConfig extends BaseConfig
328331
{
@@ -366,6 +369,9 @@ namespace App\Models;
366369

367370
class RegionalSales
368371
{
372+
/**
373+
* @return array<string, int>
374+
*/
369375
public static function MySalesConfig(): array
370376
{
371377
return [

0 commit comments

Comments
 (0)