Skip to content

Commit e223a19

Browse files
committed
Rely on default type map conversion
1 parent 4b84bd9 commit e223a19

File tree

9 files changed

+7
-37
lines changed

9 files changed

+7
-37
lines changed

src/Operation/Aggregate.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,8 @@ public function execute(Server $server)
122122
return $cursor;
123123
}
124124

125-
$cursor->setTypeMap(array('document' => 'stdClass'));
126125
$result = current($cursor->toArray());
127126

128-
// TODO: Remove this once PHPC-318 is implemented
129-
is_array($result) and $result = (object) $result;
130-
131127
if (empty($result->ok)) {
132128
throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error');
133129
}

src/Operation/Count.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,18 @@ public function __construct($databaseName, $collectionName, array $filter = arra
8585
public function execute(Server $server)
8686
{
8787
$cursor = $server->executeCommand($this->databaseName, $this->createCommand());
88-
$cursor->setTypeMap(array('root' => 'array', 'document' => 'array'));
8988
$result = current($cursor->toArray());
9089

91-
if (empty($result['ok'])) {
92-
throw new RuntimeException(isset($result['errmsg']) ? $result['errmsg'] : 'Unknown error');
90+
if (empty($result->ok)) {
91+
throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error');
9392
}
9493

9594
// Older server versions may return a float
96-
if ( ! isset($result['n']) || ! (is_integer($result['n']) || is_float($result['n']))) {
97-
throw new UnexpectedValueException('count command did not return an "n" value');
95+
if ( ! isset($result->n) || ! (is_integer($result->n) || is_float($result->n))) {
96+
throw new UnexpectedValueException('count command did not return a numeric "n" value');
9897
}
9998

100-
return (integer) $result['n'];
99+
return (integer) $result->n;
101100
}
102101

103102
/**

src/Operation/CreateCollection.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,8 @@ public function __construct($databaseName, $collectionName, array $options = arr
102102
public function execute(Server $server)
103103
{
104104
$cursor = $server->executeCommand($this->databaseName, $this->createCommand());
105-
$cursor->setTypeMap(array('document' => 'stdClass'));
106105
$result = current($cursor->toArray());
107106

108-
// TODO: Remove this once PHPC-318 is implemented
109-
is_array($result) and $result = (object) $result;
110-
111107
if (empty($result->ok)) {
112108
throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error');
113109
}

src/Operation/CreateIndexes.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,10 @@ private function executeCommand(Server $server)
9191
));
9292

9393
$cursor = $server->executeCommand($this->databaseName, $command);
94-
$cursor->setTypeMap(array('root' => 'array', 'document' => 'array'));
9594
$result = current($cursor->toArray());
9695

97-
if (empty($result['ok'])) {
98-
throw new RuntimeException(isset($result['errmsg']) ? $result['errmsg'] : 'Unknown error');
96+
if (empty($result->ok)) {
97+
throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error');
9998
}
10099
}
101100

src/Operation/Distinct.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,8 @@ public function __construct($databaseName, $collectionName, $fieldName, array $f
6262
public function execute(Server $server)
6363
{
6464
$cursor = $server->executeCommand($this->databaseName, $this->createCommand());
65-
$cursor->setTypeMap(array('document' => 'stdClass'));
6665
$result = current($cursor->toArray());
6766

68-
// TODO: Remove this once PHPC-318 is implemented
69-
is_array($result) and $result = (object) $result;
70-
7167
if (empty($result->ok)) {
7268
throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error');
7369
}

src/Operation/DropCollection.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,8 @@ public function __construct($databaseName, $collectionName)
4141
public function execute(Server $server)
4242
{
4343
$cursor = $server->executeCommand($this->databaseName, new Command(array('drop' => $this->collectionName)));
44-
$cursor->setTypeMap(array('document' => 'stdClass'));
4544
$result = current($cursor->toArray());
4645

47-
// TODO: Remove this once PHPC-318 is implemented
48-
is_array($result) and $result = (object) $result;
49-
5046
if (empty($result->ok)) {
5147
throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error');
5248
}

src/Operation/DropDatabase.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,8 @@ public function __construct($databaseName)
3939
public function execute(Server $server)
4040
{
4141
$cursor = $server->executeCommand($this->databaseName, new Command(array('dropDatabase' => 1)));
42-
$cursor->setTypeMap(array('document' => 'stdClass'));
4342
$result = current($cursor->toArray());
4443

45-
// TODO: Remove this once PHPC-318 is implemented
46-
is_array($result) and $result = (object) $result;
47-
4844
if (empty($result->ok)) {
4945
throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error');
5046
}

src/Operation/DropIndexes.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,8 @@ public function execute(Server $server)
5656
);
5757

5858
$cursor = $server->executeCommand($this->databaseName, new Command($cmd));
59-
$cursor->setTypeMap(array('document' => 'stdClass'));
6059
$result = current($cursor->toArray());
6160

62-
// TODO: Remove this once PHPC-318 is implemented
63-
is_array($result) and $result = (object) $result;
64-
6561
if (empty($result->ok)) {
6662
throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error');
6763
}

src/Operation/FindAndModify.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,8 @@ public function __construct($databaseName, $collectionName, array $options)
118118
public function execute(Server $server)
119119
{
120120
$cursor = $server->executeCommand($this->databaseName, $this->createCommand());
121-
$cursor->setTypeMap(array('document' => 'stdClass'));
122121
$result = current($cursor->toArray());
123122

124-
// TODO: Remove this once PHPC-318 is implemented
125-
is_array($result) and $result = (object) $result;
126-
127123
if (empty($result->ok)) {
128124
throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error');
129125
}

0 commit comments

Comments
 (0)