Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.

Commit f8fae79

Browse files
committed
Simplified helper validation logic
Instead of using the `$instanceOf` property, uses a compound conditional testing for either callables or `HelperInterface` implementations.
1 parent 89f86b7 commit f8fae79

File tree

2 files changed

+14
-21
lines changed

2 files changed

+14
-21
lines changed

src/HelperPluginManager.php

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,6 @@ class HelperPluginManager extends AbstractPluginManager
137137
'ViewModel' => Helper\ViewModel::class,
138138
];
139139

140-
protected $instanceOf = 'callable';
141-
142140
/**
143141
* Default factories
144142
*
@@ -397,29 +395,19 @@ public function injectEventManager($first, $second)
397395
/**
398396
* Validate the plugin is of the expected type (v3).
399397
*
400-
* Validates against `$instanceOf`.
398+
* Validates against callables and HelperInterface implementations.
401399
*
402400
* @param mixed $instance
403401
* @throws InvalidServiceException
404402
*/
405403
public function validate($instance)
406404
{
407-
if ('callable' === $this->instanceOf) {
408-
if (is_callable($instance)) {
409-
return;
410-
}
411-
412-
$instanceOf = Helper\HelperInterface::class;
413-
} else {
414-
$instanceOf = $this->instanceOf;
415-
}
416-
417-
if (!$instance instanceof $instanceOf) {
405+
if (! is_callable($instance) && ! $instance instanceof Helper\HelperInterface) {
418406
throw new InvalidServiceException(
419407
sprintf(
420-
'%s can only create instances of %s; %s is invalid',
408+
'%s can only create instances of %s and/or callables; %s is invalid',
421409
get_class($this),
422-
$this->instanceOf,
410+
Helper\HelperInterface::class,
423411
(is_object($instance) ? get_class($instance) : gettype($instance))
424412
)
425413
);

test/HelperPluginManagerCompatibilityTest.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@ protected function getV2InvalidPluginException()
5555
return InvalidHelperException::class;
5656
}
5757

58-
protected function getInstanceOf()
59-
{
60-
return 'callable';
61-
}
62-
6358
public function aliasProvider()
6459
{
6560
$pluginManager = $this->getPluginManager();
@@ -81,4 +76,14 @@ public function aliasProvider()
8176
yield $alias => [$alias, $target];
8277
}
8378
}
79+
80+
public function getInstanceOf()
81+
{
82+
// no-op; instanceof is not used in this implementation
83+
}
84+
85+
public function testInstanceOfMatches()
86+
{
87+
$this->markTestSkipped('instanceOf is not used with this implementation');
88+
}
8489
}

0 commit comments

Comments
 (0)