-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
31eac4f
commit 9876dee
Showing
10 changed files
with
219 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PHPStanExtension; | ||
|
||
class ImpureAttributeTest extends BaseAttributeTestCase | ||
{ | ||
public function testMethodImpureAttribute(): void | ||
{ | ||
$errors = $this->analyse(__DIR__ . '/data/Impure/MethodImpureAttribute.php'); | ||
$this->assertCount(0, $errors); | ||
} | ||
|
||
public function testFunctionImpureAttribute(): void | ||
{ | ||
$errors = $this->analyse(__DIR__ . '/data/Impure/FunctionImpureAttribute.php'); | ||
$this->assertCount(0, $errors); | ||
} | ||
|
||
public function testInvalidMethodImpureAttribute(): void | ||
{ | ||
$errors = $this->analyse(__DIR__ . '/data/Impure/InvalidMethodImpureAttribute.php'); | ||
|
||
$expectedErrors = [ | ||
'Attribute class PhpStaticAnalysis\Attributes\Impure does not have the property target.' => 11, | ||
'Attribute class PhpStaticAnalysis\Attributes\Impure is not repeatable but is already present above the method.' => 15, | ||
]; | ||
|
||
$this->checkExpectedErrors($errors, $expectedErrors); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PHPStanExtension; | ||
|
||
class PureAttributeTest extends BaseAttributeTestCase | ||
{ | ||
public function testMethodPureAttribute(): void | ||
{ | ||
$errors = $this->analyse(__DIR__ . '/data/Pure/MethodPureAttribute.php'); | ||
$this->assertCount(0, $errors); | ||
} | ||
|
||
public function testFunctionPureAttribute(): void | ||
{ | ||
$errors = $this->analyse(__DIR__ . '/data/Pure/FunctionPureAttribute.php'); | ||
$this->assertCount(0, $errors); | ||
} | ||
|
||
public function testInvalidMethodPureAttribute(): void | ||
{ | ||
$errors = $this->analyse(__DIR__ . '/data/Pure/InvalidMethodPureAttribute.php'); | ||
|
||
$expectedErrors = [ | ||
'Attribute class PhpStaticAnalysis\Attributes\Pure does not have the property target.' => 11, | ||
'Attribute class PhpStaticAnalysis\Attributes\Pure is not repeatable but is already present above the method.' => 15, | ||
]; | ||
|
||
$this->checkExpectedErrors($errors, $expectedErrors); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PHPStanExtension\data; | ||
|
||
use PhpStaticAnalysis\Attributes\Impure; | ||
|
||
$i = 0; | ||
|
||
#[Impure] | ||
function add(int $left): int | ||
{ | ||
global $i; | ||
|
||
$i += $left; | ||
return $i; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PHPStanExtension\data\Impure; | ||
|
||
use PhpStaticAnalysis\Attributes\Impure; | ||
use PhpStaticAnalysis\Attributes\Param; | ||
use PhpStaticAnalysis\Attributes\Returns; | ||
|
||
class InvalidMethodImpureAttribute | ||
{ | ||
#[Impure] | ||
public string $name = ''; | ||
|
||
#[Impure] | ||
#[Impure] | ||
public function getMoreName(): void | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PHPStanExtension\data\Impure; | ||
|
||
use PhpStaticAnalysis\Attributes\Impure; | ||
|
||
class MethodImpureAttribute | ||
{ | ||
public static int $i = 0; | ||
|
||
#[Impure] | ||
public static function add(int $left): int | ||
{ | ||
self::$i += $left; | ||
return self::$i; | ||
} | ||
|
||
/** | ||
* @codeCoverageIgnore | ||
*/ | ||
#[Impure] | ||
public function addAnother(int $left): int | ||
{ | ||
self::$i += $left; | ||
return self::$i; | ||
} | ||
|
||
/** | ||
* @impure | ||
*/ | ||
public function addMore(int $left): int | ||
{ | ||
self::$i += $left; | ||
return self::$i; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PHPStanExtension\data; | ||
|
||
use PhpStaticAnalysis\Attributes\Pure; | ||
|
||
#[Pure] | ||
function add(int $left, int $right): int | ||
{ | ||
return $left + $right; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PHPStanExtension\data\Pure; | ||
|
||
use PhpStaticAnalysis\Attributes\Param; | ||
use PhpStaticAnalysis\Attributes\Pure; | ||
use PhpStaticAnalysis\Attributes\Returns; | ||
|
||
class InvalidMethodPureAttribute | ||
{ | ||
#[Pure] | ||
public string $name = ''; | ||
|
||
#[Pure] | ||
#[Pure] | ||
public function getMoreName(): void | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PHPStanExtension\data\Pure; | ||
|
||
use PhpStaticAnalysis\Attributes\Pure; | ||
|
||
class MethodPureAttribute | ||
{ | ||
#[Pure] | ||
public function add(int $left, int $right): int | ||
{ | ||
return $left + $right; | ||
} | ||
|
||
/** | ||
* @codeCoverageIgnore | ||
*/ | ||
#[Pure] | ||
public function addAnother(int $left, int $right): int | ||
{ | ||
return $left + $right; | ||
} | ||
|
||
/** | ||
* @pure | ||
*/ | ||
public function addMore(int $left, int $right): int | ||
{ | ||
return $left + $right; | ||
} | ||
} |