Skip to content

Commit

Permalink
Merge branch 'master' into fix-issue-1777-trailing-dot-during-request…
Browse files Browse the repository at this point in the history
…-signing
  • Loading branch information
ruflin authored Aug 15, 2022
2 parents 857717a + 535fb09 commit 6e93bae
Show file tree
Hide file tree
Showing 36 changed files with 389 additions and 212 deletions.
47 changes: 15 additions & 32 deletions .github/workflows/continuous-integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
php-version: '7.4'
coverage: 'none'
extensions: 'json, mbstring, tokenizer'
tools: 'composer-normalize:2.28.0, php-cs-fixer:3.8.0'
tools: 'composer-normalize:2.28.0, php-cs-fixer:3.9.5'

- name: 'Check PHP code'
run: |
Expand All @@ -36,8 +36,15 @@ jobs:
- '7.4'
- '8.0'
- '8.1'
dependencies:
- 'highest'
elasticsearch:
- '7.15.2'
include:
# Test with the lowest set of dependencies
- dependencies: 'lowest'
php: '7.2'
elasticsearch: '7.15.2'
fail-fast: false
steps:
- name: 'Checkout'
Expand All @@ -51,23 +58,11 @@ jobs:
tools: 'pecl, composer:v2'
extensions: 'curl, json, mbstring, openssl'

- name: 'Get composer cache directory'
id: 'composer_cache'
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: 'Cache dependencies'
uses: 'actions/cache@v2'
- name: 'Install dependencies with Composer'
uses: 'ramsey/composer-install@v2'
with:
path: '${{ steps.composer_cache.outputs.dir }}'
key: '${{ runner.os }}-composer-php${{ matrix.php }}-${{ hashFiles(''**/composer.json'') }}'
restore-keys: |
${{ runner.os }}-composer-php${{ matrix.php }}-
${{ runner.os }}-composer-
- name: 'Update dependencies'
run: |
composer update --prefer-dist --no-interaction --no-progress --ansi ${{ matrix.composer_flags }}
dependency-versions: '${{ matrix.dependencies }}'
composer-options: '--prefer-dist'

- name: 'Run unit tests'
run: |
Expand Down Expand Up @@ -115,23 +110,11 @@ jobs:
tools: 'pecl, composer:v2'
extensions: 'curl, json, mbstring, openssl'

- name: 'Get composer cache directory'
id: 'composer_cache'
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: 'Cache dependencies'
uses: 'actions/cache@v2'
- name: 'Install dependencies with Composer'
uses: 'ramsey/composer-install@v2'
with:
path: '${{ steps.composer_cache.outputs.dir }}'
key: '${{ runner.os }}-composer-php${{ matrix.php }}-${{ hashFiles(''**/composer.json'') }}'
restore-keys: |
${{ runner.os }}-composer-php${{ matrix.php }}-
${{ runner.os }}-composer-
- name: 'Update dependencies'
run: |
composer update --prefer-dist --no-interaction --no-progress --ansi ${{ matrix.composer_flags }}
composer-options: '--prefer-dist'

