The `php_sapi_name() == 'cli'` happens several times in the class. I think the code might be simpler if you set a protected property. It would also save calling a function many times.