Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
83.33% |
10 / 12 |
CRAP | |
82.61% |
19 / 23 |
FormatToken | |
0.00% |
0 / 1 |
|
83.33% |
10 / 12 |
17.35 | |
82.61% |
19 / 23 |
__construct | |
100.00% |
1 / 1 |
1 | |
100.00% |
3 / 3 |
|||
getValue | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
getName | |
100.00% |
1 / 1 |
2 | |
100.00% |
1 / 1 |
|||
withAlias | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
|||
is | |
100.00% |
1 / 1 |
2 | |
100.00% |
1 / 1 |
|||
isOne | |
100.00% |
1 / 1 |
3 | |
100.00% |
6 / 6 |
|||
setType | |
100.00% |
1 / 1 |
1 | |
100.00% |
3 / 3 |
|||
isSymbol | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
isLitteral | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
setLitteral | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
isType | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
getType | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
<?php | |
namespace Popy\Calendar\Parser; | |
/** | |
* Format Token used by FormatLexer & FormatParser. Immutable. | |
*/ | |
class FormatToken | |
{ | |
const TYPE_LITTERAL = 1; | |
const TYPE_SYMBOL = 2; | |
const TYPE_EOF = 3; | |
/** | |
* Token value. | |
* | |
* @var string|null | |
*/ | |
protected $value; | |
/** | |
* Token type. | |
* | |
* @var integer | |
*/ | |
protected $type; | |
/** | |
* Token alias. Usefull to map new tokens to already existing behaviours in | |
* ResultMappers | |
* | |
* @var string|null | |
*/ | |
protected $alias; | |
/** | |
* Class constructor. | |
* | |
* @param string|null $value Token value. | |
* @param integer $type Token type. | |
*/ | |
public function __construct($value, $type) | |
{ | |
$this->value = $value; | |
$this->type = $type; | |
} | |
/** | |
* Gets the token value. | |
* | |
* @return string | |
*/ | |
public function getValue() | |
{ | |
return $this->value; | |
} | |
/** | |
* Gets the token name (possibly aliased). | |
* | |
* @return string | |
*/ | |
public function getName() | |
{ | |
return $this->alias ?: $this->value; | |
} | |
/** | |
* Returns a new instance with the input alias. | |
* | |
* @param string|null $alias | |
* | |
* @return static | |
*/ | |
public function withAlias($alias) | |
{ | |
$res = clone $this; | |
$res->alias = $alias; | |
return $res; | |
} | |
/** | |
* Checks if token is a TYPE_SYMBOL matching the input symbol. | |
* | |
* @param string $symbol | |
* | |
* @return boolean | |
*/ | |
public function is($symbol) | |
{ | |
return $this->type === self::TYPE_SYMBOL && $this->value === $symbol; | |
} | |
/** | |
* Checks if token is a TYPE_SYMBOL matching one of the arguments, | |
* or one of the symbol contained in the first argument if it is an array | |
* | |
* @param array|string $symbols | |
* @param string ...$symbol | |
* | |
* @return boolean | |
*/ | |
public function isOne($symbols) | |
{ | |
if ($this->type !== self::TYPE_SYMBOL) { | |
return false; | |
} | |
if (!is_array($symbols)) { | |
$symbols = func_get_args(); | |
} | |
return in_array($this->value, $symbols); | |
} | |
/** | |
* Set type. | |
* | |
* @param integer $type | |
*/ | |
public function setType($type) | |
{ | |
$res = clone $this; | |
$res->type = $type; | |
return $res; | |
} | |
/** | |
* Checks if token is a symbol. | |
* | |
* @return boolean | |
*/ | |
public function isSymbol() | |
{ | |
return $this->type === self::TYPE_SYMBOL; | |
} | |
/** | |
* Checks if symbol is litteral | |
* | |
* @return boolean | |
*/ | |
public function isLitteral() | |
{ | |
return $this->type === self::TYPE_LITTERAL; | |
} | |
/** | |
* Set litteral. | |
*/ | |
public function setLitteral() | |
{ | |
return $this->setType(self::TYPE_LITTERAL); | |
} | |
/** | |
* Checks if token is of given type. | |
* | |
* @param integer $type | |
* | |
* @return boolean | |
*/ | |
public function isType($type) | |
{ | |
return $this->type === $type; | |
} | |
/** | |
* Get token type. | |
* | |
* @return integer | |
*/ | |
public function getType() | |
{ | |
return $this->type; | |
} | |
} |