[Doctrine] Add stubs instead of full orm dependencies (#1928)

[Doctrine] Add stubs instead of full orm dependencies
This commit is contained in:
Tomáš Votruba 2019-08-30 19:59:04 +02:00 committed by GitHub
commit d0e6422dab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 478 additions and 15 deletions

View File

@ -14,7 +14,6 @@
"composer/xdebug-handler": "^1.3",
"doctrine/annotations": "^1.7",
"doctrine/inflector": "^1.3",
"doctrine/orm": "^2.6",
"jean85/pretty-package-versions": "^1.2",
"nette/robot-loader": "^3.1",
"nette/utils": "^2.5|^3.0",

View File

@ -11,6 +11,15 @@ final class AnnotationReaderFactory
{
AnnotationRegistry::registerLoader('class_exists');
return new AnnotationReader();
$annotationReader = new AnnotationReader();
// without this the reader will try to resolve them and fails with an exception
// don't forget to add it to "stubs/Doctrine/Empty" directory, because the class needs to exists
// and run "composer dump-autoload", because the directory is loaded by classmap
$annotationReader::addGlobalIgnoredName('ORM\GeneratedValue');
$annotationReader::addGlobalIgnoredName('ORM\InheritanceType');
$annotationReader::addGlobalIgnoredName('ORM\OrderBy');
return $annotationReader;
}
}

View File

