Herzult / SimplePHPEasyPlus

A simple, pragmatic numeric operation api written in PHP. It does addition.
MIT License
1.16k stars 46 forks source link

Use reflection instead of string class name #35

Closed VaclavSir closed 9 years ago

VaclavSir commented 11 years ago

I don't really like this line from the readme:

$addition = new AdditionOperator('SimplePHPEasyPlus\Number\SimpleNumber');

String constants are almost as bad code smell as the addition operator. SimpleNumber class should provide a static method that returns its reflection. Something like this:

public static function getReflection()
{
    return new ReflectionClass(get_called_class());
}

AdditionOperator could use ReflectionClass::newInstance() instead of new $resultClass() and the line mentioned above would look much cleaner then:

$addition = new AdditionOperator(SimpleNumber::getReflection());