-
-
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.
Add the PropertyRead and PropertyWrite attributes
- Loading branch information
1 parent
bc532d5
commit e572de8
Showing
32 changed files
with
202 additions
and
47 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
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,28 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PHPStanExtension; | ||
|
||
class PropertyReadAttributeTest extends BaseAttributeTestCase | ||
{ | ||
public function testClassPropertyReadAttribute(): void | ||
{ | ||
$errors = $this->analyse(__DIR__ . '/data/PropertyRead/ClassPropertyReadAttribute.php'); | ||
$this->assertCount(0, $errors); | ||
} | ||
|
||
public function testInvalidClassPropertyReadAttribute(): void | ||
{ | ||
$errors = $this->analyse(__DIR__ . '/data/PropertyRead/InvalidClassPropertyReadAttribute.php'); | ||
|
||
$expectedErrors = [ | ||
'PHPDoc tag @property-read has invalid value (): Unexpected token "\n * ", expected type at offset 21' => 7, | ||
'PHPDoc tag @property-read has invalid value (count($a) $name): Unexpected token "(", expected variable at offset 70' => 7, | ||
'PHPDoc tag @property-read has invalid value (string): Unexpected token "\n * ", expected variable at offset 46' => 7, | ||
'Parameter #1 ...$params of attribute class PhpStaticAnalysis\Attributes\PropertyRead constructor expects string, int given.' => 7, | ||
'Attribute class PhpStaticAnalysis\Attributes\PropertyRead does not have the method target.' => 13, | ||
'Property test\PhpStaticAnalysis\PHPStanExtension\data\PropertyRead\ClassPropertyReadAttribute::$age is not writable.' => 21, | ||
]; | ||
|
||
$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,28 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PHPStanExtension; | ||
|
||
class PropertyWriteAttributeTest extends BaseAttributeTestCase | ||
{ | ||
public function testClassPropertyWriteAttribute(): void | ||
{ | ||
$errors = $this->analyse(__DIR__ . '/data/PropertyWrite/ClassPropertyWriteAttribute.php'); | ||
$this->assertCount(0, $errors); | ||
} | ||
|
||
public function testInvalidClassPropertyWriteAttribute(): void | ||
{ | ||
$errors = $this->analyse(__DIR__ . '/data/PropertyWrite/InvalidClassPropertyWriteAttribute.php'); | ||
|
||
$expectedErrors = [ | ||
'PHPDoc tag @property-write has invalid value (): Unexpected token "\n * ", expected type at offset 22' => 7, | ||
'PHPDoc tag @property-write has invalid value (count($a) $name): Unexpected token "(", expected variable at offset 73' => 7, | ||
'PHPDoc tag @property-write has invalid value (string): Unexpected token "\n * ", expected variable at offset 48' => 7, | ||
'Parameter #1 ...$params of attribute class PhpStaticAnalysis\Attributes\PropertyWrite constructor expects string, int given.' => 7, | ||
'Attribute class PhpStaticAnalysis\Attributes\PropertyWrite does not have the method target.' => 13, | ||
'Property test\PhpStaticAnalysis\PHPStanExtension\data\PropertyWrite\ClassPropertyWriteAttribute::$age is not readable.' => 21, | ||
]; | ||
|
||
$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
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
2 changes: 1 addition & 1 deletion
2
...ta/InvalidPropertyIsReadOnlyAttribute.php → ...ly/InvalidPropertyIsReadOnlyAttribute.php
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
2 changes: 1 addition & 1 deletion
2
tests/data/PropertyIsReadOnlyAttribute.php → ...sReadOnly/PropertyIsReadOnlyAttribute.php
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
2 changes: 1 addition & 1 deletion
2
tests/data/FunctionParamAttribute.php → tests/data/Param/FunctionParamAttribute.php
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
2 changes: 1 addition & 1 deletion
2
tests/data/InvalidMethodParamAttribute.php → ...ata/Param/InvalidMethodParamAttribute.php
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
2 changes: 1 addition & 1 deletion
2
tests/data/MethodParamAttribute.php → tests/data/Param/MethodParamAttribute.php
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
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,24 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PHPStanExtension\data\PropertyRead; | ||
|
||
use PhpStaticAnalysis\Attributes\PropertyRead; | ||
|
||
#[PropertyRead(name: 'string')] | ||
#[PropertyRead('int $age')] | ||
#[PropertyRead( | ||
index1: 'string[]', | ||
index2: 'string[]', | ||
)] | ||
class ClassPropertyReadAttribute | ||
{ | ||
public function __get(string $name): mixed | ||
{ | ||
return $name; | ||
} | ||
} | ||
|
||
$class = new ClassPropertyReadAttribute(); | ||
$foo = $class->name; | ||
$bar = $class->age; | ||
$indexes = $class->index1 + $class->index2; |
21 changes: 21 additions & 0 deletions
21
tests/data/PropertyRead/InvalidClassPropertyReadAttribute.php
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,21 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PHPStanExtension\data\PropertyRead; | ||
|
||
use PhpStaticAnalysis\Attributes\PropertyRead; | ||
|
||
#[PropertyRead(0)] | ||
#[PropertyRead('string')] | ||
#[PropertyRead(name: 'count($a)')] | ||
#[PropertyRead(age: 'int')] | ||
class InvalidClassPropertyReadAttribute | ||
{ | ||
#[PropertyRead('string')] | ||
public function getName(): string | ||
{ | ||
return "John"; | ||
} | ||
} | ||
|
||
$class = new ClassPropertyReadAttribute(); | ||
$class->age = 7; |
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,25 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PHPStanExtension\data\PropertyWrite; | ||
|
||
use PhpStaticAnalysis\Attributes\PropertyWrite; | ||
|
||
#[PropertyWrite(name: 'string')] | ||
#[PropertyWrite('int $age')] | ||
#[PropertyWrite( | ||
index1: 'string[]', | ||
index2: 'string[]', | ||
)] | ||
class ClassPropertyWriteAttribute | ||
{ | ||
public function __set(string $name, mixed $value) | ||
{ | ||
$this->$name = $value; | ||
} | ||
} | ||
|
||
$class = new ClassPropertyWriteAttribute(); | ||
$class->name = 'John'; | ||
$class->age = 7; | ||
$class->index1 = []; | ||
$class->index2 = []; |
Oops, something went wrong.