Skip to content
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

Extra test scenarios #208

Draft
wants to merge 6 commits into
base: 8.2.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/fixed/array_indentation.php
Expand Up @@ -3,7 +3,7 @@
declare(strict_types=1);

$array = [
0,
0, // this is the first index
1,
2,
3,
Expand Down
37 changes: 36 additions & 1 deletion tests/fixed/doc-comment-spacing.php
Expand Up @@ -46,7 +46,8 @@ public function c(iterable $foo): void
* @deprecated
*
* @link https://example.com
* @see other
* @see Something else and make this see annotation
* multiline
gmponos marked this conversation as resolved.
Show resolved Hide resolved
* @uses other
*
* @ORM\Id
Expand All @@ -67,4 +68,38 @@ public function c(iterable $foo): void
public function d(iterable $foo, iterable $bar): iterable
{
}

/**
* Description
* More Description
*
* @internal
* @deprecated
*
* @link https://example.com
* @see other
* @uses other
*
* @ORM\Id
* @ORM\Column
* @ODM\Id
* @ODM\Column
* @PHPCR\Uuid
* @PHPCR\Field
*
* @param int[] $foo
* @param int[] $bar
*
* @return int[]
*
* @throws FooException
* @throws BarException
*
* @phpstan-param string $foo
* @psalm-param string $foo
* @phpstan-return true
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to handle these?

*/
public function f(iterable $foo, iterable $bar): iterable
{
}
}
3 changes: 3 additions & 0 deletions tests/fixed/forbidden-functions.php
Expand Up @@ -4,6 +4,7 @@

namespace Test;

use function array_map;
use function chop;
use function compact;
use function extract;
Expand All @@ -28,3 +29,5 @@
extract($bar);

compact('foo', 'bar');

array_map('is_null', ['1', '2', null]); // forbidden function will not be detected
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI codesniffer can not detect these.. is this fine?

1 change: 1 addition & 0 deletions tests/fixed/optimized-functions.php
Expand Up @@ -4,3 +4,4 @@

$args = [123, [123], true];
in_array(...$args);
in_array(...$args);
3 changes: 3 additions & 0 deletions tests/fixed/semicolon_spacing.php
Expand Up @@ -9,3 +9,6 @@
$qb->select()
->from()
->where();

$qb->select()
->from('mytable'); // we select from my table
4 changes: 4 additions & 0 deletions tests/fixed/superfluous-naming.php
Expand Up @@ -12,6 +12,10 @@ class FooException extends RuntimeException
{
}

class FooError extends \Error
{
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is superfluous but not reported.. i guess there is no existing rule for this

interface FooInterface
{
}
Expand Down
5 changes: 5 additions & 0 deletions tests/fixed/trailing_comma_on_array.php
Expand Up @@ -6,3 +6,8 @@
'key1' => 'value',
'key2' => 'value',
];

$arrayWithComment = [
'key1' => 'value',
'key2' => 'value', // comment
];
7 changes: 7 additions & 0 deletions tests/fixed/useless-semicolon.php
Expand Up @@ -13,3 +13,10 @@
for (;;) {
echo 'To infity and beyond';
}

for ($i = 0 ; $i < 10; $i++);
{
echo 'This will not be executed inside the for-loop';
}

$myvar = 3;;
11 changes: 11 additions & 0 deletions tests/input/UselessConditions.php
Expand Up @@ -27,6 +27,17 @@ public function uselessIfCondition(): bool
return false;
}

public function uselessIfConditionWithComment(): bool
{
if ($bar === 'bar') {
// Return true here in case $bar is bar
return true;
}

// Return true here in case $bar is bar
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return false;
}

public function uselessNegativeCondition(): bool
{
if ($foo !== 'foo') {
Expand Down
2 changes: 1 addition & 1 deletion tests/input/array_indentation.php
Expand Up @@ -3,7 +3,7 @@
declare(strict_types=1);

$array = [
0,
0, // this is the first index
1,
2,
3,
Expand Down
32 changes: 31 additions & 1 deletion tests/input/doc-comment-spacing.php
Expand Up @@ -57,10 +57,40 @@ public function c(iterable $foo): void
* @PHPCR\Field
* @ODM\Column
* @ORM\Column
* @see other
* @see Something else and make this see annotation
* multiline
*
*/
public function d(iterable $foo, iterable $bar): iterable
{
}

/**
*
* Description
* More Description
* @phpstan-param string $foo
* @psalm-param string $foo
* @phpstan-return true
* @throws FooException
* @param int[] $foo
* @uses other
* @throws BarException
* @return int[]
* @ORM\Id
* @internal
* @link https://example.com
* @ODM\Id
* @deprecated
* @PHPCR\Uuid
* @param int[] $bar
* @PHPCR\Field
* @ODM\Column
* @ORM\Column
* @see other
*
*/
public function f(iterable $foo, iterable $bar): iterable
{
}
}
2 changes: 2 additions & 0 deletions tests/input/forbidden-functions.php
Expand Up @@ -28,3 +28,5 @@
extract($bar);

compact('foo', 'bar');

array_map('is_null', ['1', '2', null]); // forbidden function will not be detected
1 change: 1 addition & 0 deletions tests/input/optimized-functions.php
Expand Up @@ -4,3 +4,4 @@

$args = [123, [123], true];
in_array(...$args);
\in_array(...$args);
4 changes: 4 additions & 0 deletions tests/input/semicolon_spacing.php
Expand Up @@ -11,3 +11,7 @@
->from()
->where()
;

$qb->select()
->from('mytable') // we select from my table
;
4 changes: 4 additions & 0 deletions tests/input/superfluous-naming.php
Expand Up @@ -12,6 +12,10 @@ class FooException extends RuntimeException
{
}

class FooError extends \Error
{
}

interface FooInterface
{
}
Expand Down
5 changes: 5 additions & 0 deletions tests/input/trailing_comma_on_array.php
Expand Up @@ -6,3 +6,8 @@
'key1' => 'value',
'key2' => 'value'
];

$arrayWithComment = [
'key1' => 'value',
'key2' => 'value' // comment
];
7 changes: 7 additions & 0 deletions tests/input/useless-semicolon.php
Expand Up @@ -13,3 +13,10 @@
for (;;) {
echo 'To infity and beyond';
};

for ($i = 0 ; $i < 10; $i++);
{
echo 'This will not be executed inside the for-loop';
};

$myvar = 3;;