Skip to content

Commit b64b35e

Browse files
Merge pull request #34 from DaveLiddament/fix/examples
FIX README and TestTag examples
2 parents 17ff755 + 2128043 commit b64b35e

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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

140140
E.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

164164
But this would be OK:

examples/testTag/testTagOnClass.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace TestTagOnConstructor;
3+
namespace TestTagOnClass;
44

55
use 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
}
Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace TestTagOnConstructor;
3+
namespace TestTagOnClassIgnoredInTestClass;
44

55
use 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

2024
class 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
}

0 commit comments

Comments
 (0)