Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
phan/src/Phan/Library/Some.php
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
63 lines (55 sloc)
1.21 KB
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
<?php | |
declare(strict_types=1); | |
namespace Phan\Library; | |
/** | |
* `Some<T>` is a sub-type of `Option<T>` representing an option with a value. | |
* @see Option | |
* | |
* @template T | |
* The type of the element. Should implement __toString() | |
* | |
* @inherits Option<T> | |
* phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore | |
* @phan-pure | |
*/ | |
class Some extends Option | |
{ | |
/** @var T the value wrapped by this Some<T>*/ | |
private $_; | |
/** | |
* @param T $_ | |
* @phan-file-suppress PhanParamNameIndicatingUnused | |
*/ | |
public function __construct($_) | |
{ | |
$this->_ = $_; | |
} | |
public function isDefined(): bool | |
{ | |
return true; | |
} | |
/** | |
* @return T | |
*/ | |
public function get() | |
{ | |
return $this->_; | |
} | |
/** | |
* @param T $else used in the None sibling class (@phan-unused-param) | |
* @return T | |
*/ | |
public function getOrElse($else) | |
{ | |
return $this->_; | |
} | |
/** | |
* @return string | |
* @suppress PhanTypeSuspiciousStringExpression this should be used with T where __toString() is defined. | |
* A string representation of this object | |
*/ | |
public function __toString(): string | |
{ | |
return 'Some(' . $this->_ . ')'; | |
} | |
} |