Skip to content

Commit 4dca8e6

Browse files
committed
MAGETWO-69559: Declaration of dependencies for indexers
1 parent 6cdfd68 commit 4dca8e6

File tree

12 files changed

+256
-257
lines changed

12 files changed

+256
-257
lines changed

app/code/Magento/Indexer/Model/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ public function getIndexers()
4444
*/
4545
public function getIndexer($indexerId)
4646
{
47-
return $this->configData->get($indexerId);
47+
return $this->configData->get($indexerId) ?: [];
4848
}
4949
}

app/code/Magento/Indexer/Model/Indexer/Collection.php

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ class Collection extends \Magento\Framework\Data\Collection
2424
* Collection items
2525
*
2626
* @var IndexerInterface[]
27-
* @since 2.2.0
2827
*/
2928
protected $_items = [];
3029

@@ -86,7 +85,6 @@ public function loadData($printQuery = false, $logQuery = false)
8685

8786
/**
8887
* {@inheritdoc} Prevents handle collection items as DataObject class instances.
89-
* @since 2.2.0
9088
*/
9189
public function getAllIds()
9290
{
@@ -100,7 +98,6 @@ public function getAllIds()
10098
/**
10199
* @inheritdoc
102100
* @return IndexerInterface[]
103-
* @since 2.2.0
104101
*/
105102
public function getItems()
106103
{
@@ -109,9 +106,8 @@ public function getItems()
109106

110107
/**
111108
* {@inheritdoc} Prevents handle collection items as DataObject class instances.
112-
* @deprecated
109+
* @deprecated Should not be used in the current implementation.
113110
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
114-
* @since 2.2.0
115111
*/
116112
public function getColumnValues($colName)
117113
{
@@ -120,9 +116,8 @@ public function getColumnValues($colName)
120116

121117
/**
122118
* {@inheritdoc} Prevents handle collection items as DataObject class instances.
123-
* @deprecated
119+
* @deprecated Should not be used in the current implementation.
124120
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
125-
* @since 2.2.0
126121
*/
127122
public function getItemsByColumnValue($column, $value)
128123
{
@@ -131,9 +126,8 @@ public function getItemsByColumnValue($column, $value)
131126

132127
/**
133128
* {@inheritdoc} Prevents handle collection items as DataObject class instances.
134-
* @deprecated
129+
* @deprecated Should not be used in the current implementation.
135130
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
136-
* @since 2.2.0
137131
*/
138132
public function getItemByColumnValue($column, $value)
139133
{
@@ -142,9 +136,8 @@ public function getItemByColumnValue($column, $value)
142136

143137
/**
144138
* {@inheritdoc} Prevents handle collection items as DataObject class instances.
145-
* @deprecated
139+
* @deprecated Should not be used in the current implementation.
146140
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
147-
* @since 2.2.0
148141
*/
149142
public function setDataToAll($key, $value = null)
150143
{
@@ -153,9 +146,8 @@ public function setDataToAll($key, $value = null)
153146

154147
/**
155148
* {@inheritdoc} Prevents handle collection items as DataObject class instances.
156-
* @deprecated
149+
* @deprecated Should not be used in the current implementation.
157150
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
158-
* @since 2.2.0
159151
*/
160152
public function setItemObjectClass($className)
161153
{
@@ -164,8 +156,7 @@ public function setItemObjectClass($className)
164156

165157
/**
166158
* {@inheritdoc} Prevents handle collection items as DataObject class instances.
167-
* @deprecated
168-
* @since 2.2.0
159+
* @deprecated Should not be used in the current implementation.
169160
*/
170161
public function toXml()
171162
{
@@ -174,9 +165,8 @@ public function toXml()
174165

175166
/**
176167
* {@inheritdoc} Prevents handle collection items as DataObject class instances.
177-
* @deprecated
168+
* @deprecated Should not be used in the current implementation.
178169
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
179-
* @since 2.2.0
180170
*/
181171
public function toArray($arrRequiredFields = [])
182172
{
@@ -185,8 +175,7 @@ public function toArray($arrRequiredFields = [])
185175

186176
/**
187177
* {@inheritdoc} Prevents handle collection items as DataObject class instances.
188-
* @deprecated
189-
* @since 2.2.0
178+
* @deprecated Should not be used in the current implementation.
190179
*/
191180
public function toOptionArray()
192181
{
@@ -195,8 +184,7 @@ public function toOptionArray()
195184

196185
/**
197186
* {@inheritdoc} Prevents handle collection items as DataObject class instances.
198-
* @deprecated
199-
* @since 2.2.0
187+
* @deprecated Should not be used in the current implementation.
200188
*/
201189
public function toOptionHash()
202190
{
@@ -205,9 +193,8 @@ public function toOptionHash()
205193

206194
/**
207195
* {@inheritdoc} Prevents handle collection items as DataObject class instances.
208-
* @deprecated
196+
* @deprecated Should not be used in the current implementation.
209197
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
210-
* @since 2.2.0
211198
*/
212199
protected function _toOptionArray($valueField = 'id', $labelField = 'name', $additional = [])
213200
{
@@ -216,9 +203,8 @@ protected function _toOptionArray($valueField = 'id', $labelField = 'name', $add
216203

217204
/**
218205
* {@inheritdoc} Prevents handle collection items as DataObject class instances.
219-
* @deprecated
206+
* @deprecated Should not be used in the current implementation.
220207
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
221-
* @since 2.2.0
222208
*/
223209
protected function _toOptionHash($valueField = 'id', $labelField = 'name')
224210
{

app/code/Magento/Indexer/Model/Indexer/DependencyDecorator.php

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Indexer\Model\Indexer;
89

910
use Magento\Framework\Indexer\Config\DependencyInfoProviderInterface;
1011
use Magento\Framework\Indexer\IndexerInterface;
1112
use Magento\Framework\Indexer\IndexerRegistry;
1213
use Magento\Framework\Indexer\StateInterface;
14+
use Magento\Framework\Mview\ViewInterface;
1315

1416
/**
1517
* The decorator, which implements logic of the dependency between the indexers.
@@ -51,17 +53,17 @@ public function __construct(
5153
/**
5254
* @inheritdoc
5355
*/
54-
public function __call($method, $args)
56+
public function __call(string $method, array $args)
5557
{
56-
return $this->indexer->__call($method, $args);
58+
return call_user_func_array([$this->indexer, $method], $args);
5759
}
5860

5961
/**
6062
* @return array
6163
*/
6264
public function __sleep()
6365
{
64-
return ['indexer', 'dependencyProvider', 'indexerRegistry', 'mapperHandler'];
66+
return ['indexer', 'dependencyInfoProvider', 'indexerRegistry'];
6567
}
6668

6769
/**
@@ -75,71 +77,71 @@ public function __clone()
7577
/**
7678
* @inheritdoc
7779
*/
78-
public function getId()
80+
public function getId(): string
7981
{
8082
return $this->indexer->getId();
8183
}
8284

8385
/**
8486
* @inheritdoc
8587
*/
86-
public function getViewId()
88+
public function getViewId(): string
8789
{
8890
return $this->indexer->getViewId();
8991
}
9092

9193
/**
9294
* @inheritdoc
9395
*/
94-
public function getActionClass()
96+
public function getActionClass(): string
9597
{
9698
return $this->indexer->getActionClass();
9799
}
98100

99101
/**
100102
* @inheritdoc
101103
*/
102-
public function getTitle()
104+
public function getTitle(): string
103105
{
104106
return $this->indexer->getTitle();
105107
}
106108

107109
/**
108110
* @inheritdoc
109111
*/
110-
public function getDescription()
112+
public function getDescription(): string
111113
{
112114
return $this->indexer->getDescription();
113115
}
114116

115117
/**
116118
* @inheritdoc
117119
*/
118-
public function getFields()
120+
public function getFields(): array
119121
{
120122
return $this->indexer->getFields();
121123
}
122124

123125
/**
124126
* @inheritdoc
125127
*/
126-
public function getSources()
128+
public function getSources(): array
127129
{
128130
return $this->indexer->getSources();
129131
}
130132

131133
/**
132134
* @inheritdoc
133135
*/
134-
public function getHandlers()
136+
public function getHandlers(): array
135137
{
136138
return $this->indexer->getHandlers();
137139
}
138140

139141
/**
140142
* @inheritdoc
141143
*/
142-
public function load($indexerId)
144+
public function load($indexerId): self
143145
{
144146
$this->indexer->load($indexerId);
145147
return $this;
@@ -148,31 +150,32 @@ public function load($indexerId)
148150
/**
149151
* @inheritdoc
150152
*/
151-
public function getView()
153+
public function getView(): ViewInterface
152154
{
153155
return $this->indexer->getView();
154156
}
155157

156158
/**
157159
* @inheritdoc
158160
*/
159-
public function getState()
161+
public function getState(): StateInterface
160162
{
161163
return $this->indexer->getState();
162164
}
163165

164166
/**
165167
* @inheritdoc
166168
*/
167-
public function setState(StateInterface $state)
169+
public function setState(StateInterface $state): self
168170
{
169-
return $this->indexer->setState($state);
171+
$this->indexer->setState($state);
172+
return $this;
170173
}
171174

172175
/**
173176
* @inheritdoc
174177
*/
175-
public function isScheduled()
178+
public function isScheduled(): bool
176179
{
177180
return $this->indexer->isScheduled();
178181
}
@@ -188,29 +191,29 @@ public function setScheduled($scheduled)
188191
/**
189192
* @inheritdoc
190193
*/
191-
public function isValid()
194+
public function isValid(): bool
192195
{
193196
return $this->indexer->isValid();
194197
}
195198

196199
/**
197200
* @inheritdoc
198201
*/
199-
public function isInvalid()
202+
public function isInvalid(): bool
200203
{
201204
return $this->indexer->isInvalid();
202205
}
203206

204207
/**
205208
* @inheritdoc
206209
*/
207-
public function isWorking()
210+
public function isWorking(): bool
208211
{
209212
return $this->indexer->isWorking();
210213
}
211214

212215
/**
213-
* {@inheritdoc}
216+
* @inheritdoc
214217
*/
215218
public function invalidate()
216219
{
@@ -224,15 +227,15 @@ public function invalidate()
224227
/**
225228
* @inheritdoc
226229
*/
227-
public function getStatus()
230+
public function getStatus(): string
228231
{
229232
return $this->indexer->getStatus();
230233
}
231234

232235
/**
233236
* @inheritdoc
234237
*/
235-
public function getLatestUpdated()
238+
public function getLatestUpdated(): string
236239
{
237240
return $this->indexer->getLatestUpdated();
238241
}
@@ -246,7 +249,7 @@ public function reindexAll()
246249
}
247250

248251
/**
249-
* {@inheritdoc}
252+
* @inheritdoc
250253
*/
251254
public function reindexRow($id)
252255
{
@@ -258,7 +261,7 @@ public function reindexRow($id)
258261
}
259262

260263
/**
261-
* {@inheritdoc}
264+
* @inheritdoc
262265
*/
263266
public function reindexList($ids)
264267
{

app/code/Magento/Indexer/Test/Unit/Model/ConfigTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,14 @@ public function testGetIndexer()
4141
$this->configMock->expects($this->once())->method('get')->with($indexerId)->willReturnSelf();
4242
$this->model->getIndexer($indexerId);
4343
}
44+
45+
public function testGetNotExistingIndexer()
46+
{
47+
$indexerId = 1;
48+
$this->configMock
49+
->expects($this->once())
50+
->method('get')
51+
->with($indexerId);
52+
$this->assertEquals([], $this->model->getIndexer($indexerId));
53+
}
4454
}

0 commit comments

Comments
 (0)