Skip to content

Commit 6a6134c

Browse files
authored
[5.4][PHP8.5] setAccessible() methods of various Reflection objects have been deprecated (joomla#46202)
https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_reflectionsetaccessible
1 parent 7df622b commit 6a6134c

File tree

8 files changed

+1
-44
lines changed

8 files changed

+1
-44
lines changed

administrator/components/com_scheduler/src/Traits/TaskPluginTrait.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,6 @@ public function standardRoutineHandler(ExecuteTaskEvent $event): void
296296
}
297297

298298
try {
299-
// Enable invocation of private/protected methods.
300-
$method->setAccessible(true);
301299
$exitCode = $method->invoke($this, $event);
302300
} catch (\ReflectionException $e) {
303301
// @todo replace with language string (?)

tests/Unit/Libraries/Cms/Feed/FeedFactoryTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,7 @@ public function testFetchFeedParser()
145145
// Use reflection to test private method
146146
$reflectionClass = new \ReflectionClass($this->feedFactory);
147147
$method = $reflectionClass->getMethod('_fetchFeedParser');
148-
$method->setAccessible(true);
149-
$parser = $method->invoke($this->feedFactory, $tagName, new \XMLReader());
148+
$parser = $method->invoke($this->feedFactory, $tagName, new \XMLReader());
150149

151150
$this->assertInstanceOf(FeedParser::class, $parser);
152151
$this->assertSame(\get_class($parseMock), \get_class($parser));
@@ -166,7 +165,6 @@ public function testFetchFeedParserWithInvalidTag()
166165
// Use reflection to test private method
167166
$reflectionClass = new \ReflectionClass($this->feedFactory);
168167
$method = $reflectionClass->getMethod('_fetchFeedParser');
169-
$method->setAccessible(true);
170168
$method->invoke($this->feedFactory, 'not-existing', new \XMLReader());
171169
}
172170
}

tests/Unit/Libraries/Cms/Feed/FeedParserTest.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ public function testMoveToNextElement()
227227
// Use reflection to test protected method (it's easier than testing this using the public interface)
228228
$reflectionClass = new \ReflectionClass($parser);
229229
$method = $reflectionClass->getMethod('moveToNextElement');
230-
$method->setAccessible(true);
231230

232231
// Move to next element
233232
$method->invoke($parser);
@@ -272,7 +271,6 @@ public function testMoveToNextElementByName()
272271
// Use reflection to test protected method (it's easier than testing this using the public interface)
273272
$reflectionClass = new \ReflectionClass($parser);
274273
$method = $reflectionClass->getMethod('moveToNextElement');
275-
$method->setAccessible(true);
276274

277275
// Move to next element
278276
$method->invoke($parser, 'node');
@@ -305,7 +303,6 @@ public function testMoveToClosingElement()
305303
// Use reflection to test protected method (it's easier than testing this using the public interface)
306304
$reflectionClass = new \ReflectionClass($parser);
307305
$method = $reflectionClass->getMethod('moveToClosingElement');
308-
$method->setAccessible(true);
309306

310307
// Move to next element
311308
$method->invoke($parser);
@@ -334,7 +331,6 @@ public function testMoveToClosingElementWithInternalElements()
334331
// Use reflection to test protected method (it's easier than testing this using the public interface)
335332
$reflectionClass = new \ReflectionClass($parser);
336333
$method = $reflectionClass->getMethod('moveToClosingElement');
337-
$method->setAccessible(true);
338334

339335
// Move to next element
340336
$method->invoke($parser);
@@ -363,7 +359,6 @@ public function testMoveToClosingElementWithSelfClosingTag()
363359
// Use reflection to test protected method (it's easier than testing this using the public interface)
364360
$reflectionClass = new \ReflectionClass($parser);
365361
$method = $reflectionClass->getMethod('moveToClosingElement');
366-
$method->setAccessible(true);
367362

368363
// Move to closing element
369364
$method->invoke($parser);

tests/Unit/Libraries/Cms/Feed/Parser/AtomParserTest.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ public function testHandleAuthor()
5858
$atomParser = new AtomParser(new \XMLReader());
5959
$reflectionClass = new \ReflectionClass($atomParser);
6060
$method = $reflectionClass->getMethod('handleAuthor');
61-
$method->setAccessible(true);
6261
$method->invoke($atomParser, $feedMock, $xmlElement);
6362
}
6463

