Skip to content

Commit

Permalink
Merge pull request #5 from Spameri/version-one
Browse files Browse the repository at this point in the history
Version one
  • Loading branch information
Spamercz authored Feb 23, 2022
2 parents 04295e5 + b7ea62e commit 0d5483b
Show file tree
Hide file tree
Showing 219 changed files with 2,905 additions and 1,100 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: [ 7.4 ]
elastic: [ 7.12.1, 6.8.15, 5.6.16 ]
php: [ 7.4, 8.1 ]
elastic: [ 7.17.0 ]

steps:
- uses: actions/checkout@v2
Expand All @@ -33,14 +33,14 @@ jobs:
- name: Composer
run: make composer

- if: matrix.php == '7.4' && matrix.elastic == '7.12.1'
- if: matrix.php == '8.1' && matrix.elastic == '7.17.0'
name: Coding standard
run: make cs

- if: matrix.php == '7.4' && matrix.elastic == '7.12.1'
- if: matrix.php == '8.1' && matrix.elastic == '7.17.0'
name: PHPStan
run: make phpstan

- if: matrix.php == '7.4'
- if: matrix.php == '8.1'
name: Tests
run: make tests
46 changes: 0 additions & 46 deletions .travis.yml

This file was deleted.

13 changes: 11 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
.PHONY: composer
.PHONY: phpstan
.PHONY: cs
.PHONY: cs-local
.PHONY: cbf
.PHONY: tests
.PHONY: coverage


composer:
composer update --no-interaction --no-suggest --no-progress --prefer-dist --prefer-stable

phpstan:
vendor/bin/phpstan analyse -l 7 -c phpstan.neon src tests

cs:
vendor/bin/phpcs --standard=ruleset.xml --cache=$HOME/phpcs-cache/.phpcs-cache src tests
vendor/bin/phpcs --standard=ruleset.xml --cache=.phpcs-cache src tests/SpameriTests

cs-local:
vendor/bin/phpcs --standard=ruleset.xml src tests/SpameriTests

cbf:
vendor/bin/phpcbf --standard=ruleset.xml src tests/SpameriTests

tests:
vendor/bin/tester -s -p php --colors 1 -C tests
vendor/bin/tester -s -p php --colors 1 -C -j 1 tests

coverage:
vendor/bin/tester -s -p php --colors 1 -C --coverage ./coverage.html --coverage-src ./src tests
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# ElasticQuery
Elastic documentation converted to php objects for easy using.

