Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
78.95% covered (warning)
78.95%
15 / 19
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
command
78.95% covered (warning)
78.95%
15 / 19
50.00% covered (danger)
50.00%
1 / 2
6.34
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 create_progress_bar
76.47% covered (warning)
76.47%
13 / 17
0.00% covered (danger)
0.00%
0 / 1
5.33
1<?php
2/**
3*
4* This file is part of the phpBB Forum Software package.
5*
6* @copyright (c) phpBB Limited <https://www.phpbb.com>
7* @license GNU General Public License, version 2 (GPL-2.0)
8*
9* For full copyright and license information, please see
10* the docs/CREDITS.txt file.
11*
12*/
13
14namespace phpbb\console\command;
15
16use Symfony\Component\Console\Helper\ProgressBar;
17use Symfony\Component\Console\Output\OutputInterface;
18use Symfony\Component\Console\Style\SymfonyStyle;
19
20abstract class command extends \Symfony\Component\Console\Command\Command
21{
22    /** @var \phpbb\user */
23    protected $user;
24
25    /**
26    * Constructor
27    *
28    * @param \phpbb\user $user User instance (mostly for translation)
29    */
30    public function __construct(\phpbb\user $user)
31    {
32        $this->user = $user;
33        parent::__construct();
34    }
35
36    /**
37     * Create a styled progress bar
38     *
39     * @param int             $max     Max value for the progress bar
40     * @param SymfonyStyle    $io      Symfony style output decorator
41     * @param OutputInterface $output  The output stream, used to print messages
42     * @param bool            $message Should we display message output under the progress bar?
43     * @return ProgressBar
44     */
45    public function create_progress_bar($max, SymfonyStyle $io, OutputInterface $output, $message = false)
46    {
47        $progress = $io->createProgressBar($max);
48        if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE)
49        {
50            $progress->setFormat('<info>[%percent:3s%%]</info> %message%');
51            $progress->setOverwrite(false);
52        }
53        else if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE)
54        {
55            $progress->setFormat('<info>[%current:s%/%max:s%]</info><comment>[%elapsed%/%estimated%][%memory%]</comment> %message%');
56            $progress->setOverwrite(false);
57        }
58        else
59        {
60            $io->newLine(2);
61            $progress->setFormat(
62                "    %current:s%/%max:s% %bar%  %percent:3s%%\n" .
63                "        " . ($message ? '%message%' : '                ') . " %elapsed:6s%/%estimated:-6s% %memory:6s%\n");
64            $progress->setBarWidth(60);
65        }
66
67        if (!defined('PHP_WINDOWS_VERSION_BUILD'))
68        {
69            $progress->setEmptyBarCharacter('░'); // light shade character \u2591
70            $progress->setProgressCharacter('');
71            $progress->setBarCharacter('▓'); // dark shade character \u2593
72        }
73
74        return $progress;
75    }
76}