Skip to content

Commit

Permalink
Cleaned up, added proper deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
Radiergummi committed Nov 30, 2021
1 parent 0d6a054 commit 9ffab37
Show file tree
Hide file tree
Showing 10 changed files with 2,373 additions and 2,315 deletions.
220 changes: 112 additions & 108 deletions src/Classes/Bulk.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php

declare(strict_types=1);

namespace Matchory\Elasticsearch\Classes;

use JetBrains\PhpStorm\Deprecated;
use Matchory\Elasticsearch\Query;

/**
Expand All @@ -11,13 +14,6 @@
*/
class Bulk
{
/**
* The query object
*
* @var Query
*/
public $query;

/**
* The document key
*
Expand All @@ -26,25 +22,25 @@ class Bulk
public $_id;

/**
* The index name
* Operation count which will trigger autocommit
*
* @var string|null
* @var int
*/
public $index;
public $autocommitAfter = 0;

/**
* The type name
* Bulk body
*
* @var string|null
* @var array
*/
public $type;
public $body = [];

/**
* Bulk body
* The index name
*
* @var array
* @var string|null
*/
public $body = [];
public $index;

/**
* Number of pending operations
Expand All @@ -54,11 +50,18 @@ class Bulk
public $operationCount = 0;

/**
* Operation count which will trigger autocommit
* The query object
*
* @var int
* @var Query
*/
public $autocommitAfter = 0;
public $query;

/**
* The type name
*
* @var string|null
*/
public $type;

/**
* @param Query $query
Expand All @@ -71,34 +74,6 @@ public function __construct(Query $query, ?int $autocommitAfter = null)
$this->autocommitAfter = (int)$autocommitAfter;
}

/**
* Set the index name
*
* @param string|null $index
*
* @return $this
*/
public function index(?string $index = null): self
{
$this->index = $index;

return $this;
}

/**
* Set the type name
*
* @param string|null $type
*
* @return $this
*/
public function type(?string $type = null): self
{
$this->type = $type;

return $this;
}

/**
* Filter by _id
*
Expand All @@ -113,52 +88,6 @@ public function _id(?string $_id = null): self
return $this;
}

/**
* Just an alias for _id() method
*
* @param string|null $_id
*
* @return $this
*/
public function id(?string $_id = null): self
{
return $this->_id($_id);
}

/**
* Add pending document for insert
*
* @param array $data
*
* @return bool
*/
public function insert(array $data = []): bool
{
return $this->action('index', $data);
}

/**
* Add pending document for update
*
* @param array $data
*
* @return bool
*/
public function update(array $data = []): bool
{
return $this->action('update', $data);
}

/**
* Add pending document for deletion
*
* @return bool
*/
public function delete(): bool
{
return $this->action('delete');
}

/**
* Add pending document abstract action
*
Expand All @@ -169,7 +98,7 @@ public function delete(): bool
*/
public function action(string $actionType, array $data = []): bool
{
$this->body["body"][] = [
$this->body['body'][] = [
$actionType => [
'_index' => $this->getIndex(),
'_type' => $this->getType(),
Expand All @@ -178,8 +107,8 @@ public function action(string $actionType, array $data = []): bool
];

if ( ! empty($data)) {
$this->body["body"][] = $actionType === "update"
? ["doc" => $data]
$this->body['body'][] = $actionType === 'update'
? ['doc' => $data]
: $data;
}

Expand Down Expand Up @@ -207,17 +136,6 @@ public function body(): array
return $this->body;
}

/**
* Reset names
*
* @return void
*/
public function reset(): void
{
$this->index();
$this->type();
}

/**
* Commit all pending operations
*
Expand All @@ -241,6 +159,91 @@ public function commit(): ?array
return $result;
}

/**
* Add pending document for deletion
*
* @return bool
*/
public function delete(): bool
{
return $this->action('delete');
}

/**
* Just an alias for _id() method
*
* @param string|null $_id
*
* @return $this
*/
public function id(?string $_id = null): self
{
return $this->_id($_id);
}

/**
* Set the index name
*
* @param string|null $index
*
* @return $this
*/
public function index(?string $index = null): self
{
$this->index = $index;

return $this;
}

/**
* Add pending document for insert
*
* @param array $data
*
* @return bool
*/
public function insert(array $data = []): bool
{
return $this->action('index', $data);
}

/**
* Reset names
*
* @return void
*/
public function reset(): void
{
$this->index();
$this->type();
}

/**
* Set the type name
*
* @param string|null $type
*
* @return $this
*/
public function type(?string $type = null): self
{
$this->type = $type;

return $this;
}

/**
* Add pending document for update
*
* @param array $data
*
* @return bool
*/
public function update(array $data = []): bool
{
return $this->action('update', $data);
}

/**
* Get the index name
*
Expand All @@ -255,9 +258,10 @@ protected function getIndex(): ?string
* Get the type name
*
* @return string|null
* @deprecated Mapping types are deprecated as of Elasticsearch 6.0.0
* @deprecated Mapping types are deprecated as of Elasticsearch 7.0.0
* @see https://www.elastic.co/guide/en/elasticsearch/reference/7.10/removal-of-types.html
*/
#[Deprecated(reason: 'Mapping types are deprecated as of Elasticsearch 7.0.0')]
protected function getType(): ?string
{
return $this->type ?: $this->query->getType();
Expand Down
4 changes: 3 additions & 1 deletion src/Compatibility/HasAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Str;
use InvalidArgumentException;
use JetBrains\PhpStorm\Deprecated;
use JsonException;
use LogicException;
use Matchory\Elasticsearch\Compatibility\Exceptions\InvalidCastException;
Expand Down Expand Up @@ -176,12 +177,13 @@ trait HasAttributes
protected $classCastCache = [];

/**
* The attributes that should be mutated to dates.
* The attributes that should be mutated to date objects.
*
* @deprecated Use the "casts" property
*
* @var array
*/
#[Deprecated(replacement: '%class%->casts')]
protected $dates = [];

/**
Expand Down
Loading

0 comments on commit 9ffab37

Please sign in to comment.