Skip to content
This repository was archived by the owner on Jul 31, 2018. It is now read-only.

Commit 8660688

Browse files
committed
convert variables to Snake Case. Fixes issue #13
1 parent 1aacec0 commit 8660688

File tree

6 files changed

+25
-25
lines changed

6 files changed

+25
-25
lines changed

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ class Contact extends \Illuminate\Database\Eloquent\Model
7474

7575
public function getAlgoliaRecord()
7676
{
77-
$extra_data = [
77+
$extraData = [
7878
'custom_name' => 'Custom Name'
7979
];
8080

81-
return array_merge($this->toArray(), $extra_data);
81+
return array_merge($this->toArray(), $extraData);
8282
}
8383
}
8484
```
@@ -92,7 +92,7 @@ class Contact extends \Illuminate\Database\Eloquent\Model
9292
{
9393
use AlgoliaEloquentTrait;
9494

95-
public $algolia_settings = [
95+
public $algoliaSettings = [
9696
'attributesToIndex => ['id', 'name'],
9797
'customRanking => ['desc(popularity)'], 'asc(name)]'
9898
]
@@ -143,15 +143,15 @@ class Contact extends \Illuminate\Database\Eloquent\Model
143143
{
144144
use AlgoliaEloquentTrait;
145145

146-
public $auto_index = false;
147-
public $auto_delete = false;
146+
public $autoIndex = false;
147+
public $autoDelete = false;
148148
}
149149
```
150150

151151
You can temporary disable auto-indexing. This is often used for performance reason.
152152

153153
```php
154-
Contact::$auto_index = false;
154+
Contact::$autoIndex = false;
155155
Contact.clearIndices();
156156

157157
for ($i = 0; $i < 10000; $i++)
@@ -182,7 +182,7 @@ class Contact extends \Illuminate\Database\Eloquent\Model
182182
{
183183
use AlgoliaEloquentTrait;
184184

185-
public $per_environment = true; # index name will be "Contacts_{\App::environnement()}"
185+
public $perEnvironment = true; # index name will be "Contacts_{\App::environnement()}"
186186
}
187187
```
188188

@@ -195,7 +195,7 @@ class Contact extends \Illuminate\Database\Eloquent\Model
195195
{
196196
use AlgoliaEloquentTrait;
197197

198-
public $object_id_key = 'new_key';
198+
public $objectIdKey = 'new_key';
199199
}
200200
```
201201

@@ -271,7 +271,7 @@ class Contact extends \Illuminate\Database\Eloquent\Model
271271
{
272272
use AlgoliaEloquentTrait;
273273

274-
public $algolia_settings = [
274+
public $algoliaSettings = [
275275
'attributesToIndex' => ['id', 'name'],
276276
'customRanking' => ['desc(popularity)', 'asc(name)'],
277277
'slaves' => ['contacts_desc']
@@ -312,9 +312,9 @@ class Contact extends \Illuminate\Database\Eloquent\Model
312312

313313
public $indices = ["contact_public", "contact_private"];
314314

315-
public function indexOnly($index_name)
315+
public function indexOnly($indexName)
316316
{
317-
if ($index_name == "contact_public")
317+
if ($indexName == "contact_public")
318318
return $this->isPublic == 1;
319319

320320
return $this->isPublic == 0;

src/ModelHelper.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ private function hasAlgoliaTrait(Model $model)
2626

2727
public function isAutoIndex(Model $model)
2828
{
29-
return ($this->hasAlgoliaTrait($model) && (property_exists($model, 'auto_index') == false || $model::$auto_index === true));
29+
return ($this->hasAlgoliaTrait($model) && (property_exists($model, 'autoIndex') == false || $model::$autoIndex === true));
3030
}
3131

3232
public function isAutoDelete(Model $model)
3333
{
34-
return ($this->hasAlgoliaTrait($model) && (property_exists($model, 'auto_delete') == false || $model::$auto_delete === true));
34+
return ($this->hasAlgoliaTrait($model) && (property_exists($model, 'autoDelete') == false || $model::$autoDelete === true));
3535
}
3636

3737
public function getKey(Model $model)
@@ -51,17 +51,17 @@ public function getObjectId(Model $model)
5151

5252
public function getObjectIdKey(Model $model)
5353
{
54-
return property_exists($model, 'object_id_key') ? $model->object_id_key : $model->getKeyName();
54+
return property_exists($model, 'objectIdKey') ? $model->objectIdKey : $model->getKeyName();
5555
}
5656

5757
public function getSettings(Model $model)
5858
{
59-
return property_exists($model, 'algolia_settings') ? $model->algolia_settings : [];
59+
return property_exists($model, 'algoliaSettings') ? $model->algoliaSettings : [];
6060
}
6161

6262
public function getSlavesSettings(Model $model)
6363
{
64-
return property_exists($model, 'slaves_settings') ? $model->slaves_settings : [];
64+
return property_exists($model, 'slavesSettings') ? $model->slavesSettings : [];
6565
}
6666

6767
/**
@@ -77,7 +77,7 @@ public function getIndices(Model $model)
7777
$indicesName[] = $this->getIndexName($model);
7878
}
7979

80-
$env_suffix = property_exists($model, 'per_environment') && $model->per_environment === true ? '_'.\App::environment() : '';
80+
$env_suffix = property_exists($model, 'perEnvironment') && $model->perEnvironment === true ? '_'.\App::environment() : '';
8181

8282
$indices = array_map(function ($index_name) use ($env_suffix) {
8383
return $this->algolia->initIndex($index_name.$env_suffix);
@@ -96,7 +96,7 @@ public function getIndicesTmp(Model $model)
9696
$indicesName[] = $this->getIndexName($model);
9797
}
9898

99-
$env_suffix = property_exists($model, 'per_environment') && $model->per_environment === true ? '_'.\App::environment() : '';
99+
$env_suffix = property_exists($model, 'perEnvironment') && $model->perEnvironment === true ? '_'.\App::environment() : '';
100100

101101
$indices = array_map(function ($index_name) use ($env_suffix) {
102102
return $this->algolia->initIndex($index_name.$env_suffix.'_tmp');

tests/Models/Model2.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ class Model2 extends Model
99
{
1010
use AlgoliaEloquentTrait;
1111

12-
public static $auto_index = false;
13-
public static $auto_delete = false;
12+
public static $autoIndex = false;
13+
public static $autoDelete = false;
1414

1515
protected $primaryKey = 'id2';
1616

tests/Models/Model3.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66

77
class Model3 extends Model
88
{
9-
public static $auto_index = true;
10-
public static $auto_delete = true;
9+
public static $autoIndex = true;
10+
public static $autoDelete = true;
1111
}

tests/Models/Model4.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ class Model4 extends Model
99
{
1010
use AlgoliaEloquentTrait;
1111

12-
public $object_id_key = 'id3';
12+
public $objectIdKey = 'id3';
1313

1414
protected $primaryKey = 'id2';
1515

16-
public $per_environment = false;
16+
public $perEnvironment = false;
1717

1818
public function __construct()
1919
{

tests/Models/Model5.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ class Model5 extends Model
99
{
1010
use AlgoliaEloquentTrait;
1111

12-
public $per_environment = true;
12+
public $perEnvironment = true;
1313
}

0 commit comments

Comments
 (0)