@@ -95,7 +94,6 @@ public function testHandleContributor()
9594
$atomParser = new AtomParser(new \XMLReader());
9695
$reflectionClass = new \ReflectionClass($atomParser);
9796
$method = $reflectionClass->getMethod('handleContributor');
98-
$method->setAccessible(true);
9997
$method->invoke($atomParser, $feedMock, $xmlElement);
10098
}
10199

@@ -125,7 +123,6 @@ public function testHandleGenerator()
125123
$atomParser = new AtomParser(new \XMLReader());
126124
$reflectionClass = new \ReflectionClass($atomParser);
127125
$method = $reflectionClass->getMethod('handleGenerator');
128-
$method->setAccessible(true);
129126
$method->invoke($atomParser, $feedMock, $xmlElement);
130127
}
131128

@@ -155,7 +152,6 @@ public function testHandleId()
155152
$atomParser = new AtomParser(new \XMLReader());
156153
$reflectionClass = new \ReflectionClass($atomParser);
157154
$method = $reflectionClass->getMethod('handleId');
158-
$method->setAccessible(true);
159155
$method->invoke($atomParser, $feedMock, $xmlElement);
160156
}
161157

@@ -192,7 +188,6 @@ function ($param) use ($href) {
192188
$atomParser = new AtomParser(new \XMLReader());
193189
$reflectionClass = new \ReflectionClass($atomParser);
194190
$method = $reflectionClass->getMethod('handleLink');
195-
$method->setAccessible(true);
196191
$method->invoke($atomParser, $feedMock, $xmlElement);
197192
}
198193

@@ -222,7 +217,6 @@ public function testHandleRights()
222217
$atomParser = new AtomParser(new \XMLReader());
223218
$reflectionClass = new \ReflectionClass($atomParser);
224219
$method = $reflectionClass->getMethod('handleRights');
225-
$method->setAccessible(true);
226220
$method->invoke($atomParser, $feedMock, $xmlElement);
227221
}
228222

@@ -252,7 +246,6 @@ public function testHandleSubtitle()
252246
$atomParser = new AtomParser(new \XMLReader());
253247
$reflectionClass = new \ReflectionClass($atomParser);
254248
$method = $reflectionClass->getMethod('handleSubtitle');
255-
$method->setAccessible(true);
256249
$method->invoke($atomParser, $feedMock, $xmlElement);
257250
}
258251

@@ -282,7 +275,6 @@ public function testHandleTitle()
282275
$atomParser = new AtomParser(new \XMLReader());
283276
$reflectionClass = new \ReflectionClass($atomParser);
284277
$method = $reflectionClass->getMethod('handleTitle');
285-
$method->setAccessible(true);
286278
$method->invoke($atomParser, $feedMock, $xmlElement);
287279
}
288280

@@ -312,7 +304,6 @@ public function testHandleUpdated()
312304
$atomParser = new AtomParser(new \XMLReader());
313305
$reflectionClass = new \ReflectionClass($atomParser);
314306
$method = $reflectionClass->getMethod('handleUpdated');
315-
$method->setAccessible(true);
316307
$method->invoke($atomParser, $feedMock, $xmlElement);
317308
}
318309

@@ -335,7 +326,6 @@ public function testInitialiseSetsDefaultVersionWithXmlDocType()
335326
// Use reflection to check the value
336327
$reflectionClass = new \ReflectionClass($atomParser);
337328
$attribute = $reflectionClass->getProperty('version');
338-
$attribute->setAccessible(true);
339329

340330
$this->assertEquals('1.0', $attribute->getValue($atomParser));
341331
}
@@ -375,7 +365,6 @@ public function testInitialiseSetsDefaultVersion()
375365
// Use reflection to check the value
376366
$reflectionClass = new \ReflectionClass($atomParser);
377367
$attribute = $reflectionClass->getProperty('version');
378-
$attribute->setAccessible(true);
379368

380369
$this->assertEquals('1.0', $attribute->getValue($atomParser));
381370
}
@@ -415,7 +404,6 @@ public function testInitialiseSetsOldVersion()
415404
// Use reflection to check the value
416405
$reflectionClass = new \ReflectionClass($atomParser);
417406
$attribute = $reflectionClass->getProperty('version');
418-
$attribute->setAccessible(true);
419407

