Skip to content

Commit 0974fb4

Browse files
committed
change from protected to private where possible
1 parent 11ac772 commit 0974fb4

12 files changed

+35
-35
lines changed

src/Client/ElasticaClient.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
class ElasticaClient
1111
{
12-
protected Client $client;
12+
private Client $client;
1313

14-
protected static ?bool $listenToEvents = null;
14+
private static ?bool $listenToEvents = null;
1515

1616
public function __construct()
1717
{

src/Commands/DeleteCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ class DeleteCommand extends Command
1515
protected $description = 'Delete all Elasticsearch indices known to the package';
1616

1717
public function __construct(
18-
protected ElasticaClient $elastica,
19-
protected IndexRepository $indexRepository
18+
private readonly ElasticaClient $elastica,
19+
private readonly IndexRepository $indexRepository
2020
) {
2121
parent::__construct();
2222
}

src/Commands/IndexCommand.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use Illuminate\Console\Command;
88
use Illuminate\Support\Facades\Bus;
9-
use Limenet\LaravelElasticaBridge\Client\ElasticaClient;
109
use Limenet\LaravelElasticaBridge\Jobs\ActivateIndex;
1110
use Limenet\LaravelElasticaBridge\Jobs\PopulateIndex;
1211
use Limenet\LaravelElasticaBridge\Jobs\SetupIndex;
@@ -19,8 +18,7 @@ class IndexCommand extends Command
1918
protected $description = 'Re-create the ES index and populate with data';
2019

2120
public function __construct(
22-
protected ElasticaClient $elastica,
23-
protected IndexRepository $indexRepository
21+
private readonly IndexRepository $indexRepository
2422
) {
2523
parent::__construct();
2624
}

src/Commands/StatusCommand.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class StatusCommand extends Command
1717
protected $description = 'Displays the status of the configured Elasticsearch indices';
1818

1919
public function __construct(
20-
protected ElasticaClient $elastica,
21-
protected IndexRepository $indexRepository
20+
private readonly ElasticaClient $elastica,
21+
private readonly IndexRepository $indexRepository
2222
) {
2323
parent::__construct();
2424
}
@@ -85,7 +85,7 @@ public function handle(): int
8585
return self::SUCCESS;
8686
}
8787

88-
protected function formatBoolean(bool $val): string
88+
private function formatBoolean(bool $val): string
8989
{
9090
if ($val) {
9191
return '';
@@ -97,7 +97,7 @@ protected function formatBoolean(bool $val): string
9797
/**
9898
* @see https://stackoverflow.com/a/2510540
9999
*/
100-
protected function formatBytes(int $bytes): string
100+
private function formatBytes(int $bytes): string
101101
{
102102
$base = log($bytes, 1024);
103103
$suffixes = ['', 'K', 'M', 'G', 'T'];

src/Index/AbstractIndex.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020

2121
abstract class AbstractIndex implements IndexInterface
2222
{
23-
public function __construct(protected ElasticaClient $client)
24-
{
23+
public function __construct(
24+
protected ElasticaClient $client
25+
) {
2526
$this->client = $client;
2627
}
2728

src/Jobs/ActivateIndex.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88

99
class ActivateIndex extends AbstractIndexJob
1010
{
11-
public function __construct(protected IndexInterface $indexConfig)
12-
{
11+
public function __construct(
12+
protected IndexInterface $indexConfig
13+
) {
1314
}
1415

1516
public function handle(): void

src/Jobs/PopulateBatchIndex.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ class PopulateBatchIndex implements ShouldQueue
2424
use SerializesModels;
2525

2626
public function __construct(
27-
protected Index $index,
28-
protected IndexInterface $indexConfig,
29-
protected string $indexDocument,
30-
protected int $limit,
31-
protected int $offset
27+
private readonly Index $index,
28+
private readonly IndexInterface $indexConfig,
29+
private readonly string $indexDocument,
30+
private readonly int $limit,
31+
private readonly int $offset
3232
) {
3333
}
3434

src/Jobs/PopulateIndex.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ class PopulateIndex extends AbstractIndexJob
1111
{
1212
use Batchable;
1313

14-
public function __construct(protected IndexInterface $indexConfig)
15-
{
14+
public function __construct(
15+
protected IndexInterface $indexConfig
16+
) {
1617
}
1718

1819
public function handle(): void

src/Jobs/SetupIndex.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class SetupIndex extends AbstractIndexJob
1818

1919
public function __construct(
2020
protected IndexInterface $indexConfig,
21-
protected bool $deleteExisting
21+
private readonly bool $deleteExisting
2222
) {
2323
}
2424

src/Model/ElasticsearchableTrait.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,11 @@ public function toElasticaDocument(IndexInterface $indexConfig): Document
3232
{
3333
return new Document(
3434
$this->getElasticsearchId(),
35-
array_merge(
36-
$this->toElasticsearch($indexConfig),
37-
[
38-
IndexInterface::DOCUMENT_MODEL_CLASS => $this::class,
39-
IndexInterface::DOCUMENT_MODEL_ID => $this->id,
40-
]
41-
)
35+
[
36+
...$this->toElasticsearch($indexConfig),
37+
IndexInterface::DOCUMENT_MODEL_CLASS => $this::class,
38+
IndexInterface::DOCUMENT_MODEL_ID => $this->id,
39+
]
4240
);
4341
}
4442
}

src/Repository/IndexRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
class IndexRepository
1515
{
16-
protected array $indices;
16+
private array $indices;
1717

1818
public function __construct(array $indices)
1919
{

src/Services/ModelEventListener.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ class ModelEventListener
3030
self::EVENT_DELETED,
3131
];
3232

33-
public function __construct(protected IndexRepository $indexRepository)
34-
{
33+
public function __construct(
34+
private readonly IndexRepository $indexRepository
35+
) {
3536
}
3637

3738
public function handle(string $event, Model $model): void
@@ -58,13 +59,13 @@ public function handle(string $event, Model $model): void
5859
}
5960

6061
/** @param ElasticsearchableInterface&Model $model */
61-
protected function ensureModelPresentInIndex(IndexInterface $index, Model $model): void
62+
private function ensureModelPresentInIndex(IndexInterface $index, Model $model): void
6263
{
6364
$index->getElasticaIndex()->addDocument($model->toElasticaDocument($index));
6465
}
6566

6667
/** @param ElasticsearchableInterface&Model $model */
67-
protected function ensureModelMissingFromIndex(IndexInterface $index, Model $model): void
68+
private function ensureModelMissingFromIndex(IndexInterface $index, Model $model): void
6869
{
6970
try {
7071
$index->getElasticaIndex()->deleteById($model->getElasticsearchId());

0 commit comments

Comments
 (0)