dg/composer-backslasher

Local function overriding the one from PHP API

trejjam opened this issue · 0 comments

  • bug report? yes
  • feature request? yes

Description

This tool is incompatible with package https://github.com/guzzle/promises which override PHP function each by its own version (and maybe some other).

Steps To Reproduce

Use library with following content:

<?php
namespace A;

function settle($promises)
{
    $results = [];
    return each(
        $promises,
        function () {},
        function () {}
    )->then(function () use (&$results) {
        ksort($results);
        return $results;
    });
}

function each(
    $iterable,
    callable $onFulfilled = null,
    callable $onRejected = null
) {
    return 'baz';
}

Expected result after processed by this tool

<?php
namespace A;

function settle($promises)
{
    $results = [];
    return each(
        $promises,
        function () {},
        function () {}
    )->then(function () use (&$results) {
        \ksort($results);
        return $results;
    });
}

function each(
    $iterable,
    callable $onFulfilled = null,
    callable $onRejected = null
) {
    return 'baz';
}

What is produced instead

<?php
namespace A;

function settle($promises)
{
    $results = [];
    return \each( // notice this back slash, targeting global method instead local one
        $promises,
        function () {},
        function () {}
    )->then(function () use (&$results) {
        \ksort($results);
        return $results;
    });
}

function each(
    $iterable,
    callable $onFulfilled = null,
    callable $onRejected = null
) {
    return 'baz';
}

Proposed solution

  • Add possibility to blacklist some directories
  • Check existence of overriding functions