Skip to content

Commit

Permalink
Fixed Tree __set accept types
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Wright <tom@inflatablecookie.com>
  • Loading branch information
betterthanclay committed Oct 26, 2023
1 parent d046776 commit dfb6bcf
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* Fixed Tree __set accept types

## v0.6.6 (2022-11-28)
* Made lucid a dev dependency

Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"phpstan/phpstan": "^1"
},
"require-dev": {
"decodelabs/collections": "^0.8.3",
"decodelabs/exemplar": "^0.3",
"decodelabs/lucid": "^0.4",
"decodelabs/metamorph": "^0.5",
Expand Down
3 changes: 3 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
includes:
- ./extension.neon
parameters:
paths:
- src/
- tests/
level: max
10 changes: 1 addition & 9 deletions src/Collections/TreeReflectionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,10 @@ public function getProperty(
ClassReflection $classReflection,
string $propertyName
): PropertyReflectionInterface {
$t = $classReflection->getMethod('__set', new OutOfClassScope())->getVariants()[0]->getParameters()[0]->getType();

return new PropertyReflection(
$classReflection,
new ObjectType($classReflection->getName()),
new UnionType([
$t,
new IterableType(new UnionType([
new IntegerType(),
new StringType()
]), $t)
])
$classReflection->getMethod('__set', new OutOfClassScope())->getVariants()[0]->getParameters()[1]->getType()
);
}
}
2 changes: 1 addition & 1 deletion src/PropertyReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function isPublic(): bool

public function getType(): Type
{
if($this->writableType) {
if ($this->writableType) {
return new UnionType([
$this->readableType,
$this->writableType
Expand Down
16 changes: 16 additions & 0 deletions tests/Tree.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

use DecodeLabs\Collections\Tree\NativeMutable;

class TestTree
{
public function test(): void
{
/**
* @var NativeMutable<string> $tree
*/
$tree = new NativeMutable();

$tree->test = 'hello';

Check failure on line 14 in tests/Tree.php

View workflow job for this annotation

GitHub Actions / 3️⃣ Static Analysis (8.0)

Property DecodeLabs\Collections\Tree\NativeMutable<string>::$test (DecodeLabs\Collections\Tree\NativeMutable) does not accept string.

Check failure on line 14 in tests/Tree.php

View workflow job for this annotation

GitHub Actions / 3️⃣ Static Analysis (8.1)

Property DecodeLabs\Collections\Tree\NativeMutable<string>::$test (DecodeLabs\Collections\Tree\NativeMutable) does not accept string.
}
}

0 comments on commit dfb6bcf

Please sign in to comment.