Skip to content

Use array_any/array_all/array_find (8.4) and fix latent strpos prefix-test bugs #609

Description

@lisachenko

Summary

From the PHP 8.5 support audit (PR #597); user-approved modernization batch. Includes two latent bugs found on the way.

Latent bugs (fix regardless)

  1. src/Instrument/FileSystem/Enumerator.php:158:
    if (strpos($path, $this->rootDirectory, 0) === false) {
    This is a substring-anywhere test posing as a prefix test — /other/app passes validation if it merely contains the root path string. Intent is !str_starts_with($path, $this->rootDirectory).
  2. tests/Instrument/Transformer/WeavingTransformerTest.php:136:
    $this->assertFalse(strpos($proxyContent, '\\\\Exception'));
    Passes when the needle sits at offset 0 (the classic pre-8.0 trap). Should be assertStringNotContainsString.

Modernizations

  • src/Instrument/FileSystem/Enumerator.php:84strpos(PHP_OS, 'WIN') === 0PHP_OS_FAMILY === 'Windows'; :108strpos(...) !== 0!str_starts_with(...)
  • src/Instrument/PathResolver.php:66, src/Core/AdviceMatcher.php:90strpos(...) !== falsestr_contains(...)
  • array_any/array_all/array_find (8.4) for hand-rolled loops:
    • src/Aop/Pointcut/OrPointcut.php:56-62array_any
    • src/Aop/Pointcut/AndPointcut.php:59-65array_all
    • src/Instrument/FileSystem/Enumerator.php:112-129 include/exclude loops → array_any
    • src/Proxy/Part/AbstractInterceptedPropertyGenerator.php:101-103 union-type scan → array_any
    • src/Instrument/Transformer/WeavingTransformer.php:567-572 flag loop → array_any; :513-527 comma scans → array_find
  • src/Instrument/Transformer/WeavingTransformer.php:492end($groupPositions) + @var annotation; array_last() is 8.5-only, so keep end() until the floor rises (note in code), or drop the annotation via a local typed helper.
  • tests/Functional/ReflectionFilenameTest.php:49ReflectionProperty::setValue(null) single-arg form is deprecated since 8.3 (the suite's only deprecation); pass the object/null pair explicitly.

Pipe-operator (|>) rewrites of internal call chains stay blocked until the package floor is ^8.5 — not part of this issue.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions