Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

php-cs-fixer native_function_invocation rule #1606

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ $config = PhpCsFixer\Config::create()
'no_useless_else' => true,
'@PHPUnit60Migration:risky' => true,
'php_unit_dedicate_assert' => ['target' => 'newest'],
'native_function_invocation' => true,
])
;

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file based on the
### Added

### Improvements
* Added `native_function_invocation` CS rule [#1606](https://github.com/ruflin/Elastica/pull/1606)

### Deprecated

Expand Down
8 changes: 4 additions & 4 deletions lib/Elastica/AbstractUpdateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ public function hasRouting()
*/
public function setFields($fields)
{
if (is_array($fields)) {
$fields = implode(',', $fields);
if (\is_array($fields)) {
$fields = \implode(',', $fields);
}

return $this->setParam('_fields', (string) $fields);
Expand Down Expand Up @@ -465,7 +465,7 @@ public function getOptions(array $fields = [], $withUnderscore = false)
if (!empty($fields)) {
$data = [];
foreach ($fields as $field) {
$key = '_'.ltrim($field, '_');
$key = '_'.\ltrim($field, '_');
if ($this->hasParam($key) && '' !== (string) $this->getParam($key)) {
$data[$key] = $this->getParam($key);
}
Expand All @@ -475,7 +475,7 @@ public function getOptions(array $fields = [], $withUnderscore = false)
}
if (!$withUnderscore) {
foreach ($data as $key => $value) {
$data[ltrim($key, '_')] = $value;
$data[\ltrim($key, '_')] = $value;
unset($data[$key]);
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Elastica/Aggregation/AbstractAggregation.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ public function toArray(): array
{
$array = parent::toArray();

if (array_key_exists('global_aggregation', $array)) {
if (\array_key_exists('global_aggregation', $array)) {
// compensate for class name GlobalAggregation
$array = ['global' => new \stdClass()];
}
if (sizeof($this->_aggs)) {
if (\sizeof($this->_aggs)) {
$array['aggs'] = $this->_convertArrayable($this->_aggs);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Elastica/Aggregation/AbstractSimpleAggregation.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ public function toArray(): array

$baseName = $this->_getBaseName();

if (isset($array[$baseName]['script']) && is_array($array[$baseName]['script'])) {
if (isset($array[$baseName]['script']) && \is_array($array[$baseName]['script'])) {
$script = $array[$baseName]['script'];

unset($array[$baseName]['script']);

$array[$baseName] = array_merge($array[$baseName], $script);
$array[$baseName] = \array_merge($array[$baseName], $script);
}

return $array;
Expand Down
2 changes: 1 addition & 1 deletion lib/Elastica/Aggregation/DateHistogram.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function setExtendedBounds(string $min = '', string $max = ''): self
$bounds['min'] = $min;
$bounds['max'] = $max;
// switch if min is higher then max
if (strtotime($min) > strtotime($max)) {
if (\strtotime($min) > \strtotime($max)) {
$bounds['min'] = $max;
$bounds['max'] = $min;
}
Expand Down
8 changes: 4 additions & 4 deletions lib/Elastica/Aggregation/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function addFilter(AbstractQuery $filter, string $name = null): self
}

if ($this->hasParam('filters')
&& count($this->getParam('filters'))
&& \count($this->getParam('filters'))
&& $this->_type !== $type
) {
throw new InvalidException('Mix named and anonymous keys are not allowed');
Expand Down Expand Up @@ -85,10 +85,10 @@ public function toArray(): array

foreach ($filters as $filter) {
if (self::NAMED_TYPE === $this->_type) {
$key = key($filter);
$array['filters']['filters'][$key] = current($filter)->toArray();
$key = \key($filter);
$array['filters']['filters'][$key] = \current($filter)->toArray();
} else {
$array['filters']['filters'][] = current($filter)->toArray();
$array['filters']['filters'][] = \current($filter)->toArray();
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Elastica/Aggregation/TopHits.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function setExplain(bool $explain): self
*/
public function setScriptFields($scriptFields): self
{
if (is_array($scriptFields)) {
if (\is_array($scriptFields)) {
$scriptFields = new ScriptFields($scriptFields);
}

Expand Down
14 changes: 7 additions & 7 deletions lib/Elastica/Bulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public function addScripts(array $scripts, $opType = null): self
*/
public function addData($data, string $opType = null)
{
if (!is_array($data)) {
if (!\is_array($data)) {
$data = [$data];
}

Expand All @@ -255,9 +255,9 @@ public function addData($data, string $opType = null)
public function addRawData(array $data): self
{
foreach ($data as $row) {
if (is_array($row)) {
$opType = key($row);
$metadata = reset($row);
if (\is_array($row)) {
$opType = \key($row);
$metadata = \reset($row);
if (Action::isValidOpType($opType)) {
// add previous action
if (isset($action)) {
Expand Down Expand Up @@ -377,16 +377,16 @@ protected function _processResponse(Response $response): ResponseSet

$bulkResponses = [];

if (isset($responseData['items']) && is_array($responseData['items'])) {
if (isset($responseData['items']) && \is_array($responseData['items'])) {
foreach ($responseData['items'] as $key => $item) {
if (!isset($actions[$key])) {
throw new InvalidException('No response found for action #'.$key);
}

$action = $actions[$key];

$opType = key($item);
$bulkResponseData = reset($item);
$opType = \key($item);
$bulkResponseData = \reset($item);

if ($action instanceof AbstractDocumentAction) {
$data = $action->getData();
Expand Down
6 changes: 3 additions & 3 deletions lib/Elastica/Bulk/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ public function toString(): string
$string = JSON::stringify($this->getActionMetadata(), JSON_FORCE_OBJECT).Bulk::DELIMITER;
if ($this->hasSource()) {
$source = $this->getSource();
if (is_string($source)) {
if (\is_string($source)) {
$string .= $source;
} elseif (is_array($source) && array_key_exists('doc', $source) && is_string($source['doc'])) {
} elseif (\is_array($source) && \array_key_exists('doc', $source) && \is_string($source['doc'])) {
if (isset($source['doc_as_upsert'])) {
$docAsUpsert = ', "doc_as_upsert": '.($source['doc_as_upsert'] ? 'true' : 'false');
} else {
Expand All @@ -228,6 +228,6 @@ public function toString(): string
*/
public static function isValidOpType(string $opType = null): bool
{
return in_array($opType, self::$opTypes, true);
return \in_array($opType, self::$opTypes, true);
}
}
2 changes: 1 addition & 1 deletion lib/Elastica/Bulk/ResponseSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,6 @@ public function rewind()
*/
public function count(): int
{
return count($this->_bulkResponses);
return \count($this->_bulkResponses);
}
}
18 changes: 9 additions & 9 deletions lib/Elastica/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ protected function _prepareConnectionParams(array $config)
$params = [];
$params['config'] = [];
foreach ($config as $key => $value) {
if (in_array($key, ['bigintConversion', 'curl', 'headers', 'url'])) {
if (\in_array($key, ['bigintConversion', 'curl', 'headers', 'url'])) {
$params['config'][$key] = $value;
} else {
$params[$key] = $value;
Expand Down Expand Up @@ -202,7 +202,7 @@ public function getConfig($key = '')
return $this->_config;
}

if (!array_key_exists($key, $this->_config)) {
if (!\array_key_exists($key, $this->_config)) {
throw new InvalidException('Config key is not set: '.$key);
}

Expand Down Expand Up @@ -266,7 +266,7 @@ public function getIndex($name)
*/
public function addHeader($header, $headerValue)
{
if (is_string($header) && is_string($headerValue)) {
if (\is_string($header) && \is_string($headerValue)) {
$this->_config['headers'][$header] = $headerValue;
} else {
throw new InvalidException('Header must be a string');
Expand All @@ -286,8 +286,8 @@ public function addHeader($header, $headerValue)
*/
public function removeHeader($header)
{
if (is_string($header)) {
if (array_key_exists($header, $this->_config['headers'])) {
if (\is_string($header)) {
if (\array_key_exists($header, $this->_config['headers'])) {
unset($this->_config['headers'][$header]);
}
} else {
Expand Down Expand Up @@ -461,11 +461,11 @@ protected function _populateDocumentFieldsFromResponse(Response $response, Docum
{
$responseData = $response->getData();
if ('_source' == $fields) {
if (isset($responseData['get']['_source']) && is_array($responseData['get']['_source'])) {
if (isset($responseData['get']['_source']) && \is_array($responseData['get']['_source'])) {
$document->setData($responseData['get']['_source']);
}
} else {
$keys = explode(',', $fields);
$keys = \explode(',', $fields);
$data = $document->getData();
foreach ($keys as $key) {
if (isset($responseData['get']['fields'][$key])) {
Expand Down Expand Up @@ -715,7 +715,7 @@ public function request($path, $method = Request::GET, $data = [], array $query
public function requestEndpoint(AbstractEndpoint $endpoint)
{
return $this->request(
ltrim($endpoint->getURI(), '/'),
\ltrim($endpoint->getURI(), '/'),
$endpoint->getMethod(),
null === $endpoint->getBody() ? [] : $endpoint->getBody(),
$endpoint->getParams()
Expand Down Expand Up @@ -768,7 +768,7 @@ protected function _log($context)
*/
public function optimizeAll($args = [])
{
trigger_error('Deprecated: Elastica\Client::optimizeAll() is deprecated and will be removed in further Elastica releases. Use Elastica\Client::forcemergeAll() instead.', E_USER_DEPRECATED);
\trigger_error('Deprecated: Elastica\Client::optimizeAll() is deprecated and will be removed in further Elastica releases. Use Elastica\Client::forcemergeAll() instead.', E_USER_DEPRECATED);

return $this->forcemergeAll($args);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Elastica/Cluster.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function getResponse()
*/
public function getIndexNames()
{
return array_keys($this->_data['metadata']['indices']);
return \array_keys($this->_data['metadata']['indices']);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/Elastica/Cluster/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ public function getTransient(string $setting = '')
return $settings[$setting];
}

if (false !== strpos($setting, '.')) {
if (false !== \strpos($setting, '.')) {
// convert dot notation to nested arrays
$keys = explode('.', $setting);
$keys = \explode('.', $setting);
foreach ($keys as $key) {
if (isset($settings[$key])) {
$settings = $settings[$key];
Expand Down
4 changes: 2 additions & 2 deletions lib/Elastica/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public function getConfig($key = '')
return $config;
}

if (!array_key_exists($key, $config)) {
if (!\array_key_exists($key, $config)) {
throw new InvalidException('Config key is not set: '.$key);
}

Expand All @@ -331,7 +331,7 @@ public function getConfig($key = '')
*/
public static function create($params = [])
{
if (is_array($params)) {
if (\is_array($params)) {
return new self($params);
}

Expand Down
6 changes: 3 additions & 3 deletions lib/Elastica/Connection/Strategy/StrategyFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ public static function create($strategyName): StrategyInterface
return new CallbackStrategy($strategyName);
}

if (is_string($strategyName)) {
if (\is_string($strategyName)) {
$requiredInterface = StrategyInterface::class;
$predefinedStrategy = '\\Elastica\\Connection\\Strategy\\'.$strategyName;

if (class_exists($predefinedStrategy) && class_implements($predefinedStrategy, $requiredInterface)) {
if (\class_exists($predefinedStrategy) && \class_implements($predefinedStrategy, $requiredInterface)) {
return new $predefinedStrategy();
}

if (class_exists($strategyName) && class_implements($strategyName, $requiredInterface)) {
if (\class_exists($strategyName) && \class_implements($strategyName, $requiredInterface)) {
return new $strategyName();
}
}
Expand Down
10 changes: 5 additions & 5 deletions lib/Elastica/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function get($key)
*/
public function set($key, $value)
{
if (!is_array($this->_data)) {
if (!\is_array($this->_data)) {
throw new InvalidException('Document data is serialized data. Data creation is forbidden.');
}
$this->_data[$key] = $value;
Expand All @@ -127,7 +127,7 @@ public function set($key, $value)
*/
public function has($key)
{
return is_array($this->_data) && array_key_exists($key, $this->_data);
return \is_array($this->_data) && \array_key_exists($key, $this->_data);
}

/**
Expand Down Expand Up @@ -166,7 +166,7 @@ public function remove($key)
*/
public function addFile($key, $filepath, $mimeType = '')
{
$value = base64_encode(file_get_contents($filepath));
$value = \base64_encode(\file_get_contents($filepath));

if (!empty($mimeType)) {
$value = ['_content_type' => $mimeType, '_name' => $filepath, '_content' => $value];
Expand All @@ -187,7 +187,7 @@ public function addFile($key, $filepath, $mimeType = '')
*/
public function addFileContent($key, $content)
{
return $this->set($key, base64_encode($content));
return $this->set($key, \base64_encode($content));
}

/**
Expand Down Expand Up @@ -330,7 +330,7 @@ public static function create($data)
return $data;
}

if (is_array($data)) {
if (\is_array($data)) {
return new self('', $data);
}

Expand Down
8 changes: 4 additions & 4 deletions lib/Elastica/Exception/ElasticsearchException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Elastica\Exception;

trigger_error('Elastica\Exception\ElasticsearchException is deprecated. Use Elastica\Exception\ResponseException::getResponse::getFullError instead.', E_USER_DEPRECATED);
\trigger_error('Elastica\Exception\ElasticsearchException is deprecated. Use Elastica\Exception\ResponseException::getResponse::getFullError instead.', E_USER_DEPRECATED);

/**
* Elasticsearch exception.
Expand Down Expand Up @@ -47,9 +47,9 @@ public function __construct(int $code, string $error)
*/
protected function _parseError(string $error)
{
$errors = explode(']; nested: ', $error);
$errors = \explode(']; nested: ', $error);

if (1 === count($errors)) {
if (1 === \count($errors)) {
$this->_exception = $this->_extractException($errors[0]);
} else {
if (self::REMOTE_TRANSPORT_EXCEPTION === $this->_extractException($errors[0])) {
Expand All @@ -70,7 +70,7 @@ protected function _parseError(string $error)
*/
protected function _extractException(string $error)
{
if (preg_match('/^(\w+)\[.*\]/', $error, $matches)) {
if (\preg_match('/^(\w+)\[.*\]/', $error, $matches)) {
return $matches[1];
}

Expand Down
Loading