420408
$this->assertEquals('0.3', $attribute->getValue($atomParser));
421409
}
@@ -463,7 +451,6 @@ public function testProcessFeedEntry()
463451
$atomParser = new AtomParser(new \XMLReader());
464452
$reflectionClass = new \ReflectionClass($atomParser);
465453
$method = $reflectionClass->getMethod('processFeedEntry');
466-
$method->setAccessible(true);
467454
$method->invoke($atomParser, $feedEntryMock, $xmlElement);
468455
}
469456
}

tests/Unit/Libraries/Cms/Feed/Parser/RssParserTest.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ public function testHandleCategory()
5252
$rssParser = new RssParser(new \XMLReader());
5353
$reflectionClass = new \ReflectionClass($rssParser);
5454
$method = $reflectionClass->getMethod('handleCategory');
55-
$method->setAccessible(true);
5655
$method->invoke($rssParser, $feedMock, $xmlElement);
5756
}
5857

@@ -102,7 +101,6 @@ function ($value) use ($cloud) {
102101
$rssParser = new RssParser(new \XMLReader());
103102
$reflectionClass = new \ReflectionClass($rssParser);
104103
$method = $reflectionClass->getMethod('handleCloud');
105-
$method->setAccessible(true);
106104
$method->invoke($rssParser, $feedMock, $xmlElement);
107105
}
108106

@@ -132,7 +130,6 @@ public function testHandleCopyright()
132130
$rssParser = new RssParser(new \XMLReader());
133131
$reflectionClass = new \ReflectionClass($rssParser);
134132
$method = $reflectionClass->getMethod('handleCopyright');
135-
$method->setAccessible(true);
136133
$method->invoke($rssParser, $feedMock, $xmlElement);
137134
}
138135

@@ -162,7 +159,6 @@ public function testHandleDescription()
162159
$rssParser = new RssParser(new \XMLReader());
163160
$reflectionClass = new \ReflectionClass($rssParser);
164161
$method = $reflectionClass->getMethod('handleDescription');
165-
$method->setAccessible(true);
166162
$method->invoke($rssParser, $feedMock, $xmlElement);
167163
}
168164

@@ -192,7 +188,6 @@ public function testHandleGenerator()
192188
$rssParser = new RssParser(new \XMLReader());
193189
$reflectionClass = new \ReflectionClass($rssParser);
194190
$method = $reflectionClass->getMethod('handleGenerator');
195-
$method->setAccessible(true);
196191
$method->invoke($rssParser, $feedMock, $xmlElement);
197192
}
198193

@@ -244,7 +239,6 @@ function ($value) use ($image) {
244239
$rssParser = new RssParser(new \XMLReader());
245240
$reflectionClass = new \ReflectionClass($rssParser);
246241
$method = $reflectionClass->getMethod('handleImage');
247-
$method->setAccessible(true);
248242
$method->invoke($rssParser, $feedMock, $xmlElement);
249243
}
250244

@@ -274,7 +268,6 @@ public function testHandleLanguage()
274268
$rssParser = new RssParser(new \XMLReader());
275269
$reflectionClass = new \ReflectionClass($rssParser);
276270
$method = $reflectionClass->getMethod('handleLanguage');
277-
$method->setAccessible(true);
278271
$method->invoke($rssParser, $feedMock, $xmlElement);
279272
}
280273

@@ -304,7 +297,6 @@ public function testHandleLastBuildDate()
304297
$rssParser = new RssParser(new \XMLReader());
305298
$reflectionClass = new \ReflectionClass($rssParser);
306299
$method = $reflectionClass->getMethod('handleLastBuildDate');
307-
$method->setAccessible(true);
308300
$method->invoke($rssParser, $feedMock, $xmlElement);
309301
}
310302

@@ -341,7 +333,6 @@ function ($value) use ($link) {
341333
$rssParser = new RssParser(new \XMLReader());
342334
$reflectionClass = new \ReflectionClass($rssParser);
343335
$method = $reflectionClass->getMethod('handleLink');
344-
$method->setAccessible(true);
345336
$method->invoke($rssParser, $feedMock, $xmlElement);
346337
}
347338

@@ -383,7 +374,6 @@ function ($value) use ($editor) {
383374
$rssParser = new RssParser(new \XMLReader());
384375
$reflectionClass = new \ReflectionClass($rssParser);
385376
$method = $reflectionClass->getMethod('handleManagingEditor');
386-
$method->setAccessible(true);
387377
$method->invoke($rssParser, $feedMock, $xmlElement);
388378
}
389379

