Skip to content

Commit 8d542e2

Browse files
committed
MAGE-941 Refactor entity helpers to use trait
1 parent 8a001f6 commit 8d542e2

File tree

6 files changed

+23
-40
lines changed

6 files changed

+23
-40
lines changed

Helper/Entity/AdditionalSectionHelper.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
class AdditionalSectionHelper extends AbstractEntityHelper
1313
{
14+
use EntityHelperTrait;
15+
public const INDEX_NAME_SUFFIX = '_section';
16+
1417
public function __construct(
1518
protected ManagerInterface $eventManager,
1619
protected CollectionFactory $collectionFactory,
@@ -21,14 +24,6 @@ public function __construct(
2124
parent::__construct($indexNameFetcher);
2225
}
2326

24-
/**
25-
* @inheritDoc
26-
*/
27-
public function getIndexNameSuffix(): string
28-
{
29-
return '_section';
30-
}
31-
3227
public function getIndexSettings($storeId): array
3328
{
3429
$indexSettings = [

Helper/Entity/CategoryHelper.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
class CategoryHelper extends AbstractEntityHelper
2626
{
27+
use EntityHelperTrait;
28+
public const INDEX_NAME_SUFFIX = '_categories';
2729
protected $isCategoryVisibleInMenuCache;
2830
protected $coreCategories;
2931
protected $idColumn;
@@ -48,14 +50,6 @@ public function __construct(
4850
parent::__construct($indexNameFetcher);
4951
}
5052

51-
/**
52-
* @inheritDoc
53-
*/
54-
public function getIndexNameSuffix(): string
55-
{
56-
return '_categories';
57-
}
58-
5953
/**
6054
* @param $storeId
6155
* @return array|mixed|null

Helper/Entity/EntityHelperTrait.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Algolia\AlgoliaSearch\Helper\Entity;
4+
5+
trait EntityHelperTrait
6+
{
7+
public function getIndexNameSuffix(): string
8+
{
9+
return self::INDEX_NAME_SUFFIX;
10+
}
11+
}

Helper/Entity/PageHelper.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
class PageHelper extends AbstractEntityHelper
1717
{
18+
use EntityHelperTrait;
19+
public const INDEX_NAME_SUFFIX = '_pages';
20+
1821
public function __construct(
1922
protected ManagerInterface $eventManager,
2023
protected PageCollectionFactory $pageCollectionFactory,
@@ -28,14 +31,6 @@ public function __construct(
2831
parent::__construct($indexNameFetcher);
2932
}
3033

31-
/**
32-
* @inheritDoc
33-
*/
34-
public function getIndexNameSuffix(): string
35-
{
36-
return '_pages';
37-
}
38-
3934
public function getIndexSettings($storeId)
4035
{
4136
$indexSettings = [

Helper/Entity/ProductHelper.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
class ProductHelper extends AbstractEntityHelper
4343
{
44+
use EntityHelperTrait;
4445
public const INDEX_NAME_SUFFIX = '_products';
4546
/**
4647
* @var AbstractType[]
@@ -113,14 +114,6 @@ public function __construct(
113114
parent::__construct($indexNameFetcher);
114115
}
115116

116-
/**
117-
* @inheritDoc
118-
*/
119-
public function getIndexNameSuffix(): string
120-
{
121-
return self::INDEX_NAME_SUFFIX;
122-
}
123-
124117
/**
125118
* @param bool $addEmptyRow
126119
* @return array

Helper/Entity/SuggestionHelper.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
class SuggestionHelper extends AbstractEntityHelper
1717
{
18+
use EntityHelperTrait;
19+
public const INDEX_NAME_SUFFIX = '_suggestions';
20+
1821
/**
1922
* @var string
2023
*/
@@ -32,14 +35,6 @@ public function __construct(
3235
parent::__construct($indexNameFetcher);
3336
}
3437

35-
/**
36-
* @inheritDoc
37-
*/
38-
public function getIndexNameSuffix(): string
39-
{
40-
return '_suggestions';
41-
}
42-
4338
/**
4439
* @param $storeId
4540
* @return array|mixed|null

0 commit comments

Comments
 (0)