Skip to content

Commit

Permalink
Add php-cs-fixer config, code formatted
Browse files Browse the repository at this point in the history
  • Loading branch information
yukato committed Oct 14, 2016
1 parent 7a873aa commit 97090db
Show file tree
Hide file tree
Showing 23 changed files with 208 additions and 254 deletions.
65 changes: 65 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

$finder = Symfony\Component\Finder\Finder::create()
->notPath('bootstrap/cache')
->notPath('storage')
->notPath('vendor')
->in(__DIR__)
->name('*.php')
->ignoreDotFiles(true)
->ignoreVCS(true);

$fixers = [
'-psr0',
'-php_closing_tag',
'blankline_after_open_tag',
'concat_without_spaces',
'double_arrow_multiline_whitespaces',
'duplicate_semicolon',
'empty_return',
'extra_empty_lines',
'include',
'join_function',
'list_commas',
'multiline_array_trailing_comma',
'namespace_no_leading_whitespace',
'newline_after_open_tag',
'no_blank_lines_after_class_opening',
'no_empty_lines_after_phpdocs',
'object_operator',
'operators_spaces',
'phpdoc_indent',
'phpdoc_no_access',
'phpdoc_no_package',
'phpdoc_scalar',
'phpdoc_short_description',
'phpdoc_to_comment',
'phpdoc_trim',
'phpdoc_type_to_var',
'phpdoc_var_without_name',
'remove_leading_slash_use',
'remove_lines_between_uses',
'return',
'self_accessor',
'single_array_no_trailing_comma',
'single_blank_line_before_namespace',
'single_quote',
'spaces_before_semicolon',
'spaces_cast',
'standardize_not_equal',
'ternary_spaces',
'trim_array_spaces',
'unalign_equals',
'unary_operators_spaces',
'whitespacy_lines',
'multiline_spaces_before_semicolon',
'short_array_syntax',
'short_echo_tag',
];

return Symfony\CS\Config\Config::create()
->level(Symfony\CS\FixerInterface::PSR2_LEVEL)
->fixers($fixers)
->finder($finder)
->setUsingCache(true);

14 changes: 5 additions & 9 deletions src/ElasticquentClientTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@

trait ElasticquentClientTrait
{

use ElasticquentConfigTrait;


/**
* Get ElasticSearch Client
* Get ElasticSearch Client.
*
* @return \Elasticsearch\Client
*/
Expand All @@ -27,7 +25,7 @@ public function getElasticSearchClient()
// elasticsearch v2.0 using builder
if (class_exists('\Elasticsearch\ClientBuilder')) {
$awsConfig = $this->getElasticConfig('aws');
if ( ! empty($awsConfig) && array_get($this->getElasticConfig('aws'), 'iam', false)) {
if (!empty($awsConfig) && array_get($this->getElasticConfig('aws'), 'iam', false)) {
if ($handler = $this->getAwsESHandler()) {
array_set($config, 'handler', $handler);
}
Expand All @@ -40,7 +38,6 @@ public function getElasticSearchClient()
return new \Elasticsearch\Client($config);
}


/**
* @return bool|\Closure
*/
Expand All @@ -51,12 +48,12 @@ private function getAwsESHandler()
return false;
}

$key = array_get($awsConfig, 'key');
$key = array_get($awsConfig, 'key');
$secret = array_get($awsConfig, 'secret');
$region = array_get($awsConfig, 'region', 'us-west-2');

$psr7Handler = \Aws\default_http_handler();
$signer = new SignatureV4('es', $region);
$signer = new SignatureV4('es', $region);

$handler = function (array $request) use (
$psr7Handler,
Expand Down Expand Up @@ -87,11 +84,10 @@ private function getAwsESHandler()
'headers' => $response->getHeaders(),
'body' => $response->getBody()->detach(),
'transfer_stats' => ['total_time' => 0],
'effective_url' => (string)$psr7Request->getUri(),
'effective_url' => (string) $psr7Request->getUri(),
]);
};

return $handler;
}

}
8 changes: 4 additions & 4 deletions src/ElasticquentCollection.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php namespace Elasticquent;
<?php

namespace Elasticquent;

class ElasticquentCollection extends \Illuminate\Database\Eloquent\Collection
{

use ElasticquentCollectionTrait;

}
}
19 changes: 8 additions & 11 deletions src/ElasticquentCollectionTrait.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<?php namespace Elasticquent;
<?php

namespace Elasticquent;

/**
* Elasticquent Collection Trait
* Elasticquent Collection Trait.
*
* Elasticsearch functions that you
* can run on collections of documents.
*/
trait ElasticquentCollectionTrait
{

use ElasticquentClientTrait;


/**
* Add To Index
* Add To Index.
*
* Add all documents in this collection to to the Elasticsearch document index.
*
Expand All @@ -22,7 +22,7 @@ trait ElasticquentCollectionTrait
public function addToIndex()
{
if ($this->isEmpty()) {
return null;
return;
}

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


/**
* Delete From Index
* Delete From Index.
*
* @return array
*/
Expand All @@ -67,9 +66,8 @@ public function deleteFromIndex()
return $this->getElasticSearchClient()->bulk($params);
}


/**
* Reindex
* Reindex.
*
* Delete the items and then re-index them.
*
Expand All @@ -81,5 +79,4 @@ public function reindex()

return $this->addToIndex();
}

}
20 changes: 8 additions & 12 deletions src/ElasticquentConfigTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

trait ElasticquentConfigTrait
{

/**
* Get Index Name
* Get Index Name.
*
* @return string
*/
Expand All @@ -16,17 +15,16 @@ public function getIndexName()
// config file and if there is a default index.
$index_name = $this->getElasticConfig('default_index');

if ( ! empty($index_name)) {
if (!empty($index_name)) {
return $index_name;
}

// Otherwise we will just go with 'default'
return 'default';
}


/**
* Get the Elasticquent config
* Get the Elasticquent config.
*
* @param string $key the configuration key
* @param string $prefix filename of configuration file
Expand All @@ -35,7 +33,7 @@ public function getIndexName()
*/
public function getElasticConfig($key = 'config', $prefix = 'elasticquent')
{
$key = $prefix . ($key ? '.' : '') . $key;
$key = $prefix.($key ? '.' : '').$key;

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


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

if ( ! file_exists($config_file)) {
if (!file_exists($config_file)) {
throw new \Exception('Config file not found.');
}

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


/**
* Get the config path and file name to use when Laravel framework isn't present
* e.g. using Eloquent stand-alone or running unit tests
* e.g. using Eloquent stand-alone or running unit tests.
*
* @return string config file path
*/
protected function getConfigFile()
{
return __DIR__ . '/config/elasticquent.php';
return __DIR__.'/config/elasticquent.php';
}
}
1 change: 0 additions & 1 deletion src/ElasticquentElasticsearchFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/
class ElasticquentElasticsearchFacade extends Facade
{

/**
* Get the registered name of the component.
*
Expand Down
Loading

0 comments on commit 97090db

Please sign in to comment.