Skip to content

Commit 7709f6b

Browse files
committed
Add php-cs-fixer config, code formatted
1 parent 84d36b0 commit 7709f6b

23 files changed

+208
-254
lines changed

.php_cs

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
$finder = Symfony\Component\Finder\Finder::create()
4+
->notPath('bootstrap/cache')
5+
->notPath('storage')
6+
->notPath('vendor')
7+
->in(__DIR__)
8+
->name('*.php')
9+
->ignoreDotFiles(true)
10+
->ignoreVCS(true);
11+
12+
$fixers = [
13+
'-psr0',
14+
'-php_closing_tag',
15+
'blankline_after_open_tag',
16+
'concat_without_spaces',
17+
'double_arrow_multiline_whitespaces',
18+
'duplicate_semicolon',
19+
'empty_return',
20+
'extra_empty_lines',
21+
'include',
22+
'join_function',
23+
'list_commas',
24+
'multiline_array_trailing_comma',
25+
'namespace_no_leading_whitespace',
26+
'newline_after_open_tag',
27+
'no_blank_lines_after_class_opening',
28+
'no_empty_lines_after_phpdocs',
29+
'object_operator',
30+
'operators_spaces',
31+
'phpdoc_indent',
32+
'phpdoc_no_access',
33+
'phpdoc_no_package',
34+
'phpdoc_scalar',
35+
'phpdoc_short_description',
36+
'phpdoc_to_comment',
37+
'phpdoc_trim',
38+
'phpdoc_type_to_var',
39+
'phpdoc_var_without_name',
40+
'remove_leading_slash_use',
41+
'remove_lines_between_uses',
42+
'return',
43+
'self_accessor',
44+
'single_array_no_trailing_comma',
45+
'single_blank_line_before_namespace',
46+
'single_quote',
47+
'spaces_before_semicolon',
48+
'spaces_cast',
49+
'standardize_not_equal',
50+
'ternary_spaces',
51+
'trim_array_spaces',
52+
'unalign_equals',
53+
'unary_operators_spaces',
54+
'whitespacy_lines',
55+
'multiline_spaces_before_semicolon',
56+
'short_array_syntax',
57+
'short_echo_tag',
58+
];
59+
60+
return Symfony\CS\Config\Config::create()
61+
->level(Symfony\CS\FixerInterface::PSR2_LEVEL)
62+
->fixers($fixers)
63+
->finder($finder)
64+
->setUsingCache(true);
65+

src/ElasticquentClientTrait.php

+5-9
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@
1111

1212
trait ElasticquentClientTrait
1313
{
14-
1514
use ElasticquentConfigTrait;
1615

17-
1816
/**
19-
* Get ElasticSearch Client
17+
* Get ElasticSearch Client.
2018
*
2119
* @return \Elasticsearch\Client
2220
*/
@@ -27,7 +25,7 @@ public function getElasticSearchClient()
2725
// elasticsearch v2.0 using builder
2826
if (class_exists('\Elasticsearch\ClientBuilder')) {
2927
$awsConfig = $this->getElasticConfig('aws');
30-
if ( ! empty($awsConfig) && array_get($this->getElasticConfig('aws'), 'iam', false)) {
28+
if (!empty($awsConfig) && array_get($this->getElasticConfig('aws'), 'iam', false)) {
3129
if ($handler = $this->getAwsESHandler()) {
3230
array_set($config, 'handler', $handler);
3331
}
@@ -40,7 +38,6 @@ public function getElasticSearchClient()
4038
return new \Elasticsearch\Client($config);
4139
}
4240

43-
4441
/**
4542
* @return bool|\Closure
4643
*/
@@ -51,12 +48,12 @@ private function getAwsESHandler()
5148
return false;
5249
}
5350

54-
$key = array_get($awsConfig, 'key');
51+
$key = array_get($awsConfig, 'key');
5552
$secret = array_get($awsConfig, 'secret');
5653
$region = array_get($awsConfig, 'region', 'us-west-2');
5754

5855
$psr7Handler = \Aws\default_http_handler();
59-
$signer = new SignatureV4('es', $region);
56+
$signer = new SignatureV4('es', $region);
6057

6158
$handler = function (array $request) use (
6259
$psr7Handler,
@@ -87,11 +84,10 @@ private function getAwsESHandler()
8784
'headers' => $response->getHeaders(),
8885
'body' => $response->getBody()->detach(),
8986
'transfer_stats' => ['total_time' => 0],
90-
'effective_url' => (string)$psr7Request->getUri(),
87+
'effective_url' => (string) $psr7Request->getUri(),
9188
]);
9289
};
9390

9491
return $handler;
9592
}
96-
9793
}

src/ElasticquentCollection.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
<?php namespace Elasticquent;
1+
<?php
2+
3+
namespace Elasticquent;
24

35
class ElasticquentCollection extends \Illuminate\Database\Eloquent\Collection
46
{
5-
67
use ElasticquentCollectionTrait;
7-
8-
}
8+
}

src/ElasticquentCollectionTrait.php

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
<?php namespace Elasticquent;
1+
<?php
2+
3+
namespace Elasticquent;
24

35
/**
4-
* Elasticquent Collection Trait
6+
* Elasticquent Collection Trait.
57
*
68
* Elasticsearch functions that you
79
* can run on collections of documents.
810
*/
911
trait ElasticquentCollectionTrait
1012
{
11-
1213
use ElasticquentClientTrait;
1314

14-
1515
/**
16-
* Add To Index
16+
* Add To Index.
1717
*
1818
* Add all documents in this collection to to the Elasticsearch document index.
1919
*
@@ -22,7 +22,7 @@ trait ElasticquentCollectionTrait
2222
public function addToIndex()
2323
{
2424
if ($this->isEmpty()) {
25-
return null;
25+
return;
2626
}
2727

2828
$params = [];
@@ -42,9 +42,8 @@ public function addToIndex()
4242
return $this->getElasticSearchClient()->bulk($params);
4343
}
4444

45-
4645
/**
47-
* Delete From Index
46+
* Delete From Index.
4847
*
4948
* @return array
5049
*/
@@ -67,9 +66,8 @@ public function deleteFromIndex()
6766
return $this->getElasticSearchClient()->bulk($params);
6867
}
6968

70-
7169
/**
72-
* Reindex
70+
* Reindex.
7371
*
7472
* Delete the items and then re-index them.
7573
*
@@ -81,5 +79,4 @@ public function reindex()
8179

8280
return $this->addToIndex();
8381
}
84-
8582
}

src/ElasticquentConfigTrait.php

+8-12
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44

55
trait ElasticquentConfigTrait
66
{
7-
87
/**
9-
* Get Index Name
8+
* Get Index Name.
109
*
1110
* @return string
1211
*/
@@ -16,17 +15,16 @@ public function getIndexName()
1615
// config file and if there is a default index.
1716
$index_name = $this->getElasticConfig('default_index');
1817

19-
if ( ! empty($index_name)) {
18+
if (!empty($index_name)) {
2019
return $index_name;
2120
}
2221

2322
// Otherwise we will just go with 'default'
2423
return 'default';
2524
}
2625

27-
2826
/**
29-
* Get the Elasticquent config
27+
* Get the Elasticquent config.
3028
*
3129
* @param string $key the configuration key
3230
* @param string $prefix filename of configuration file
@@ -35,7 +33,7 @@ public function getIndexName()
3533
*/
3634
public function getElasticConfig($key = 'config', $prefix = 'elasticquent')
3735
{
38-
$key = $prefix . ($key ? '.' : '') . $key;
36+
$key = $prefix.($key ? '.' : '').$key;
3937

4038
if (function_exists('config')) {
4139
// Get config helper for Laravel 5.1+
@@ -51,9 +49,8 @@ public function getElasticConfig($key = 'config', $prefix = 'elasticquent')
5149
return $config_helper->get($key);
5250
}
5351

54-
5552
/**
56-
* Inject given config file into an instance of Laravel's config
53+
* Inject given config file into an instance of Laravel's config.
5754
*
5855
* @throws \Exception when the configuration file is not found
5956
* @return \Illuminate\Config\Repository configuration repository
@@ -62,22 +59,21 @@ protected function getConfigHelper()
6259
{
6360
$config_file = $this->getConfigFile();
6461

65-
if ( ! file_exists($config_file)) {
62+
if (!file_exists($config_file)) {
6663
throw new \Exception('Config file not found.');
6764
}
6865

6966
return new \Illuminate\Config\Repository(['elasticquent' => require($config_file)]);
7067
}
7168

72-
7369
/**
7470
* Get the config path and file name to use when Laravel framework isn't present
75-
* e.g. using Eloquent stand-alone or running unit tests
71+
* e.g. using Eloquent stand-alone or running unit tests.
7672
*
7773
* @return string config file path
7874
*/
7975
protected function getConfigFile()
8076
{
81-
return __DIR__ . '/config/elasticquent.php';
77+
return __DIR__.'/config/elasticquent.php';
8278
}
8379
}

src/ElasticquentElasticsearchFacade.php

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
*/
1010
class ElasticquentElasticsearchFacade extends Facade
1111
{
12-
1312
/**
1413
* Get the registered name of the component.
1514
*

0 commit comments

Comments
 (0)