Skip to content

Commit 1eaac5b

Browse files
committed
tests: replace NativeCallsTest with the NamespacedCallsCheck copy-in pair
The old test enforced only the ~28 opcode built-ins from a hardcoded list. The new pair from the docs repo enforces the full house rule in src/: one use function line naming exactly the built-ins the file calls, no backslashed calls, no unused imports. NamespacedCallsCheck.php is a tokenizer scanner with a --fix mode and no function list to maintain; NamespacedCallsTest.php fails CI on any gap and self-checks both files. src/ imports regenerated with --fix (import lines only, no call-site changes), and the ad-hoc speed notes above the lists replaced with the standard one-line comment. SharedHelpers.php got the same import line in both twins, keeping the byte-compare contract.
1 parent f18ff2d commit 1eaac5b

9 files changed

Lines changed: 787 additions & 141 deletions

src/Deprecations.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
use Itools\SmartString\SmartString;
1111
use JetBrains\PhpStorm\Deprecated;
1212

13-
// compile to single opcodes instead of runtime name lookups; see the note in SmartArrayBase.php
14-
use function array_key_exists, func_num_args, is_array, is_bool, is_float, is_int, is_null, is_scalar, is_string;
13+
// import built-ins so calls resolve at compile time instead of per-call lookups; NamespacedCallsTest keeps this list exact
14+
use function array_chunk, array_key_exists, array_keys, array_map, func_num_args, get_debug_type, implode, in_array, is_array, is_bool, is_float, is_int, is_null, is_scalar, is_string, preg_match, sprintf, str_replace, strtolower, trigger_error;
1515

1616
/**
1717
* Old and retired method names, phased out in stages.

src/SharedHelpers.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
namespace Itools\SmartArray;
55

6+
// import built-ins so calls resolve at compile time instead of per-call lookups; NamespacedCallsTest keeps this list exact
7+
use function array_column, array_map, basename, debug_backtrace, dirname, headers_list, implode, in_array, preg_match, str_ireplace, str_replace, trait_exists, trigger_error, trim;
8+
69
/**
710
* SharedHelpers - common functions used across our libraries.
811
*

src/SmartArray.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Itools\SmartString\SmartString;
88
use JetBrains\PhpStorm\Deprecated;
99

10-
// compile to single opcodes instead of runtime name lookups; see the note in SmartArrayBase.php
10+
// import built-ins so calls resolve at compile time instead of per-call lookups; NamespacedCallsTest keeps this list exact
1111
use function func_get_args, is_array;
1212

1313
/**

src/SmartArrayBase.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,8 @@
88
use ArrayAccess, ArrayIterator, IteratorAggregate, Iterator, Countable, JsonSerializable, Closure, ReflectionFunction;
99
use Itools\SmartString\SmartString;
1010

11-
// Speed: an unqualified builtin call in a namespaced file compiles to a runtime
12-
// name lookup; importing the name lets these compile to single opcodes instead of
13-
// function calls (~4ns each; SmartString's constructor measured ~12% faster from
14-
// the same change). Only builtins the compiler turns into opcodes are listed -
15-
// other builtins gain ~1ns and stay out. NativeCallsTest holds the opcode list
16-
// and names any uncovered call site or unused import.
17-
use function array_key_exists, count, func_num_args, is_array, is_bool, is_float,
18-
is_int, is_null, is_object, is_scalar, is_string, strlen;
11+
// import built-ins so calls resolve at compile time instead of per-call lookups; NamespacedCallsTest keeps this list exact
12+
use function addcslashes, array_column, array_filter, array_key_exists, array_key_first, array_key_last, array_keys, array_map, array_merge, array_multisort, array_slice, array_unique, array_values, basename, count, debug_backtrace, func_num_args, get_debug_type, header, headers_sent, htmlspecialchars, http_response_code, implode, is_array, is_bool, is_callable, is_float, is_int, is_null, is_numeric, is_object, is_scalar, is_string, json_decode, json_encode, max, method_exists, preg_match, preg_replace, rtrim, sort, spl_object_id, sprintf, str_contains, str_pad, str_repeat, strlen, trigger_error, trim, var_export;
1913

2014
/**
2115
* SmartArrayBase - Base implementation for SmartArray and SmartArrayHtml.

src/SmartArrayHtml.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use Itools\SmartString\SmartString;
77
use JetBrains\PhpStorm\Deprecated;
88

9-
// compile to single opcodes instead of runtime name lookups; see the note in SmartArrayBase.php
9+
// import built-ins so calls resolve at compile time instead of per-call lookups; NamespacedCallsTest keeps this list exact
1010
use function func_get_args, is_array;
1111

1212
/**

src/SmartNull.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
use JsonSerializable;
1212
use stdClass;
1313

14-
// compile to single opcodes instead of runtime name lookups; see the note in SmartArrayBase.php
15-
use function count, is_null;
14+
// import built-ins so calls resolve at compile time instead of per-call lookups; NamespacedCallsTest keeps this list exact
15+
use function count, in_array, is_null, method_exists, property_exists, strtolower;
1616

1717
/**
1818
* SmartNull - Chainable null object for missing elements.

0 commit comments

Comments
 (0)