-
Notifications
You must be signed in to change notification settings - Fork 11
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
Finalize on Magento 1 #87
Comments
Hi, working autoload is requirement for this tool to run. Afaik Zend 1 has custom magic loading, that combines prefixes and short class name. I would not recommend to run this tool, untill you upgrade to newer Zend version with PSR-4. |
I am using Composer's autoloader and everything is working fine. It's not an autoloader issue as PSR-0 and PSR-4 work fine. I am using a modified version of https://github.com/openmage |
I haven't tested this, but this would support PSR-0: <?php
declare (strict_types=1);
namespace Rector\SwissKnife\PhpParser\NodeVisitor;
use PhpParser\Node;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt\Class_;
use PhpParser\NodeVisitorAbstract;
use ReflectionClass;
use ReflectionException;
final class ParentClassNameCollectingNodeVisitor extends NodeVisitorAbstract
{
/**
* @var string[]
*/
private $parentClassNames = [];
public function enterNode(Node $node) : ?Node
{
if (!$node instanceof Class_) {
return null;
}
if (!$node->extends instanceof Name) {
return null;
}
$this->parentClassNames[$node->extends->toString()] = true;
return $node;
}
/**
* @return string[]
*/
public function getParentClassNames(): array
{
$filteredClassNames = array_filter(
$this->parentClassNames,
function (string $parentClassName): bool {
// If it has underscores, it's likely PSR-0 userland code
if (str_contains($parentClassName, '_')) {
return true;
}
// If it has a namespace separator, handle vendor filtering
if (str_contains($parentClassName, '\\')) {
// Filter out vendor-specific namespaces
return !str_contains($parentClassName, 'Symfony\\')
&& !str_contains($parentClassName, 'PHPStan\\')
&& !str_contains($parentClassName, 'PhpParser\\');
}
// If it exists, check if it's a built-in PHP class (no file path)
if (class_exists($parentClassName, true)) {
try {
$reflection = new ReflectionClass($parentClassName);
// Native PHP classes return empty string or false for getFileName()
$fileName = $reflection->getFileName();
return $fileName !== false && $fileName !== '';
} catch (ReflectionException) {
// If reflection fails, assume it's not userland code
return false;
}
}
// If it doesn't exist yet, assume it's userland code that needs autoloading
return true;
},
ARRAY_FILTER_USE_KEY
);
ksort($filteredClassNames);
return array_keys($filteredClassNames);
}
} |
|
I just attempted to run finalize-classes on a Magento 1 install. PhpStan has >3000 errors like
Class Zend_Session_SaveHandler_Exception extends final class Zend_Session_Exception
. Perhaps the problem is the PSR-0 namespacing?The text was updated successfully, but these errors were encountered: