Description
Helpers are not final classes, so it is assumed we can extend them.
If, for any chance, you needed to extend ProgressBar
, it would fail.
This test
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Tests\Fixtures\DummyOutput;
class ProgressBarExtensibilityTest extends PHPUnit_Framework_TestCase
{
public function testStart()
{
$progressBar = new ExtendedProgressBar(new DummyOutput());
$progressBar->start(10);
}
}
class ExtendedProgressBar extends ProgressBar
{
}
fails with the message
PHP Fatal error: Call to private method Symfony\Component\Console\Helper\ProgressBar::getStepWidth() from context 'ProgressBar'
in vendor/symfony/symfony/src/Symfony/Component/Console/Helper/ProgressBar.php on line 573
It happens because the private method getStepWidth
is called in a closure:
'current' => function (ProgressBar $bar) {
return str_pad($bar->getProgress(), $bar->getStepWidth(), ' ', STR_PAD_LEFT);
},
It works only inside ProgressBar
but ExtendedProgressBar
has no access to private methods of the parent class.
My proposal is to change a visibility of ProgressBar::getStepWidth
to protected
.
All other ProgressBar
methods that are used in the same context (in initPlaceholderFormatters
) are public.
(I'd work on PR if there are no objections or other ideas.)