Skip to content

Commit

Permalink
Replace private methods with generate_index_name() function
Browse files Browse the repository at this point in the history
  • Loading branch information
jmikola committed Jun 18, 2015
1 parent 3028dfd commit bc65629
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 38 deletions.
20 changes: 1 addition & 19 deletions src/Model/IndexInput.php
Expand Up @@ -50,7 +50,7 @@ public function __construct(array $index)
}

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

if ( ! is_string($index['name'])) {
Expand Down Expand Up @@ -80,22 +80,4 @@ public function bsonSerialize()
{
return $this->index;
}

/**
* Generates an index name from its key specification.
*
* @param array|object $key Document containing fields mapped to values,
* which denote order or an index type
* @return string
*/
private function generateName($key)
{
$name = '';

foreach ($key as $field => $type) {
$name .= ($name != '' ? '_' : '') . $field . '_' . $type;
}

return $name;
}
}
20 changes: 1 addition & 19 deletions src/Operation/Count.php
Expand Up @@ -49,7 +49,7 @@ public function __construct($databaseName, $collectionName, array $filter = arra
{
if (isset($options['hint'])) {
if (is_array($options['hint']) || is_object($options['hint'])) {
$options['hint'] = $this->generateIndexName($options['hint']);
$options['hint'] = \MongoDB\generate_index_name($options['hint']);
}

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

return new Command($cmd);
}

/**
* Generates an index name from its key specification.
*
* @param array|object $key Document containing fields mapped to values,
* which denote order or an index type
* @return string
*/
private function generateIndexName($key)
{
$name = '';

foreach ($key as $field => $type) {
$name .= ($name != '' ? '_' : '') . $field . '_' . $type;
}

return $name;
}
}

0 comments on commit bc65629

Please sign in to comment.