Skip to content

Commit d2678f7

Browse files
MaerF0x0jmikola
authored andcommitted
CS and documentation fixes
Updated docs to support IDE autocompletion and hinting. Re-ordered "use" statements, and removed unnecessary ones. Fixed some class references (e.g. "InvalidArgumentException" becomes "\InvalidArgumentException"). Additional revisions from @jmikola. Closes doctrine#549
1 parent 6fd7a46 commit d2678f7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+822
-514
lines changed

lib/Doctrine/ODM/MongoDB/Configuration.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919

2020
namespace Doctrine\ODM\MongoDB;
2121

22-
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
23-
use Doctrine\ODM\MongoDB\Mapping\Driver\PHPDriver;
22+
use Doctrine\Common\Annotations\AnnotationReader;
2423
use Doctrine\Common\Cache\Cache;
24+
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
25+
use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver;
2526

2627
/**
2728
* Configuration class for the DocumentManager. When setting up your DocumentManager
@@ -79,7 +80,7 @@ public function getDocumentNamespaces()
7980
/**
8081
* Set the document alias map
8182
*
82-
* @param array $documentAliasMap
83+
* @param array $documentNamespaces
8384
* @return void
8485
*/
8586
public function setDocumentNamespaces(array $documentNamespaces)
@@ -107,9 +108,9 @@ public function setMetadataDriverImpl(MappingDriver $driverImpl)
107108
*/
108109
public function newDefaultAnnotationDriver($paths = array())
109110
{
110-
$reader = new \Doctrine\Common\Annotations\AnnotationReader();
111+
$reader = new AnnotationReader();
111112

112-
return new \Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver($reader, (array) $paths);
113+
return new AnnotationDriver($reader, (array)$paths);
113114
}
114115

115116
/**
@@ -131,7 +132,7 @@ public function getMetadataDriverImpl()
131132
public function getMetadataCacheImpl()
132133
{
133134
return isset($this->attributes['metadataCacheImpl']) ?
134-
$this->attributes['metadataCacheImpl'] : null;
135+
$this->attributes['metadataCacheImpl'] : null;
135136
}
136137

137138
/**
@@ -162,7 +163,7 @@ public function setProxyDir($dir)
162163
public function getProxyDir()
163164
{
164165
return isset($this->attributes['proxyDir']) ?
165-
$this->attributes['proxyDir'] : null;
166+
$this->attributes['proxyDir'] : null;
166167
}
167168

168169
/**
@@ -174,7 +175,7 @@ public function getProxyDir()
174175
public function getAutoGenerateProxyClasses()
175176
{
176177
return isset($this->attributes['autoGenerateProxyClasses']) ?
177-
$this->attributes['autoGenerateProxyClasses'] : true;
178+
$this->attributes['autoGenerateProxyClasses'] : true;
178179
}
179180

180181
/**
@@ -196,7 +197,7 @@ public function setAutoGenerateProxyClasses($bool)
196197
public function getProxyNamespace()
197198
{
198199
return isset($this->attributes['proxyNamespace']) ?
199-
$this->attributes['proxyNamespace'] : null;
200+
$this->attributes['proxyNamespace'] : null;
200201
}
201202

202203
/**
@@ -227,7 +228,7 @@ public function setHydratorDir($dir)
227228
public function getHydratorDir()
228229
{
229230
return isset($this->attributes['hydratorDir']) ?
230-
$this->attributes['hydratorDir'] : null;
231+
$this->attributes['hydratorDir'] : null;
231232
}
232233

233234
/**
@@ -239,7 +240,7 @@ public function getHydratorDir()
239240
public function getAutoGenerateHydratorClasses()
240241
{
241242
return isset($this->attributes['autoGenerateHydratorClasses']) ?
242-
$this->attributes['autoGenerateHydratorClasses'] : true;
243+
$this->attributes['autoGenerateHydratorClasses'] : true;
243244
}
244245

245246
/**
@@ -261,7 +262,7 @@ public function setAutoGenerateHydratorClasses($bool)
261262
public function getHydratorNamespace()
262263
{
263264
return isset($this->attributes['hydratorNamespace']) ?
264-
$this->attributes['hydratorNamespace'] : null;
265+
$this->attributes['hydratorNamespace'] : null;
265266
}
266267

267268
/**
@@ -300,7 +301,7 @@ public function getDefaultDB()
300301
/**
301302
* Set the class metadata factory class name.
302303
*
303-
* @param string $cmf
304+
* @param string $cmfName
304305
*/
305306
public function setClassMetadataFactoryName($cmfName)
306307
{

lib/Doctrine/ODM/MongoDB/Cursor.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
class Cursor extends BaseCursor
3838
{
3939
/**
40-
* The Doctrine\MongoDB\Cursor this object is wrapping
40+
* The \Doctrine\MongoDB\Cursor this object is wrapping
4141
*
42-
* @var Doctrine\MongoDB\Cursor $baseCursor
42+
* @var \Doctrine\MongoDB\Cursor $baseCursor
4343
*/
4444
private $baseCursor;
4545

@@ -60,14 +60,14 @@ class Cursor extends BaseCursor
6060
/**
6161
* The UnitOfWork used to coordinate object-level transactions.
6262
*
63-
* @var Doctrine\ODM\MongoDB\UnitOfWork
63+
* @var UnitOfWork
6464
*/
6565
private $unitOfWork;
6666

6767
/**
6868
* The ClassMetadata instance.
6969
*
70-
* @var Doctrine\ODM\MongoDB\Mapping\ClassMetadata
70+
* @var Mapping\ClassMetadata
7171
*/
7272
private $class;
7373

@@ -83,7 +83,7 @@ public function __construct(Connection $connection, Collection $collection, Unit
8383
/**
8484
* Gets the base cursor.
8585
*
86-
* @return Doctrine\MongoDB\Cursor $baseCursor
86+
* @return \Doctrine\MongoDB\Cursor $baseCursor
8787
*/
8888
public function getBaseCursor()
8989
{
@@ -134,6 +134,7 @@ public function getNext()
134134
* Set whether to hydrate the documents to objects or not.
135135
*
136136
* @param boolean $bool
137+
* @return self
137138
*/
138139
public function hydrate($bool = true)
139140
{
@@ -145,6 +146,7 @@ public function hydrate($bool = true)
145146
* Sets whether to refresh the documents data if it already exists in the identity map.
146147
*
147148
* @param boolean $bool
149+
* @return self
148150
*/
149151
public function refresh($bool = true)
150152
{

lib/Doctrine/ODM/MongoDB/DocumentManager.php

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,13 @@
1919

2020
namespace Doctrine\ODM\MongoDB;
2121

22+
use Doctrine\Common\EventManager;
23+
use Doctrine\Common\Persistence\ObjectManager;
24+
use Doctrine\MongoDB\Connection;
25+
use Doctrine\ODM\MongoDB\Hydrator\HydratorFactory;
2226
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
2327
use Doctrine\ODM\MongoDB\Mapping\ClassMetadataFactory;
24-
use Doctrine\ODM\MongoDB\Mapping\Driver\PHPDriver;
25-
use Doctrine\MongoDB\Connection;
26-
use Doctrine\ODM\MongoDB\PersistentCollection;
2728
use Doctrine\ODM\MongoDB\Proxy\ProxyFactory;
28-
use Doctrine\Common\Collections\ArrayCollection;
29-
use Doctrine\Common\EventManager;
30-
use Doctrine\ODM\MongoDB\Hydrator\HydratorFactory;
31-
use Doctrine\Common\Persistence\ObjectManager;
3229
use Doctrine\ODM\MongoDB\Query\FilterCollection;
3330

3431
/**
@@ -84,7 +81,7 @@ class DocumentManager implements ObjectManager
8481
/**
8582
* The event manager that is the central point of the event system.
8683
*
87-
* @var Doctrine\Common\EventManager
84+
* @var \Doctrine\Common\EventManager
8885
*/
8986
private $eventManager;
9087

@@ -98,7 +95,7 @@ class DocumentManager implements ObjectManager
9895
/**
9996
* SchemaManager instance
10097
*
101-
* @var Doctrine\ODM\MongoDB\SchemaManager
98+
* @var SchemaManager
10299
*/
103100
private $schemaManager;
104101

@@ -130,7 +127,6 @@ class DocumentManager implements ObjectManager
130127
*/
131128
private $cmd;
132129

133-
134130
/**
135131
* Collection of query filters.
136132
*
@@ -146,8 +142,7 @@ class DocumentManager implements ObjectManager
146142
* @param Configuration|null $config
147143
* @param \Doctrine\Common\EventManager|null $eventManager
148144
*/
149-
protected function __construct(Connection $conn = null, Configuration $config = null, EventManager $eventManager = null)
150-
{
145+
protected function __construct(Connection $conn = null, Configuration $config = null, EventManager $eventManager = null) {
151146
$this->config = $config ?: new Configuration();
152147
$this->eventManager = $eventManager ?: new EventManager();
153148
$this->cmd = $this->config->getMongoCmd();
@@ -164,21 +159,21 @@ protected function __construct(Connection $conn = null, Configuration $config =
164159
$hydratorDir = $this->config->getHydratorDir();
165160
$hydratorNs = $this->config->getHydratorNamespace();
166161
$this->hydratorFactory = new HydratorFactory(
167-
$this,
168-
$this->eventManager,
169-
$hydratorDir,
170-
$hydratorNs,
171-
$this->config->getAutoGenerateHydratorClasses(),
172-
$this->config->getMongoCmd()
162+
$this,
163+
$this->eventManager,
164+
$hydratorDir,
165+
$hydratorNs,
166+
$this->config->getAutoGenerateHydratorClasses(),
167+
$this->config->getMongoCmd()
173168
);
174169

175170
$this->unitOfWork = new UnitOfWork($this, $this->eventManager, $this->hydratorFactory, $this->cmd);
176171
$this->hydratorFactory->setUnitOfWork($this->unitOfWork);
177172
$this->schemaManager = new SchemaManager($this, $this->metadataFactory);
178173
$this->proxyFactory = new ProxyFactory($this,
179-
$this->config->getProxyDir(),
180-
$this->config->getProxyNamespace(),
181-
$this->config->getAutoGenerateProxyClasses()
174+
$this->config->getProxyDir(),
175+
$this->config->getProxyNamespace(),
176+
$this->config->getAutoGenerateProxyClasses()
182177
);
183178
}
184179

@@ -325,6 +320,7 @@ public function getDocumentDatabases()
325320
* Returns the MongoCollection instance for a class.
326321
*
327322
* @param string $className The class name.
323+
* @throws MongoDBException When the $className param is not mapped to a collection
328324
* @return \Doctrine\MongoDB\Collection
329325
*/
330326
public function getDocumentCollection($className)
@@ -382,10 +378,11 @@ public function createQueryBuilder($documentName = null)
382378
* this DocumentManager as NEW. Do not pass detached documents to the persist operation.
383379
*
384380
* @param object $document The instance to make managed and persistent.
381+
* @throws \InvalidArgumentException When the given $document param is not an object
385382
*/
386383
public function persist($document)
387384
{
388-
if (!is_object($document)) {
385+
if ( ! is_object($document)) {
389386
throw new \InvalidArgumentException(gettype($document));
390387
}
391388
$this->errorIfClosed();
@@ -399,10 +396,11 @@ public function persist($document)
399396
* or as a result of the flush operation.
400397
*
401398
* @param object $document The document instance to remove.
399+
* @throws \InvalidArgumentException when the $document param is not an object
402400
*/
403401
public function remove($document)
404402
{
405-
if (!is_object($document)) {
403+
if ( ! is_object($document)) {
406404
throw new \InvalidArgumentException(gettype($document));
407405
}
408406
$this->errorIfClosed();
@@ -414,10 +412,11 @@ public function remove($document)
414412
* overriding any local changes that have not yet been persisted.
415413
*
416414
* @param object $document The document to refresh.
415+
* @throws \InvalidArgumentException When the given $document param is not an object
417416
*/
418417
public function refresh($document)
419418
{
420-
if (!is_object($document)) {
419+
if ( ! is_object($document)) {
421420
throw new \InvalidArgumentException(gettype($document));
422421
}
423422
$this->errorIfClosed();
@@ -432,10 +431,11 @@ public function refresh($document)
432431
* reference it.
433432
*
434433
* @param object $document The document to detach.
434+
* @throws \InvalidArgumentException when the $document param is not an object
435435
*/
436436
public function detach($document)
437437
{
438-
if (!is_object($document)) {
438+
if ( ! is_object($document)) {
439439
throw new \InvalidArgumentException(gettype($document));
440440
}
441441
$this->unitOfWork->detach($document);
@@ -447,11 +447,13 @@ public function detach($document)
447447
* The document passed to merge will not become associated/managed with this DocumentManager.
448448
*
449449
* @param object $document The detached document to merge into the persistence context.
450+
* @throws LockException
451+
* @throws \InvalidArgumentException if the $document param is not an object
450452
* @return object The managed copy of the document.
451453
*/
452454
public function merge($document)
453455
{
454-
if (!is_object($document)) {
456+
if ( ! is_object($document)) {
455457
throw new \InvalidArgumentException(gettype($document));
456458
}
457459
$this->errorIfClosed();
@@ -464,12 +466,11 @@ public function merge($document)
464466
* @param object $document
465467
* @param int $lockMode
466468
* @param int $lockVersion
467-
* @throws LockException
468-
* @throws LockException
469+
* @throws \InvalidArgumentException
469470
*/
470471
public function lock($document, $lockMode, $lockVersion = null)
471472
{
472-
if (!is_object($document)) {
473+
if ( ! is_object($document)) {
473474
throw new \InvalidArgumentException(gettype($document));
474475
}
475476
$this->unitOfWork->lock($document, $lockMode, $lockVersion);
@@ -479,10 +480,11 @@ public function lock($document, $lockMode, $lockVersion = null)
479480
* Releases a lock on the given document.
480481
*
481482
* @param object $document
483+
* @throws \InvalidArgumentException if the $document param is not an object
482484
*/
483485
public function unlock($document)
484486
{
485-
if (!is_object($document)) {
487+
if ( ! is_object($document)) {
486488
throw new \InvalidArgumentException(gettype($document));
487489
}
488490
$this->unitOfWork->unlock($document);
@@ -521,10 +523,11 @@ public function getRepository($documentName)
521523
*
522524
* @param object $document
523525
* @param array $options Array of options to be used with batchInsert(), update() and remove()
526+
* @throws \InvalidArgumentException
524527
*/
525528
public function flush($document = null, array $options = array())
526529
{
527-
if (null !== $document && !is_object($document) && !is_array($document)) {
530+
if (null !== $document && ! is_object($document) && ! is_array($document)) {
528531
throw new \InvalidArgumentException(gettype($document));
529532
}
530533
$this->errorIfClosed();
@@ -636,16 +639,17 @@ public function close()
636639
* Determines whether a document instance is managed in this DocumentManager.
637640
*
638641
* @param object $document
642+
* @throws \InvalidArgumentException When the $document param is not an object
639643
* @return boolean TRUE if this DocumentManager currently manages the given document, FALSE otherwise.
640644
*/
641645
public function contains($document)
642646
{
643-
if (!is_object($document)) {
647+
if ( ! is_object($document)) {
644648
throw new \InvalidArgumentException(gettype($document));
645649
}
646650
return $this->unitOfWork->isScheduledForInsert($document) ||
647-
$this->unitOfWork->isInIdentityMap($document) &&
648-
! $this->unitOfWork->isScheduledForDelete($document);
651+
$this->unitOfWork->isInIdentityMap($document) &&
652+
! $this->unitOfWork->isScheduledForDelete($document);
649653
}
650654

651655
/**
@@ -683,11 +687,12 @@ public function getClassNameFromDiscriminatorValue(array $mapping, $value)
683687
* @param mixed $document A document object
684688
* @param array $referenceMapping Mapping for the field the references the document
685689
*
690+
* @throws \InvalidArgumentException
686691
* @return array A DBRef array
687692
*/
688693
public function createDBRef($document, array $referenceMapping = null)
689694
{
690-
if (!is_object($document)) {
695+
if ( ! is_object($document)) {
691696
throw new \InvalidArgumentException('Cannot create a DBRef, the document is not an object');
692697
}
693698
$className = get_class($document);

0 commit comments

Comments
 (0)