Skip to content

Commit fa01d30

Browse files
committed
PSR-2 code formatted, php syntax to >=5.4
1 parent 03aa15d commit fa01d30

21 files changed

+327
-187
lines changed

src/ElasticquentClientTrait.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
trait ElasticquentClientTrait
66
{
7+
78
use ElasticquentConfigTrait;
89

10+
911
/**
1012
* Get ElasticSearch Client
1113
*

src/ElasticquentCollectionTrait.php

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
*/
99
trait ElasticquentCollectionTrait
1010
{
11+
1112
use ElasticquentClientTrait;
1213

14+
1315
/**
1416
* Add To Index
1517
*
@@ -23,23 +25,24 @@ public function addToIndex()
2325
return null;
2426
}
2527

26-
$params = array();
28+
$params = [];
2729

2830
foreach ($this->all() as $item) {
29-
$params['body'][] = array(
30-
'index' => array(
31-
'_id' => $item->getKey(),
32-
'_type' => $item->getTypeName(),
31+
$params['body'][] = [
32+
'index' => [
33+
'_id' => $item->getKey(),
34+
'_type' => $item->getTypeName(),
3335
'_index' => $item->getIndexName(),
34-
),
35-
);
36+
],
37+
];
3638

3739
$params['body'][] = $item->getIndexDocumentData();
3840
}
3941

4042
return $this->getElasticSearchClient()->bulk($params);
4143
}
4244

45+
4346
/**
4447
* Delete From Index
4548
*
@@ -49,21 +52,22 @@ public function deleteFromIndex()
4952
{
5053
$all = $this->all();
5154

52-
$params = array();
55+
$params = [];
5356

5457
foreach ($all as $item) {
55-
$params['body'][] = array(
56-
'delete' => array(
57-
'_id' => $item->getKey(),
58-
'_type' => $item->getTypeName(),
58+
$params['body'][] = [
59+
'delete' => [
60+
'_id' => $item->getKey(),
61+
'_type' => $item->getTypeName(),
5962
'_index' => $item->getIndexName(),
60-
),
61-
);
63+
],
64+
];
6265
}
6366

6467
return $this->getElasticSearchClient()->bulk($params);
6568
}
6669

70+
6771
/**
6872
* Reindex
6973
*
@@ -74,6 +78,7 @@ public function deleteFromIndex()
7478
public function reindex()
7579
{
7680
$this->deleteFromIndex();
81+
7782
return $this->addToIndex();
7883
}
7984

src/ElasticquentConfigTrait.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
trait ElasticquentConfigTrait
66
{
7+
78
/**
89
* Get Index Name
910
*
@@ -15,19 +16,21 @@ public function getIndexName()
1516
// config file and if there is a default index.
1617
$index_name = $this->getElasticConfig('default_index');
1718

18-
if (!empty($index_name)) {
19+
if ( ! empty($index_name)) {
1920
return $index_name;
2021
}
2122

2223
// Otherwise we will just go with 'default'
2324
return 'default';
2425
}
2526

27+
2628
/**
2729
* Get the Elasticquent config
2830
*
29-
* @param string $key the configuration key
31+
* @param string $key the configuration key
3032
* @param string $prefix filename of configuration file
33+
*
3134
* @return array configuration
3235
*/
3336
public function getElasticConfig($key = 'config', $prefix = 'elasticquent')
@@ -48,6 +51,7 @@ public function getElasticConfig($key = 'config', $prefix = 'elasticquent')
4851
return $config_helper->get($key);
4952
}
5053

54+
5155
/**
5256
* Inject given config file into an instance of Laravel's config
5357
*
@@ -58,18 +62,19 @@ protected function getConfigHelper()
5862
{
5963
$config_file = $this->getConfigFile();
6064

61-
if (!file_exists($config_file)) {
65+
if ( ! file_exists($config_file)) {
6266
throw new \Exception('Config file not found.');
6367
}
6468

65-
return new \Illuminate\Config\Repository(array('elasticquent' => require($config_file)));
69+
return new \Illuminate\Config\Repository(['elasticquent' => require($config_file)]);
6670
}
6771

72+
6873
/**
6974
* Get the config path and file name to use when Laravel framework isn't present
7075
* e.g. using Eloquent stand-alone or running unit tests
7176
*
72-
* @return string config file path
77+
* @return string config file path
7378
*/
7479
protected function getConfigFile()
7580
{

src/ElasticquentElasticsearchFacade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010
class ElasticquentElasticsearchFacade extends Facade
1111
{
12+
1213
/**
1314
* Get the registered name of the component.
1415
*

src/ElasticquentInterface.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,24 @@
22

33
interface ElasticquentInterface
44
{
5+
56
/**
67
* Get ElasticSearch Client
78
*
89
* @return Elasticsearch\Client
910
*/
1011
public function getElasticSearchClient();
1112

13+
1214
/**
1315
* New Collection
1416
*
1517
* @param array $models
18+
*
1619
* @return Collection
1720
*/
18-
public function newCollection(array $models = array());
21+
public function newCollection(array $models = []);
22+
1923

2024
/**
2125
* Get Index Name
@@ -24,32 +28,37 @@ public function newCollection(array $models = array());
2428
*/
2529
public function getIndexName();
2630

31+
2732
/**
2833
* Get Type Name
2934
*
3035
* @return string
3136
*/
3237
public function getTypeName();
3338

39+
3440
/**
3541
* Uses Timestamps In Index.
3642
*/
3743
public function usesTimestampsInIndex();
3844

45+
3946
/**
4047
* Get Mapping Properties
4148
*
4249
* @return array
4350
*/
4451
public function getMappingProperties();
4552

53+
4654
/**
4755
* Set Mapping Properties
4856
*
4957
* @param array $mapping
5058
*/
5159
public function setMappingProperties(array $mapping = null);
5260

61+
5362
/**
5463
* Get Index Document Data
5564
*
@@ -60,6 +69,7 @@ public function setMappingProperties(array $mapping = null);
6069
*/
6170
public function getIndexDocumentData();
6271

72+
6373
/**
6474
* Index Documents
6575
*
@@ -69,10 +79,12 @@ public function getIndexDocumentData();
6979
*/
7080
public static function addAllToIndex();
7181

82+
7283
/**
7384
* Search a Type.
7485
*/
75-
public static function search($query = array());
86+
public static function search($query = []);
87+
7688

7789
/**
7890
* Add to Search Index
@@ -81,13 +93,15 @@ public static function search($query = array());
8193
*/
8294
public function addToIndex();
8395

96+
8497
/**
8598
* Remove From Search Index
8699
*
87100
* @return
88101
*/
89102
public function removeFromIndex();
90103

104+
91105
/**
92106
* Get Search Document
93107
*
@@ -98,6 +112,7 @@ public function removeFromIndex();
98112
*/
99113
public function getIndexedDocument();
100114

115+
101116
/**
102117
* Get Basic Elasticsearch Params
103118
*
@@ -110,6 +125,7 @@ public function getIndexedDocument();
110125
*/
111126
public function getBasicEsParams($getIdIfPossible = true);
112127

128+
113129
/**
114130
* Is Elasticsearch Document.
115131
*
@@ -120,13 +136,15 @@ public function getBasicEsParams($getIdIfPossible = true);
120136
*/
121137
public function isDocument();
122138

139+
123140
/**
124141
* Get Document Score
125142
*
126143
* @return null|float
127144
*/
128145
public function documentScore();
129146

147+
130148
/**
131149
* Put Mapping.
132150
*
@@ -136,13 +154,15 @@ public function documentScore();
136154
*/
137155
public static function putMapping($ignoreConflicts = false);
138156

157+
139158
/**
140159
* Delete Mapping
141160
*
142161
* @return
143162
*/
144163
public static function deleteMapping();
145164

165+
146166
/**
147167
* Rebuild Mapping
148168
*
@@ -153,6 +173,7 @@ public static function deleteMapping();
153173
*/
154174
public static function rebuildMapping();
155175

176+
156177
/**
157178
* Get Mapping
158179
*
@@ -163,6 +184,7 @@ public static function rebuildMapping();
163184
*/
164185
public static function getMapping();
165186

187+
166188
/**
167189
* Type Exists
168190
*

src/ElasticquentPaginator.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,32 @@
55

66
class ElasticquentPaginator extends Paginator
77
{
8+
89
/**
910
* Create a new paginator instance.
1011
*
11-
* @param mixed $items
12-
* @param mixed $hits
13-
* @param int $total
14-
* @param int $perPage
15-
* @param int|null $currentPage
16-
* @param array $options (path, query, fragment, pageName)
12+
* @param mixed $items
13+
* @param mixed $hits
14+
* @param int $total
15+
* @param int $perPage
16+
* @param int|null $currentPage
17+
* @param array $options (path, query, fragment, pageName)
1718
*/
1819
public function __construct($items, $hits, $total, $perPage, $currentPage = null, array $options = [])
1920
{
2021
foreach ($options as $key => $value) {
2122
$this->{$key} = $value;
2223
}
23-
$this->total = $total;
24-
$this->perPage = $perPage;
25-
$this->lastPage = (int) ceil($total / $perPage);
24+
$this->total = $total;
25+
$this->perPage = $perPage;
26+
$this->lastPage = (int)ceil($total / $perPage);
2627
$this->currentPage = $this->setCurrentPage($currentPage, $this->lastPage);
27-
$this->path = $this->path != '/' ? rtrim($this->path, '/') . '/' : $this->path;
28-
$this->items = $items instanceof Collection ? $items : Collection::make($items);
29-
$this->hits = $hits;
28+
$this->path = $this->path != '/' ? rtrim($this->path, '/') . '/' : $this->path;
29+
$this->items = $items instanceof Collection ? $items : Collection::make($items);
30+
$this->hits = $hits;
3031
}
3132

33+
3234
/**
3335
* Get the instance as an array.
3436
*

0 commit comments

Comments
 (0)