<?php

namespace Concise\Console\ResultPrinter\Utilities;

use Concise\Core\ArgumentChecker;

class ProportionalProgressBar extends ProgressBar
{
    /**
     * @param integer $size
     * @param integer $total
     * @param array   $parts
     * @return string
     */
    public function renderProportional($size, $total, array $parts)
    {
        ArgumentChecker::check($size, 'integer');
        ArgumentChecker::check($total, 'integer', 2);

        $this->calculateTotal($parts);
        if (0 === $total) {
            $total = $this->total;
        }
        if (0 === $total) {
            return str_repeat('_', $size);
        }
        $barSize = $size * $this->total / $total;
        $bar = parent::render((int)$barSize, $parts);
        $spaces = $size - substr_count($bar, ' ');

        return $bar . str_repeat('_', $spaces);
    }
}

<?php

namespace Concise\Console\ResultPrinter\Utilities;

use Concise\Core\ArgumentChecker;

class ProportionalProgressBar extends ProgressBar
{
    /**
     * @param integer $size
     * @param integer $total
     * @param array   $parts
     * @return string
     */
    public function renderProportional($size, $total, array $parts)
    {
        ArgumentChecker::check($size, 'integer');
        ArgumentChecker::check($total, 'integer', 2);

        $this->calculateTotal($parts);
        if (0 === $total) {
            $total = $this->total;
        }
        if (0 === $total) {
            return str_repeat('_', $size);
        }
        $barSize = min($size * $this->total / $total, $size);
        $bar = parent::render((int)$barSize, $parts);
        $spaces = max(0, $size - substr_count($bar, ' '));

        return $bar . str_repeat('_', $spaces);
    }
}

Fix bug where progress bar can be wider than the screen
Fix bug where progress bar can be wider than the screen
