Skip to content

Adopt PSR-12 for return types #163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Doctrine/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@
<!-- Require space around colon in return types -->
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHintSpacing">
<properties>
<property name="spacesCountBeforeColon" value="1"/>
<property name="spacesCountBeforeColon" value="0"/>
</properties>
</rule>
<!-- Require types to be written as natively if possible;
Expand Down
16 changes: 8 additions & 8 deletions tests/fixed/ControlStructures.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ControlStructures
/**
* @return iterable<int>
*/
public function varAndIfNoSpaceBetween() : iterable
public function varAndIfNoSpaceBetween(): iterable
{
$var = 1;
if (self::VERSION === 0) {
Expand All @@ -26,7 +26,7 @@ public function varAndIfNoSpaceBetween() : iterable
/**
* @return iterable<int>
*/
public function ifAndYieldSpaceBetween() : iterable
public function ifAndYieldSpaceBetween(): iterable
{
if (self::VERSION === 0) {
yield 0;
Expand All @@ -38,7 +38,7 @@ public function ifAndYieldSpaceBetween() : iterable
/**
* @return iterable<int>
*/
public function ifAndYieldFromSpaceBetween() : iterable
public function ifAndYieldFromSpaceBetween(): iterable
{
if (self::VERSION === 0) {
yield 0;
Expand All @@ -47,7 +47,7 @@ public function ifAndYieldFromSpaceBetween() : iterable
yield from [];
}

public function ifAndThrowSpaceBetween() : void
public function ifAndThrowSpaceBetween(): void
{
if (self::VERSION === 0) {
return;
Expand All @@ -56,7 +56,7 @@ public function ifAndThrowSpaceBetween() : void
throw new InvalidArgumentException();
}

public function ifAndReturnSpaceBetween() : int
public function ifAndReturnSpaceBetween(): int
{
if (self::VERSION === 0) {
return 0;
Expand All @@ -65,7 +65,7 @@ public function ifAndReturnSpaceBetween() : int
return 1;
}

public function noSpaceAroundCase() : void
public function noSpaceAroundCase(): void
{
switch (self::VERSION) {
case 1:
Expand All @@ -79,7 +79,7 @@ public function noSpaceAroundCase() : void
}
}

public function spaceBelowBlocks() : void
public function spaceBelowBlocks(): void
{
if (true) {
echo 1;
Expand Down Expand Up @@ -113,7 +113,7 @@ public function spaceBelowBlocks() : void
echo 5;
}

public function spaceAroundMultilineIfs() : void
public function spaceAroundMultilineIfs(): void
{
if (
true
Expand Down
8 changes: 4 additions & 4 deletions tests/fixed/EarlyReturn.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

class EarlyReturn
{
public function bar() : bool
public function bar(): bool
{
return $bar === 'bar';
}

public function foo() : ?string
public function foo(): ?string
{
foreach ($itens as $item) {
if (! $item->isItem()) {
Expand All @@ -24,7 +24,7 @@ public function foo() : ?string
return null;
}

public function baz() : string
public function baz(): string
{
if ($number > 0) {
return 'Number is grater then 0';
Expand All @@ -33,7 +33,7 @@ public function baz() : string
exit;
}

public function quoox() : bool
public function quoox(): bool
{
if (true !== 'true') {
return false;
Expand Down
4 changes: 2 additions & 2 deletions tests/fixed/LowCaseTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

class LowCaseTypes
{
public function stringToInt(string $string) : int
public function stringToInt(string $string): int
{
return (int) $string;
}

public function returnString() : string
public function returnString(): string
{
return 'foo';
}
Expand Down
2 changes: 1 addition & 1 deletion tests/fixed/NamingCamelCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class NamingCamelCase
/** @var mixed */
private $C;

public function fcn(string $A) : void
public function fcn(string $A): void
{
$Test = $A;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/fixed/UnusedVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

class UnusedVariables
{
public function unusedInheritedVariablePassedToClosure() : void
public function unusedInheritedVariablePassedToClosure(): void
{
$foo = 'foo';

$bar = static function () : int {
$bar = static function (): int {
return 1;
};
}
Expand Down
36 changes: 18 additions & 18 deletions tests/fixed/UselessConditions.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@

class UselessConditions
{
public function uselessCondition() : bool
public function uselessCondition(): bool
{
return $foo === 'foo';
}

public function uselessIfCondition() : bool
public function uselessIfCondition(): bool
{
return $bar === 'bar';
}

public function uselessNegativeCondition() : bool
public function uselessNegativeCondition(): bool
{
return $foo === 'foo';
}

public function uselessIfNegativeCondition() : bool
public function uselessIfNegativeCondition(): bool
{
return $bar !== 'bar';
}

public function unecessaryIfMethodForEarlyReturn() : bool
public function unecessaryIfMethodForEarlyReturn(): bool
{
if ($bar === 'bar') {
return false;
Expand All @@ -42,7 +42,7 @@ public function unecessaryIfMethodForEarlyReturn() : bool
return $baz !== 'baz';
}

public function uselessIfConditionWithParameter(bool $bool) : bool
public function uselessIfConditionWithParameter(bool $bool): bool
{
if ($bool) {
return false;
Expand All @@ -51,7 +51,7 @@ public function uselessIfConditionWithParameter(bool $bool) : bool
return true;
}

public function uselessIfConditionWithBoolMethod() : bool
public function uselessIfConditionWithBoolMethod(): bool
{
if ($this->isTrue()) {
return false;
Expand All @@ -60,22 +60,22 @@ public function uselessIfConditionWithBoolMethod() : bool
return true;
}

public function uselessIfConditionWithComplexIf() : bool
public function uselessIfConditionWithComplexIf(): bool
{
return $bar === 'bar' && $foo === 'foo' && $baz !== 'quox';
}

public function uselessIfConditionWithEvenMoreComplexIf() : bool
public function uselessIfConditionWithEvenMoreComplexIf(): bool
{
return $bar === 'bar' || $foo === 'foo' || $baz !== 'quox';
}

public function uselessIfConditionWithComplexCondition() : bool
public function uselessIfConditionWithComplexCondition(): bool
{
return $bar !== 'bar' && $foo !== 'foo' && $baz === 'quox';
}

public function uselessIfConditionWithTernary() : bool
public function uselessIfConditionWithTernary(): bool
{
if ($this->isTrue()) {
return $this->isTrulyTrue() ? true : false;
Expand All @@ -84,7 +84,7 @@ public function uselessIfConditionWithTernary() : bool
return false;
}

public function necessaryIfConditionWithMethodCall() : bool
public function necessaryIfConditionWithMethodCall(): bool
{
if ($this->shouldBeQueued()) {
$this->queue();
Expand All @@ -95,7 +95,7 @@ public function necessaryIfConditionWithMethodCall() : bool
return false;
}

public function nullShouldNotBeTreatedAsFalse() : ?bool
public function nullShouldNotBeTreatedAsFalse(): ?bool
{
if (! $this->isAdmin) {
return null;
Expand All @@ -104,30 +104,30 @@ public function nullShouldNotBeTreatedAsFalse() : ?bool
return true;
}

public function uselessTernary() : bool
public function uselessTernary(): bool
{
return $foo !== 'bar';
}

public function uselessTernaryWithParameter(bool $condition) : bool
public function uselessTernaryWithParameter(bool $condition): bool
{
return $condition ? true : false;
}

public function uselessTernaryWithMethod() : bool
public function uselessTernaryWithMethod(): bool
{
return $this->isFalse() ? true : false;
}

/**
* @param string[] $words
*/
public function uselessTernaryCheck(array $words) : bool
public function uselessTernaryCheck(array $words): bool
{
return count($words) < 1;
}

public function necessaryTernary() : int
public function necessaryTernary(): int
{
return strpos('foo', 'This is foo and bar') !== false ? 1 : 0;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/fixed/class-references.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Bar extends Foo
/**
* @return string[]
*/
public function names() : iterable
public function names(): iterable
{
yield self::class;
yield self::class;
Expand Down
8 changes: 4 additions & 4 deletions tests/fixed/doc-comment-spacing.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Test
/**
* Description
*/
public function a() : void
public function a(): void
{
}

Expand All @@ -21,7 +21,7 @@ public function a() : void
* More Description
* Even More Description
*/
public function b() : void
public function b(): void
{
}

Expand All @@ -34,7 +34,7 @@ public function b() : void
*
* @throws FooException
*/
public function c(iterable $foo) : void
public function c(iterable $foo): void
{
}

Expand Down Expand Up @@ -64,7 +64,7 @@ public function c(iterable $foo) : void
* @throws FooException
* @throws BarException
*/
public function d(iterable $foo, iterable $bar) : iterable
public function d(iterable $foo, iterable $bar): iterable
{
}
}
12 changes: 6 additions & 6 deletions tests/fixed/example-class.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,22 @@ public function __construct(?int $foo = null, array $bar = [], bool $baz = false
/**
* Description
*/
public function getFoo() : ?int
public function getFoo(): ?int
{
return $this->foo;
}

/**
* @return iterable
*/
public function getIterator() : array
public function getIterator(): array
{
assert($this->bar !== null);

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

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

Expand All @@ -71,7 +71,7 @@ public function isBaz() : bool
/**
* @throws InvalidArgumentException if this example cannot baz.
*/
public function mangleBar(int $length) : void
public function mangleBar(int $length): void
{
if (! $this->baz) {
throw new InvalidArgumentException();
Expand All @@ -80,12 +80,12 @@ public function mangleBar(int $length) : void
$this->bar = (string) $this->baxBax ?? substr($this->bar, stringLength($this->bar - $length));
}

public static function getMinorVersion() : int
public static function getMinorVersion(): int
{
return self::VERSION;
}

public static function getTestCase() : TestCase
public static function getTestCase(): TestCase
{
return new TestCase();
}
Expand Down
4 changes: 2 additions & 2 deletions tests/fixed/forbidden-comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ public function __construct()
echo 'Hello';
}

public function getBar() : int
public function getBar(): int
{
return 123;
}

/**
* Very important getter.
*/
public function getBaz() : int
public function getBaz(): int
{
return 456;
}
Expand Down
Loading