From bc65629c772a53c57b4f5debad6aae5b76c9a01c Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Sun, 14 Jun 2015 22:26:12 -0400 Subject: [PATCH] Replace private methods with generate_index_name() function --- src/Model/IndexInput.php | 20 +------------------- src/Operation/Count.php | 20 +------------------- 2 files changed, 2 insertions(+), 38 deletions(-) diff --git a/src/Model/IndexInput.php b/src/Model/IndexInput.php index dc6338f7e..db4288992 100644 --- a/src/Model/IndexInput.php +++ b/src/Model/IndexInput.php @@ -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'])) { @@ -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; - } } diff --git a/src/Operation/Count.php b/src/Operation/Count.php index a4ec031d9..8eb93b00e 100644 --- a/src/Operation/Count.php +++ b/src/Operation/Count.php @@ -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'])) { @@ -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; - } }