Skip to content

Commit 7ac22d8

Browse files
committed
Use constructor property promotion
1 parent 0d2c4b6 commit 7ac22d8

11 files changed

Lines changed: 109 additions & 147 deletions

File tree

src/Documents/Document.php

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,24 @@
77

88
class Document implements Arrayable
99
{
10-
/**
11-
* The OpenSearch document identifier.
12-
*/
13-
protected string $id;
14-
15-
/**
16-
* The document source payload.
17-
*
18-
* @var array<string, mixed>
19-
*/
20-
protected array $content;
21-
2210
/**
2311
* Create a new document instance.
2412
*
2513
* @param array<string, mixed> $content
2614
*/
27-
public function __construct(string $id, array $content)
28-
{
29-
$this->id = $id;
30-
$this->content = $content;
31-
}
15+
public function __construct(
16+
/**
17+
* The OpenSearch document identifier.
18+
*/
19+
protected string $id,
20+
21+
/**
22+
* The document source payload.
23+
*
24+
* @var array<string, mixed>
25+
*/
26+
protected array $content,
27+
) {}
3228

3329
/**
3430
* Get the document identifier.

src/Documents/DocumentManager.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,15 @@
1010

1111
class DocumentManager
1212
{
13-
/**
14-
* The OpenSearch client instance.
15-
*/
16-
protected Client $client;
17-
1813
/**
1914
* Create a new document manager instance.
2015
*/
21-
public function __construct(Client $client)
22-
{
23-
$this->client = $client;
24-
}
16+
public function __construct(
17+
/**
18+
* The OpenSearch client instance.
19+
*/
20+
protected Client $client,
21+
) {}
2522

2623
/**
2724
* Index the given documents into OpenSearch.

src/Exceptions/BulkRequestException.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,19 @@
66

77
class BulkRequestException extends ErrorException
88
{
9-
/**
10-
* The OpenSearch bulk response.
11-
*
12-
* @var array<string, mixed>
13-
*/
14-
protected array $response;
15-
169
/**
1710
* Create a new bulk request exception instance.
1811
*
1912
* @param array<string, mixed> $response
2013
*/
21-
public function __construct(array $response)
22-
{
23-
$this->response = $response;
24-
14+
public function __construct(
15+
/**
16+
* The OpenSearch bulk response.
17+
*
18+
* @var array<string, mixed>
19+
*/
20+
protected array $response,
21+
) {
2522
parent::__construct($this->makeErrorFromResponse());
2623
}
2724

src/Indices/Alias.php

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,29 @@
44

55
class Alias
66
{
7-
/**
8-
* The alias name.
9-
*/
10-
protected string $name;
11-
12-
/**
13-
* The optional alias filter.
14-
*
15-
* @var array<string, mixed>|null
16-
*/
17-
protected ?array $filter;
18-
19-
/**
20-
* The optional alias routing value.
21-
*/
22-
protected ?string $routing;
23-
247
/**
258
* Create a new alias instance.
269
*
2710
* @param array<string, mixed>|null $filter
2811
*/
29-
public function __construct(string $name, ?array $filter = null, ?string $routing = null)
30-
{
31-
$this->name = $name;
32-
$this->filter = $filter;
33-
$this->routing = $routing;
34-
}
12+
public function __construct(
13+
/**
14+
* The alias name.
15+
*/
16+
protected string $name,
17+
18+
/**
19+
* The optional alias filter.
20+
*
21+
* @var array<string, mixed>|null
22+
*/
23+
protected ?array $filter = null,
24+
25+
/**
26+
* The optional alias routing value.
27+
*/
28+
protected ?string $routing = null,
29+
) {}
3530

3631
/**
3732
* Get the alias name.

src/Indices/IndexBlueprint.php

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,25 @@
44

55
class IndexBlueprint
66
{
7-
/**
8-
* The index name.
9-
*/
10-
protected string $name;
11-
12-
/**
13-
* The index mapping definition.
14-
*/
15-
protected ?Mapping $mapping;
16-
17-
/**
18-
* The index settings definition.
19-
*/
20-
protected ?Settings $settings;
21-
227
/**
238
* Create a new index blueprint instance.
249
*/
25-
public function __construct(string $name, ?Mapping $mapping = null, ?Settings $settings = null)
26-
{
27-
$this->name = $name;
28-
$this->mapping = $mapping;
29-
$this->settings = $settings;
30-
}
10+
public function __construct(
11+
/**
12+
* The index name.
13+
*/
14+
protected string $name,
15+
16+
/**
17+
* The index mapping definition.
18+
*/
19+
protected ?Mapping $mapping = null,
20+
21+
/**
22+
* The index settings definition.
23+
*/
24+
protected ?Settings $settings = null,
25+
) {}
3126

3227
/**
3328
* Get the index name.

src/Search/Aggregation.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,19 @@
66

77
class Aggregation implements RawResponseInterface
88
{
9-
/**
10-
* The raw OpenSearch aggregation payload.
11-
*
12-
* @var array<string, mixed>
13-
*/
14-
protected array $aggregation;
15-
169
/**
1710
* Create a new aggregation instance.
1811
*
1912
* @param array<string, mixed> $aggregation
2013
*/
21-
public function __construct(array $aggregation)
22-
{
23-
$this->aggregation = $aggregation;
24-
}
14+
public function __construct(
15+
/**
16+
* The raw OpenSearch aggregation payload.
17+
*
18+
* @var array<string, mixed>
19+
*/
20+
protected array $aggregation,
21+
) {}
2522

2623
/**
2724
* Get the aggregation buckets.

src/Search/Bucket.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,19 @@
44

55
class Bucket implements RawResponseInterface
66
{
7-
/**
8-
* The raw OpenSearch bucket payload.
9-
*
10-
* @var array<string, mixed>
11-
*/
12-
protected array $bucket;
13-
147
/**
158
* Create a new bucket instance.
169
*
1710
* @param array<string, mixed> $bucket
1811
*/
19-
public function __construct(array $bucket)
20-
{
21-
$this->bucket = $bucket;
22-
}
12+
public function __construct(
13+
/**
14+
* The raw OpenSearch bucket payload.
15+
*
16+
* @var array<string, mixed>
17+
*/
18+
protected array $bucket,
19+
) {}
2320

2421
/**
2522
* Get the number of documents in the bucket.

src/Search/Highlight.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,19 @@
66

77
class Highlight implements RawResponseInterface
88
{
9-
/**
10-
* The raw OpenSearch highlight payload.
11-
*
12-
* @var array<string, array<int, string>>
13-
*/
14-
protected array $highlight;
15-
169
/**
1710
* Create a new highlight instance.
1811
*
1912
* @param array<string, array<int, string>> $highlight
2013
*/
21-
public function __construct(array $highlight)
22-
{
23-
$this->highlight = $highlight;
24-
}
14+
public function __construct(
15+
/**
16+
* The raw OpenSearch highlight payload.
17+
*
18+
* @var array<string, array<int, string>>
19+
*/
20+
protected array $highlight,
21+
) {}
2522

2623
/**
2724
* Get highlighted snippets for the given field.

src/Search/Hit.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,19 @@
77

88
class Hit implements RawResponseInterface
99
{
10-
/**
11-
* The raw OpenSearch hit payload.
12-
*
13-
* @var array<string, mixed>
14-
*/
15-
protected array $hit;
16-
1710
/**
1811
* Create a new hit instance.
1912
*
2013
* @param array<string, mixed> $hit
2114
*/
22-
public function __construct(array $hit)
23-
{
24-
$this->hit = $hit;
25-
}
15+
public function __construct(
16+
/**
17+
* The raw OpenSearch hit payload.
18+
*
19+
* @var array<string, mixed>
20+
*/
21+
protected array $hit,
22+
) {}
2623

2724
/**
2825
* Get the index name for the hit.

src/Search/SearchResponse.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,19 @@
66

77
class SearchResponse implements RawResponseInterface
88
{
9-
/**
10-
* The raw OpenSearch search response.
11-
*
12-
* @var array<string, mixed>
13-
*/
14-
protected array $response;
15-
169
/**
1710
* Create a new search response instance.
1811
*
1912
* @param array<string, mixed> $response
2013
*/
21-
public function __construct(array $response)
22-
{
23-
$this->response = $response;
24-
}
14+
public function __construct(
15+
/**
16+
* The raw OpenSearch search response.
17+
*
18+
* @var array<string, mixed>
19+
*/
20+
protected array $response,
21+
) {}
2522

2623
/**
2724
* Get the search hits.

0 commit comments

Comments
 (0)