Skip to content

Commit

Permalink
Rename PhpToken::getAll() to PhpToken::tokenize()
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Nov 9, 2020
1 parent fe2cbca commit b1019f4
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 16 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ PHP NEWS
message). (Nikita)
. Fixed bug #80266 (parse_url silently drops port number 0). (cmb, Nikita)

- Tokenizer:
. Fixed bug #80328 (PhpToken::getAll() confusing name). (Nikita)

29 Oct 2020, PHP 8.0.0RC3

- Core:
Expand Down
2 changes: 1 addition & 1 deletion ext/tokenizer/tests/PhpToken_extension.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class MyPhpToken extends PhpToken {
}
}

foreach (MyPhpToken::getAll($code) as $token) {
foreach (MyPhpToken::tokenize($code) as $token) {
echo $token->getLoweredText();

if ($token->extra !== 123) {
Expand Down
4 changes: 2 additions & 2 deletions ext/tokenizer/tests/PhpToken_extension_errors.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class MyPhpToken1 extends PhpToken {
}

try {
var_dump(MyPhpToken1::getAll("<?php foo"));
var_dump(MyPhpToken1::tokenize("<?php foo"));
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
Expand All @@ -19,7 +19,7 @@ abstract class MyPhpToken2 extends PhpToken {
}

try {
var_dump(MyPhpToken2::getAll("<?php foo"));
var_dump(MyPhpToken2::tokenize("<?php foo"));
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
Expand Down
2 changes: 1 addition & 1 deletion ext/tokenizer/tests/PhpToken_methods.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function foo() {
PHP;

// Token names and ignorability.
$tokens = PhpToken::getAll($code);
$tokens = PhpToken::tokenize($code);
foreach ($tokens as $i => $token) {
printf("[%2d] %-26s %s\n", $i, $token->getTokenName(),
$token->isIgnorable() ? "ignorable" : "meaningful");
Expand Down
2 changes: 1 addition & 1 deletion ext/tokenizer/tests/PhpToken_toString.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ PhpToken implements __toString()
--FILE--
<?php

$tokens = PhpToken::getAll('<?php echo "Hello ". $what;');
$tokens = PhpToken::tokenize('<?php echo "Hello ". $what;');
var_dump(implode($tokens));

var_dump($tokens[0] instanceof Stringable);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
PhpToken::getAll() method
PhpToken::tokenize() method
--SKIPIF--
<?php if (!extension_loaded("tokenizer")) print "skip tokenizer extension not enabled"; ?>
--FILE--
Expand All @@ -11,8 +11,8 @@ function foo() {
echo "bar";
}
PHP;
var_dump(PhpToken::getAll($code));
var_dump(PhpToken::getAll($code, TOKEN_PARSE));
var_dump(PhpToken::tokenize($code));
var_dump(PhpToken::tokenize($code, TOKEN_PARSE));

?>
--EXPECTF--
Expand Down
2 changes: 1 addition & 1 deletion ext/tokenizer/tests/bug77966.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class C {
}
CODE;

$tokens = PhpToken::getAll($code, TOKEN_PARSE);
$tokens = PhpToken::tokenize($code, TOKEN_PARSE);
foreach ($tokens as $token) {
echo "{$token->getTokenName()}: \"$token->text\"\n";
}
Expand Down
2 changes: 1 addition & 1 deletion ext/tokenizer/tests/namespaced_names.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace\Foo
Foo \ Bar
CODE;

foreach (PhpToken::getAll($code) as $token) {
foreach (PhpToken::tokenize($code) as $token) {
echo "{$token->getTokenName()}: \"$token->text\"\n";
}

Expand Down
2 changes: 1 addition & 1 deletion ext/tokenizer/tokenizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ static zend_string *php_token_get_text(zval *obj) {
static zend_bool tokenize_common(
zval *return_value, zend_string *source, zend_long flags, zend_class_entry *token_class);

PHP_METHOD(PhpToken, getAll)
PHP_METHOD(PhpToken, tokenize)
{
zend_string *source;
zend_long flags = 0;
Expand Down
2 changes: 1 addition & 1 deletion ext/tokenizer/tokenizer.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function token_name(int $id): string {}
class PhpToken implements Stringable
{
/** @return static[] */
public static function getAll(string $code, int $flags = 0): array {}
public static function tokenize(string $code, int $flags = 0): array {}

final public function __construct(int $id, string $text, int $line = -1, int $pos = -1) {}

Expand Down
8 changes: 4 additions & 4 deletions ext/tokenizer/tokenizer_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: ef39f4efec05a3ebc5cf56a6b26e01369f00d129 */
* Stub hash: a06da9ea0191ed78ee7af8f0d9eaccb17dfa4b20 */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_token_get_all, 0, 1, IS_ARRAY, 0)
ZEND_ARG_TYPE_INFO(0, code, IS_STRING, 0)
Expand All @@ -10,7 +10,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_token_name, 0, 1, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, id, IS_LONG, 0)
ZEND_END_ARG_INFO()

#define arginfo_class_PhpToken_getAll arginfo_token_get_all
#define arginfo_class_PhpToken_tokenize arginfo_token_get_all

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PhpToken___construct, 0, 0, 2)
ZEND_ARG_TYPE_INFO(0, id, IS_LONG, 0)
Expand All @@ -35,7 +35,7 @@ ZEND_END_ARG_INFO()

ZEND_FUNCTION(token_get_all);
ZEND_FUNCTION(token_name);
ZEND_METHOD(PhpToken, getAll);
ZEND_METHOD(PhpToken, tokenize);
ZEND_METHOD(PhpToken, __construct);
ZEND_METHOD(PhpToken, is);
ZEND_METHOD(PhpToken, isIgnorable);
Expand All @@ -51,7 +51,7 @@ static const zend_function_entry ext_functions[] = {


static const zend_function_entry class_PhpToken_methods[] = {
ZEND_ME(PhpToken, getAll, arginfo_class_PhpToken_getAll, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
ZEND_ME(PhpToken, tokenize, arginfo_class_PhpToken_tokenize, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
ZEND_ME(PhpToken, __construct, arginfo_class_PhpToken___construct, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
ZEND_ME(PhpToken, is, arginfo_class_PhpToken_is, ZEND_ACC_PUBLIC)
ZEND_ME(PhpToken, isIgnorable, arginfo_class_PhpToken_isIgnorable, ZEND_ACC_PUBLIC)
Expand Down

0 comments on commit b1019f4

Please sign in to comment.