Skip to content

Commit 1053dae

Browse files
authored
tests: use namespaces in code samples (#23)
1 parent 365e87c commit 1053dae

File tree

15 files changed

+82
-27
lines changed

15 files changed

+82
-27
lines changed

tests/Rule/data/AllowComparingOnlyComparableTypesRule/code.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
<?php declare(strict_types = 1);
22

3+
namespace AllowComparingOnlyComparableTypesRule;
4+
5+
use DateTime;
6+
use DateTimeImmutable;
7+
38
interface Foo {}
49
interface Bar {}
510

@@ -21,20 +26,20 @@ interface Bar {}
2126
float $float,
2227
bool $bool,
2328
) {
24-
$foos > $foo; // error: Comparison array > Foo contains non-comparable type, only int|float|string|DateTimeInterface is allowed.
29+
$foos > $foo; // error: Comparison array > AllowComparingOnlyComparableTypesRule\Foo contains non-comparable type, only int|float|string|DateTimeInterface is allowed.
2530
$nullableInt > $int; // error: Comparison int|null > int contains non-comparable type, only int|float|string|DateTimeInterface is allowed.
2631
null > $int; // error: Comparison null > int contains non-comparable type, only int|float|string|DateTimeInterface is allowed.
27-
$foo > $foo2; // error: Comparison Foo > Foo contains non-comparable type, only int|float|string|DateTimeInterface is allowed.
28-
$foo > $fooOrBar; // error: Comparison Foo > Bar|Foo contains non-comparable type, only int|float|string|DateTimeInterface is allowed.
29-
$foo > $fooAndBar; // error: Comparison Foo > Bar&Foo contains non-comparable type, only int|float|string|DateTimeInterface is allowed.
32+
$foo > $foo2; // error: Comparison AllowComparingOnlyComparableTypesRule\Foo > AllowComparingOnlyComparableTypesRule\Foo contains non-comparable type, only int|float|string|DateTimeInterface is allowed.
33+
$foo > $fooOrBar; // error: Comparison AllowComparingOnlyComparableTypesRule\Foo > AllowComparingOnlyComparableTypesRule\Bar|AllowComparingOnlyComparableTypesRule\Foo contains non-comparable type, only int|float|string|DateTimeInterface is allowed.
34+
$foo > $fooAndBar; // error: Comparison AllowComparingOnlyComparableTypesRule\Foo > AllowComparingOnlyComparableTypesRule\Bar&AllowComparingOnlyComparableTypesRule\Foo contains non-comparable type, only int|float|string|DateTimeInterface is allowed.
3035
$string > 'foo';
3136
$int > 2;
3237
$float > 2;
3338
$int > $intOrFloat;
3439
$string > $intOrFloat; // error: Cannot compare different types in string > float|int.
3540
$bool > true; // error: Comparison bool > true contains non-comparable type, only int|float|string|DateTimeInterface is allowed.
3641
$dateTime > $dateTimeImmutable;
37-
$dateTime > $foo; // error: Comparison DateTime > Foo contains non-comparable type, only int|float|string|DateTimeInterface is allowed.
42+
$dateTime > $foo; // error: Comparison DateTime > AllowComparingOnlyComparableTypesRule\Foo contains non-comparable type, only int|float|string|DateTimeInterface is allowed.
3843

3944
$string > $int; // error: Cannot compare different types in string > int.
4045
$float > $int;

tests/Rule/data/AllowNamedArgumentOnlyInAttributesRule/code.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
<?php declare(strict_types = 1);
22

3+
namespace AllowNamedArgumentOnlyInAttributesRule;
34

4-
#[\Attribute(flags: \Attribute::TARGET_ALL)]
5+
use Attribute;
6+
7+
#[Attribute(flags: Attribute::TARGET_ALL)]
58
class UniversalAttribute
69
{
710
public function __construct(int $argument)

tests/Rule/data/BackedEnumGenericsRule/code.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<?php
22

3+
namespace BackedEnumGenericsRule;
4+
5+
use BackedEnum;
6+
37
/**
48
* @implements BackedEnum<string>
59
*/
@@ -19,7 +23,7 @@ interface MyBackedEnum extends BackedEnum {
1923

2024
}
2125

22-
enum MyIntEnumWithoutImplements: int { // error: Class MyIntEnumWithoutImplements extends generic BackedEnum, but does not specify its type. Use @implements BackedEnum<int>
26+
enum MyIntEnumWithoutImplements: int { // error: Class BackedEnumGenericsRule\MyIntEnumWithoutImplements extends generic BackedEnum, but does not specify its type. Use @implements BackedEnum<int>
2327
}
2428

2529
enum MyIntEnumWithImplementsInParent: int implements MyBackedEnum {

tests/Rule/data/ForbidEnumInFunctionArgumentsRule/code.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php declare(strict_types = 1);
22

3+
namespace ForbidEnumInFunctionArgumentsRule;
4+
35
enum SomeEnum: string {
46
case Bar = 'bar';
57
case Baz = 'baz';

tests/Rule/data/ForbidFetchOnMixedRuleTest/code.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<?php
22

3+
namespace ForbidFetchOnMixedRuleTest;
4+
5+
use ReflectionClass;
6+
37
$fn = function (mixed $mixed, $unknown, array $array, ReflectionClass $reflection) {
48
$mixed->fetch1; // error: Property fetch ->fetch1 is prohibited on unknown type ($mixed)
59
$unknown->fetch2; // error: Property fetch ->fetch2 is prohibited on unknown type ($unknown)

tests/Rule/data/ForbidMatchDefaultArmForEnumsRule/code.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php declare(strict_types = 1);
22

3+
namespace ForbidMatchDefaultArmForEnumsRule;
4+
35
enum MyEnum: string {
46
case MyCase1 = 'MyCase1';
57
case MyCase2 = 'MyCase2';

tests/Rule/data/ForbidMethodCallOnMixedRule/code.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<?php
22

3+
namespace ForbidMethodCallOnMixedRule;
4+
5+
use ReflectionClass;
6+
37
$fn = function (mixed $mixed, $unknown, array $array, ReflectionClass $reflection) {
48
$mixed->call1(); // error: Method call ->call1() is prohibited on unknown type ($mixed)
59
$unknown->call2(); // error: Method call ->call2() is prohibited on unknown type ($unknown)

tests/Rule/data/ForbidReturnInConstructorRule/code.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php declare(strict_types = 1);
22

3+
namespace ForbidReturnInConstructorRule;
4+
35
class WithReturn {
46

57
public function __construct()

tests/Rule/data/ForbidUnsetClassFieldRule/code.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
namespace ForbidUnsetClassFieldRule;
4+
35
class Clazz {
46

57
public ?int $foo;

tests/Rule/data/ForbidUnusedExceptionRule/code.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
11
<?php declare(strict_types = 1);
22

3+
namespace ForbidUnusedExceptionRule;
4+
5+
use Exception;
6+
use LogicException;
7+
use RuntimeException;
8+
use Throwable;
9+
310
class ExampleClass
411
{
512

613
public function __construct()
714
{
815
$this->getExceptionAtRuntime(); // error: Method $this->getExceptionAtRuntime() returns exception that was not used in any way.
916
$this->getException(); // error: Method $this->getException() returns exception that was not used in any way.
10-
new \Exception(); // error: Exception new \Exception() was not used in any way.
17+
new Exception(); // error: Exception new \Exception() was not used in any way.
1118

1219
$this->okUsage1();
1320
$this->okUsage2();
1421
$this->okUsage3();
15-
$this->okUsage4(new \LogicException());
22+
$this->okUsage4(new LogicException());
1623
}
1724

1825
public function okUsage1(): void
1926
{
20-
throw new \LogicException();
27+
throw new LogicException();
2128
}
2229

2330
public function okUsage2(): void
@@ -35,14 +42,14 @@ public function okUsage4(Throwable $throwable): void
3542
$this->okUsage4($throwable);
3643
}
3744

38-
public function getExceptionAtRuntime(): \RuntimeException
45+
public function getExceptionAtRuntime(): RuntimeException
3946
{
40-
return new \RuntimeException();
47+
return new RuntimeException();
4148
}
4249

43-
public static function getException(): \RuntimeException
50+
public static function getException(): RuntimeException
4451
{
45-
return new \RuntimeException();
52+
return new RuntimeException();
4653
}
4754

4855
}

0 commit comments

Comments
 (0)