@ -2,7 +2,6 @@
namespace Rector\Symfony\Bridge;
use Doctrine\ORM\EntityManagerInterface;
use Rector\Bridge\Contract\AnalyzedApplicationContainerInterface;
use Rector\Configuration\Option;
use Rector\Exception\ShouldNotHappenException;
@ -40,8 +39,8 @@ final class DefaultAnalyzedSymfonyApplicationContainer implements AnalyzedApplic
*/
private $commonNamesToTypes = [
'doctrine' => 'Symfony\Bridge\Doctrine\RegistryInterface',
'doctrine.orm.entity_manager' => EntityManagerInterface::class,
'doctrine.orm.default_entity_manager' => EntityManagerInterface::class,
'doctrine.orm.entity_manager' => 'Doctrine\ORM\EntityManagerInterface',
'doctrine.orm.default_entity_manager' => 'Doctrine\ORM\EntityManagerInterface',
];
public function __construct(

View File

@ -2,7 +2,6 @@
namespace Rector\TypeDeclaration\TypeInferer\PropertyTypeInferer;
use Doctrine\Common\Collections\Collection;
use PhpParser\Node\Stmt\Property;
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\Property_\JoinColumnTagValueNode;
use Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc\ToManyTagNodeInterface;
@ -15,7 +14,7 @@ final class DoctrineRelationPropertyTypeInferer implements PropertyTypeInfererIn
/**
* @var string
*/
private const COLLECTION_TYPE = Collection::class;
private const COLLECTION_TYPE = 'Doctrine\Common\Collections\Collection';
/**
* @var DocBlockManipulator

View File

@ -2,8 +2,6 @@
namespace Rector\Rector\Architecture\RepositoryAsService;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityRepository;
use Nette\Utils\Strings;
use PhpParser\Node;
use PhpParser\Node\Expr\Assign;
@ -43,8 +41,8 @@ final class MoveRepositoryFromParentToConstructorRector extends AbstractRector
public function __construct(
DoctrineEntityAndRepositoryMapperInterface $doctrineEntityAndRepositoryMapper,
ClassManipulator $classManipulator,
string $entityRepositoryClass = EntityRepository::class,
string $entityManagerClass = EntityManager::class
string $entityRepositoryClass = 'Doctrine\ORM\EntityRepository',
string $entityManagerClass = 'Doctrine\ORM\EntityManager'
) {
$this->doctrineEntityAndRepositoryMapper = $doctrineEntityAndRepositoryMapper;
$this->entityRepositoryClass = $entityRepositoryClass;
@ -86,8 +84,8 @@ final class PostRepository
CODE_SAMPLE
,
[
'$entityRepositoryClass' => EntityRepository::class,
'$entityManagerClass' => EntityManager::class,
'$entityRepositoryClass' => 'Doctrine\ORM\EntityRepository',
'$entityManagerClass' => 'Doctrine\ORM\EntityManager',
]
),
]);

View File

@ -2,7 +2,6 @@
namespace Rector\Rector\Architecture\RepositoryAsService;
use Doctrine\ORM\EntityRepository;
use PhpParser\Node;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Identifier;
@ -33,7 +32,7 @@ final class ReplaceParentRepositoryCallsByRepositoryPropertyRector extends Abstr
'matching',
];
public function __construct(string $entityRepositoryClass = EntityRepository::class)
public function __construct(string $entityRepositoryClass = 'Doctrine\ORM\EntityRepository')
{
$this->entityRepositoryClass = $entityRepositoryClass;
}

View File

@ -0,0 +1,11 @@
<?php
namespace Doctrine\ORM\Mapping;
if (interface_exists('Doctrine\ORM\Mapping\Annotation')) {
return;
}
interface Annotation
{
}

63
stubs/Doctrine/Column.php Normal file
View File

@ -0,0 +1,63 @@
<?php
namespace Doctrine\ORM\Mapping;
if (interface_exists('Doctrine\ORM\Mapping\Column')) {
return;
}
/**
* @Annotation
* @Target({"PROPERTY","ANNOTATION"})
*/
final class Column implements Annotation
{
/**
* @var string
*/
public $name;
/**
* @var mixed
*/
public $type = 'string';
/**
* @var integer
*/
public $length;
/**
* The precision for a decimal (exact numeric) column (Applies only for decimal column).
*
* @var integer
*/
public $precision = 0;
/**
* The scale for a decimal (exact numeric) column (Applies only for decimal column).
*
* @var integer
*/
public $scale = 0;
/**
* @var boolean
*/
public $unique = false;
/**
* @var boolean
*/
public $nullable = false;
/**
* @var array
*/
public $options = [];
/**
* @var string
*/
public $columnDefinition;
}

View File

@ -0,0 +1,12 @@
<?php
namespace Doctrine\ORM\Mapping;
if (class_exists('Doctrine\ORM\Mapping\GeneratedValue')) {
return;
}
class GeneratedValue
{
}

View File

@ -0,0 +1,12 @@
<?php
namespace Doctrine\ORM\Mapping;
if (class_exists('Doctrine\ORM\Mapping\InheritanceType')) {
return;
}
class InheritanceType
{
}

View File

@ -0,0 +1,12 @@
<?php
namespace Doctrine\ORM\Mapping;
if (class_exists('Doctrine\ORM\Mapping\OrderBy')) {
return;
}
class OrderBy
{
}

24
stubs/Doctrine/Entity.php Normal file
View File

@ -0,0 +1,24 @@
<?php
namespace Doctrine\ORM\Mapping;
if (interface_exists('Doctrine\ORM\Mapping\Entity')) {
return;
}
/**
* @Annotation
* @Target("CLASS")
*/
final class Entity implements Annotation
{
/**
* @var string
*/
public $repositoryClass;
/**
* @var boolean
*/
public $readOnly = false;
}

15
stubs/Doctrine/Id.php Normal file
View File

@ -0,0 +1,15 @@
<?php
namespace Doctrine\ORM\Mapping;
if (interface_exists('Doctrine\ORM\Mapping\Id')) {
return;
}
/**
* @Annotation
* @Target("PROPERTY")
*/
final class Id implements Annotation
{
}

View File

@ -0,0 +1,51 @@
<?php
namespace Doctrine\ORM\Mapping;
if (interface_exists('Doctrine\ORM\Mapping\JoinColumn')) {
return;
}
/**
* @Annotation
* @Target({"PROPERTY","ANNOTATION"})
*/
final class JoinColumn implements Annotation
{
/**
* @var string
*/
public $name;
/**
* @var string
*/
public $referencedColumnName = 'id';
/**
* @var boolean
*/
public $unique = false;
/**
* @var boolean
*/
public $nullable = true;
/**
* @var mixed
*/
public $onDelete;
/**
* @var string
*/
public $columnDefinition;
/**
* Field name used in non-object hydration (array/scalar).
*
* @var string
*/
public $fieldName;
}

View File

@ -0,0 +1,34 @@
<?php
namespace Doctrine\ORM\Mapping;
if (interface_exists('Doctrine\ORM\Mapping\JoinTable')) {
return;
}
/**
* @Annotation
* @Target({"PROPERTY","ANNOTATION"})
*/
final class JoinTable implements Annotation
{
/**
* @var string
*/
public $name;
/**
* @var string
*/
public $schema;
/**
* @var array<\Doctrine\ORM\Mapping\JoinColumn>
*/
public $joinColumns = [];
/**
* @var array<\Doctrine\ORM\Mapping\JoinColumn>
*/
public $inverseJoinColumns = [];
}

View File

@ -0,0 +1,53 @@
<?php
namespace Doctrine\ORM\Mapping;
if (interface_exists('Doctrine\ORM\Mapping\ManyToMany')) {
return;
}
/**
* @Annotation
* @Target("PROPERTY")
*/
final class ManyToMany implements Annotation
{
/**
* @var string
*/
public $targetEntity;
/**
* @var string
*/
public $mappedBy;
/**
* @var string
*/
public $inversedBy;
/**
* @var array<string>
*/
public $cascade;
/**
* The fetching strategy to use for the association.
*
* @var string
*
* @Enum({"LAZY", "EAGER", "EXTRA_LAZY"})
*/
public $fetch = 'LAZY';
/**
* @var boolean
*/
public $orphanRemoval = false;
/**
* @var string
*/
public $indexBy;
}

View File

@ -0,0 +1,38 @@
<?php
namespace Doctrine\ORM\Mapping;
if (interface_exists('Doctrine\ORM\Mapping\ManyToOne')) {
return;
}
/**
* @Annotation
* @Target("PROPERTY")
*/
final class ManyToOne implements Annotation
{
/**
* @var string
*/
public $targetEntity;
/**
* @var array<string>
*/
public $cascade;
/**
* The fetching strategy to use for the association.
*
* @var string
*
* @Enum({"LAZY", "EAGER", "EXTRA_LAZY"})
*/
public $fetch = 'LAZY';
/**
* @var string
*/
public $inversedBy;
}

View File

@ -0,0 +1,48 @@
<?php
namespace Doctrine\ORM\Mapping;
if (interface_exists('Doctrine\ORM\Mapping\OneToMany')) {
return;
}
/**
* @Annotation
* @Target("PROPERTY")
*/
final class OneToMany implements Annotation
{
/**
* @var string
*/
public $mappedBy;
/**
* @var string
*/
public $targetEntity;
/**
* @var array<string>
*/
public $cascade;
/**
* The fetching strategy to use for the association.
*
* @var string
*
* @Enum({"LAZY", "EAGER", "EXTRA_LAZY"})
*/
public $fetch = 'LAZY';
/**
* @var boolean
*/
public $orphanRemoval = false;
/**
* @var string
*/
public $indexBy;
}

View File

@ -0,0 +1,48 @@
<?php
namespace Doctrine\ORM\Mapping;
if (interface_exists('Doctrine\ORM\Mapping\OneToOne')) {
return;
}
/**
* @Annotation
* @Target("PROPERTY")
*/
final class OneToOne implements Annotation
{
/**
* @var string
*/
public $targetEntity;
/**
* @var string
*/
public $mappedBy;
/**
* @var string
*/
public $inversedBy;
/**
* @var array<string>
*/
public $cascade;
/**
* The fetching strategy to use for the association.
*
* @var string
*
* @Enum({"LAZY", "EAGER", "EXTRA_LAZY"})
*/
public $fetch = 'LAZY';
/**
* @var boolean
*/
public $orphanRemoval = false;
}

39
stubs/Doctrine/Table.php Normal file
View File

@ -0,0 +1,39 @@
<?php
namespace Doctrine\ORM\Mapping;
if (interface_exists('Doctrine\ORM\Mapping\Table')) {
return;
}
/**
* @Annotation
* @Target("CLASS")
*/
final class Table implements Annotation
{
/**
* @var string
*/
public $name;
/**
* @var string
*/
public $schema;
/**
* @var array<\Doctrine\ORM\Mapping\Index>
*/
public $indexes;
/**
* @var array<\Doctrine\ORM\Mapping\UniqueConstraint>
*/
public $uniqueConstraints;
/**
* @var array
*/
public $options = [];
}