Skip to content

Commit bc65629

Browse files
committed
Replace private methods with generate_index_name() function
1 parent 3028dfd commit bc65629

File tree

2 files changed

+2
-38
lines changed

2 files changed

+2
-38
lines changed

src/Model/IndexInput.php

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function __construct(array $index)
5050
}
5151

5252
if ( ! isset($index['name'])) {
53-
$index['name'] = $this->generateName($index['key']);
53+
$index['name'] = \MongoDB\generate_index_name($index['key']);
5454
}
5555

5656
if ( ! is_string($index['name'])) {
@@ -80,22 +80,4 @@ public function bsonSerialize()
8080
{
8181
return $this->index;
8282
}
83-
84-
/**
85-
* Generates an index name from its key specification.
86-
*
87-
* @param array|object $key Document containing fields mapped to values,
88-
* which denote order or an index type
89-
* @return string
90-
*/
91-
private function generateName($key)
92-
{
93-
$name = '';
94-
95-
foreach ($key as $field => $type) {
96-
$name .= ($name != '' ? '_' : '') . $field . '_' . $type;
97-
}
98-
99-
return $name;
100-
}
10183
}

src/Operation/Count.php

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function __construct($databaseName, $collectionName, array $filter = arra
4949
{
5050
if (isset($options['hint'])) {
5151
if (is_array($options['hint']) || is_object($options['hint'])) {
52-
$options['hint'] = $this->generateIndexName($options['hint']);
52+
$options['hint'] = \MongoDB\generate_index_name($options['hint']);
5353
}
5454

5555
if ( ! is_string($options['hint'])) {
@@ -121,22 +121,4 @@ private function createCommand()
121121

122122
return new Command($cmd);
123123
}
124-
125-
/**
126-
* Generates an index name from its key specification.
127-
*
128-
* @param array|object $key Document containing fields mapped to values,
129-
* which denote order or an index type
130-
* @return string
131-
*/
132-
private function generateIndexName($key)
133-
{
134-
$name = '';
135-
136-
foreach ($key as $field => $type) {
137-
$name .= ($name != '' ? '_' : '') . $field . '_' . $type;
138-
}
139-
140-
return $name;
141-
}
142124
}

0 commit comments

Comments
 (0)