Skip to content

Commit 99eef0d

Browse files
committed
Favour bool and int over boolean and integer
1 parent efdde4c commit 99eef0d

11 files changed

+27
-9
lines changed

UPGRADE-2.1.md

+3
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ the `Doctrine\ODM\MongoDB\Id\IdGenerator` interface.
55

66
The `Doctrine\ODM\MongoDB\Mapping\ClassMetadata` class has been marked final. The class will no longer be extendable
77
in ODM 3.0.
8+
9+
The `boolean` and `integer` mapping types have been deprecated. Use their shorthand counterparts: `bool` and `int`
10+
respectively.

docs/en/cookbook/blending-orm-and-mongodb-odm.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Next create the ``Order`` entity that has a ``$product`` and ``$productId`` prop
6161
class Order
6262
{
6363
/**
64-
* @Id @Column(type="integer")
64+
* @Id @Column(type="int")
6565
* @GeneratedValue(strategy="AUTO")
6666
*/
6767
private $id;

docs/en/cookbook/mapping-classes-to-orm-and-odm.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ First define the mapping for the ORM:
5252
/** @Entity(repositoryClass=BlogPostRepository::class) */
5353
class BlogPost
5454
{
55-
/** @Id @Column(type="integer") */
55+
/** @Id @Column(type="int") */
5656
private $id;
5757
5858
/** @Column(type="string") */
@@ -73,7 +73,7 @@ First define the mapping for the ORM:
7373
http://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
7474
7575
<entity name="Documents\Blog\BlogPost" repository-class="Documents\Blog\Repository\ORM\BlogPostRepository">
76-
<id name="id" type="integer" />
76+
<id name="id" type="int" />
7777
<field name="name" type="string" />
7878
<field name="email" type="text" />
7979
</entity>

lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php

+13
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
use function sprintf;
3737
use function strtolower;
3838
use function strtoupper;
39+
use function trigger_error;
3940

4041
/**
4142
* A <tt>ClassMetadata</tt> instance holds all the object-document mapping metadata
@@ -1983,6 +1984,18 @@ public function mapField(array $mapping) : array
19831984
$this->checkDuplicateMapping($mapping);
19841985
$this->typeRequirementsAreMet($mapping);
19851986

1987+
$deprecatedTypes = [
1988+
Type::BOOLEAN => Type::BOOL,
1989+
Type::INTEGER => Type::INT,
1990+
];
1991+
if (isset($deprecatedTypes[$mapping['type']])) {
1992+
@trigger_error(sprintf(
1993+
'"%s" type was deprecated in 2.1 and will be removed in 3.0. Use "%s" instead.',
1994+
$mapping['type'],
1995+
$deprecatedTypes[$mapping['type']]
1996+
));
1997+
}
1998+
19861999
$this->fieldMappings[$mapping['fieldName']] = $mapping;
19872000
if (isset($mapping['association'])) {
19882001
$this->associationMappings[$mapping['fieldName']] = $mapping;

lib/Doctrine/ODM/MongoDB/Types/Type.php

+2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ abstract class Type
2727
public const INTID = 'int_id';
2828
public const CUSTOMID = 'custom_id';
2929
public const BOOL = 'bool';
30+
/** @deprecated const was deprecated in 2.1 and will be removed in 3.0. Use Type::BOOL instead */
3031
public const BOOLEAN = 'boolean';
3132
public const INT = 'int';
33+
/** @deprecated const was deprecated in 2.1 and will be removed in 3.0. Use Type::INT instead */
3234
public const INTEGER = 'integer';
3335
public const FLOAT = 'float';
3436
public const STRING = 'string';

tests/Doctrine/ODM/MongoDB/Tests/Functional/IndexesTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ class PartialIndexOnDocumentTest
268268
/** @ODM\Field(type="string") */
269269
public $email;
270270

271-
/** @ODM\Field(type="integer") */
271+
/** @ODM\Field(type="int") */
272272
public $counter;
273273
}
274274

tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/AbstractDriverTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ public function testDriver()
281281
$this->assertEquals([
282282
'fieldName' => 'count',
283283
'name' => 'count',
284-
'type' => 'integer',
284+
'type' => 'int',
285285
'isCascadeDetach' => false,
286286
'isCascadeMerge' => false,
287287
'isCascadePersist' => false,

tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/fixtures/xml/TestDocuments.QueryResultDocument.dcm.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<query-result-document name="TestDocuments\QueryResultDocument">
99
<field name="name" type="string" />
10-
<field name="count" type="integer" />
10+
<field name="count" type="int" />
1111
</query-result-document>
1212

1313
</doctrine-mongo-mapping>

tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/fixtures/xml/TestDocuments.View.dcm.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<view name="TestDocuments\View">
99
<field name="name" type="string" />
10-
<field name="count" type="integer" />
10+
<field name="count" type="int" />
1111
</view>
1212

1313
</doctrine-mongo-mapping>

tests/Doctrine/ODM/MongoDB/Tests/Mapping/xml/Doctrine.ODM.MongoDB.Tests.Mapping.AbstractMappingDriverUser.dcm.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<field field-name="lock" lock="true" type="int" />
2626
<field field-name="name" name="username" type="string" />
2727
<field field-name="email" type="string" unique="true" drop-dups="true" order="desc" />
28-
<field field-name="mysqlProfileId" type="integer" unique="true" drop-dups="true" order="desc" />
28+
<field field-name="mysqlProfileId" type="int" unique="true" drop-dups="true" order="desc" />
2929
<field field-name="createdAt" type="date" />
3030
<field field-name="roles" type="collection" />
3131
<indexes>

tests/Doctrine/ODM/MongoDB/Tests/Persisters/DocumentPersisterGetShardKeyQueryTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class ShardedByScalars
117117
/** @ODM\Field(type="string") */
118118
public $string;
119119

120-
/** @ODM\Field(type="boolean") */
120+
/** @ODM\Field(type="bool") */
121121
public $bool;
122122

123123
/** @ODM\Field(type="float") */

0 commit comments

Comments
 (0)