TASK: Refactor code

* Reduce indentation.
* Provide internal API to add new feature with necessary checks.
This commit is contained in:
Daniel Siepmann 2017-04-25 16:36:12 +02:00
parent 7f7a7aa38d
commit 370015e7c0
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4

View file

@ -47,16 +47,28 @@ class Features implements \Iterator
{ {
foreach (Options::getFeaturesConfiguration() as $featureName => $sniffs) { foreach (Options::getFeaturesConfiguration() as $featureName => $sniffs) {
if (in_array(get_class($sniff), $sniffs)) { if (in_array(get_class($sniff), $sniffs)) {
$this->addFeature($featureName);
}
}
}
/**
* Add the given feature.
*
* @param string $featureName
* @return void
*/
protected function addFeature($featureName)
{
if (!class_implements($featureName, FeatureInterface::class)) { if (!class_implements($featureName, FeatureInterface::class)) {
throw new \Exception( throw new \Exception(
'Configured Feature "' . $featureName . '" does not implement "' . FeatureInterface::class . '".', 'Configured Feature "' . $featureName . '" does not implement "' . FeatureInterface::class . '".',
1493115488 1493115488
); );
} }
$this->features[] = $featureName; $this->features[] = $featureName;
} }
}
}
// implement Iterator interface: // implement Iterator interface:
public function current() public function current()