- name: 'Run phpstan'
run: |
Expand Down
24 changes: 20 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,20 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased](https://github.com/ruflin/Elastica/compare/7.1.5...master)
## [Unreleased](https://github.com/ruflin/Elastica/compare/7.2.0...master)
### Backward Compatibility Breaks
### Added
### Changed
* Use `ramsey/composer-install` to simplify CI jobs and test with the lowest set of dependencies [#2113](https://github.com/ruflin/Elastica/pull/2113)
* Bumped `elasticsearch/elasticsearch` to `7.10` to be able to use `OpenPointInTime` class [#2113](https://github.com/ruflin/Elastica/pull/2113)
* Updated `php-cs-fixer` to `3.9.5` [#2110](https://github.com/ruflin/Elastica/pull/2110)
### Deprecated
### Removed
* Removed `CallbackStrategyTestHelper` and `ErrorsCollector` from `tests` [#2111](https://github.com/ruflin/Elastica/pull/2111)
### Fixed
### Security

## [7.2.0](https://github.com/ruflin/Elastica/compare/7.2.0...7.1.5)
### Backward Compatibility Breaks
* Changed `SetProcessor::setValue` signature to allow to pass any type, if you are overriding this method you must update the signature removing the `string` type-hint by @franmomu [#2082](https://github.com/ruflin/Elastica/pull/2082)
* Changed `Settings::setMergePolicy` signature to allow to pass `int` and `string` as argument 2, if you are overriding this method you must update the signature removing the `string` type-hint by @franmomu [#2085](https://github.com/ruflin/Elastica/pull/2085)
Expand All @@ -13,7 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Added coverage check to CI by @franmomu [#2071](https://github.com/ruflin/Elastica/pull/2071)
* Added `string` as a valid type for `data` in `Request` by @franmomu [#2078](https://github.com/ruflin/Elastica/pull/2078)
* Added missing `throws` PHPDoc tags by @franmomu [#2077](https://github.com/ruflin/Elastica/pull/2077)

* Added `Search::addIndexByName()`, `Search::hasIndexByName()` and `Search::addIndicesByName()` by @franmomu [#2103](https://github.com/ruflin/Elastica/pull/2103)
### Changed
* Updated `symfony/phpunit-bridge` to `6.0` by @franmomu [#2067](https://github.com/ruflin/Elastica/pull/2067)
* Updated `php-cs-fixer` to `3.8.0` [#2074](https://github.com/ruflin/Elastica/pull/2074)
Expand All @@ -28,6 +41,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Deprecated
* Deprecated `Elastica\Reindex::WAIT_FOR_COMPLETION_FALSE`, use a boolean as parameter instead by @franmomu [#2070](https://github.com/ruflin/Elastica/pull/2070)
* Passing anything else than a boolean as 1st argument to `Reindex::setWaitForCompletion`, pass a boolean instead by @franmomu [#2070](https://github.com/ruflin/Elastica/pull/2070)
* Deprecated passing a `string` as 1st argument to `Search::addIndex()` and `Search::hasIndex()`, pass an Index instance instead by @franmomu [#2103](https://github.com/ruflin/Elastica/pull/2103)
* Deprecated passing an array of `string` as 1st argument to `Search::addIndices()`, use an array of Index instances by @franmomu [#2103](https://github.com/ruflin/Elastica/pull/2103)

### Removed
* Removed `egeloen/http-adapter` as suggested package since the project is abandoned by @franmomu [#2069](https://github.com/ruflin/Elastica/pull/2069)
* Removed `0` as valid request data using Analyze API by @franmomu [#2068](https://github.com/ruflin/Elastica/pull/2068)
Expand All @@ -38,8 +54,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Fixed `Http` PHPDoc adding `\CurlHandle` type for Curl connection by @franmomu [#2086](https://github.com/ruflin/Elastica/pull/2086)
* Fixed case mismatch in method calls by @franmomu [#2087](https://github.com/ruflin/Elastica/pull/2087)
* Fixed `MoreLikeThis::setLike()` PHPDoc allowing `Document` by @franmomu [#2091](https://github.com/ruflin/Elastica/pull/2091)

### Security
* Fixed `Term::setTerm()` PHPDoc allowing scalar values for `$value` parameter by @franmomu [#2094](https://github.com/ruflin/Elastica/pull/2094)
* Fixed `DateHistogram` deprecation: use `fixed_internal` or `calendar_interval` instead of `interval` by @VincentLanglet [#2099](https://github.com/ruflin/Elastica/pull/2099)

## [7.1.5](https://github.com/ruflin/Elastica/compare/7.1.5...7.1.4)
### Added
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"require": {
"php": "^7.2 || ^8.0",
"ext-json": "*",
"elasticsearch/elasticsearch": "^7.1.1",
"elasticsearch/elasticsearch": "^7.10",
"nyholm/dsn": "^2.0.0",
"psr/log": "^1.0 || ^2.0 || ^3.0",
"symfony/deprecation-contracts": "^2.2 || ^3.0",
Expand Down
2 changes: 1 addition & 1 deletion phive.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="php-cs-fixer" version="^3.0" installed="3.8.0" location="./tools/php-cs-fixer.phar" copy="true"/>
<phar name="php-cs-fixer" version="^3.0" installed="3.9.5" location="./tools/php-cs-fixer.phar" copy="true"/>
<phar name="php-coveralls" version="^2.2" installed="2.2.0" location="./tools/php-coveralls.phar" copy="true"/>
</phive>
2 changes: 2 additions & 0 deletions src/AbstractUpdateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class AbstractUpdateAction extends Param

/**
* Sets the id of the document.
*
* @return $this
*/
public function setId(?string $id = null): self
{
Expand Down
51 changes: 51 additions & 0 deletions src/Aggregation/DateHistogram.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,57 @@ class DateHistogram extends Histogram
{
public const DEFAULT_TIMEZONE_VALUE = 'UTC';

private const CALENDAR_INTERVAL_VALUES = [
'1m',
'minute',
'1h',
'hour',
'1d',
'day',
'1w',
'week',
'1M',
'month',
'1q',
'quarter',
'1y',
'year',
];

/**
* Set the interval by which documents will be bucketed.
*
* @param int|string $interval
*
* @return $this
*/
public function setInterval($interval)
{
$interval = (string) $interval;

if (\in_array($interval, self::CALENDAR_INTERVAL_VALUES, true)) {
return $this->setCalendarInterval($interval);
}

return $this->setFixedInterval($interval);
}

/**
* @return $this
*/
public function setCalendarInterval(string $interval): self
{
return $this->setParam('calendar_interval', $interval);
}

/**
* @return $this
*/
public function setFixedInterval(string $interval): self
{
return $this->setParam('fixed_interval', $interval);
}

/**
* Set time_zone option.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Aggregation/Histogram.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct(string $name, string $field, $interval)
*
* @return $this
*/
public function setInterval($interval): self
public function setInterval($interval)
{
return $this->setParam('interval', $interval);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Query/Term.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public function setRawTerm(array $term): self
/**
* Adds a term to the term query.
*
* @param string $key Key to query
* @param array|string $value Values(s) for the query. Boost can be set with array
* @param float $boost OPTIONAL Boost value (default = 1.0)
* @param string $key Key to query
* @param bool|float|int|string $value Values(s) for the query
* @param float $boost OPTIONAL Boost value (default = 1.0)
*
* @return $this
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Reindex.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function setWaitForCompletion($value): void
if (\is_bool($value)) {
$value = $value ? 'true' : 'false';
} else {
\trigger_deprecation('ruflin/elastica', '7.1.6', 'Passing anything else than a boolean as 1st argument to "%s()" is deprecated, pass a boolean instead. It will be removed in 8.0.', __METHOD__);
\trigger_deprecation('ruflin/elastica', '7.2.0', 'Passing anything else than a boolean as 1st argument to "%s()" is deprecated, pass a boolean instead. It will be removed in 8.0.', __METHOD__);
}

$this->setParam(self::WAIT_FOR_COMPLETION, $value);
Expand Down
69 changes: 65 additions & 4 deletions src/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,39 +80,87 @@ public function __construct(Client $client, ?BuilderInterface $builder = null)
/**
* Adds a index to the list.
*
* @param Index|string $index Index object or string
* @param Index $index Index object or string
*
* @throws InvalidException
*/
public function addIndex($index): self
{
if ($index instanceof Index) {
$index = $index->getName();
} else {
\trigger_deprecation(
'ruflin/elastica',
'7.2.0',
'Passing a string as 1st argument to "%s()" is deprecated, pass an Index instance or use "addIndexByName" instead. It will throw a %s in 8.0.',
__METHOD__,
\TypeError::class
);
}

if (!\is_scalar($index)) {
throw new InvalidException('Invalid param type');
}

$this->_indices[] = (string) $index;
return $this->addIndexByName((string) $index);
}

/**
* Adds an index to the list.
*/
public function addIndexByName(string $index): self
{
$this->_indices[] = $index;

return $this;
}

/**
* Add array of indices at once.
*
* @param Index[]|string[] $indices
* @param Index[] $indices
*/
public function addIndices(array $indices = []): self
{
foreach ($indices as $index) {
if (\is_string($index)) {
\trigger_deprecation(
'ruflin/elastica',
'7.2.0',
'Passing a array of strings as 1st argument to "%s()" is deprecated, pass an array of Indexes or use "addIndicesByName" instead. It will throw a %s in 8.0.',
__METHOD__,
\TypeError::class
);
$this->addIndexByName($index);

continue;
}

if (!$index instanceof Index) {
throw new InvalidException('Invalid param type for addIndices(), expected Index[]');
}

$this->addIndex($index);
}

return $this;
}

/**
* @param string[] $indices
*/
public function addIndicesByName(array $indices = []): self
{
foreach ($indices as $index) {
if (!\is_string($index)) {
throw new InvalidException('Invalid param type for addIndicesByName(), expected string[]');
}
$this->addIndexByName($index);
}

return $this;
}

/**
* @param AbstractQuery|AbstractSuggest|array|Collapse|Query|string|Suggest $query
*/
Expand Down Expand Up @@ -213,14 +261,27 @@ public function hasIndices(): bool
}

/**
* @param Index|string $index
* @param Index $index
*/
public function hasIndex($index): bool
{
if ($index instanceof Index) {
$index = $index->getName();
} else {
\trigger_deprecation(
'ruflin/elastica',
'7.2.0',
'Passing a string as 1st argument to "%s()" is deprecated, pass an Index instance or use "hasIndexByName" instead. It will throw a %s in 8.0.',
__METHOD__,
\TypeError::class
);
}

return $this->hasIndexByName($index);
}

public function hasIndexByName(string $index): bool
{
return \in_array($index, $this->_indices, true);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Aggregation/AvgBucketTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function testAvgBucketAggregation(): void
)
)
->addAggregation(
(new AvgBucket('avg_likes_by_page', 'pages>avg_likes'))
new AvgBucket('avg_likes_by_page', 'pages>avg_likes')
)
;

Expand Down
2 changes: 1 addition & 1 deletion tests/Aggregation/CumulativeSumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function testCumulativeSumAggregation(): void
->setField('price')
)
->addAggregation(
(new CumulativeSum('cumulative_sales', 'sales'))
new CumulativeSum('cumulative_sales', 'sales')
)
)
;
Expand Down
Loading

0 comments on commit 6e93bae

Please sign in to comment.