Problems with native class ArrayAccess as Interface
jg-development opened this issue · 3 comments
jg-development commented
When I try to reflect a class with arrayaccess interface it does not work:
https://github.com/docusign/docusign-esign-php-client/blob/master/src/Model/AccessCodeFormat.php
Roave\BetterReflection\Reflection\ReflectionClass "ArrayAccess" could not be found in the located source
kukulich commented
How do you set up BetterReflection?
jg-development commented
Cannot show you everything, but it was like this:
public const string OLD_NAMESPACE = 'DocuSign\eSign\Model';
public const string NEW_NAMESPACE = 'DocusignEsignatureClient\Structs';
$finder
->in(__DIR__ . '/../../vendor/docusign/esign-client/src/Model')
->files()
->name('*.php')
->notName('*Interface.php')
->sortByName(true);
$iterator = $finder->getIterator();
$iterator->rewind();
foreach ($iterator as $modelFile) {
$classLoader = require __DIR__ . '/../../vendor/autoload.php';
$astLocator = (new BetterReflection())->astLocator();
$reflector = new DefaultReflector(new ComposerSourceLocator($classLoader, $astLocator));
$class = $reflector->reflectClass(self::OLD_NAMESPACE . '\\' . $modelFile->getFilenameWithoutExtension());
/** @var ReflectionProperty $swaggerTypeProperty */
$swaggerTypeProperty = $class->getProperty('swaggerTypes');
$swaggerTypes = $swaggerTypeProperty->getDefaultValue();
$class = new ClassType($modelFile->getFilenameWithoutExtension());
$namespace = new PhpNamespace(self::NEW_NAMESPACE);
$namespace->add($class);
$namespace->addUse(SerializedName::class);
}
Ocramius commented
I think the composer source locator is not sufficient there: needs to be composed together with an internal classes source locator.