Skip to content

Commit 7e7aff6

Browse files
authored
Merge pull request #163 from doctrine/rules/adopt-psr-12-for-return-types
Adopt PSR-12 for return types
2 parents 723f4da + cb924f4 commit 7e7aff6

33 files changed

+143
-143
lines changed

lib/Doctrine/ruleset.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@
354354
<!-- Require space around colon in return types -->
355355
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHintSpacing">
356356
<properties>
357-
<property name="spacesCountBeforeColon" value="1"/>
357+
<property name="spacesCountBeforeColon" value="0"/>
358358
</properties>
359359
</rule>
360360
<!-- Require types to be written as natively if possible;

tests/fixed/ControlStructures.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ControlStructures
1515
/**
1616
* @return iterable<int>
1717
*/
18-
public function varAndIfNoSpaceBetween() : iterable
18+
public function varAndIfNoSpaceBetween(): iterable
1919
{
2020
$var = 1;
2121
if (self::VERSION === 0) {
@@ -26,7 +26,7 @@ public function varAndIfNoSpaceBetween() : iterable
2626
/**
2727
* @return iterable<int>
2828
*/
29-
public function ifAndYieldSpaceBetween() : iterable
29+
public function ifAndYieldSpaceBetween(): iterable
3030
{
3131
if (self::VERSION === 0) {
3232
yield 0;
@@ -38,7 +38,7 @@ public function ifAndYieldSpaceBetween() : iterable
3838
/**
3939
* @return iterable<int>
4040
*/
41-
public function ifAndYieldFromSpaceBetween() : iterable
41+
public function ifAndYieldFromSpaceBetween(): iterable
4242
{
4343
if (self::VERSION === 0) {
4444
yield 0;
@@ -47,7 +47,7 @@ public function ifAndYieldFromSpaceBetween() : iterable
4747
yield from [];
4848
}
4949

50-
public function ifAndThrowSpaceBetween() : void
50+
public function ifAndThrowSpaceBetween(): void
5151
{
5252
if (self::VERSION === 0) {
5353
return;
@@ -56,7 +56,7 @@ public function ifAndThrowSpaceBetween() : void
5656
throw new InvalidArgumentException();
5757
}
5858

59-
public function ifAndReturnSpaceBetween() : int
59+
public function ifAndReturnSpaceBetween(): int
6060
{
6161
if (self::VERSION === 0) {
6262
return 0;
@@ -65,7 +65,7 @@ public function ifAndReturnSpaceBetween() : int
6565
return 1;
6666
}
6767

68-
public function noSpaceAroundCase() : void
68+
public function noSpaceAroundCase(): void
6969
{
7070
switch (self::VERSION) {
7171
case 1:
@@ -79,7 +79,7 @@ public function noSpaceAroundCase() : void
7979
}
8080
}
8181

82-
public function spaceBelowBlocks() : void
82+
public function spaceBelowBlocks(): void
8383
{
8484
if (true) {
8585
echo 1;
@@ -113,7 +113,7 @@ public function spaceBelowBlocks() : void
113113
echo 5;
114114
}
115115

116-
public function spaceAroundMultilineIfs() : void
116+
public function spaceAroundMultilineIfs(): void
117117
{
118118
if (
119119
true

tests/fixed/EarlyReturn.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
class EarlyReturn
88
{
9-
public function bar() : bool
9+
public function bar(): bool
1010
{
1111
return $bar === 'bar';
1212
}
1313

14-
public function foo() : ?string
14+
public function foo(): ?string
1515
{
1616
foreach ($itens as $item) {
1717
if (! $item->isItem()) {
@@ -24,7 +24,7 @@ public function foo() : ?string
2424
return null;
2525
}
2626

27-
public function baz() : string
27+
public function baz(): string
2828
{
2929
if ($number > 0) {
3030
return 'Number is grater then 0';
@@ -33,7 +33,7 @@ public function baz() : string
3333
exit;
3434
}
3535

36-
public function quoox() : bool
36+
public function quoox(): bool
3737
{
3838
if (true !== 'true') {
3939
return false;

tests/fixed/LowCaseTypes.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
class LowCaseTypes
88
{
9-
public function stringToInt(string $string) : int
9+
public function stringToInt(string $string): int
1010
{
1111
return (int) $string;
1212
}
1313

14-
public function returnString() : string
14+
public function returnString(): string
1515
{
1616
return 'foo';
1717
}

tests/fixed/NamingCamelCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class NamingCamelCase
1515
/** @var mixed */
1616
private $C;
1717

18-
public function fcn(string $A) : void
18+
public function fcn(string $A): void
1919
{
2020
$Test = $A;
2121
}

tests/fixed/UnusedVariables.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
class UnusedVariables
88
{
9-
public function unusedInheritedVariablePassedToClosure() : void
9+
public function unusedInheritedVariablePassedToClosure(): void
1010
{
1111
$foo = 'foo';
1212

13-
$bar = static function () : int {
13+
$bar = static function (): int {
1414
return 1;
1515
};
1616
}

tests/fixed/UselessConditions.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,27 @@
99

1010
class UselessConditions
1111
{
12-
public function uselessCondition() : bool
12+
public function uselessCondition(): bool
1313
{
1414
return $foo === 'foo';
1515
}
1616

17-
public function uselessIfCondition() : bool
17+
public function uselessIfCondition(): bool
1818
{
1919
return $bar === 'bar';
2020
}
2121

22-
public function uselessNegativeCondition() : bool
22+
public function uselessNegativeCondition(): bool
2323
{
2424
return $foo === 'foo';
2525
}
2626

27-
public function uselessIfNegativeCondition() : bool
27+
public function uselessIfNegativeCondition(): bool
2828
{
2929
return $bar !== 'bar';
3030
}
3131

32-
public function unecessaryIfMethodForEarlyReturn() : bool
32+
public function unecessaryIfMethodForEarlyReturn(): bool
3333
{
3434
if ($bar === 'bar') {
3535
return false;
@@ -42,7 +42,7 @@ public function unecessaryIfMethodForEarlyReturn() : bool
4242
return $baz !== 'baz';
4343
}
4444

45-
public function uselessIfConditionWithParameter(bool $bool) : bool
45+
public function uselessIfConditionWithParameter(bool $bool): bool
4646
{
4747
if ($bool) {
4848
return false;
@@ -51,7 +51,7 @@ public function uselessIfConditionWithParameter(bool $bool) : bool
5151
return true;
5252
}
5353

54-
public function uselessIfConditionWithBoolMethod() : bool
54+
public function uselessIfConditionWithBoolMethod(): bool
5555
{
5656
if ($this->isTrue()) {
5757
return false;
@@ -60,22 +60,22 @@ public function uselessIfConditionWithBoolMethod() : bool
6060
return true;
6161
}
6262

63-
public function uselessIfConditionWithComplexIf() : bool
63+
public function uselessIfConditionWithComplexIf(): bool
6464
{
6565
return $bar === 'bar' && $foo === 'foo' && $baz !== 'quox';
6666
}
6767

68-
public function uselessIfConditionWithEvenMoreComplexIf() : bool
68+
public function uselessIfConditionWithEvenMoreComplexIf(): bool
6969
{
7070
return $bar === 'bar' || $foo === 'foo' || $baz !== 'quox';
7171
}
7272

73-
public function uselessIfConditionWithComplexCondition() : bool
73+
public function uselessIfConditionWithComplexCondition(): bool
7474
{
7575
return $bar !== 'bar' && $foo !== 'foo' && $baz === 'quox';
7676
}
7777

78-
public function uselessIfConditionWithTernary() : bool
78+
public function uselessIfConditionWithTernary(): bool
7979
{
8080
if ($this->isTrue()) {
8181
return $this->isTrulyTrue() ? true : false;
@@ -84,7 +84,7 @@ public function uselessIfConditionWithTernary() : bool
8484
return false;
8585
}
8686

87-
public function necessaryIfConditionWithMethodCall() : bool
87+
public function necessaryIfConditionWithMethodCall(): bool
8888
{
8989
if ($this->shouldBeQueued()) {
9090
$this->queue();
@@ -95,7 +95,7 @@ public function necessaryIfConditionWithMethodCall() : bool
9595
return false;
9696
}
9797

98-
public function nullShouldNotBeTreatedAsFalse() : ?bool
98+
public function nullShouldNotBeTreatedAsFalse(): ?bool
9999
{
100100
if (! $this->isAdmin) {
101101
return null;
@@ -104,30 +104,30 @@ public function nullShouldNotBeTreatedAsFalse() : ?bool
104104
return true;
105105
}
106106

107-
public function uselessTernary() : bool
107+
public function uselessTernary(): bool
108108
{
109109
return $foo !== 'bar';
110110
}
111111

112-
public function uselessTernaryWithParameter(bool $condition) : bool
112+
public function uselessTernaryWithParameter(bool $condition): bool
113113
{
114114
return $condition ? true : false;
115115
}
116116

117-
public function uselessTernaryWithMethod() : bool
117+
public function uselessTernaryWithMethod(): bool
118118
{
119119
return $this->isFalse() ? true : false;
120120
}
121121

122122
/**
123123
* @param string[] $words
124124
*/
125-
public function uselessTernaryCheck(array $words) : bool
125+
public function uselessTernaryCheck(array $words): bool
126126
{
127127
return count($words) < 1;
128128
}
129129

130-
public function necessaryTernary() : int
130+
public function necessaryTernary(): int
131131
{
132132
return strpos('foo', 'This is foo and bar') !== false ? 1 : 0;
133133
}

tests/fixed/class-references.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Bar extends Foo
1111
/**
1212
* @return string[]
1313
*/
14-
public function names() : iterable
14+
public function names(): iterable
1515
{
1616
yield self::class;
1717
yield self::class;

tests/fixed/doc-comment-spacing.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Test
1212
/**
1313
* Description
1414
*/
15-
public function a() : void
15+
public function a(): void
1616
{
1717
}
1818

@@ -21,7 +21,7 @@ public function a() : void
2121
* More Description
2222
* Even More Description
2323
*/
24-
public function b() : void
24+
public function b(): void
2525
{
2626
}
2727

@@ -34,7 +34,7 @@ public function b() : void
3434
*
3535
* @throws FooException
3636
*/
37-
public function c(iterable $foo) : void
37+
public function c(iterable $foo): void
3838
{
3939
}
4040

@@ -64,7 +64,7 @@ public function c(iterable $foo) : void
6464
* @throws FooException
6565
* @throws BarException
6666
*/
67-
public function d(iterable $foo, iterable $bar) : iterable
67+
public function d(iterable $foo, iterable $bar): iterable
6868
{
6969
}
7070
}

tests/fixed/example-class.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,22 @@ public function __construct(?int $foo = null, array $bar = [], bool $baz = false
4646
/**
4747
* Description
4848
*/
49-
public function getFoo() : ?int
49+
public function getFoo(): ?int
5050
{
5151
return $this->foo;
5252
}
5353

5454
/**
5555
* @return iterable
5656
*/
57-
public function getIterator() : array
57+
public function getIterator(): array
5858
{
5959
assert($this->bar !== null);
6060

6161
return new ArrayIterator($this->bar);
6262
}
6363

64-
public function isBaz() : bool
64+
public function isBaz(): bool
6565
{
6666
[$foo, $bar, $baz] = $this->bar;
6767

@@ -71,7 +71,7 @@ public function isBaz() : bool
7171
/**
7272
* @throws InvalidArgumentException if this example cannot baz.
7373
*/
74-
public function mangleBar(int $length) : void
74+
public function mangleBar(int $length): void
7575
{
7676
if (! $this->baz) {
7777
throw new InvalidArgumentException();
@@ -80,12 +80,12 @@ public function mangleBar(int $length) : void
8080
$this->bar = (string) $this->baxBax ?? substr($this->bar, stringLength($this->bar - $length));
8181
}
8282

83-
public static function getMinorVersion() : int
83+
public static function getMinorVersion(): int
8484
{
8585
return self::VERSION;
8686
}
8787

88-
public static function getTestCase() : TestCase
88+
public static function getTestCase(): TestCase
8989
{
9090
return new TestCase();
9191
}

tests/fixed/forbidden-comments.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ public function __construct()
1111
echo 'Hello';
1212
}
1313

14-
public function getBar() : int
14+
public function getBar(): int
1515
{
1616
return 123;
1717
}
1818

1919
/**
2020
* Very important getter.
2121
*/
22-
public function getBaz() : int
22+
public function getBaz(): int
2323
{
2424
return 456;
2525
}

0 commit comments

Comments
 (0)