-
Notifications
You must be signed in to change notification settings - Fork 426
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix SplObjectStorage::removeAll/Except
- Loading branch information
1 parent
0f8a352
commit e8e466d
Showing
3 changed files
with
93 additions
and
2 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
80 changes: 80 additions & 0 deletions
80
tests/PHPStan/Rules/Methods/data/bug-SplObjectStorage-remove.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,80 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace BugSplObjectStorageRemove; | ||
|
||
class A {} | ||
|
||
class B extends A {} | ||
|
||
class C extends B {} | ||
|
||
class Foo {} | ||
|
||
interface BarInterface {} | ||
|
||
/** @phpstan-type ObjectStorage \SplObjectStorage<B, int> */ | ||
class HelloWorld | ||
{ | ||
/** @var ObjectStorage */ | ||
private \SplObjectStorage $foo; | ||
|
||
/** | ||
* @param ObjectStorage $other | ||
* @return ObjectStorage | ||
*/ | ||
public function removeSame(\SplObjectStorage $other): \SplObjectStorage | ||
{ | ||
$this->foo->removeAll($other); | ||
$this->foo->removeAllExcept($other); | ||
|
||
return $this->foo; | ||
} | ||
|
||
/** | ||
* @param \SplObjectStorage<C, string> $other | ||
* @return ObjectStorage | ||
*/ | ||
public function removeNarrower(\SplObjectStorage $other): \SplObjectStorage | ||
{ | ||
$this->foo->removeAll($other); | ||
$this->foo->removeAllExcept($other); | ||
|
||
return $this->foo; | ||
} | ||
|
||
/** | ||
* @param \SplObjectStorage<B, string> $other | ||
* @return ObjectStorage | ||
*/ | ||
public function removeWider(\SplObjectStorage $other): \SplObjectStorage | ||
{ | ||
$this->foo->removeAll($other); | ||
$this->foo->removeAllExcept($other); | ||
|
||
return $this->foo; | ||
} | ||
|
||
/** | ||
* @param \SplObjectStorage<BarInterface, string> $other | ||
* @return ObjectStorage | ||
*/ | ||
public function removePossibleIntersect(\SplObjectStorage $other): \SplObjectStorage | ||
{ | ||
$this->foo->removeAll($other); | ||
$this->foo->removeAllExcept($other); | ||
|
||
return $this->foo; | ||
} | ||
|
||
/** | ||
* @param \SplObjectStorage<Foo, string> $other | ||
* @return ObjectStorage | ||
*/ | ||
public function removeNoIntersect(\SplObjectStorage $other): \SplObjectStorage | ||
{ | ||
$this->foo->removeAll($other); | ||
$this->foo->removeAllExcept($other); | ||
|
||
return $this->foo; | ||
} | ||
} |