-
-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
classmap_prefix duplication and other issues with classmaps #106
Comments
The following <?php
/**
* The purpose of this file is to find and update classnames (and interfaces...) in their declarations.
* Those replaced are recorded and their uses elsewhere are updated in a later step.
*/
namespace CoenJacobs\Mozart\Replace;
class ClassmapReplacer extends BaseReplacer
{
/** @var string[] */
public $replacedClasses = [];
/** @var string */
public $classmap_prefix;
public function replace($contents)
{
return preg_replace_callback(
"
/ # Start the pattern
namespace\s+[a-zA-Z0-9_\x7f-\xff\\\\]+[;{\s\n]{1}.*?(?=namespace|$)
# Look for a preceeding namespace declaration, up until
# a potential second namespace declaration
| # if found, match that much before repeating the search
# on the remainder of the string
[^a-zA-Z0-9_\x7f-\xff]+ # After a non-class character,
{$this->classmap_prefix} # match an already prefixed classname
[a-zA-Z0-9_\x7f-\xff]+ # before continuing on the remainder of the string
|
(?:abstract\sclass|class|interface)\s+ # Look behind for class, abstract class, interface
([a-zA-Z0-9_\x7f-\xff]+) # Match the word until the first
# non-classname-valid character
\s? # Allow a space after
(?:{|extends|implements|\n) # Class declaration can be followed by {, extends,
# implements, or a new line
/sx", // # dot matches newline, ignore whitespace in regex.
function ($matches) use ($contents) {
// If we're inside a namespace other than the global namesspace, just return.
if (preg_match('/^namespace\s+[a-zA-Z0-9_\x7f-\xff\\\\]+[;{\s\n]{1}.*/', $matches[0])) {
return $matches[0];
}
if (preg_match("/[^a-zA-Z0-9_\x7f-\xff]+{$this->classmap_prefix}[a-zA-Z0-9_\x7f-\xff]+/", $matches[0])) {
return $matches[0];
}
// The prepended class name.
$replace = $this->classmap_prefix . $matches[1];
$this->saveReplacedClass($matches[1], $replace);
return str_replace($matches[1], $replace, $matches[0]);
},
$contents
);
}
public function saveReplacedClass($classname, $replacedName)
{
$this->replacedClasses[ $classname ] = $replacedName;
}
} It is PR #101 with this added: [^a-zA-Z0-9_\x7f-\xff]+ # After a non-class character,
{$this->classmap_prefix} # match an already prefixed classname
[a-zA-Z0-9_\x7f-\xff]+ # before continuing on the remainder of the string
| Updating '/(.*)([^a-zA-Z0-9_\x7f-\xff\\\\])'. $original . '([^a-zA-Z0-9_\x7f-\xff])/U', fixes the PhpStorm was highlighting the namespace in |
That PR that was referred above is now released as part of Mozart 0.6.0. @olegabr can you confirm this is now resolved? |
It created file
/home/USER/PROJECT/vendor-epg/classes/symfony/polyfill-intl-normalizer/Resources/stubs/Normalizer.php
with contents:Three issues here:
Symfony\Polyfill\Intl\
namespace is not prefixed withEthereumico\Epg\Dependencies\
ether_and_erc20_tokens_woocommerce_payment_gateway_ether_and_erc20_tokens_woocommerce_payment_gateway_ether_and_erc20_tokens_woocommerce_payment_gateway_ether_and_erc20_tokens_woocommerce_payment_gateway_Normalizer
The
/home/USER/PROJECT/vendor-epg/Symfony/Polyfill/Intl/Normalizer/Normalizer.php
file is defined correctly as:The text was updated successfully, but these errors were encountered: