Skip to content

Commit 4dd1659

Browse files
committed
Reorder methods for reasons of pedantry
1 parent af42e76 commit 4dd1659

File tree

6 files changed

+84
-84
lines changed

6 files changed

+84
-84
lines changed

src/Client.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,44 +79,44 @@ public function listDatabases()
7979
}
8080

8181
/**
82-
* Select a database.
82+
* Select a collection.
8383
*
8484
* If a write concern or read preference is not specified, the write concern
8585
* or read preference of the Client will be applied, respectively.
8686
*
87-
* @param string $databaseName Name of the database to select
87+
* @param string $databaseName Name of the database containing the collection
88+
* @param string $collectionName Name of the collection to select
8889
* @param WriteConcern $writeConcern Default write concern to apply
8990
* @param ReadPreference $readPreference Default read preference to apply
90-
* @return Database
91+
* @return Collection
9192
*/
92-
public function selectDatabase($databaseName, WriteConcern $writeConcern = null, ReadPreference $readPreference = null)
93+
public function selectCollection($databaseName, $collectionName, WriteConcern $writeConcern = null, ReadPreference $readPreference = null)
9394
{
95+
$namespace = $databaseName . '.' . $collectionName;
9496
// TODO: inherit from Manager options once PHPC-196 is implemented
9597
$writeConcern = $writeConcern ?: $this->writeConcern;
9698
$readPreference = $readPreference ?: $this->readPreference;
9799

98-
return new Database($this->manager, $databaseName, $writeConcern, $readPreference);
100+
return new Collection($this->manager, $namespace, $writeConcern, $readPreference);
99101
}
100102

101103
/**
102-
* Select a collection.
104+
* Select a database.
103105
*
104106
* If a write concern or read preference is not specified, the write concern
105107
* or read preference of the Client will be applied, respectively.
106108
*
107-
* @param string $databaseName Name of the database containing the collection
108-
* @param string $collectionName Name of the collection to select
109+
* @param string $databaseName Name of the database to select
109110
* @param WriteConcern $writeConcern Default write concern to apply
110111
* @param ReadPreference $readPreference Default read preference to apply
111-
* @return Collection
112+
* @return Database
112113
*/
113-
public function selectCollection($databaseName, $collectionName, WriteConcern $writeConcern = null, ReadPreference $readPreference = null)
114+
public function selectDatabase($databaseName, WriteConcern $writeConcern = null, ReadPreference $readPreference = null)
114115
{
115-
$namespace = $databaseName . '.' . $collectionName;
116116
// TODO: inherit from Manager options once PHPC-196 is implemented
117117
$writeConcern = $writeConcern ?: $this->writeConcern;
118118
$readPreference = $readPreference ?: $this->readPreference;
119119

120-
return new Collection($this->manager, $namespace, $writeConcern, $readPreference);
120+
return new Database($this->manager, $databaseName, $writeConcern, $readPreference);
121121
}
122122
}

src/Model/CollectionInfo.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,53 +28,53 @@ public function __construct(array $info)
2828
}
2929

3030
/**
31-
* Return the collection name.
31+
* Return the maximum number of documents to keep in the capped collection.
3232
*
33-
* @return string
33+
* @return integer|null
3434
*/
35-
public function getName()
35+
public function getCappedMax()
3636
{
37-
return (string) $this->info['name'];
37+
return isset($this->info['options']['max']) ? (integer) $this->info['options']['max'] : null;
3838
}
3939

4040
/**
41-
* Return the collection options.
41+
* Return the maximum size (in bytes) of the capped collection.
4242
*
43-
* @return array
43+
* @return integer|null
4444
*/
45-
public function getOptions()
45+
public function getCappedSize()
4646
{
47-
return isset($this->info['options']) ? (array) $this->info['options'] : array();
47+
return isset($this->info['options']['size']) ? (integer) $this->info['options']['size'] : null;
4848
}
4949

5050
/**
51-
* Return whether the collection is a capped collection.
51+
* Return the collection name.
5252
*
53-
* @return boolean
53+
* @return string
5454
*/
55-
public function isCapped()
55+
public function getName()
5656
{
57-
return ! empty($this->info['options']['capped']);
57+
return (string) $this->info['name'];
5858
}
5959

6060
/**
61-
* Return the maximum number of documents to keep in the capped collection.
61+
* Return the collection options.
6262
*
63-
* @return integer|null
63+
* @return array
6464
*/
65-
public function getCappedMax()
65+
public function getOptions()
6666
{
67-
return isset($this->info['options']['max']) ? (integer) $this->info['options']['max'] : null;
67+
return isset($this->info['options']) ? (array) $this->info['options'] : array();
6868
}
6969

7070
/**
71-
* Return the maximum size (in bytes) of the capped collection.
71+
* Return whether the collection is a capped collection.
7272
*
73-
* @return integer|null
73+
* @return boolean
7474
*/
75-
public function getCappedSize()
75+
public function isCapped()
7676
{
77-
return isset($this->info['options']['size']) ? (integer) $this->info['options']['size'] : null;
77+
return ! empty($this->info['options']['capped']);
7878
}
7979

8080
/**

src/Model/CollectionInfoLegacyIterator.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,6 @@ public function __construct(Traversable $iterator)
4040
parent::__construct($iterator);
4141
}
4242

43-
/**
44-
* Return the current element as a CollectionInfo instance.
45-
*
46-
* @see CollectionInfoIterator::current()
47-
* @see http://php.net/iterator.current
48-
* @return CollectionInfo
49-
*/
50-
public function current()
51-
{
52-
$info = parent::current();
53-
54-
// Trim the database prefix up to and including the first dot
55-
$firstDot = strpos($info['name'], '.');
56-
57-
if ($firstDot !== false) {
58-
$info['name'] = (string) substr($info['name'], $firstDot + 1);
59-
}
60-
61-
return new CollectionInfo($info);
62-
}
63-
6443
/**
6544
* Filter out internal or invalid collections.
6645
*
@@ -92,4 +71,25 @@ public function accept()
9271

9372
return true;
9473
}
74+
75+
/**
76+
* Return the current element as a CollectionInfo instance.
77+
*
78+
* @see CollectionInfoIterator::current()
79+
* @see http://php.net/iterator.current
80+
* @return CollectionInfo
81+
*/
82+
public function current()
83+
{
84+
$info = parent::current();
85+
86+
// Trim the database prefix up to and including the first dot
87+
$firstDot = strpos($info['name'], '.');
88+
89+
if ($firstDot !== false) {
90+
$info['name'] = (string) substr($info['name'], $firstDot + 1);
91+
}
92+
93+
return new CollectionInfo($info);
94+
}
9595
}

src/Model/DatabaseInfo.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ public function __construct(array $info)
2626
$this->info = $info;
2727
}
2828

29+
/**
30+
* Return the collection info as an array.
31+
*
32+
* @see http://php.net/oop5.magic#language.oop5.magic.debuginfo
33+
* @return array
34+
*/
35+
public function __debugInfo()
36+
{
37+
return $this->info;
38+
}
39+
2940
/**
3041
* Return the database name.
3142
*
@@ -55,15 +66,4 @@ public function isEmpty()
5566
{
5667
return (boolean) $this->info['empty'];
5768
}
58-
59-
/**
60-
* Return the collection info as an array.
61-
*
62-
* @see http://php.net/oop5.magic#language.oop5.magic.debuginfo
63-
* @return array
64-
*/
65-
public function __debugInfo()
66-
{
67-
return $this->info;
68-
}
6969
}

src/Model/IndexInfo.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ public function __construct(array $info)
3434
$this->info = $info;
3535
}
3636

37+
/**
38+
* Return the collection info as an array.
39+
*
40+
* @see http://php.net/oop5.magic#language.oop5.magic.debuginfo
41+
* @return array
42+
*/
43+
public function __debugInfo()
44+
{
45+
return $this->info;
46+
}
47+
3748
/**
3849
* Return the index key.
3950
*
@@ -157,15 +168,4 @@ public function offsetUnset($key)
157168
{
158169
throw new BadMethodCallException('IndexInfo is immutable');
159170
}
160-
161-
/**
162-
* Return the collection info as an array.
163-
*
164-
* @see http://php.net/oop5.magic#language.oop5.magic.debuginfo
165-
* @return array
166-
*/
167-
public function __debugInfo()
168-
{
169-
return $this->info;
170-
}
171171
}

src/Model/IndexInput.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,24 +61,24 @@ public function __construct(array $index)
6161
}
6262

6363
/**
64-
* Serialize the index information to BSON for index creation.
64+
* Return the index name.
6565
*
66-
* @see MongoDB\Collection::createIndexes()
67-
* @see http://php.net/bson-serializable.bsonserialize
66+
* @param string
6867
*/
69-
public function bsonSerialize()
68+
public function __toString()
7069
{
71-
return $this->index;
70+
return $this->index['name'];
7271
}
7372

7473
/**
75-
* Return the index name.
74+
* Serialize the index information to BSON for index creation.
7675
*
77-
* @param string
76+
* @see MongoDB\Collection::createIndexes()
77+
* @see http://php.net/bson-serializable.bsonserialize
7878
*/
79-
public function __toString()
79+
public function bsonSerialize()
8080
{
81-
return $this->index['name'];
81+
return $this->index;
8282
}
8383

8484
/**

0 commit comments

Comments
 (0)