-
-
Notifications
You must be signed in to change notification settings - Fork 14
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
98aaa5f
commit 2167139
Showing
10 changed files
with
344 additions
and
36 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 |
---|---|---|
|
@@ -43,7 +43,7 @@ | |
}, | ||
"extra": { | ||
"branch-alias": { | ||
"dev-master": "2.2-dev" | ||
"dev-master": "2.3-dev" | ||
} | ||
} | ||
} |
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,60 @@ | ||
<?php declare(strict_types=1); | ||
/* | ||
* This file is part of sebastian/type. | ||
* | ||
* (c) Sebastian Bergmann <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace SebastianBergmann\Type; | ||
|
||
final class StaticType extends Type | ||
{ | ||
/** | ||
* @var TypeName | ||
*/ | ||
private $className; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
private $allowsNull; | ||
|
||
public function __construct(TypeName $className, bool $allowsNull) | ||
{ | ||
$this->className = $className; | ||
$this->allowsNull = $allowsNull; | ||
} | ||
|
||
public function isAssignable(Type $other): bool | ||
{ | ||
if ($this->allowsNull && $other instanceof NullType) { | ||
return true; | ||
} | ||
|
||
if (!$other instanceof ObjectType) { | ||
return false; | ||
} | ||
|
||
if (0 === strcasecmp($this->className->qualifiedName(), $other->className()->qualifiedName())) { | ||
return true; | ||
} | ||
|
||
if (is_subclass_of($other->className()->qualifiedName(), $this->className->qualifiedName(), true)) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public function name(): string | ||
{ | ||
return 'static'; | ||
} | ||
|
||
public function allowsNull(): bool | ||
{ | ||
return $this->allowsNull; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
tests/_fixture/ChildClassThatExtendsClassWithMethodThatHasStaticReturnType.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,14 @@ | ||
<?php declare(strict_types=1); | ||
/* | ||
* This file is part of sebastian/type. | ||
* | ||
* (c) Sebastian Bergmann <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace SebastianBergmann\Type\TestFixture; | ||
|
||
class ChildClassThatExtendsClassWithMethodThatHasStaticReturnType extends ParentClassWithMethodThatHasStaticReturnType | ||
{ | ||
} |
25 changes: 25 additions & 0 deletions
25
tests/_fixture/ClassWithMethodsThatHaveStaticReturnTypes.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,25 @@ | ||
<?php declare(strict_types=1); | ||
/* | ||
* This file is part of sebastian/type. | ||
* | ||
* (c) Sebastian Bergmann <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace SebastianBergmann\Type\TestFixture; | ||
|
||
class ClassWithMethodsThatHaveStaticReturnTypes | ||
{ | ||
public function returnsStatic(): static | ||
{ | ||
} | ||
|
||
public function returnsNullableStatic(): ?static | ||
{ | ||
} | ||
|
||
public function returnsUnionWithStatic(): static|\stdClass | ||
{ | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/_fixture/ParentClassWithMethodThatHasStaticReturnType.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,17 @@ | ||
<?php declare(strict_types=1); | ||
/* | ||
* This file is part of sebastian/type. | ||
* | ||
* (c) Sebastian Bergmann <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace SebastianBergmann\Type\TestFixture; | ||
|
||
class ParentClassWithMethodThatHasStaticReturnType | ||
{ | ||
public function m(): static | ||
{ | ||
} | ||
} |
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
Oops, something went wrong.