php-scoper icon indicating copy to clipboard operation
php-scoper copied to clipboard

use not supported in classes

Open pcfreak30 opened this issue 4 years ago • 5 comments

Bug report

Question Answer
PHP-Scoper version 0.14.0
PHP version 7.4.14
Platform with version Manjaro Linux 20.2.1
Github Repo -

PHP Scoper does not currently seem to support changing references for traits inside classes. Example:

<?php

namespace A\B;
class A {
	use SomeTraitC;
}

None of the namespace or trait-related visitor classes seem to deal with TraitUse.

pcfreak30 avatar Feb 17 '21 23:02 pcfreak30

Revisiting this issue, what would be the desired output here? SomeTraitC is not imported via a use statement hence belongs to the current namespace so it should not be changed

theofidry avatar Jun 16 '21 22:06 theofidry

Sorry, I dont follow your question/what your saying?

pcfreak30 avatar Jun 16 '21 22:06 pcfreak30

That traits looks to be handled at first glance and that I'm not sure what is expected there in the sample you provided

theofidry avatar Jun 16 '21 22:06 theofidry

If I remember right it was that the trait was not copied to the new namespace and the references properly updated. I would have to test again to get details.

pcfreak30 avatar Jun 16 '21 22:06 pcfreak30

Hi I also have encountered this problem.

And I have a nice way to reproduce it:

    composer require "ivopetkov/html5-dom-document-php:2.*"
    composer require humbug/php-scoper
    ./vendor/bin/php-scoper init
    mkdir src
    ./vendor/bin/php-scoper add-prefix
    head build/vendor/ivopetkov/html5-dom-document-php/src/HTML5DOMDocument.php  -n20 

You will see the class like this:

<?php

/*
 * HTML5 DOMDocument PHP library (extends DOMDocument)
 * https://github.com/ivopetkov/html5-dom-document-php
 * Copyright (c) Ivo Petkov
 * Free to use under the MIT license.
 */
namespace _PhpScoper56249b31f25a\IvoPetkov;

/**
 * Represents a live (can be manipulated) representation of a HTML5 document.
 */
class HTML5DOMDocument extends \DOMDocument
{
    use \IvoPetkov\HTML5DOMDocument\Internal\QuerySelectors;
    /**
     * An option passed to loadHTML() and loadHTMLFile() to disable duplicate element IDs exception.
     */
    const ALLOW_DUPLICATE_IDS = 67108864;

The namespace is nicely updated. But the trait included with use is not.

janw-me avatar Sep 24 '21 12:09 janw-me