File tree Expand file tree Collapse file tree 3 files changed +31
-10
lines changed Expand file tree Collapse file tree 3 files changed +31
-10
lines changed Original file line number Diff line number Diff line change @@ -135,7 +135,7 @@ $person = new Person();
135135
136136## MustUseResult
137137
138- Add #[ MustUseResult] attribute that can be used on methods. This enforces the result from the method call must be used.
138+ A ` #[MustUseResult] ` attribute can be used on methods. This enforces the result from the method call must be used.
139139
140140E.g. if you have a class like this:
141141
@@ -158,7 +158,7 @@ You might misuse the `add` method in this way:
158158
159159``` php
160160$cost = new Money(5);
161- $cost->add(6); // ERROR - This statement has no effect.
161+ $cost->add(6); // ERROR - The call to the add method has no effect.
162162```
163163
164164But this would be OK:
Original file line number Diff line number Diff line change 11<?php
22
3- namespace TestTagOnConstructor ;
3+ namespace TestTagOnClass ;
44
55use DaveLiddament \PhpLanguageExtensions \TestTag ;
66
@@ -11,9 +11,16 @@ public function __construct()
1111 {
1212 }
1313
14- public static function create (): Person // No Error , class can interact with itself
14+ public static function create (): Person // OK , class can interact with itself
1515 {
16- return new Person (); // No Error, class can interact with itself
16+ return new Person (); // OK, class can interact with itself
17+ }
18+
19+ public function aMethod (int $ number ): void
20+ {
21+ if ($ number > 0 ) {
22+ $ this ->aMethod ($ number - 1 ); // OK, class can interact with itself
23+ }
1724 }
1825}
1926
@@ -28,4 +35,9 @@ public function buildPerson(): Person
2835 {
2936 return Person::create (); // ERROR
3037 }
38+
39+ public function aMethod (Person $ person ): void
40+ {
41+ $ person ->aMethod (1 ); // ERROR
42+ }
3143}
Original file line number Diff line number Diff line change 11<?php
22
3- namespace TestTagOnConstructor ;
3+ namespace TestTagOnClassIgnoredInTestClass ;
44
55use DaveLiddament \PhpLanguageExtensions \TestTag ;
66
@@ -11,21 +11,30 @@ public function __construct()
1111 {
1212 }
1313
14- public static function create (): Person // No Error, class can interact with itself
14+ public static function create (): Person // OK, class can interact with itself
15+ {
16+ return new Person (); // OK, class can interact with itself
17+ }
18+
19+ public function aMethod (): void
1520 {
16- return new Person (); // No Error, class can interact with itself
1721 }
1822}
1923
2024class PersonTest
2125{
2226 public function newInstance (): Person
2327 {
24- return new Person (); // No Error
28+ return new Person (); // OK, call from test class
2529 }
2630
2731 public function buildPerson (): Person
2832 {
29- return Person::create (); // No error
33+ return Person::create (); // OK, call from test class
34+ }
35+
36+ public function aMethod (Person $ person ): void
37+ {
38+ $ this ->aMethod (); // OK, call from test class
3039 }
3140}
You can’t perform that action at this time.
0 commit comments