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