for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
/**
* @license http://opensource.org/licenses/mit-license.php MIT
* @link https://github.com/nicoSWD
* @author Nicolas Oelgart <[email protected]>
*/
namespace nicoSWD\Rule\Grammar\JavaScript\Methods;
use nicoSWD\Rule\Grammar\CallableFunction;
use nicoSWD\Rule\TokenStream\Token\BaseToken;
use nicoSWD\Rule\TokenStream\Token\TokenArray;
use nicoSWD\Rule\TokenStream\Token\TokenRegex;
final class Split extends CallableFunction
{
* @param BaseToken $separator
* @param BaseToken $limit
* @return BaseToken
public function call($separator = null, $limit = null): BaseToken
if (!$separator || !is_string($separator->getValue())) {
$newValue = [$this->token->getValue()];
} else {
$params = [$separator->getValue(), $this->token->getValue()];
if ($limit) {
$params[] = (int) $limit->getValue();
}
if ($separator instanceof TokenRegex) {
$func = 'preg_split';
$func = 'explode';
$newValue = $func(...$params);
return new TokenArray(
$newValue,
$this->token->getOffset(),
$this->token->getStack()
);