Skip to content

Commit

Permalink
Use symfony/deprecation-contracts to announce deprecations in code (#…
Browse files Browse the repository at this point in the history
…2249)

* Use symfony/deprecation-contracts to announce deprecations in code

* Update lib/Doctrine/ODM/MongoDB/Mapping/Driver/AnnotationDriver.php

Co-authored-by: Claudio Zizza <859964+SenseException@users.noreply.github.com>

* Update lib/Doctrine/ODM/MongoDB/Mapping/Driver/AnnotationDriver.php

Co-authored-by: Claudio Zizza <859964+SenseException@users.noreply.github.com>

Co-authored-by: Claudio Zizza <859964+SenseException@users.noreply.github.com>
  • Loading branch information
alcaeus and SenseException authored Nov 27, 2020
1 parent 285a805 commit 3bdfe97
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 56 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"mongodb/mongodb": "^1.2.0",
"ocramius/proxy-manager": "^2.2",
"symfony/console": "^3.4|^4.1|^5.0",
"symfony/deprecation-contracts": "^2.2",
"symfony/var-dumper": "^3.4|^4.1|^5.0"
},
"require-dev": {
Expand Down
12 changes: 7 additions & 5 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use MongoDB\Collection;
use OutOfRangeException;
use TypeError;
use const E_USER_DEPRECATED;
use function array_map;
use function array_unshift;
use function func_get_arg;
Expand All @@ -22,7 +21,7 @@
use function is_array;
use function is_bool;
use function sprintf;
use function trigger_error;
use function trigger_deprecation;

/**
* Fluent interface for building aggregation pipelines.
Expand Down Expand Up @@ -169,9 +168,12 @@ public function count(string $fieldName) : Stage\Count
*/
public function execute(array $options = []) : Iterator
{
@trigger_error(
sprintf('The "%s" method was deprecated in doctrine/mongodb-odm 2.2. Please use getAggregation() instead.', __METHOD__),
E_USER_DEPRECATED
trigger_deprecation(
'doctrine/mongodb-odm',
'2.2',
'Using "%s" is deprecated. Please use "%s::getAggregation()" instead.',
__METHOD__,
self::class
);

return $this->getAggregation($options)->getIterator();
Expand Down
13 changes: 7 additions & 6 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

use Doctrine\ODM\MongoDB\Iterator\Iterator;
use GeoJson\Geometry\Point;
use const E_USER_DEPRECATED;
use function sprintf;
use function trigger_error;
use function trigger_deprecation;

/**
* Fluent interface for building aggregation pipelines.
Expand Down Expand Up @@ -37,9 +35,12 @@ abstract public function getExpression() : array;
*/
public function execute(array $options = []) : Iterator
{
@trigger_error(
sprintf('The "%s" method was deprecated in doctrine/mongodb-odm 2.2. Please use getAggregation() instead.', __METHOD__),
E_USER_DEPRECATED
trigger_deprecation(
'doctrine/mongodb-odm',
'2.2',
'Using "%s" is deprecated, use "%s::getAggregation()" instead.',
__METHOD__,
self::class
);

return $this->builder->execute($options);
Expand Down
21 changes: 0 additions & 21 deletions lib/Doctrine/ODM/MongoDB/Mapping/Annotations/AbstractField.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Doctrine\ODM\MongoDB\Mapping\Annotations;

use Doctrine\Common\Annotations\Annotation;
use function sprintf;

abstract class AbstractField extends Annotation
{
Expand All @@ -26,24 +25,4 @@ abstract class AbstractField extends Annotation

/** @var bool */
public $notSaved = false;

/**
* Gets deprecation message. The method *WILL* be removed in 2.0.
*
* @internal
*/
public function getDeprecationMessage() : string
{
return sprintf('%s will be removed in ODM 2.0. Use `@ODM\Field(type="%s")` instead.', static::class, $this->type);
}

/**
* Gets whether the annotation is deprecated. The method *WILL* be removed in 2.0.
*
* @internal
*/
public function isDeprecated() : bool
{
return false;
}
}
11 changes: 6 additions & 5 deletions lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use ProxyManager\Proxy\GhostObjectInterface;
use ReflectionClass;
use ReflectionProperty;
use const E_USER_DEPRECATED;
use function array_filter;
use function array_key_exists;
use function array_keys;
Expand All @@ -41,7 +40,7 @@
use function sprintf;
use function strtolower;
use function strtoupper;
use function trigger_error;
use function trigger_deprecation;

/**
* A <tt>ClassMetadata</tt> instance holds all the object-document mapping metadata
Expand Down Expand Up @@ -1999,11 +1998,13 @@ public function mapField(array $mapping) : array
Type::INTID => Type::INT,
];
if (isset($deprecatedTypes[$mapping['type']])) {
@trigger_error(sprintf(
'"%s" type was deprecated in doctrine/mongodb-odm 2.1 and will be removed in 3.0. Use "%s" instead.',
trigger_deprecation(
'doctrine/mongodb-odm',
'2.1',
'The "%s" mapping type is deprecated. Use "%s" instead.',
$mapping['type'],
$deprecatedTypes[$mapping['type']]
), E_USER_DEPRECATED);
);
}

$this->fieldMappings[$mapping['fieldName']] = $mapping;
Expand Down
32 changes: 13 additions & 19 deletions lib/Doctrine/ODM/MongoDB/Mapping/Driver/AnnotationDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Doctrine\Persistence\Mapping\Driver\AnnotationDriver as AbstractAnnotationDriver;
use ReflectionClass;
use ReflectionMethod;
use const E_USER_DEPRECATED;
use function array_merge;
use function array_replace;
use function assert;
Expand All @@ -25,8 +24,7 @@
use function get_class;
use function interface_exists;
use function is_array;
use function sprintf;
use function trigger_error;
use function trigger_deprecation;

/**
* The AnnotationDriver reads the mapping metadata from docblock annotations.
Expand Down Expand Up @@ -72,12 +70,11 @@ public function loadMetadataForClass($className, \Doctrine\Persistence\Mapping\C
$this->addIndex($class, $annot);
}
if ($annot instanceof ODM\Indexes) {
@trigger_error(
sprintf(
'Indexes annotation used in %s was deprecated in doctrine/mongodb-odm 2.2 and will be removed in 3.0. Specify all Index and UniqueIndex annotations on a class level.',
$className
),
E_USER_DEPRECATED
trigger_deprecation(
'doctrine/mongodb-odm',
'2.2',
'The "@Indexes" annotation used in class "%s" is deprecated. Specify all "@Index" and "@UniqueIndex" annotations on the class.',
$className
);
$value = $annot->value;
foreach (is_array($value) ? $value : [$value] as $index) {
Expand Down Expand Up @@ -150,14 +147,14 @@ public function loadMetadataForClass($className, \Doctrine\Persistence\Mapping\C
$class->setWriteConcern($documentAnnot->writeConcern);
}
if (isset($documentAnnot->indexes) && count($documentAnnot->indexes)) {
@trigger_error(
sprintf(
'Indexes parameter used in %s\'s %s was deprecated in doctrine/mongodb-odm 2.2 and will be removed in 3.0. Specify all Index and UniqueIndex annotations on a class level.',
$className,
get_class($documentAnnot)
),
E_USER_DEPRECATED
trigger_deprecation(
'doctrine/mongodb-odm',
'2.2',
'The "indexes" parameter in the "%s" annotation for class "%s" is deprecated. Specify all "@Index" and "@UniqueIndex" annotations on the class.',
$className,
get_class($documentAnnot)
);

foreach ($documentAnnot->indexes as $index) {
$this->addIndex($class, $index);
}
Expand All @@ -180,9 +177,6 @@ public function loadMetadataForClass($className, \Doctrine\Persistence\Mapping\C
foreach ($this->reader->getPropertyAnnotations($property) as $annot) {
if ($annot instanceof ODM\AbstractField) {
$fieldAnnot = $annot;
if ($annot->isDeprecated()) {
@trigger_error($annot->getDeprecationMessage(), E_USER_DEPRECATED);
}
}
if ($annot instanceof ODM\AbstractIndex) {
$indexes[] = $annot;
Expand Down

0 comments on commit 3bdfe97

Please sign in to comment.