[![Build Status](https://travis-ci.org/Spameri/ElasticQuery.svg?branch=master)](https://travis-ci.org/Spameri/ElasticQuery)

Installation
------------

Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
"issues": "https://github.com/Spameri/ElasticQuery/issues"
},
"require": {
"php": ">=7.1",
"php": ">=7.4",
"ext-json": "*"
},
"require-dev": {
"phpstan/phpstan": "v0.12.37",
"ext-curl": "*",
"phpstan/phpstan": "^1.4.6",
"nette/tester": "v2.3.1",
"elasticsearch/elasticsearch": "^7",
"guzzlehttp/guzzle": "^6.3",
Expand Down
3 changes: 2 additions & 1 deletion doc/01-usage.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Using with [ElasticSearch/ElasticSearch](https://github.com/elastic/elasticsearch-php)
First we need to prepare query for what we want to search.

```php
$query = new \Spameri\ElasticQuery\ElasticQuery();
$query->query()->must()->add(
new \Spameri\ElasticQuery\Query\Match(
new \Spameri\ElasticQuery\Query\ElasticMatch(
'name',
'Avengers'
)
Expand Down
5 changes: 4 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
parameters:
ignoreErrors:
- "#Call to function array_key_exists\\(\\) with string and array<int, mixed> will always evaluate to false#"
- "#Call to function array_key_exists\\(\\) with string and array<int, string> will always evaluate to false#"

checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
1 change: 1 addition & 0 deletions ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<properties>
<property name="rootNamespaces" type="array">
<element key="src" value="Spameri\ElasticQuery"/>
<element key="tests/SpameriTests" value="SpameriTests"/>
</property>
</properties>
</rule>
Expand Down
14 changes: 7 additions & 7 deletions src/Aggregation/AggregationCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,47 +31,47 @@ public function __construct(
}


public function key() : string
public function key(): string
{
return 'top-aggs-collection';
}


public function filter() : \Spameri\ElasticQuery\Filter\FilterCollection
public function filter(): \Spameri\ElasticQuery\Filter\FilterCollection
{
return $this->filter;
}


public function add(
LeafAggregationCollection $leafAggregation
) : void
): void
{
$this->aggregations[$leafAggregation->key()] = $leafAggregation;
}


public function keys() : array
public function keys(): array
{
return \array_map('\strval', \array_keys($this->aggregations));
}


public function isKey(
string $key
) : bool
): bool
{
return \array_key_exists($key, \array_map('\strval', \array_keys($this->aggregations)));
}


public function count() : int
public function count(): int
{
return \count($this->aggregations);
}


public function toArray() : array
public function toArray(): array
{
$array = [];

Expand Down
37 changes: 37 additions & 0 deletions src/Aggregation/Avg.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php declare(strict_types = 1);

namespace Spameri\ElasticQuery\Aggregation;

/**
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-avg-aggregation.html
*/
class Avg implements \Spameri\ElasticQuery\Aggregation\LeafAggregationInterface
{

private string $field;


public function __construct(
string $field
)
{
$this->field = $field;
}


public function key(): string
{
return 'avg_' . $this->field;
}


public function toArray(): array
{
return [
'avg' => [
'field' => $this->field,
],
];
}

}
27 changes: 27 additions & 0 deletions src/Aggregation/Filter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php declare(strict_types = 1);

namespace Spameri\ElasticQuery\Aggregation;

/**
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filter-aggregation.html
*/
class Filter extends \Spameri\ElasticQuery\Filter\FilterCollection
implements \Spameri\ElasticQuery\Aggregation\LeafAggregationInterface
{

public function toArray(): array
{
$array = parent::toArray();

if ($array === []) {
$array['must'] = [];
}

return [
'filter' => [
'bool' => $array,
],
];
}

}
14 changes: 4 additions & 10 deletions src/Aggregation/Histogram.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,9 @@
class Histogram implements LeafAggregationInterface
{

/**
* @var string
*/
private $field;
private string $field;

/**
* @var int
*/
private $interval;
private int $interval;


public function __construct(
Expand All @@ -30,13 +24,13 @@ public function __construct(
}


public function key() : string
public function key(): string
{
return $this->field;
}


public function toArray() : array
public function toArray(): array
{
return [
'histogram' => [
Expand Down
16 changes: 11 additions & 5 deletions src/Aggregation/LeafAggregationCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,34 @@ public function __construct(
}


public function key() : string
public function addAggregation(LeafAggregationInterface $aggregation): void
{
$this->aggregations[$aggregation->key()] = $aggregation;
}


public function key(): string
{
return $this->name;
}


public function filter() : \Spameri\ElasticQuery\Filter\FilterCollection
public function filter(): \Spameri\ElasticQuery\Filter\FilterCollection
{
return $this->filter;
}


public function getIterator() : \ArrayIterator
public function getIterator(): \ArrayIterator
{
return new \ArrayIterator($this->aggregations);
}


public function toArray() : array
public function toArray(): array
{
$array = [];
$hasFilter = $this->filter && \count($this->filter->toArray());
$hasFilter = \count($this->filter->toArray());

foreach ($this->aggregations as $aggregation) {
if ($aggregation instanceof \Spameri\ElasticQuery\Aggregation\LeafAggregationCollection) {
Expand Down
37 changes: 37 additions & 0 deletions src/Aggregation/Max.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php declare(strict_types = 1);

namespace Spameri\ElasticQuery\Aggregation;

class Max implements \Spameri\ElasticQuery\Aggregation\LeafAggregationInterface
{

private string $field;


public function __construct(
string $field
)
{
$this->field = $field;
}


public function key(): string
{
return 'max_' . $this->field;
}


/**
* @return array<string, array<string, string>>
*/
public function toArray(): array
{
return [
'max' => [
'field' => $this->field,
],
];
}

}
Loading

0 comments on commit 0d5483b

Please sign in to comment.