@@ -413,7 +403,6 @@ public function testHandlePubDate()
413403
$rssParser = new RssParser(new \XMLReader());
414404
$reflectionClass = new \ReflectionClass($rssParser);
415405
$method = $reflectionClass->getMethod('handlePubDate');
416-
$method->setAccessible(true);
417406
$method->invoke($rssParser, $feedMock, $xmlElement);
418407
}
419408

@@ -443,7 +432,6 @@ public function testHandleSkipDays()
443432
$rssParser = new RssParser(new \XMLReader());
444433
$reflectionClass = new \ReflectionClass($rssParser);
445434
$method = $reflectionClass->getMethod('handleSkipDays');
446-
$method->setAccessible(true);
447435
$method->invoke($rssParser, $feedMock, $xmlElement);
448436
}
449437

@@ -473,7 +461,6 @@ public function testHandleSkipHours()
473461
$rssParser = new RssParser(new \XMLReader());
474462
$reflectionClass = new \ReflectionClass($rssParser);
475463
$method = $reflectionClass->getMethod('handleSkipHours');
476-
$method->setAccessible(true);
477464
$method->invoke($rssParser, $feedMock, $xmlElement);
478465
}
479466

@@ -503,7 +490,6 @@ public function testHandleTitle()
503490
$rssParser = new RssParser(new \XMLReader());
504491
$reflectionClass = new \ReflectionClass($rssParser);
505492
$method = $reflectionClass->getMethod('handleTitle');
506-
$method->setAccessible(true);
507493
$method->invoke($rssParser, $feedMock, $xmlElement);
508494
}
509495

@@ -533,7 +519,6 @@ public function testHandleTtl()
533519
$rssParser = new RssParser(new \XMLReader());
534520
$reflectionClass = new \ReflectionClass($rssParser);
535521
$method = $reflectionClass->getMethod('handleTtl');
536-
$method->setAccessible(true);
537522
$method->invoke($rssParser, $feedMock, $xmlElement);
538523
}
539524

@@ -566,7 +551,6 @@ public function testHandleWebmaster()
566551
$rssParser = new RssParser(new \XMLReader());
567552
$reflectionClass = new \ReflectionClass($rssParser);
568553
$method = $reflectionClass->getMethod('handleWebmaster');
569-
$method->setAccessible(true);
570554
$method->invoke($rssParser, $feedMock, $xmlElement);
571555
}
572556

@@ -608,7 +592,6 @@ public function testParseSetsVersion()
608592
$reflectionClass = new \ReflectionClass($rssParser);
609593
$attribute = $reflectionClass->getProperty('version');
610594

611-
$attribute->setAccessible(true);
612595
$this->assertEquals('2.0', $attribute->getValue($rssParser));
613596
}
614597

@@ -697,7 +680,6 @@ function ($value) use ($entry) {
697680
$rssParser = new RssParser(new \XMLReader());
698681
$reflectionClass = new \ReflectionClass($rssParser);
699682
$method = $reflectionClass->getMethod('processFeedEntry');
700-
$method->setAccessible(true);
701683
$method->invoke($rssParser, $feedEntryMock, $xmlElement);
702684
}
703685
}

tests/Unit/Libraries/Cms/Microdata/MicrodataTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,6 @@ public function testExpectedDisplayType()
929929
// Use reflection to test protected method (it's easier than testing this using the public interface)
930930
$reflectionClass = new \ReflectionClass($microdata);
931931
$method = $reflectionClass->getMethod('getExpectedDisplayType');
932-
$method->setAccessible(true);
933932

934933
$this->assertEquals('normal', $method->invoke($microdata, 'Article', 'articleBody'));
935934
$this->assertEquals('nested', $method->invoke($microdata, 'Article', 'about'));

tests/Unit/Libraries/Cms/Updater/ConstraintCheckerTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ protected function getPublicMethod($method)
219219
{
220220
$reflectionClass = new \ReflectionClass($this->checker);
221221
$method = $reflectionClass->getMethod($method);
222-
$method->setAccessible(true);
223222

224223
return $method;
225224
}

tests/Unit/Libraries/Cms/Updater/TufAdapterTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ protected function getPublicMethod($object, $method)
124124
{
125125
$reflectionClass = new \ReflectionClass($object);
126126
$method = $reflectionClass->getMethod($method);
127-
$method->setAccessible(true);
128127

129128
return $method;
130129
}

0 commit comments

Comments
 (0)