Skip to content

Commit dba1111

Browse files
docs: Update documentation for consistency and clarity; change section titles and add strict types declaration. (#53)
1 parent d21fc9c commit dba1111

File tree

5 files changed

+66
-16
lines changed

5 files changed

+66
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
- Bug #50: Add Testing Guide link to `installation` and `examples` documentation (@terabytesoftw)
2121
- Bug #51: Reorder Installation section in `README.md` for improved clarity (@terabytesoftw)
2222
- Bug #52: Standardize headings and improve clarity in documentation files (@terabytesoftw)
23+
- Bug #53: Update documentation for consistency and clarity; change section titles and add strict types declaration (@terabytesoftw)
2324

2425
## 0.2.3 June 09, 2025
2526

README.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ inference, dynamic method resolution, and comprehensive property reflection.
5757
- Stub files for different application types (web, console, base).
5858
- Support for Yii2 constants (`YII_DEBUG`, `YII_ENV_*`).
5959

60-
## Installation
60+
## Quick start
61+
62+
### Installation
6163

6264
```bash
6365
composer require --dev yii2-extensions/phpstan
6466
```
6567

66-
## Quick start
67-
6868
Create a `phpstan.neon` file in your project root.
6969

7070
```neon
@@ -89,6 +89,9 @@ Create a PHPStan-specific config file (`config/phpstan-config.php`).
8989

9090
```php
9191
<?php
92+
93+
declare(strict_types=1);
94+
9295
return [
9396
'components' => [
9497
'db' => [
@@ -110,9 +113,9 @@ Run `PHPStan`.
110113
vendor/bin/phpstan analyse
111114
```
112115

113-
## Type inference examples
116+
### Type inference examples
114117

115-
### Active Record
118+
#### Active Record
116119

117120
```php
118121
// ✅ Typed as User|null
@@ -134,7 +137,7 @@ $userName = $user->getAttribute('name');
134137
$slug = $user->getAttribute('slug');
135138
```
136139

137-
### Application components
140+
#### Application components
138141

139142
```php
140143
// ✅ Typed based on your configuration
@@ -149,7 +152,7 @@ if (Yii::$app->user->isGuest === false) {
149152
}
150153
```
151154

152-
### Dependency injection
155+
#### Dependency injection
153156

154157
```php
155158
$container = new Container();

docs/configuration.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ parameters:
6060

6161
```php
6262
<?php
63+
64+
declare(strict_types=1);
65+
6366
// config/phpstan-config.php
6467
return [
6568
'phpstan' => [
@@ -75,6 +78,9 @@ For console applications, you **must** explicitly specify the application type.
7578

7679
```php
7780
<?php
81+
82+
declare(strict_types=1);
83+
7884
// config/phpstan-console-config.php
7985
return [
8086
'phpstan' => [
@@ -150,6 +156,9 @@ Define your application components for proper type inference:
150156

151157
```php
152158
<?php
159+
160+
declare(strict_types=1);
161+
153162
// config/phpstan-config.php
154163
return [
155164
'components' => [
@@ -203,6 +212,9 @@ Configure behaviors for proper method and property reflection.
203212

204213
```php
205214
<?php
215+
216+
declare(strict_types=1);
217+
206218
return [
207219
'behaviors' => [
208220
\app\models\User::class => [
@@ -224,6 +236,8 @@ For accurate type inference, behaviors should define their properties using PHPD
224236
```php
225237
<?php
226238

239+
declare(strict_types=1);
240+
227241
use yii\base\Behavior;
228242
use yii\db\ActiveRecord;
229243

@@ -245,6 +259,9 @@ Define DI container services.
245259

246260
```php
247261
<?php
262+
263+
declare(strict_types=1);
264+
248265
return [
249266
'container' => [
250267
'definitions' => [
@@ -345,9 +362,10 @@ Optimized bootstrap file.
345362

346363
```php
347364
<?php
348-
// config/phpstan-bootstrap.php
365+
349366
declare(strict_types=1);
350367

368+
// config/phpstan-bootstrap.php
351369
error_reporting(-1);
352370

353371
// Define constants without a full application bootstrap
@@ -437,7 +455,6 @@ vendor/bin/phpstan analyse -c phpstan-console.neon
437455
### File-Level suppression
438456

439457
```php
440-
<?php
441458
// In your PHP files
442459
/** @phpstan-ignore-next-line */
443460
$result = $someObject->unknownMethod();
@@ -464,3 +481,4 @@ vendor/bin/phpstan analyse --generate-baseline
464481
## Next steps
465482

466483
- 💡 [Usage Examples](examples.md)
484+
- 🧪 [Testing Guide](testing.md)

docs/examples.md

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ analysis in real-world scenarios.
1010
```php
1111
<?php
1212

13+
declare(strict_types=1);
14+
1315
use app\models\User;
1416
use yii\db\ActiveRecord;
1517

@@ -53,6 +55,8 @@ class UserService
5355
```php
5456
<?php
5557

58+
declare(strict_types=1);
59+
5660
use app\models\{User, Post};
5761
use yii\db\ActiveQuery;
5862

@@ -102,6 +106,8 @@ class PostRepository
102106
```php
103107
<?php
104108

109+
declare(strict_types=1);
110+
105111
use app\models\{User, Post, Category};
106112

107113
class UserModel extends \yii\db\ActiveRecord
@@ -161,6 +167,8 @@ class PostService
161167
```php
162168
<?php
163169

170+
declare(strict_types=1);
171+
164172
use yii\db\ActiveQuery;
165173

166174
class PostQuery extends ActiveQuery
@@ -224,9 +232,11 @@ class PostController
224232
```php
225233
<?php
226234

235+
declare(strict_types=1);
236+
227237
use Yii;
228-
use yii\web\Controller;
229238
use yii\mail\MessageInterface;
239+
use yii\web\Controller;
230240

231241
class SiteController extends Controller
232242
{
@@ -283,8 +293,10 @@ class SiteController extends Controller
283293
```php
284294
<?php
285295

286-
use Yii;
296+
declare(strict_types=1);
297+
287298
use app\models\User;
299+
use Yii;
288300

289301
class UserService
290302
{
@@ -338,6 +350,8 @@ class UserService
338350
```php
339351
<?php
340352

353+
declare(strict_types=1);
354+
341355
// Component configuration in config/phpstan.php
342356
return [
343357
'components' => [
@@ -399,8 +413,10 @@ class PaymentController extends Controller
399413
```php
400414
<?php
401415

402-
use yii\di\Container;
416+
declare(strict_types=1);
417+
403418
use app\services\{PaymentService, EmailService, CacheService};
419+
use yii\di\Container;
404420

405421
class ServiceManager
406422
{
@@ -442,8 +458,10 @@ class ServiceManager
442458

443459
```php
444460
<?php
445-
// config/phpstan.php - Container configuration
446461

462+
declare(strict_types=1);
463+
464+
// config/phpstan.php - Container configuration
447465
return [
448466
'container' => [
449467
'definitions' => [
@@ -510,6 +528,8 @@ class ApplicationService
510528
```php
511529
<?php
512530

531+
declare(strict_types=1);
532+
513533
use yii\di\Container;
514534

515535
class ServiceFactory
@@ -557,6 +577,8 @@ class ServiceFactory
557577
```php
558578
<?php
559579

580+
declare(strict_types=1);
581+
560582
use yii\behaviors\Behavior;
561583
use yii\db\ActiveRecord;
562584

@@ -626,6 +648,8 @@ class CategoryService
626648
```php
627649
<?php
628650

651+
declare(strict_types=1);
652+
629653
// Configuration in config/phpstan.php
630654
return [
631655
'behaviors' => [
@@ -721,6 +745,8 @@ class PostService
721745
```php
722746
<?php
723747

748+
declare(strict_types=1);
749+
724750
use yii\web\HeaderCollection;
725751

726752
class ApiController extends \yii\web\Controller

docs/installation.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,10 @@ Create a simple test file to verify type inference is working.
191191

192192
```php
193193
<?php
194-
// test-phpstan.php
195194

195+
declare(strict_types=1);
196+
197+
// test-phpstan.php
196198
use yii\web\Application;
197199

198200
// This should be typed as an Application
@@ -211,11 +213,11 @@ vendor/bin/phpstan analyse test-phpstan.php --level=5
211213

212214
## Bootstrap configuration
213215

214-
If your application requires custom bootstrap logic, create a bootstrap file.
216+
If your application requires custom bootstrap logic, create a bootstrap file (for example, `tests/bootstrap.php`).
215217

216218
```php
217219
<?php
218-
// tests/bootstrap.php
220+
219221
declare(strict_types=1);
220222

221223
error_reporting(-1);

0 commit comments

Comments
 (0)