for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* @license http://opensource.org/licenses/mit-license.php MIT
* @link https://github.com/nicoSWD
* @author Nicolas Oelgart <[email protected]>
*/
declare(strict_types=1);
namespace nicoSWD\Rules\Grammar\JavaScript\Methods;
use nicoSWD\Rules\Core\CallableFunction;
use nicoSWD\Rules\Tokens\BaseToken;
use nicoSWD\Rules\Tokens\TokenInteger;
use nicoSWD\Rules\Tokens\TokenString;
final class CharAt extends CallableFunction
{
* @param BaseToken $offset
* @return BaseToken
public function call($offset = null): BaseToken
$tokenValue = $this->token->getValue();
if (!$offset) {
$offset = 0;
}
elseif (!$offset instanceof TokenInteger) {
$offset = (int) $offset->getValue();
} else {
$offset = $offset->getValue();
if (!isset($tokenValue[$offset])) {
$char = '';
$char = $tokenValue[$offset];
return new TokenString(
$char,
$this->token->getOffset(),
$this->token->getStack()
);