@@ -21,79 +21,79 @@ |
||
21 | 21 | */ |
22 | 22 | class HelperSet implements \IteratorAggregate |
23 | 23 | { |
24 | - /** |
|
25 | - * @var Helper[] |
|
26 | - */ |
|
27 | - private $helpers = []; |
|
28 | - private $command; |
|
24 | + /** |
|
25 | + * @var Helper[] |
|
26 | + */ |
|
27 | + private $helpers = []; |
|
28 | + private $command; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @param Helper[] $helpers An array of helper |
|
32 | - */ |
|
33 | - public function __construct(array $helpers = []) |
|
34 | - { |
|
35 | - foreach ($helpers as $alias => $helper) { |
|
36 | - $this->set($helper, \is_int($alias) ? null : $alias); |
|
37 | - } |
|
38 | - } |
|
30 | + /** |
|
31 | + * @param Helper[] $helpers An array of helper |
|
32 | + */ |
|
33 | + public function __construct(array $helpers = []) |
|
34 | + { |
|
35 | + foreach ($helpers as $alias => $helper) { |
|
36 | + $this->set($helper, \is_int($alias) ? null : $alias); |
|
37 | + } |
|
38 | + } |
|
39 | 39 | |
40 | - public function set(HelperInterface $helper, string $alias = null) |
|
41 | - { |
|
42 | - $this->helpers[$helper->getName()] = $helper; |
|
43 | - if (null !== $alias) { |
|
44 | - $this->helpers[$alias] = $helper; |
|
45 | - } |
|
40 | + public function set(HelperInterface $helper, string $alias = null) |
|
41 | + { |
|
42 | + $this->helpers[$helper->getName()] = $helper; |
|
43 | + if (null !== $alias) { |
|
44 | + $this->helpers[$alias] = $helper; |
|
45 | + } |
|
46 | 46 | |
47 | - $helper->setHelperSet($this); |
|
48 | - } |
|
47 | + $helper->setHelperSet($this); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * Returns true if the helper if defined. |
|
52 | - * |
|
53 | - * @return bool true if the helper is defined, false otherwise |
|
54 | - */ |
|
55 | - public function has(string $name) |
|
56 | - { |
|
57 | - return isset($this->helpers[$name]); |
|
58 | - } |
|
50 | + /** |
|
51 | + * Returns true if the helper if defined. |
|
52 | + * |
|
53 | + * @return bool true if the helper is defined, false otherwise |
|
54 | + */ |
|
55 | + public function has(string $name) |
|
56 | + { |
|
57 | + return isset($this->helpers[$name]); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Gets a helper value. |
|
62 | - * |
|
63 | - * @return HelperInterface The helper instance |
|
64 | - * |
|
65 | - * @throws InvalidArgumentException if the helper is not defined |
|
66 | - */ |
|
67 | - public function get(string $name) |
|
68 | - { |
|
69 | - if (!$this->has($name)) { |
|
70 | - throw new InvalidArgumentException(sprintf('The helper "%s" is not defined.', $name)); |
|
71 | - } |
|
60 | + /** |
|
61 | + * Gets a helper value. |
|
62 | + * |
|
63 | + * @return HelperInterface The helper instance |
|
64 | + * |
|
65 | + * @throws InvalidArgumentException if the helper is not defined |
|
66 | + */ |
|
67 | + public function get(string $name) |
|
68 | + { |
|
69 | + if (!$this->has($name)) { |
|
70 | + throw new InvalidArgumentException(sprintf('The helper "%s" is not defined.', $name)); |
|
71 | + } |
|
72 | 72 | |
73 | - return $this->helpers[$name]; |
|
74 | - } |
|
73 | + return $this->helpers[$name]; |
|
74 | + } |
|
75 | 75 | |
76 | - public function setCommand(Command $command = null) |
|
77 | - { |
|
78 | - $this->command = $command; |
|
79 | - } |
|
76 | + public function setCommand(Command $command = null) |
|
77 | + { |
|
78 | + $this->command = $command; |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * Gets the command associated with this helper set. |
|
83 | - * |
|
84 | - * @return Command A Command instance |
|
85 | - */ |
|
86 | - public function getCommand() |
|
87 | - { |
|
88 | - return $this->command; |
|
89 | - } |
|
81 | + /** |
|
82 | + * Gets the command associated with this helper set. |
|
83 | + * |
|
84 | + * @return Command A Command instance |
|
85 | + */ |
|
86 | + public function getCommand() |
|
87 | + { |
|
88 | + return $this->command; |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * @return \Traversable<Helper> |
|
93 | - */ |
|
94 | - #[\ReturnTypeWillChange] |
|
95 | - public function getIterator() |
|
96 | - { |
|
97 | - return new \ArrayIterator($this->helpers); |
|
98 | - } |
|
91 | + /** |
|
92 | + * @return \Traversable<Helper> |
|
93 | + */ |
|
94 | + #[\ReturnTypeWillChange] |
|
95 | + public function getIterator() |
|
96 | + { |
|
97 | + return new \ArrayIterator($this->helpers); |
|
98 | + } |
|
99 | 99 | } |
@@ -24,27 +24,27 @@ discard block |
||
24 | 24 | /** |
25 | 25 | * @var Helper[] |
26 | 26 | */ |
27 | - private $helpers = []; |
|
27 | + private $helpers = [ ]; |
|
28 | 28 | private $command; |
29 | 29 | |
30 | 30 | /** |
31 | 31 | * @param Helper[] $helpers An array of helper |
32 | 32 | */ |
33 | - public function __construct(array $helpers = []) |
|
33 | + public function __construct( array $helpers = [ ] ) |
|
34 | 34 | { |
35 | - foreach ($helpers as $alias => $helper) { |
|
36 | - $this->set($helper, \is_int($alias) ? null : $alias); |
|
35 | + foreach ( $helpers as $alias => $helper ) { |
|
36 | + $this->set( $helper, \is_int( $alias ) ? null : $alias ); |
|
37 | 37 | } |
38 | 38 | } |
39 | 39 | |
40 | - public function set(HelperInterface $helper, string $alias = null) |
|
40 | + public function set( HelperInterface $helper, string $alias = null ) |
|
41 | 41 | { |
42 | - $this->helpers[$helper->getName()] = $helper; |
|
43 | - if (null !== $alias) { |
|
44 | - $this->helpers[$alias] = $helper; |
|
42 | + $this->helpers[ $helper->getName() ] = $helper; |
|
43 | + if ( null !== $alias ) { |
|
44 | + $this->helpers[ $alias ] = $helper; |
|
45 | 45 | } |
46 | 46 | |
47 | - $helper->setHelperSet($this); |
|
47 | + $helper->setHelperSet( $this ); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
@@ -52,9 +52,9 @@ discard block |
||
52 | 52 | * |
53 | 53 | * @return bool true if the helper is defined, false otherwise |
54 | 54 | */ |
55 | - public function has(string $name) |
|
55 | + public function has( string $name ) |
|
56 | 56 | { |
57 | - return isset($this->helpers[$name]); |
|
57 | + return isset( $this->helpers[ $name ] ); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -64,16 +64,16 @@ discard block |
||
64 | 64 | * |
65 | 65 | * @throws InvalidArgumentException if the helper is not defined |
66 | 66 | */ |
67 | - public function get(string $name) |
|
67 | + public function get( string $name ) |
|
68 | 68 | { |
69 | - if (!$this->has($name)) { |
|
70 | - throw new InvalidArgumentException(sprintf('The helper "%s" is not defined.', $name)); |
|
69 | + if ( ! $this->has( $name ) ) { |
|
70 | + throw new InvalidArgumentException( sprintf( 'The helper "%s" is not defined.', $name ) ); |
|
71 | 71 | } |
72 | 72 | |
73 | - return $this->helpers[$name]; |
|
73 | + return $this->helpers[ $name ]; |
|
74 | 74 | } |
75 | 75 | |
76 | - public function setCommand(Command $command = null) |
|
76 | + public function setCommand( Command $command = null ) |
|
77 | 77 | { |
78 | 78 | $this->command = $command; |
79 | 79 | } |
@@ -94,6 +94,6 @@ discard block |
||
94 | 94 | #[\ReturnTypeWillChange] |
95 | 95 | public function getIterator() |
96 | 96 | { |
97 | - return new \ArrayIterator($this->helpers); |
|
97 | + return new \ArrayIterator( $this->helpers ); |
|
98 | 98 | } |
99 | 99 | } |
@@ -19,8 +19,7 @@ discard block |
||
19 | 19 | * |
20 | 20 | * @author Fabien Potencier <[email protected]> |
21 | 21 | */ |
22 | -class HelperSet implements \IteratorAggregate |
|
23 | -{ |
|
22 | +class HelperSet implements \IteratorAggregate { |
|
24 | 23 | /** |
25 | 24 | * @var Helper[] |
26 | 25 | */ |
@@ -30,15 +29,13 @@ discard block |
||
30 | 29 | /** |
31 | 30 | * @param Helper[] $helpers An array of helper |
32 | 31 | */ |
33 | - public function __construct(array $helpers = []) |
|
34 | - { |
|
32 | + public function __construct(array $helpers = []) { |
|
35 | 33 | foreach ($helpers as $alias => $helper) { |
36 | 34 | $this->set($helper, \is_int($alias) ? null : $alias); |
37 | 35 | } |
38 | 36 | } |
39 | 37 | |
40 | - public function set(HelperInterface $helper, string $alias = null) |
|
41 | - { |
|
38 | + public function set(HelperInterface $helper, string $alias = null) { |
|
42 | 39 | $this->helpers[$helper->getName()] = $helper; |
43 | 40 | if (null !== $alias) { |
44 | 41 | $this->helpers[$alias] = $helper; |
@@ -52,8 +49,7 @@ discard block |
||
52 | 49 | * |
53 | 50 | * @return bool true if the helper is defined, false otherwise |
54 | 51 | */ |
55 | - public function has(string $name) |
|
56 | - { |
|
52 | + public function has(string $name) { |
|
57 | 53 | return isset($this->helpers[$name]); |
58 | 54 | } |
59 | 55 | |
@@ -64,8 +60,7 @@ discard block |
||
64 | 60 | * |
65 | 61 | * @throws InvalidArgumentException if the helper is not defined |
66 | 62 | */ |
67 | - public function get(string $name) |
|
68 | - { |
|
63 | + public function get(string $name) { |
|
69 | 64 | if (!$this->has($name)) { |
70 | 65 | throw new InvalidArgumentException(sprintf('The helper "%s" is not defined.', $name)); |
71 | 66 | } |
@@ -73,8 +68,7 @@ discard block |
||
73 | 68 | return $this->helpers[$name]; |
74 | 69 | } |
75 | 70 | |
76 | - public function setCommand(Command $command = null) |
|
77 | - { |
|
71 | + public function setCommand(Command $command = null) { |
|
78 | 72 | $this->command = $command; |
79 | 73 | } |
80 | 74 | |
@@ -83,8 +77,7 @@ discard block |
||
83 | 77 | * |
84 | 78 | * @return Command A Command instance |
85 | 79 | */ |
86 | - public function getCommand() |
|
87 | - { |
|
80 | + public function getCommand() { |
|
88 | 81 | return $this->command; |
89 | 82 | } |
90 | 83 | |
@@ -92,8 +85,7 @@ discard block |
||
92 | 85 | * @return \Traversable<Helper> |
93 | 86 | */ |
94 | 87 | #[\ReturnTypeWillChange] |
95 | - public function getIterator() |
|
96 | - { |
|
88 | + public function getIterator() { |
|
97 | 89 | return new \ArrayIterator($this->helpers); |
98 | 90 | } |
99 | 91 | } |
@@ -20,88 +20,88 @@ |
||
20 | 20 | */ |
21 | 21 | class DebugFormatterHelper extends Helper |
22 | 22 | { |
23 | - private $colors = ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white', 'default']; |
|
24 | - private $started = []; |
|
25 | - private $count = -1; |
|
26 | - |
|
27 | - /** |
|
28 | - * Starts a debug formatting session. |
|
29 | - * |
|
30 | - * @return string |
|
31 | - */ |
|
32 | - public function start(string $id, string $message, string $prefix = 'RUN') |
|
33 | - { |
|
34 | - $this->started[$id] = ['border' => ++$this->count % \count($this->colors)]; |
|
35 | - |
|
36 | - return sprintf("%s<bg=blue;fg=white> %s </> <fg=blue>%s</>\n", $this->getBorder($id), $prefix, $message); |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * Adds progress to a formatting session. |
|
41 | - * |
|
42 | - * @return string |
|
43 | - */ |
|
44 | - public function progress(string $id, string $buffer, bool $error = false, string $prefix = 'OUT', string $errorPrefix = 'ERR') |
|
45 | - { |
|
46 | - $message = ''; |
|
47 | - |
|
48 | - if ($error) { |
|
49 | - if (isset($this->started[$id]['out'])) { |
|
50 | - $message .= "\n"; |
|
51 | - unset($this->started[$id]['out']); |
|
52 | - } |
|
53 | - if (!isset($this->started[$id]['err'])) { |
|
54 | - $message .= sprintf('%s<bg=red;fg=white> %s </> ', $this->getBorder($id), $errorPrefix); |
|
55 | - $this->started[$id]['err'] = true; |
|
56 | - } |
|
57 | - |
|
58 | - $message .= str_replace("\n", sprintf("\n%s<bg=red;fg=white> %s </> ", $this->getBorder($id), $errorPrefix), $buffer); |
|
59 | - } else { |
|
60 | - if (isset($this->started[$id]['err'])) { |
|
61 | - $message .= "\n"; |
|
62 | - unset($this->started[$id]['err']); |
|
63 | - } |
|
64 | - if (!isset($this->started[$id]['out'])) { |
|
65 | - $message .= sprintf('%s<bg=green;fg=white> %s </> ', $this->getBorder($id), $prefix); |
|
66 | - $this->started[$id]['out'] = true; |
|
67 | - } |
|
68 | - |
|
69 | - $message .= str_replace("\n", sprintf("\n%s<bg=green;fg=white> %s </> ", $this->getBorder($id), $prefix), $buffer); |
|
70 | - } |
|
71 | - |
|
72 | - return $message; |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Stops a formatting session. |
|
77 | - * |
|
78 | - * @return string |
|
79 | - */ |
|
80 | - public function stop(string $id, string $message, bool $successful, string $prefix = 'RES') |
|
81 | - { |
|
82 | - $trailingEOL = isset($this->started[$id]['out']) || isset($this->started[$id]['err']) ? "\n" : ''; |
|
83 | - |
|
84 | - if ($successful) { |
|
85 | - return sprintf("%s%s<bg=green;fg=white> %s </> <fg=green>%s</>\n", $trailingEOL, $this->getBorder($id), $prefix, $message); |
|
86 | - } |
|
87 | - |
|
88 | - $message = sprintf("%s%s<bg=red;fg=white> %s </> <fg=red>%s</>\n", $trailingEOL, $this->getBorder($id), $prefix, $message); |
|
89 | - |
|
90 | - unset($this->started[$id]['out'], $this->started[$id]['err']); |
|
91 | - |
|
92 | - return $message; |
|
93 | - } |
|
94 | - |
|
95 | - private function getBorder(string $id): string |
|
96 | - { |
|
97 | - return sprintf('<bg=%s> </>', $this->colors[$this->started[$id]['border']]); |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * {@inheritdoc} |
|
102 | - */ |
|
103 | - public function getName() |
|
104 | - { |
|
105 | - return 'debug_formatter'; |
|
106 | - } |
|
23 | + private $colors = ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white', 'default']; |
|
24 | + private $started = []; |
|
25 | + private $count = -1; |
|
26 | + |
|
27 | + /** |
|
28 | + * Starts a debug formatting session. |
|
29 | + * |
|
30 | + * @return string |
|
31 | + */ |
|
32 | + public function start(string $id, string $message, string $prefix = 'RUN') |
|
33 | + { |
|
34 | + $this->started[$id] = ['border' => ++$this->count % \count($this->colors)]; |
|
35 | + |
|
36 | + return sprintf("%s<bg=blue;fg=white> %s </> <fg=blue>%s</>\n", $this->getBorder($id), $prefix, $message); |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * Adds progress to a formatting session. |
|
41 | + * |
|
42 | + * @return string |
|
43 | + */ |
|
44 | + public function progress(string $id, string $buffer, bool $error = false, string $prefix = 'OUT', string $errorPrefix = 'ERR') |
|
45 | + { |
|
46 | + $message = ''; |
|
47 | + |
|
48 | + if ($error) { |
|
49 | + if (isset($this->started[$id]['out'])) { |
|
50 | + $message .= "\n"; |
|
51 | + unset($this->started[$id]['out']); |
|
52 | + } |
|
53 | + if (!isset($this->started[$id]['err'])) { |
|
54 | + $message .= sprintf('%s<bg=red;fg=white> %s </> ', $this->getBorder($id), $errorPrefix); |
|
55 | + $this->started[$id]['err'] = true; |
|
56 | + } |
|
57 | + |
|
58 | + $message .= str_replace("\n", sprintf("\n%s<bg=red;fg=white> %s </> ", $this->getBorder($id), $errorPrefix), $buffer); |
|
59 | + } else { |
|
60 | + if (isset($this->started[$id]['err'])) { |
|
61 | + $message .= "\n"; |
|
62 | + unset($this->started[$id]['err']); |
|
63 | + } |
|
64 | + if (!isset($this->started[$id]['out'])) { |
|
65 | + $message .= sprintf('%s<bg=green;fg=white> %s </> ', $this->getBorder($id), $prefix); |
|
66 | + $this->started[$id]['out'] = true; |
|
67 | + } |
|
68 | + |
|
69 | + $message .= str_replace("\n", sprintf("\n%s<bg=green;fg=white> %s </> ", $this->getBorder($id), $prefix), $buffer); |
|
70 | + } |
|
71 | + |
|
72 | + return $message; |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Stops a formatting session. |
|
77 | + * |
|
78 | + * @return string |
|
79 | + */ |
|
80 | + public function stop(string $id, string $message, bool $successful, string $prefix = 'RES') |
|
81 | + { |
|
82 | + $trailingEOL = isset($this->started[$id]['out']) || isset($this->started[$id]['err']) ? "\n" : ''; |
|
83 | + |
|
84 | + if ($successful) { |
|
85 | + return sprintf("%s%s<bg=green;fg=white> %s </> <fg=green>%s</>\n", $trailingEOL, $this->getBorder($id), $prefix, $message); |
|
86 | + } |
|
87 | + |
|
88 | + $message = sprintf("%s%s<bg=red;fg=white> %s </> <fg=red>%s</>\n", $trailingEOL, $this->getBorder($id), $prefix, $message); |
|
89 | + |
|
90 | + unset($this->started[$id]['out'], $this->started[$id]['err']); |
|
91 | + |
|
92 | + return $message; |
|
93 | + } |
|
94 | + |
|
95 | + private function getBorder(string $id): string |
|
96 | + { |
|
97 | + return sprintf('<bg=%s> </>', $this->colors[$this->started[$id]['border']]); |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * {@inheritdoc} |
|
102 | + */ |
|
103 | + public function getName() |
|
104 | + { |
|
105 | + return 'debug_formatter'; |
|
106 | + } |
|
107 | 107 | } |
@@ -20,8 +20,8 @@ discard block |
||
20 | 20 | */ |
21 | 21 | class DebugFormatterHelper extends Helper |
22 | 22 | { |
23 | - private $colors = ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white', 'default']; |
|
24 | - private $started = []; |
|
23 | + private $colors = [ 'black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white', 'default' ]; |
|
24 | + private $started = [ ]; |
|
25 | 25 | private $count = -1; |
26 | 26 | |
27 | 27 | /** |
@@ -29,11 +29,11 @@ discard block |
||
29 | 29 | * |
30 | 30 | * @return string |
31 | 31 | */ |
32 | - public function start(string $id, string $message, string $prefix = 'RUN') |
|
32 | + public function start( string $id, string $message, string $prefix = 'RUN' ) |
|
33 | 33 | { |
34 | - $this->started[$id] = ['border' => ++$this->count % \count($this->colors)]; |
|
34 | + $this->started[ $id ] = [ 'border' => ++$this->count % \count( $this->colors ) ]; |
|
35 | 35 | |
36 | - return sprintf("%s<bg=blue;fg=white> %s </> <fg=blue>%s</>\n", $this->getBorder($id), $prefix, $message); |
|
36 | + return sprintf( "%s<bg=blue;fg=white> %s </> <fg=blue>%s</>\n", $this->getBorder( $id ), $prefix, $message ); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
@@ -41,32 +41,32 @@ discard block |
||
41 | 41 | * |
42 | 42 | * @return string |
43 | 43 | */ |
44 | - public function progress(string $id, string $buffer, bool $error = false, string $prefix = 'OUT', string $errorPrefix = 'ERR') |
|
44 | + public function progress( string $id, string $buffer, bool $error = false, string $prefix = 'OUT', string $errorPrefix = 'ERR' ) |
|
45 | 45 | { |
46 | 46 | $message = ''; |
47 | 47 | |
48 | - if ($error) { |
|
49 | - if (isset($this->started[$id]['out'])) { |
|
48 | + if ( $error ) { |
|
49 | + if ( isset( $this->started[ $id ][ 'out' ] ) ) { |
|
50 | 50 | $message .= "\n"; |
51 | - unset($this->started[$id]['out']); |
|
51 | + unset( $this->started[ $id ][ 'out' ] ); |
|
52 | 52 | } |
53 | - if (!isset($this->started[$id]['err'])) { |
|
54 | - $message .= sprintf('%s<bg=red;fg=white> %s </> ', $this->getBorder($id), $errorPrefix); |
|
55 | - $this->started[$id]['err'] = true; |
|
53 | + if ( ! isset( $this->started[ $id ][ 'err' ] ) ) { |
|
54 | + $message .= sprintf( '%s<bg=red;fg=white> %s </> ', $this->getBorder( $id ), $errorPrefix ); |
|
55 | + $this->started[ $id ][ 'err' ] = true; |
|
56 | 56 | } |
57 | 57 | |
58 | - $message .= str_replace("\n", sprintf("\n%s<bg=red;fg=white> %s </> ", $this->getBorder($id), $errorPrefix), $buffer); |
|
58 | + $message .= str_replace( "\n", sprintf( "\n%s<bg=red;fg=white> %s </> ", $this->getBorder( $id ), $errorPrefix ), $buffer ); |
|
59 | 59 | } else { |
60 | - if (isset($this->started[$id]['err'])) { |
|
60 | + if ( isset( $this->started[ $id ][ 'err' ] ) ) { |
|
61 | 61 | $message .= "\n"; |
62 | - unset($this->started[$id]['err']); |
|
62 | + unset( $this->started[ $id ][ 'err' ] ); |
|
63 | 63 | } |
64 | - if (!isset($this->started[$id]['out'])) { |
|
65 | - $message .= sprintf('%s<bg=green;fg=white> %s </> ', $this->getBorder($id), $prefix); |
|
66 | - $this->started[$id]['out'] = true; |
|
64 | + if ( ! isset( $this->started[ $id ][ 'out' ] ) ) { |
|
65 | + $message .= sprintf( '%s<bg=green;fg=white> %s </> ', $this->getBorder( $id ), $prefix ); |
|
66 | + $this->started[ $id ][ 'out' ] = true; |
|
67 | 67 | } |
68 | 68 | |
69 | - $message .= str_replace("\n", sprintf("\n%s<bg=green;fg=white> %s </> ", $this->getBorder($id), $prefix), $buffer); |
|
69 | + $message .= str_replace( "\n", sprintf( "\n%s<bg=green;fg=white> %s </> ", $this->getBorder( $id ), $prefix ), $buffer ); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | return $message; |
@@ -77,24 +77,24 @@ discard block |
||
77 | 77 | * |
78 | 78 | * @return string |
79 | 79 | */ |
80 | - public function stop(string $id, string $message, bool $successful, string $prefix = 'RES') |
|
80 | + public function stop( string $id, string $message, bool $successful, string $prefix = 'RES' ) |
|
81 | 81 | { |
82 | - $trailingEOL = isset($this->started[$id]['out']) || isset($this->started[$id]['err']) ? "\n" : ''; |
|
82 | + $trailingEOL = isset( $this->started[ $id ][ 'out' ] ) || isset( $this->started[ $id ][ 'err' ] ) ? "\n" : ''; |
|
83 | 83 | |
84 | - if ($successful) { |
|
85 | - return sprintf("%s%s<bg=green;fg=white> %s </> <fg=green>%s</>\n", $trailingEOL, $this->getBorder($id), $prefix, $message); |
|
84 | + if ( $successful ) { |
|
85 | + return sprintf( "%s%s<bg=green;fg=white> %s </> <fg=green>%s</>\n", $trailingEOL, $this->getBorder( $id ), $prefix, $message ); |
|
86 | 86 | } |
87 | 87 | |
88 | - $message = sprintf("%s%s<bg=red;fg=white> %s </> <fg=red>%s</>\n", $trailingEOL, $this->getBorder($id), $prefix, $message); |
|
88 | + $message = sprintf( "%s%s<bg=red;fg=white> %s </> <fg=red>%s</>\n", $trailingEOL, $this->getBorder( $id ), $prefix, $message ); |
|
89 | 89 | |
90 | - unset($this->started[$id]['out'], $this->started[$id]['err']); |
|
90 | + unset( $this->started[ $id ][ 'out' ], $this->started[ $id ][ 'err' ] ); |
|
91 | 91 | |
92 | 92 | return $message; |
93 | 93 | } |
94 | 94 | |
95 | - private function getBorder(string $id): string |
|
95 | + private function getBorder( string $id ): string |
|
96 | 96 | { |
97 | - return sprintf('<bg=%s> </>', $this->colors[$this->started[$id]['border']]); |
|
97 | + return sprintf( '<bg=%s> </>', $this->colors[ $this->started[ $id ][ 'border' ] ] ); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
@@ -18,8 +18,7 @@ discard block |
||
18 | 18 | * |
19 | 19 | * @author Fabien Potencier <[email protected]> |
20 | 20 | */ |
21 | -class DebugFormatterHelper extends Helper |
|
22 | -{ |
|
21 | +class DebugFormatterHelper extends Helper { |
|
23 | 22 | private $colors = ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white', 'default']; |
24 | 23 | private $started = []; |
25 | 24 | private $count = -1; |
@@ -29,8 +28,7 @@ discard block |
||
29 | 28 | * |
30 | 29 | * @return string |
31 | 30 | */ |
32 | - public function start(string $id, string $message, string $prefix = 'RUN') |
|
33 | - { |
|
31 | + public function start(string $id, string $message, string $prefix = 'RUN') { |
|
34 | 32 | $this->started[$id] = ['border' => ++$this->count % \count($this->colors)]; |
35 | 33 | |
36 | 34 | return sprintf("%s<bg=blue;fg=white> %s </> <fg=blue>%s</>\n", $this->getBorder($id), $prefix, $message); |
@@ -41,8 +39,7 @@ discard block |
||
41 | 39 | * |
42 | 40 | * @return string |
43 | 41 | */ |
44 | - public function progress(string $id, string $buffer, bool $error = false, string $prefix = 'OUT', string $errorPrefix = 'ERR') |
|
45 | - { |
|
42 | + public function progress(string $id, string $buffer, bool $error = false, string $prefix = 'OUT', string $errorPrefix = 'ERR') { |
|
46 | 43 | $message = ''; |
47 | 44 | |
48 | 45 | if ($error) { |
@@ -77,8 +74,7 @@ discard block |
||
77 | 74 | * |
78 | 75 | * @return string |
79 | 76 | */ |
80 | - public function stop(string $id, string $message, bool $successful, string $prefix = 'RES') |
|
81 | - { |
|
77 | + public function stop(string $id, string $message, bool $successful, string $prefix = 'RES') { |
|
82 | 78 | $trailingEOL = isset($this->started[$id]['out']) || isset($this->started[$id]['err']) ? "\n" : ''; |
83 | 79 | |
84 | 80 | if ($successful) { |
@@ -100,8 +96,7 @@ discard block |
||
100 | 96 | /** |
101 | 97 | * {@inheritdoc} |
102 | 98 | */ |
103 | - public function getName() |
|
104 | - { |
|
99 | + public function getName() { |
|
105 | 100 | return 'debug_formatter'; |
106 | 101 | } |
107 | 102 | } |
@@ -21,158 +21,158 @@ |
||
21 | 21 | */ |
22 | 22 | abstract class Helper implements HelperInterface |
23 | 23 | { |
24 | - protected $helperSet = null; |
|
25 | - |
|
26 | - /** |
|
27 | - * {@inheritdoc} |
|
28 | - */ |
|
29 | - public function setHelperSet(HelperSet $helperSet = null) |
|
30 | - { |
|
31 | - $this->helperSet = $helperSet; |
|
32 | - } |
|
33 | - |
|
34 | - /** |
|
35 | - * {@inheritdoc} |
|
36 | - */ |
|
37 | - public function getHelperSet() |
|
38 | - { |
|
39 | - return $this->helperSet; |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * Returns the length of a string, using mb_strwidth if it is available. |
|
44 | - * |
|
45 | - * @deprecated since Symfony 5.3 |
|
46 | - * |
|
47 | - * @return int The length of the string |
|
48 | - */ |
|
49 | - public static function strlen(?string $string) |
|
50 | - { |
|
51 | - trigger_deprecation('symfony/console', '5.3', 'Method "%s()" is deprecated and will be removed in Symfony 6.0. Use Helper::width() or Helper::length() instead.', __METHOD__); |
|
52 | - |
|
53 | - return self::width($string); |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * Returns the width of a string, using mb_strwidth if it is available. |
|
58 | - * The width is how many characters positions the string will use. |
|
59 | - */ |
|
60 | - public static function width(?string $string): int |
|
61 | - { |
|
62 | - $string ?? $string = ''; |
|
63 | - |
|
64 | - if (preg_match('//u', $string)) { |
|
65 | - return (new UnicodeString($string))->width(false); |
|
66 | - } |
|
67 | - |
|
68 | - if (false === $encoding = mb_detect_encoding($string, null, true)) { |
|
69 | - return \strlen($string); |
|
70 | - } |
|
71 | - |
|
72 | - return mb_strwidth($string, $encoding); |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Returns the length of a string, using mb_strlen if it is available. |
|
77 | - * The length is related to how many bytes the string will use. |
|
78 | - */ |
|
79 | - public static function length(?string $string): int |
|
80 | - { |
|
81 | - $string ?? $string = ''; |
|
82 | - |
|
83 | - if (preg_match('//u', $string)) { |
|
84 | - return (new UnicodeString($string))->length(); |
|
85 | - } |
|
86 | - |
|
87 | - if (false === $encoding = mb_detect_encoding($string, null, true)) { |
|
88 | - return \strlen($string); |
|
89 | - } |
|
90 | - |
|
91 | - return mb_strlen($string, $encoding); |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * Returns the subset of a string, using mb_substr if it is available. |
|
96 | - * |
|
97 | - * @return string The string subset |
|
98 | - */ |
|
99 | - public static function substr(?string $string, int $from, int $length = null) |
|
100 | - { |
|
101 | - $string ?? $string = ''; |
|
102 | - |
|
103 | - if (false === $encoding = mb_detect_encoding($string, null, true)) { |
|
104 | - return substr($string, $from, $length); |
|
105 | - } |
|
106 | - |
|
107 | - return mb_substr($string, $from, $length, $encoding); |
|
108 | - } |
|
109 | - |
|
110 | - public static function formatTime($secs) |
|
111 | - { |
|
112 | - static $timeFormats = [ |
|
113 | - [0, '< 1 sec'], |
|
114 | - [1, '1 sec'], |
|
115 | - [2, 'secs', 1], |
|
116 | - [60, '1 min'], |
|
117 | - [120, 'mins', 60], |
|
118 | - [3600, '1 hr'], |
|
119 | - [7200, 'hrs', 3600], |
|
120 | - [86400, '1 day'], |
|
121 | - [172800, 'days', 86400], |
|
122 | - ]; |
|
123 | - |
|
124 | - foreach ($timeFormats as $index => $format) { |
|
125 | - if ($secs >= $format[0]) { |
|
126 | - if ((isset($timeFormats[$index + 1]) && $secs < $timeFormats[$index + 1][0]) |
|
127 | - || $index == \count($timeFormats) - 1 |
|
128 | - ) { |
|
129 | - if (2 == \count($format)) { |
|
130 | - return $format[1]; |
|
131 | - } |
|
132 | - |
|
133 | - return floor($secs / $format[2]).' '.$format[1]; |
|
134 | - } |
|
135 | - } |
|
136 | - } |
|
137 | - } |
|
138 | - |
|
139 | - public static function formatMemory(int $memory) |
|
140 | - { |
|
141 | - if ($memory >= 1024 * 1024 * 1024) { |
|
142 | - return sprintf('%.1f GiB', $memory / 1024 / 1024 / 1024); |
|
143 | - } |
|
144 | - |
|
145 | - if ($memory >= 1024 * 1024) { |
|
146 | - return sprintf('%.1f MiB', $memory / 1024 / 1024); |
|
147 | - } |
|
148 | - |
|
149 | - if ($memory >= 1024) { |
|
150 | - return sprintf('%d KiB', $memory / 1024); |
|
151 | - } |
|
152 | - |
|
153 | - return sprintf('%d B', $memory); |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * @deprecated since Symfony 5.3 |
|
158 | - */ |
|
159 | - public static function strlenWithoutDecoration(OutputFormatterInterface $formatter, ?string $string) |
|
160 | - { |
|
161 | - trigger_deprecation('symfony/console', '5.3', 'Method "%s()" is deprecated and will be removed in Symfony 6.0. Use Helper::removeDecoration() instead.', __METHOD__); |
|
162 | - |
|
163 | - return self::width(self::removeDecoration($formatter, $string)); |
|
164 | - } |
|
165 | - |
|
166 | - public static function removeDecoration(OutputFormatterInterface $formatter, ?string $string) |
|
167 | - { |
|
168 | - $isDecorated = $formatter->isDecorated(); |
|
169 | - $formatter->setDecorated(false); |
|
170 | - // remove <...> formatting |
|
171 | - $string = $formatter->format($string ?? ''); |
|
172 | - // remove already formatted characters |
|
173 | - $string = preg_replace("/\033\[[^m]*m/", '', $string ?? ''); |
|
174 | - $formatter->setDecorated($isDecorated); |
|
175 | - |
|
176 | - return $string; |
|
177 | - } |
|
24 | + protected $helperSet = null; |
|
25 | + |
|
26 | + /** |
|
27 | + * {@inheritdoc} |
|
28 | + */ |
|
29 | + public function setHelperSet(HelperSet $helperSet = null) |
|
30 | + { |
|
31 | + $this->helperSet = $helperSet; |
|
32 | + } |
|
33 | + |
|
34 | + /** |
|
35 | + * {@inheritdoc} |
|
36 | + */ |
|
37 | + public function getHelperSet() |
|
38 | + { |
|
39 | + return $this->helperSet; |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * Returns the length of a string, using mb_strwidth if it is available. |
|
44 | + * |
|
45 | + * @deprecated since Symfony 5.3 |
|
46 | + * |
|
47 | + * @return int The length of the string |
|
48 | + */ |
|
49 | + public static function strlen(?string $string) |
|
50 | + { |
|
51 | + trigger_deprecation('symfony/console', '5.3', 'Method "%s()" is deprecated and will be removed in Symfony 6.0. Use Helper::width() or Helper::length() instead.', __METHOD__); |
|
52 | + |
|
53 | + return self::width($string); |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * Returns the width of a string, using mb_strwidth if it is available. |
|
58 | + * The width is how many characters positions the string will use. |
|
59 | + */ |
|
60 | + public static function width(?string $string): int |
|
61 | + { |
|
62 | + $string ?? $string = ''; |
|
63 | + |
|
64 | + if (preg_match('//u', $string)) { |
|
65 | + return (new UnicodeString($string))->width(false); |
|
66 | + } |
|
67 | + |
|
68 | + if (false === $encoding = mb_detect_encoding($string, null, true)) { |
|
69 | + return \strlen($string); |
|
70 | + } |
|
71 | + |
|
72 | + return mb_strwidth($string, $encoding); |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Returns the length of a string, using mb_strlen if it is available. |
|
77 | + * The length is related to how many bytes the string will use. |
|
78 | + */ |
|
79 | + public static function length(?string $string): int |
|
80 | + { |
|
81 | + $string ?? $string = ''; |
|
82 | + |
|
83 | + if (preg_match('//u', $string)) { |
|
84 | + return (new UnicodeString($string))->length(); |
|
85 | + } |
|
86 | + |
|
87 | + if (false === $encoding = mb_detect_encoding($string, null, true)) { |
|
88 | + return \strlen($string); |
|
89 | + } |
|
90 | + |
|
91 | + return mb_strlen($string, $encoding); |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * Returns the subset of a string, using mb_substr if it is available. |
|
96 | + * |
|
97 | + * @return string The string subset |
|
98 | + */ |
|
99 | + public static function substr(?string $string, int $from, int $length = null) |
|
100 | + { |
|
101 | + $string ?? $string = ''; |
|
102 | + |
|
103 | + if (false === $encoding = mb_detect_encoding($string, null, true)) { |
|
104 | + return substr($string, $from, $length); |
|
105 | + } |
|
106 | + |
|
107 | + return mb_substr($string, $from, $length, $encoding); |
|
108 | + } |
|
109 | + |
|
110 | + public static function formatTime($secs) |
|
111 | + { |
|
112 | + static $timeFormats = [ |
|
113 | + [0, '< 1 sec'], |
|
114 | + [1, '1 sec'], |
|
115 | + [2, 'secs', 1], |
|
116 | + [60, '1 min'], |
|
117 | + [120, 'mins', 60], |
|
118 | + [3600, '1 hr'], |
|
119 | + [7200, 'hrs', 3600], |
|
120 | + [86400, '1 day'], |
|
121 | + [172800, 'days', 86400], |
|
122 | + ]; |
|
123 | + |
|
124 | + foreach ($timeFormats as $index => $format) { |
|
125 | + if ($secs >= $format[0]) { |
|
126 | + if ((isset($timeFormats[$index + 1]) && $secs < $timeFormats[$index + 1][0]) |
|
127 | + || $index == \count($timeFormats) - 1 |
|
128 | + ) { |
|
129 | + if (2 == \count($format)) { |
|
130 | + return $format[1]; |
|
131 | + } |
|
132 | + |
|
133 | + return floor($secs / $format[2]).' '.$format[1]; |
|
134 | + } |
|
135 | + } |
|
136 | + } |
|
137 | + } |
|
138 | + |
|
139 | + public static function formatMemory(int $memory) |
|
140 | + { |
|
141 | + if ($memory >= 1024 * 1024 * 1024) { |
|
142 | + return sprintf('%.1f GiB', $memory / 1024 / 1024 / 1024); |
|
143 | + } |
|
144 | + |
|
145 | + if ($memory >= 1024 * 1024) { |
|
146 | + return sprintf('%.1f MiB', $memory / 1024 / 1024); |
|
147 | + } |
|
148 | + |
|
149 | + if ($memory >= 1024) { |
|
150 | + return sprintf('%d KiB', $memory / 1024); |
|
151 | + } |
|
152 | + |
|
153 | + return sprintf('%d B', $memory); |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * @deprecated since Symfony 5.3 |
|
158 | + */ |
|
159 | + public static function strlenWithoutDecoration(OutputFormatterInterface $formatter, ?string $string) |
|
160 | + { |
|
161 | + trigger_deprecation('symfony/console', '5.3', 'Method "%s()" is deprecated and will be removed in Symfony 6.0. Use Helper::removeDecoration() instead.', __METHOD__); |
|
162 | + |
|
163 | + return self::width(self::removeDecoration($formatter, $string)); |
|
164 | + } |
|
165 | + |
|
166 | + public static function removeDecoration(OutputFormatterInterface $formatter, ?string $string) |
|
167 | + { |
|
168 | + $isDecorated = $formatter->isDecorated(); |
|
169 | + $formatter->setDecorated(false); |
|
170 | + // remove <...> formatting |
|
171 | + $string = $formatter->format($string ?? ''); |
|
172 | + // remove already formatted characters |
|
173 | + $string = preg_replace("/\033\[[^m]*m/", '', $string ?? ''); |
|
174 | + $formatter->setDecorated($isDecorated); |
|
175 | + |
|
176 | + return $string; |
|
177 | + } |
|
178 | 178 | } |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | /** |
27 | 27 | * {@inheritdoc} |
28 | 28 | */ |
29 | - public function setHelperSet(HelperSet $helperSet = null) |
|
29 | + public function setHelperSet( HelperSet $helperSet = null ) |
|
30 | 30 | { |
31 | 31 | $this->helperSet = $helperSet; |
32 | 32 | } |
@@ -46,49 +46,49 @@ discard block |
||
46 | 46 | * |
47 | 47 | * @return int The length of the string |
48 | 48 | */ |
49 | - public static function strlen(?string $string) |
|
49 | + public static function strlen( ?string $string ) |
|
50 | 50 | { |
51 | - trigger_deprecation('symfony/console', '5.3', 'Method "%s()" is deprecated and will be removed in Symfony 6.0. Use Helper::width() or Helper::length() instead.', __METHOD__); |
|
51 | + trigger_deprecation( 'symfony/console', '5.3', 'Method "%s()" is deprecated and will be removed in Symfony 6.0. Use Helper::width() or Helper::length() instead.', __METHOD__ ); |
|
52 | 52 | |
53 | - return self::width($string); |
|
53 | + return self::width( $string ); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
57 | 57 | * Returns the width of a string, using mb_strwidth if it is available. |
58 | 58 | * The width is how many characters positions the string will use. |
59 | 59 | */ |
60 | - public static function width(?string $string): int |
|
60 | + public static function width( ?string $string ): int |
|
61 | 61 | { |
62 | 62 | $string ?? $string = ''; |
63 | 63 | |
64 | - if (preg_match('//u', $string)) { |
|
65 | - return (new UnicodeString($string))->width(false); |
|
64 | + if ( preg_match( '//u', $string ) ) { |
|
65 | + return ( new UnicodeString( $string ) )->width( false ); |
|
66 | 66 | } |
67 | 67 | |
68 | - if (false === $encoding = mb_detect_encoding($string, null, true)) { |
|
69 | - return \strlen($string); |
|
68 | + if ( false === $encoding = mb_detect_encoding( $string, null, true ) ) { |
|
69 | + return \strlen( $string ); |
|
70 | 70 | } |
71 | 71 | |
72 | - return mb_strwidth($string, $encoding); |
|
72 | + return mb_strwidth( $string, $encoding ); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
76 | 76 | * Returns the length of a string, using mb_strlen if it is available. |
77 | 77 | * The length is related to how many bytes the string will use. |
78 | 78 | */ |
79 | - public static function length(?string $string): int |
|
79 | + public static function length( ?string $string ): int |
|
80 | 80 | { |
81 | 81 | $string ?? $string = ''; |
82 | 82 | |
83 | - if (preg_match('//u', $string)) { |
|
84 | - return (new UnicodeString($string))->length(); |
|
83 | + if ( preg_match( '//u', $string ) ) { |
|
84 | + return ( new UnicodeString( $string ) )->length(); |
|
85 | 85 | } |
86 | 86 | |
87 | - if (false === $encoding = mb_detect_encoding($string, null, true)) { |
|
88 | - return \strlen($string); |
|
87 | + if ( false === $encoding = mb_detect_encoding( $string, null, true ) ) { |
|
88 | + return \strlen( $string ); |
|
89 | 89 | } |
90 | 90 | |
91 | - return mb_strlen($string, $encoding); |
|
91 | + return mb_strlen( $string, $encoding ); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
@@ -96,82 +96,82 @@ discard block |
||
96 | 96 | * |
97 | 97 | * @return string The string subset |
98 | 98 | */ |
99 | - public static function substr(?string $string, int $from, int $length = null) |
|
99 | + public static function substr( ?string $string, int $from, int $length = null ) |
|
100 | 100 | { |
101 | 101 | $string ?? $string = ''; |
102 | 102 | |
103 | - if (false === $encoding = mb_detect_encoding($string, null, true)) { |
|
104 | - return substr($string, $from, $length); |
|
103 | + if ( false === $encoding = mb_detect_encoding( $string, null, true ) ) { |
|
104 | + return substr( $string, $from, $length ); |
|
105 | 105 | } |
106 | 106 | |
107 | - return mb_substr($string, $from, $length, $encoding); |
|
107 | + return mb_substr( $string, $from, $length, $encoding ); |
|
108 | 108 | } |
109 | 109 | |
110 | - public static function formatTime($secs) |
|
110 | + public static function formatTime( $secs ) |
|
111 | 111 | { |
112 | 112 | static $timeFormats = [ |
113 | - [0, '< 1 sec'], |
|
114 | - [1, '1 sec'], |
|
115 | - [2, 'secs', 1], |
|
116 | - [60, '1 min'], |
|
117 | - [120, 'mins', 60], |
|
118 | - [3600, '1 hr'], |
|
119 | - [7200, 'hrs', 3600], |
|
120 | - [86400, '1 day'], |
|
121 | - [172800, 'days', 86400], |
|
113 | + [ 0, '< 1 sec' ], |
|
114 | + [ 1, '1 sec' ], |
|
115 | + [ 2, 'secs', 1 ], |
|
116 | + [ 60, '1 min' ], |
|
117 | + [ 120, 'mins', 60 ], |
|
118 | + [ 3600, '1 hr' ], |
|
119 | + [ 7200, 'hrs', 3600 ], |
|
120 | + [ 86400, '1 day' ], |
|
121 | + [ 172800, 'days', 86400 ], |
|
122 | 122 | ]; |
123 | 123 | |
124 | - foreach ($timeFormats as $index => $format) { |
|
125 | - if ($secs >= $format[0]) { |
|
126 | - if ((isset($timeFormats[$index + 1]) && $secs < $timeFormats[$index + 1][0]) |
|
127 | - || $index == \count($timeFormats) - 1 |
|
124 | + foreach ( $timeFormats as $index => $format ) { |
|
125 | + if ( $secs >= $format[ 0 ] ) { |
|
126 | + if ( ( isset( $timeFormats[ $index + 1 ] ) && $secs < $timeFormats[ $index + 1 ][ 0 ] ) |
|
127 | + || $index == \count( $timeFormats ) - 1 |
|
128 | 128 | ) { |
129 | - if (2 == \count($format)) { |
|
130 | - return $format[1]; |
|
129 | + if ( 2 == \count( $format ) ) { |
|
130 | + return $format[ 1 ]; |
|
131 | 131 | } |
132 | 132 | |
133 | - return floor($secs / $format[2]).' '.$format[1]; |
|
133 | + return floor( $secs / $format[ 2 ] ) . ' ' . $format[ 1 ]; |
|
134 | 134 | } |
135 | 135 | } |
136 | 136 | } |
137 | 137 | } |
138 | 138 | |
139 | - public static function formatMemory(int $memory) |
|
139 | + public static function formatMemory( int $memory ) |
|
140 | 140 | { |
141 | - if ($memory >= 1024 * 1024 * 1024) { |
|
142 | - return sprintf('%.1f GiB', $memory / 1024 / 1024 / 1024); |
|
141 | + if ( $memory >= 1024 * 1024 * 1024 ) { |
|
142 | + return sprintf( '%.1f GiB', $memory / 1024 / 1024 / 1024 ); |
|
143 | 143 | } |
144 | 144 | |
145 | - if ($memory >= 1024 * 1024) { |
|
146 | - return sprintf('%.1f MiB', $memory / 1024 / 1024); |
|
145 | + if ( $memory >= 1024 * 1024 ) { |
|
146 | + return sprintf( '%.1f MiB', $memory / 1024 / 1024 ); |
|
147 | 147 | } |
148 | 148 | |
149 | - if ($memory >= 1024) { |
|
150 | - return sprintf('%d KiB', $memory / 1024); |
|
149 | + if ( $memory >= 1024 ) { |
|
150 | + return sprintf( '%d KiB', $memory / 1024 ); |
|
151 | 151 | } |
152 | 152 | |
153 | - return sprintf('%d B', $memory); |
|
153 | + return sprintf( '%d B', $memory ); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
157 | 157 | * @deprecated since Symfony 5.3 |
158 | 158 | */ |
159 | - public static function strlenWithoutDecoration(OutputFormatterInterface $formatter, ?string $string) |
|
159 | + public static function strlenWithoutDecoration( OutputFormatterInterface $formatter, ?string $string ) |
|
160 | 160 | { |
161 | - trigger_deprecation('symfony/console', '5.3', 'Method "%s()" is deprecated and will be removed in Symfony 6.0. Use Helper::removeDecoration() instead.', __METHOD__); |
|
161 | + trigger_deprecation( 'symfony/console', '5.3', 'Method "%s()" is deprecated and will be removed in Symfony 6.0. Use Helper::removeDecoration() instead.', __METHOD__ ); |
|
162 | 162 | |
163 | - return self::width(self::removeDecoration($formatter, $string)); |
|
163 | + return self::width( self::removeDecoration( $formatter, $string ) ); |
|
164 | 164 | } |
165 | 165 | |
166 | - public static function removeDecoration(OutputFormatterInterface $formatter, ?string $string) |
|
166 | + public static function removeDecoration( OutputFormatterInterface $formatter, ?string $string ) |
|
167 | 167 | { |
168 | 168 | $isDecorated = $formatter->isDecorated(); |
169 | - $formatter->setDecorated(false); |
|
169 | + $formatter->setDecorated( false ); |
|
170 | 170 | // remove <...> formatting |
171 | - $string = $formatter->format($string ?? ''); |
|
171 | + $string = $formatter->format( $string ?? '' ); |
|
172 | 172 | // remove already formatted characters |
173 | - $string = preg_replace("/\033\[[^m]*m/", '', $string ?? ''); |
|
174 | - $formatter->setDecorated($isDecorated); |
|
173 | + $string = preg_replace( "/\033\[[^m]*m/", '', $string ?? '' ); |
|
174 | + $formatter->setDecorated( $isDecorated ); |
|
175 | 175 | |
176 | 176 | return $string; |
177 | 177 | } |
@@ -19,23 +19,20 @@ discard block |
||
19 | 19 | * |
20 | 20 | * @author Fabien Potencier <[email protected]> |
21 | 21 | */ |
22 | -abstract class Helper implements HelperInterface |
|
23 | -{ |
|
22 | +abstract class Helper implements HelperInterface { |
|
24 | 23 | protected $helperSet = null; |
25 | 24 | |
26 | 25 | /** |
27 | 26 | * {@inheritdoc} |
28 | 27 | */ |
29 | - public function setHelperSet(HelperSet $helperSet = null) |
|
30 | - { |
|
28 | + public function setHelperSet(HelperSet $helperSet = null) { |
|
31 | 29 | $this->helperSet = $helperSet; |
32 | 30 | } |
33 | 31 | |
34 | 32 | /** |
35 | 33 | * {@inheritdoc} |
36 | 34 | */ |
37 | - public function getHelperSet() |
|
38 | - { |
|
35 | + public function getHelperSet() { |
|
39 | 36 | return $this->helperSet; |
40 | 37 | } |
41 | 38 | |
@@ -46,8 +43,7 @@ discard block |
||
46 | 43 | * |
47 | 44 | * @return int The length of the string |
48 | 45 | */ |
49 | - public static function strlen(?string $string) |
|
50 | - { |
|
46 | + public static function strlen(?string $string) { |
|
51 | 47 | trigger_deprecation('symfony/console', '5.3', 'Method "%s()" is deprecated and will be removed in Symfony 6.0. Use Helper::width() or Helper::length() instead.', __METHOD__); |
52 | 48 | |
53 | 49 | return self::width($string); |
@@ -96,8 +92,7 @@ discard block |
||
96 | 92 | * |
97 | 93 | * @return string The string subset |
98 | 94 | */ |
99 | - public static function substr(?string $string, int $from, int $length = null) |
|
100 | - { |
|
95 | + public static function substr(?string $string, int $from, int $length = null) { |
|
101 | 96 | $string ?? $string = ''; |
102 | 97 | |
103 | 98 | if (false === $encoding = mb_detect_encoding($string, null, true)) { |
@@ -107,8 +102,7 @@ discard block |
||
107 | 102 | return mb_substr($string, $from, $length, $encoding); |
108 | 103 | } |
109 | 104 | |
110 | - public static function formatTime($secs) |
|
111 | - { |
|
105 | + public static function formatTime($secs) { |
|
112 | 106 | static $timeFormats = [ |
113 | 107 | [0, '< 1 sec'], |
114 | 108 | [1, '1 sec'], |
@@ -136,8 +130,7 @@ discard block |
||
136 | 130 | } |
137 | 131 | } |
138 | 132 | |
139 | - public static function formatMemory(int $memory) |
|
140 | - { |
|
133 | + public static function formatMemory(int $memory) { |
|
141 | 134 | if ($memory >= 1024 * 1024 * 1024) { |
142 | 135 | return sprintf('%.1f GiB', $memory / 1024 / 1024 / 1024); |
143 | 136 | } |
@@ -156,15 +149,13 @@ discard block |
||
156 | 149 | /** |
157 | 150 | * @deprecated since Symfony 5.3 |
158 | 151 | */ |
159 | - public static function strlenWithoutDecoration(OutputFormatterInterface $formatter, ?string $string) |
|
160 | - { |
|
152 | + public static function strlenWithoutDecoration(OutputFormatterInterface $formatter, ?string $string) { |
|
161 | 153 | trigger_deprecation('symfony/console', '5.3', 'Method "%s()" is deprecated and will be removed in Symfony 6.0. Use Helper::removeDecoration() instead.', __METHOD__); |
162 | 154 | |
163 | 155 | return self::width(self::removeDecoration($formatter, $string)); |
164 | 156 | } |
165 | 157 | |
166 | - public static function removeDecoration(OutputFormatterInterface $formatter, ?string $string) |
|
167 | - { |
|
158 | + public static function removeDecoration(OutputFormatterInterface $formatter, ?string $string) { |
|
168 | 159 | $isDecorated = $formatter->isDecorated(); |
169 | 160 | $formatter->setDecorated(false); |
170 | 161 | // remove <...> formatting |
@@ -20,73 +20,73 @@ |
||
20 | 20 | */ |
21 | 21 | class FormatterHelper extends Helper |
22 | 22 | { |
23 | - /** |
|
24 | - * Formats a message within a section. |
|
25 | - * |
|
26 | - * @return string The format section |
|
27 | - */ |
|
28 | - public function formatSection(string $section, string $message, string $style = 'info') |
|
29 | - { |
|
30 | - return sprintf('<%s>[%s]</%s> %s', $style, $section, $style, $message); |
|
31 | - } |
|
23 | + /** |
|
24 | + * Formats a message within a section. |
|
25 | + * |
|
26 | + * @return string The format section |
|
27 | + */ |
|
28 | + public function formatSection(string $section, string $message, string $style = 'info') |
|
29 | + { |
|
30 | + return sprintf('<%s>[%s]</%s> %s', $style, $section, $style, $message); |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * Formats a message as a block of text. |
|
35 | - * |
|
36 | - * @param string|array $messages The message to write in the block |
|
37 | - * |
|
38 | - * @return string The formatter message |
|
39 | - */ |
|
40 | - public function formatBlock($messages, string $style, bool $large = false) |
|
41 | - { |
|
42 | - if (!\is_array($messages)) { |
|
43 | - $messages = [$messages]; |
|
44 | - } |
|
33 | + /** |
|
34 | + * Formats a message as a block of text. |
|
35 | + * |
|
36 | + * @param string|array $messages The message to write in the block |
|
37 | + * |
|
38 | + * @return string The formatter message |
|
39 | + */ |
|
40 | + public function formatBlock($messages, string $style, bool $large = false) |
|
41 | + { |
|
42 | + if (!\is_array($messages)) { |
|
43 | + $messages = [$messages]; |
|
44 | + } |
|
45 | 45 | |
46 | - $len = 0; |
|
47 | - $lines = []; |
|
48 | - foreach ($messages as $message) { |
|
49 | - $message = OutputFormatter::escape($message); |
|
50 | - $lines[] = sprintf($large ? ' %s ' : ' %s ', $message); |
|
51 | - $len = max(self::width($message) + ($large ? 4 : 2), $len); |
|
52 | - } |
|
46 | + $len = 0; |
|
47 | + $lines = []; |
|
48 | + foreach ($messages as $message) { |
|
49 | + $message = OutputFormatter::escape($message); |
|
50 | + $lines[] = sprintf($large ? ' %s ' : ' %s ', $message); |
|
51 | + $len = max(self::width($message) + ($large ? 4 : 2), $len); |
|
52 | + } |
|
53 | 53 | |
54 | - $messages = $large ? [str_repeat(' ', $len)] : []; |
|
55 | - for ($i = 0; isset($lines[$i]); ++$i) { |
|
56 | - $messages[] = $lines[$i].str_repeat(' ', $len - self::width($lines[$i])); |
|
57 | - } |
|
58 | - if ($large) { |
|
59 | - $messages[] = str_repeat(' ', $len); |
|
60 | - } |
|
54 | + $messages = $large ? [str_repeat(' ', $len)] : []; |
|
55 | + for ($i = 0; isset($lines[$i]); ++$i) { |
|
56 | + $messages[] = $lines[$i].str_repeat(' ', $len - self::width($lines[$i])); |
|
57 | + } |
|
58 | + if ($large) { |
|
59 | + $messages[] = str_repeat(' ', $len); |
|
60 | + } |
|
61 | 61 | |
62 | - for ($i = 0; isset($messages[$i]); ++$i) { |
|
63 | - $messages[$i] = sprintf('<%s>%s</%s>', $style, $messages[$i], $style); |
|
64 | - } |
|
62 | + for ($i = 0; isset($messages[$i]); ++$i) { |
|
63 | + $messages[$i] = sprintf('<%s>%s</%s>', $style, $messages[$i], $style); |
|
64 | + } |
|
65 | 65 | |
66 | - return implode("\n", $messages); |
|
67 | - } |
|
66 | + return implode("\n", $messages); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * Truncates a message to the given length. |
|
71 | - * |
|
72 | - * @return string |
|
73 | - */ |
|
74 | - public function truncate(string $message, int $length, string $suffix = '...') |
|
75 | - { |
|
76 | - $computedLength = $length - self::width($suffix); |
|
69 | + /** |
|
70 | + * Truncates a message to the given length. |
|
71 | + * |
|
72 | + * @return string |
|
73 | + */ |
|
74 | + public function truncate(string $message, int $length, string $suffix = '...') |
|
75 | + { |
|
76 | + $computedLength = $length - self::width($suffix); |
|
77 | 77 | |
78 | - if ($computedLength > self::width($message)) { |
|
79 | - return $message; |
|
80 | - } |
|
78 | + if ($computedLength > self::width($message)) { |
|
79 | + return $message; |
|
80 | + } |
|
81 | 81 | |
82 | - return self::substr($message, 0, $length).$suffix; |
|
83 | - } |
|
82 | + return self::substr($message, 0, $length).$suffix; |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * {@inheritdoc} |
|
87 | - */ |
|
88 | - public function getName() |
|
89 | - { |
|
90 | - return 'formatter'; |
|
91 | - } |
|
85 | + /** |
|
86 | + * {@inheritdoc} |
|
87 | + */ |
|
88 | + public function getName() |
|
89 | + { |
|
90 | + return 'formatter'; |
|
91 | + } |
|
92 | 92 | } |
@@ -25,9 +25,9 @@ discard block |
||
25 | 25 | * |
26 | 26 | * @return string The format section |
27 | 27 | */ |
28 | - public function formatSection(string $section, string $message, string $style = 'info') |
|
28 | + public function formatSection( string $section, string $message, string $style = 'info' ) |
|
29 | 29 | { |
30 | - return sprintf('<%s>[%s]</%s> %s', $style, $section, $style, $message); |
|
30 | + return sprintf( '<%s>[%s]</%s> %s', $style, $section, $style, $message ); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
@@ -37,33 +37,33 @@ discard block |
||
37 | 37 | * |
38 | 38 | * @return string The formatter message |
39 | 39 | */ |
40 | - public function formatBlock($messages, string $style, bool $large = false) |
|
40 | + public function formatBlock( $messages, string $style, bool $large = false ) |
|
41 | 41 | { |
42 | - if (!\is_array($messages)) { |
|
43 | - $messages = [$messages]; |
|
42 | + if ( ! \is_array( $messages ) ) { |
|
43 | + $messages = [ $messages ]; |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | $len = 0; |
47 | - $lines = []; |
|
48 | - foreach ($messages as $message) { |
|
49 | - $message = OutputFormatter::escape($message); |
|
50 | - $lines[] = sprintf($large ? ' %s ' : ' %s ', $message); |
|
51 | - $len = max(self::width($message) + ($large ? 4 : 2), $len); |
|
47 | + $lines = [ ]; |
|
48 | + foreach ( $messages as $message ) { |
|
49 | + $message = OutputFormatter::escape( $message ); |
|
50 | + $lines[ ] = sprintf( $large ? ' %s ' : ' %s ', $message ); |
|
51 | + $len = max( self::width( $message ) + ( $large ? 4 : 2 ), $len ); |
|
52 | 52 | } |
53 | 53 | |
54 | - $messages = $large ? [str_repeat(' ', $len)] : []; |
|
55 | - for ($i = 0; isset($lines[$i]); ++$i) { |
|
56 | - $messages[] = $lines[$i].str_repeat(' ', $len - self::width($lines[$i])); |
|
54 | + $messages = $large ? [ str_repeat( ' ', $len ) ] : [ ]; |
|
55 | + for ( $i = 0; isset( $lines[ $i ] ); ++$i ) { |
|
56 | + $messages[ ] = $lines[ $i ] . str_repeat( ' ', $len - self::width( $lines[ $i ] ) ); |
|
57 | 57 | } |
58 | - if ($large) { |
|
59 | - $messages[] = str_repeat(' ', $len); |
|
58 | + if ( $large ) { |
|
59 | + $messages[ ] = str_repeat( ' ', $len ); |
|
60 | 60 | } |
61 | 61 | |
62 | - for ($i = 0; isset($messages[$i]); ++$i) { |
|
63 | - $messages[$i] = sprintf('<%s>%s</%s>', $style, $messages[$i], $style); |
|
62 | + for ( $i = 0; isset( $messages[ $i ] ); ++$i ) { |
|
63 | + $messages[ $i ] = sprintf( '<%s>%s</%s>', $style, $messages[ $i ], $style ); |
|
64 | 64 | } |
65 | 65 | |
66 | - return implode("\n", $messages); |
|
66 | + return implode( "\n", $messages ); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -71,15 +71,15 @@ discard block |
||
71 | 71 | * |
72 | 72 | * @return string |
73 | 73 | */ |
74 | - public function truncate(string $message, int $length, string $suffix = '...') |
|
74 | + public function truncate( string $message, int $length, string $suffix = '...' ) |
|
75 | 75 | { |
76 | - $computedLength = $length - self::width($suffix); |
|
76 | + $computedLength = $length - self::width( $suffix ); |
|
77 | 77 | |
78 | - if ($computedLength > self::width($message)) { |
|
78 | + if ( $computedLength > self::width( $message ) ) { |
|
79 | 79 | return $message; |
80 | 80 | } |
81 | 81 | |
82 | - return self::substr($message, 0, $length).$suffix; |
|
82 | + return self::substr( $message, 0, $length ) . $suffix; |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
@@ -18,15 +18,13 @@ discard block |
||
18 | 18 | * |
19 | 19 | * @author Fabien Potencier <[email protected]> |
20 | 20 | */ |
21 | -class FormatterHelper extends Helper |
|
22 | -{ |
|
21 | +class FormatterHelper extends Helper { |
|
23 | 22 | /** |
24 | 23 | * Formats a message within a section. |
25 | 24 | * |
26 | 25 | * @return string The format section |
27 | 26 | */ |
28 | - public function formatSection(string $section, string $message, string $style = 'info') |
|
29 | - { |
|
27 | + public function formatSection(string $section, string $message, string $style = 'info') { |
|
30 | 28 | return sprintf('<%s>[%s]</%s> %s', $style, $section, $style, $message); |
31 | 29 | } |
32 | 30 | |
@@ -37,8 +35,7 @@ discard block |
||
37 | 35 | * |
38 | 36 | * @return string The formatter message |
39 | 37 | */ |
40 | - public function formatBlock($messages, string $style, bool $large = false) |
|
41 | - { |
|
38 | + public function formatBlock($messages, string $style, bool $large = false) { |
|
42 | 39 | if (!\is_array($messages)) { |
43 | 40 | $messages = [$messages]; |
44 | 41 | } |
@@ -71,8 +68,7 @@ discard block |
||
71 | 68 | * |
72 | 69 | * @return string |
73 | 70 | */ |
74 | - public function truncate(string $message, int $length, string $suffix = '...') |
|
75 | - { |
|
71 | + public function truncate(string $message, int $length, string $suffix = '...') { |
|
76 | 72 | $computedLength = $length - self::width($suffix); |
77 | 73 | |
78 | 74 | if ($computedLength > self::width($message)) { |
@@ -85,8 +81,7 @@ discard block |
||
85 | 81 | /** |
86 | 82 | * {@inheritdoc} |
87 | 83 | */ |
88 | - public function getName() |
|
89 | - { |
|
84 | + public function getName() { |
|
90 | 85 | return 'formatter'; |
91 | 86 | } |
92 | 87 | } |
@@ -25,85 +25,85 @@ |
||
25 | 25 | */ |
26 | 26 | class SymfonyQuestionHelper extends QuestionHelper |
27 | 27 | { |
28 | - /** |
|
29 | - * {@inheritdoc} |
|
30 | - */ |
|
31 | - protected function writePrompt(OutputInterface $output, Question $question) |
|
32 | - { |
|
33 | - $text = OutputFormatter::escapeTrailingBackslash($question->getQuestion()); |
|
34 | - $default = $question->getDefault(); |
|
28 | + /** |
|
29 | + * {@inheritdoc} |
|
30 | + */ |
|
31 | + protected function writePrompt(OutputInterface $output, Question $question) |
|
32 | + { |
|
33 | + $text = OutputFormatter::escapeTrailingBackslash($question->getQuestion()); |
|
34 | + $default = $question->getDefault(); |
|
35 | 35 | |
36 | - if ($question->isMultiline()) { |
|
37 | - $text .= sprintf(' (press %s to continue)', $this->getEofShortcut()); |
|
38 | - } |
|
36 | + if ($question->isMultiline()) { |
|
37 | + $text .= sprintf(' (press %s to continue)', $this->getEofShortcut()); |
|
38 | + } |
|
39 | 39 | |
40 | - switch (true) { |
|
41 | - case null === $default: |
|
42 | - $text = sprintf(' <info>%s</info>:', $text); |
|
40 | + switch (true) { |
|
41 | + case null === $default: |
|
42 | + $text = sprintf(' <info>%s</info>:', $text); |
|
43 | 43 | |
44 | - break; |
|
44 | + break; |
|
45 | 45 | |
46 | - case $question instanceof ConfirmationQuestion: |
|
47 | - $text = sprintf(' <info>%s (yes/no)</info> [<comment>%s</comment>]:', $text, $default ? 'yes' : 'no'); |
|
46 | + case $question instanceof ConfirmationQuestion: |
|
47 | + $text = sprintf(' <info>%s (yes/no)</info> [<comment>%s</comment>]:', $text, $default ? 'yes' : 'no'); |
|
48 | 48 | |
49 | - break; |
|
49 | + break; |
|
50 | 50 | |
51 | - case $question instanceof ChoiceQuestion && $question->isMultiselect(): |
|
52 | - $choices = $question->getChoices(); |
|
53 | - $default = explode(',', $default); |
|
51 | + case $question instanceof ChoiceQuestion && $question->isMultiselect(): |
|
52 | + $choices = $question->getChoices(); |
|
53 | + $default = explode(',', $default); |
|
54 | 54 | |
55 | - foreach ($default as $key => $value) { |
|
56 | - $default[$key] = $choices[trim($value)]; |
|
57 | - } |
|
55 | + foreach ($default as $key => $value) { |
|
56 | + $default[$key] = $choices[trim($value)]; |
|
57 | + } |
|
58 | 58 | |
59 | - $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, OutputFormatter::escape(implode(', ', $default))); |
|
59 | + $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, OutputFormatter::escape(implode(', ', $default))); |
|
60 | 60 | |
61 | - break; |
|
61 | + break; |
|
62 | 62 | |
63 | - case $question instanceof ChoiceQuestion: |
|
64 | - $choices = $question->getChoices(); |
|
65 | - $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, OutputFormatter::escape($choices[$default] ?? $default)); |
|
63 | + case $question instanceof ChoiceQuestion: |
|
64 | + $choices = $question->getChoices(); |
|
65 | + $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, OutputFormatter::escape($choices[$default] ?? $default)); |
|
66 | 66 | |
67 | - break; |
|
67 | + break; |
|
68 | 68 | |
69 | - default: |
|
70 | - $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, OutputFormatter::escape($default)); |
|
71 | - } |
|
69 | + default: |
|
70 | + $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, OutputFormatter::escape($default)); |
|
71 | + } |
|
72 | 72 | |
73 | - $output->writeln($text); |
|
73 | + $output->writeln($text); |
|
74 | 74 | |
75 | - $prompt = ' > '; |
|
75 | + $prompt = ' > '; |
|
76 | 76 | |
77 | - if ($question instanceof ChoiceQuestion) { |
|
78 | - $output->writeln($this->formatChoiceQuestionChoices($question, 'comment')); |
|
77 | + if ($question instanceof ChoiceQuestion) { |
|
78 | + $output->writeln($this->formatChoiceQuestionChoices($question, 'comment')); |
|
79 | 79 | |
80 | - $prompt = $question->getPrompt(); |
|
81 | - } |
|
80 | + $prompt = $question->getPrompt(); |
|
81 | + } |
|
82 | 82 | |
83 | - $output->write($prompt); |
|
84 | - } |
|
83 | + $output->write($prompt); |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * {@inheritdoc} |
|
88 | - */ |
|
89 | - protected function writeError(OutputInterface $output, \Exception $error) |
|
90 | - { |
|
91 | - if ($output instanceof SymfonyStyle) { |
|
92 | - $output->newLine(); |
|
93 | - $output->error($error->getMessage()); |
|
86 | + /** |
|
87 | + * {@inheritdoc} |
|
88 | + */ |
|
89 | + protected function writeError(OutputInterface $output, \Exception $error) |
|
90 | + { |
|
91 | + if ($output instanceof SymfonyStyle) { |
|
92 | + $output->newLine(); |
|
93 | + $output->error($error->getMessage()); |
|
94 | 94 | |
95 | - return; |
|
96 | - } |
|
95 | + return; |
|
96 | + } |
|
97 | 97 | |
98 | - parent::writeError($output, $error); |
|
99 | - } |
|
98 | + parent::writeError($output, $error); |
|
99 | + } |
|
100 | 100 | |
101 | - private function getEofShortcut(): string |
|
102 | - { |
|
103 | - if ('Windows' === \PHP_OS_FAMILY) { |
|
104 | - return '<comment>Ctrl+Z</comment> then <comment>Enter</comment>'; |
|
105 | - } |
|
101 | + private function getEofShortcut(): string |
|
102 | + { |
|
103 | + if ('Windows' === \PHP_OS_FAMILY) { |
|
104 | + return '<comment>Ctrl+Z</comment> then <comment>Enter</comment>'; |
|
105 | + } |
|
106 | 106 | |
107 | - return '<comment>Ctrl+D</comment>'; |
|
108 | - } |
|
107 | + return '<comment>Ctrl+D</comment>'; |
|
108 | + } |
|
109 | 109 | } |
@@ -28,79 +28,79 @@ |
||
28 | 28 | /** |
29 | 29 | * {@inheritdoc} |
30 | 30 | */ |
31 | - protected function writePrompt(OutputInterface $output, Question $question) |
|
31 | + protected function writePrompt( OutputInterface $output, Question $question ) |
|
32 | 32 | { |
33 | - $text = OutputFormatter::escapeTrailingBackslash($question->getQuestion()); |
|
33 | + $text = OutputFormatter::escapeTrailingBackslash( $question->getQuestion() ); |
|
34 | 34 | $default = $question->getDefault(); |
35 | 35 | |
36 | - if ($question->isMultiline()) { |
|
37 | - $text .= sprintf(' (press %s to continue)', $this->getEofShortcut()); |
|
36 | + if ( $question->isMultiline() ) { |
|
37 | + $text .= sprintf( ' (press %s to continue)', $this->getEofShortcut() ); |
|
38 | 38 | } |
39 | 39 | |
40 | - switch (true) { |
|
40 | + switch ( true ) { |
|
41 | 41 | case null === $default: |
42 | - $text = sprintf(' <info>%s</info>:', $text); |
|
42 | + $text = sprintf( ' <info>%s</info>:', $text ); |
|
43 | 43 | |
44 | 44 | break; |
45 | 45 | |
46 | 46 | case $question instanceof ConfirmationQuestion: |
47 | - $text = sprintf(' <info>%s (yes/no)</info> [<comment>%s</comment>]:', $text, $default ? 'yes' : 'no'); |
|
47 | + $text = sprintf( ' <info>%s (yes/no)</info> [<comment>%s</comment>]:', $text, $default ? 'yes' : 'no' ); |
|
48 | 48 | |
49 | 49 | break; |
50 | 50 | |
51 | 51 | case $question instanceof ChoiceQuestion && $question->isMultiselect(): |
52 | 52 | $choices = $question->getChoices(); |
53 | - $default = explode(',', $default); |
|
53 | + $default = explode( ',', $default ); |
|
54 | 54 | |
55 | - foreach ($default as $key => $value) { |
|
56 | - $default[$key] = $choices[trim($value)]; |
|
55 | + foreach ( $default as $key => $value ) { |
|
56 | + $default[ $key ] = $choices[ trim( $value ) ]; |
|
57 | 57 | } |
58 | 58 | |
59 | - $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, OutputFormatter::escape(implode(', ', $default))); |
|
59 | + $text = sprintf( ' <info>%s</info> [<comment>%s</comment>]:', $text, OutputFormatter::escape( implode( ', ', $default ) ) ); |
|
60 | 60 | |
61 | 61 | break; |
62 | 62 | |
63 | 63 | case $question instanceof ChoiceQuestion: |
64 | 64 | $choices = $question->getChoices(); |
65 | - $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, OutputFormatter::escape($choices[$default] ?? $default)); |
|
65 | + $text = sprintf( ' <info>%s</info> [<comment>%s</comment>]:', $text, OutputFormatter::escape( $choices[ $default ] ?? $default ) ); |
|
66 | 66 | |
67 | 67 | break; |
68 | 68 | |
69 | 69 | default: |
70 | - $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, OutputFormatter::escape($default)); |
|
70 | + $text = sprintf( ' <info>%s</info> [<comment>%s</comment>]:', $text, OutputFormatter::escape( $default ) ); |
|
71 | 71 | } |
72 | 72 | |
73 | - $output->writeln($text); |
|
73 | + $output->writeln( $text ); |
|
74 | 74 | |
75 | 75 | $prompt = ' > '; |
76 | 76 | |
77 | - if ($question instanceof ChoiceQuestion) { |
|
78 | - $output->writeln($this->formatChoiceQuestionChoices($question, 'comment')); |
|
77 | + if ( $question instanceof ChoiceQuestion ) { |
|
78 | + $output->writeln( $this->formatChoiceQuestionChoices( $question, 'comment' ) ); |
|
79 | 79 | |
80 | 80 | $prompt = $question->getPrompt(); |
81 | 81 | } |
82 | 82 | |
83 | - $output->write($prompt); |
|
83 | + $output->write( $prompt ); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
87 | 87 | * {@inheritdoc} |
88 | 88 | */ |
89 | - protected function writeError(OutputInterface $output, \Exception $error) |
|
89 | + protected function writeError( OutputInterface $output, \Exception $error ) |
|
90 | 90 | { |
91 | - if ($output instanceof SymfonyStyle) { |
|
91 | + if ( $output instanceof SymfonyStyle ) { |
|
92 | 92 | $output->newLine(); |
93 | - $output->error($error->getMessage()); |
|
93 | + $output->error( $error->getMessage() ); |
|
94 | 94 | |
95 | 95 | return; |
96 | 96 | } |
97 | 97 | |
98 | - parent::writeError($output, $error); |
|
98 | + parent::writeError( $output, $error ); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | private function getEofShortcut(): string |
102 | 102 | { |
103 | - if ('Windows' === \PHP_OS_FAMILY) { |
|
103 | + if ( 'Windows' === \PHP_OS_FAMILY ) { |
|
104 | 104 | return '<comment>Ctrl+Z</comment> then <comment>Enter</comment>'; |
105 | 105 | } |
106 | 106 |
@@ -23,13 +23,11 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @author Kevin Bond <[email protected]> |
25 | 25 | */ |
26 | -class SymfonyQuestionHelper extends QuestionHelper |
|
27 | -{ |
|
26 | +class SymfonyQuestionHelper extends QuestionHelper { |
|
28 | 27 | /** |
29 | 28 | * {@inheritdoc} |
30 | 29 | */ |
31 | - protected function writePrompt(OutputInterface $output, Question $question) |
|
32 | - { |
|
30 | + protected function writePrompt(OutputInterface $output, Question $question) { |
|
33 | 31 | $text = OutputFormatter::escapeTrailingBackslash($question->getQuestion()); |
34 | 32 | $default = $question->getDefault(); |
35 | 33 | |
@@ -86,8 +84,7 @@ discard block |
||
86 | 84 | /** |
87 | 85 | * {@inheritdoc} |
88 | 86 | */ |
89 | - protected function writeError(OutputInterface $output, \Exception $error) |
|
90 | - { |
|
87 | + protected function writeError(OutputInterface $output, \Exception $error) { |
|
91 | 88 | if ($output instanceof SymfonyStyle) { |
92 | 89 | $output->newLine(); |
93 | 90 | $output->error($error->getMessage()); |
@@ -16,17 +16,17 @@ |
||
16 | 16 | */ |
17 | 17 | class TableRows implements \IteratorAggregate |
18 | 18 | { |
19 | - private $generator; |
|
19 | + private $generator; |
|
20 | 20 | |
21 | - public function __construct(callable $generator) |
|
22 | - { |
|
23 | - $this->generator = $generator; |
|
24 | - } |
|
21 | + public function __construct(callable $generator) |
|
22 | + { |
|
23 | + $this->generator = $generator; |
|
24 | + } |
|
25 | 25 | |
26 | - public function getIterator(): \Traversable |
|
27 | - { |
|
28 | - $g = $this->generator; |
|
26 | + public function getIterator(): \Traversable |
|
27 | + { |
|
28 | + $g = $this->generator; |
|
29 | 29 | |
30 | - return $g(); |
|
31 | - } |
|
30 | + return $g(); |
|
31 | + } |
|
32 | 32 | } |
@@ -18,7 +18,7 @@ |
||
18 | 18 | { |
19 | 19 | private $generator; |
20 | 20 | |
21 | - public function __construct(callable $generator) |
|
21 | + public function __construct( callable $generator ) |
|
22 | 22 | { |
23 | 23 | $this->generator = $generator; |
24 | 24 | } |
@@ -14,12 +14,10 @@ |
||
14 | 14 | /** |
15 | 15 | * @internal |
16 | 16 | */ |
17 | -class TableRows implements \IteratorAggregate |
|
18 | -{ |
|
17 | +class TableRows implements \IteratorAggregate { |
|
19 | 18 | private $generator; |
20 | 19 | |
21 | - public function __construct(callable $generator) |
|
22 | - { |
|
20 | + public function __construct(callable $generator) { |
|
23 | 21 | $this->generator = $generator; |
24 | 22 | } |
25 | 23 |
@@ -26,594 +26,594 @@ |
||
26 | 26 | */ |
27 | 27 | final class ProgressBar |
28 | 28 | { |
29 | - public const FORMAT_VERBOSE = 'verbose'; |
|
30 | - public const FORMAT_VERY_VERBOSE = 'very_verbose'; |
|
31 | - public const FORMAT_DEBUG = 'debug'; |
|
32 | - public const FORMAT_NORMAL = 'normal'; |
|
33 | - |
|
34 | - private const FORMAT_VERBOSE_NOMAX = 'verbose_nomax'; |
|
35 | - private const FORMAT_VERY_VERBOSE_NOMAX = 'very_verbose_nomax'; |
|
36 | - private const FORMAT_DEBUG_NOMAX = 'debug_nomax'; |
|
37 | - private const FORMAT_NORMAL_NOMAX = 'normal_nomax'; |
|
38 | - |
|
39 | - private $barWidth = 28; |
|
40 | - private $barChar; |
|
41 | - private $emptyBarChar = '-'; |
|
42 | - private $progressChar = '>'; |
|
43 | - private $format; |
|
44 | - private $internalFormat; |
|
45 | - private $redrawFreq = 1; |
|
46 | - private $writeCount; |
|
47 | - private $lastWriteTime; |
|
48 | - private $minSecondsBetweenRedraws = 0; |
|
49 | - private $maxSecondsBetweenRedraws = 1; |
|
50 | - private $output; |
|
51 | - private $step = 0; |
|
52 | - private $max; |
|
53 | - private $startTime; |
|
54 | - private $stepWidth; |
|
55 | - private $percent = 0.0; |
|
56 | - private $formatLineCount; |
|
57 | - private $messages = []; |
|
58 | - private $overwrite = true; |
|
59 | - private $terminal; |
|
60 | - private $previousMessage; |
|
61 | - private $cursor; |
|
62 | - |
|
63 | - private static $formatters; |
|
64 | - private static $formats; |
|
65 | - |
|
66 | - /** |
|
67 | - * @param int $max Maximum steps (0 if unknown) |
|
68 | - */ |
|
69 | - public function __construct(OutputInterface $output, int $max = 0, float $minSecondsBetweenRedraws = 1 / 25) |
|
70 | - { |
|
71 | - if ($output instanceof ConsoleOutputInterface) { |
|
72 | - $output = $output->getErrorOutput(); |
|
73 | - } |
|
74 | - |
|
75 | - $this->output = $output; |
|
76 | - $this->setMaxSteps($max); |
|
77 | - $this->terminal = new Terminal(); |
|
78 | - |
|
79 | - if (0 < $minSecondsBetweenRedraws) { |
|
80 | - $this->redrawFreq = null; |
|
81 | - $this->minSecondsBetweenRedraws = $minSecondsBetweenRedraws; |
|
82 | - } |
|
83 | - |
|
84 | - if (!$this->output->isDecorated()) { |
|
85 | - // disable overwrite when output does not support ANSI codes. |
|
86 | - $this->overwrite = false; |
|
87 | - |
|
88 | - // set a reasonable redraw frequency so output isn't flooded |
|
89 | - $this->redrawFreq = null; |
|
90 | - } |
|
91 | - |
|
92 | - $this->startTime = time(); |
|
93 | - $this->cursor = new Cursor($output); |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Sets a placeholder formatter for a given name. |
|
98 | - * |
|
99 | - * This method also allow you to override an existing placeholder. |
|
100 | - * |
|
101 | - * @param string $name The placeholder name (including the delimiter char like %) |
|
102 | - * @param callable $callable A PHP callable |
|
103 | - */ |
|
104 | - public static function setPlaceholderFormatterDefinition(string $name, callable $callable): void |
|
105 | - { |
|
106 | - if (!self::$formatters) { |
|
107 | - self::$formatters = self::initPlaceholderFormatters(); |
|
108 | - } |
|
109 | - |
|
110 | - self::$formatters[$name] = $callable; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Gets the placeholder formatter for a given name. |
|
115 | - * |
|
116 | - * @param string $name The placeholder name (including the delimiter char like %) |
|
117 | - * |
|
118 | - * @return callable|null A PHP callable |
|
119 | - */ |
|
120 | - public static function getPlaceholderFormatterDefinition(string $name): ?callable |
|
121 | - { |
|
122 | - if (!self::$formatters) { |
|
123 | - self::$formatters = self::initPlaceholderFormatters(); |
|
124 | - } |
|
125 | - |
|
126 | - return self::$formatters[$name] ?? null; |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * Sets a format for a given name. |
|
131 | - * |
|
132 | - * This method also allow you to override an existing format. |
|
133 | - * |
|
134 | - * @param string $name The format name |
|
135 | - * @param string $format A format string |
|
136 | - */ |
|
137 | - public static function setFormatDefinition(string $name, string $format): void |
|
138 | - { |
|
139 | - if (!self::$formats) { |
|
140 | - self::$formats = self::initFormats(); |
|
141 | - } |
|
142 | - |
|
143 | - self::$formats[$name] = $format; |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * Gets the format for a given name. |
|
148 | - * |
|
149 | - * @param string $name The format name |
|
150 | - * |
|
151 | - * @return string|null A format string |
|
152 | - */ |
|
153 | - public static function getFormatDefinition(string $name): ?string |
|
154 | - { |
|
155 | - if (!self::$formats) { |
|
156 | - self::$formats = self::initFormats(); |
|
157 | - } |
|
158 | - |
|
159 | - return self::$formats[$name] ?? null; |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * Associates a text with a named placeholder. |
|
164 | - * |
|
165 | - * The text is displayed when the progress bar is rendered but only |
|
166 | - * when the corresponding placeholder is part of the custom format line |
|
167 | - * (by wrapping the name with %). |
|
168 | - * |
|
169 | - * @param string $message The text to associate with the placeholder |
|
170 | - * @param string $name The name of the placeholder |
|
171 | - */ |
|
172 | - public function setMessage(string $message, string $name = 'message') |
|
173 | - { |
|
174 | - $this->messages[$name] = $message; |
|
175 | - } |
|
176 | - |
|
177 | - public function getMessage(string $name = 'message') |
|
178 | - { |
|
179 | - return $this->messages[$name]; |
|
180 | - } |
|
181 | - |
|
182 | - public function getStartTime(): int |
|
183 | - { |
|
184 | - return $this->startTime; |
|
185 | - } |
|
186 | - |
|
187 | - public function getMaxSteps(): int |
|
188 | - { |
|
189 | - return $this->max; |
|
190 | - } |
|
191 | - |
|
192 | - public function getProgress(): int |
|
193 | - { |
|
194 | - return $this->step; |
|
195 | - } |
|
196 | - |
|
197 | - private function getStepWidth(): int |
|
198 | - { |
|
199 | - return $this->stepWidth; |
|
200 | - } |
|
201 | - |
|
202 | - public function getProgressPercent(): float |
|
203 | - { |
|
204 | - return $this->percent; |
|
205 | - } |
|
206 | - |
|
207 | - public function getBarOffset(): float |
|
208 | - { |
|
209 | - return floor($this->max ? $this->percent * $this->barWidth : (null === $this->redrawFreq ? (int) (min(5, $this->barWidth / 15) * $this->writeCount) : $this->step) % $this->barWidth); |
|
210 | - } |
|
211 | - |
|
212 | - public function getEstimated(): float |
|
213 | - { |
|
214 | - if (!$this->step) { |
|
215 | - return 0; |
|
216 | - } |
|
217 | - |
|
218 | - return round((time() - $this->startTime) / $this->step * $this->max); |
|
219 | - } |
|
220 | - |
|
221 | - public function getRemaining(): float |
|
222 | - { |
|
223 | - if (!$this->step) { |
|
224 | - return 0; |
|
225 | - } |
|
226 | - |
|
227 | - return round((time() - $this->startTime) / $this->step * ($this->max - $this->step)); |
|
228 | - } |
|
229 | - |
|
230 | - public function setBarWidth(int $size) |
|
231 | - { |
|
232 | - $this->barWidth = max(1, $size); |
|
233 | - } |
|
234 | - |
|
235 | - public function getBarWidth(): int |
|
236 | - { |
|
237 | - return $this->barWidth; |
|
238 | - } |
|
239 | - |
|
240 | - public function setBarCharacter(string $char) |
|
241 | - { |
|
242 | - $this->barChar = $char; |
|
243 | - } |
|
244 | - |
|
245 | - public function getBarCharacter(): string |
|
246 | - { |
|
247 | - if (null === $this->barChar) { |
|
248 | - return $this->max ? '=' : $this->emptyBarChar; |
|
249 | - } |
|
250 | - |
|
251 | - return $this->barChar; |
|
252 | - } |
|
253 | - |
|
254 | - public function setEmptyBarCharacter(string $char) |
|
255 | - { |
|
256 | - $this->emptyBarChar = $char; |
|
257 | - } |
|
258 | - |
|
259 | - public function getEmptyBarCharacter(): string |
|
260 | - { |
|
261 | - return $this->emptyBarChar; |
|
262 | - } |
|
263 | - |
|
264 | - public function setProgressCharacter(string $char) |
|
265 | - { |
|
266 | - $this->progressChar = $char; |
|
267 | - } |
|
268 | - |
|
269 | - public function getProgressCharacter(): string |
|
270 | - { |
|
271 | - return $this->progressChar; |
|
272 | - } |
|
273 | - |
|
274 | - public function setFormat(string $format) |
|
275 | - { |
|
276 | - $this->format = null; |
|
277 | - $this->internalFormat = $format; |
|
278 | - } |
|
279 | - |
|
280 | - /** |
|
281 | - * Sets the redraw frequency. |
|
282 | - * |
|
283 | - * @param int|null $freq The frequency in steps |
|
284 | - */ |
|
285 | - public function setRedrawFrequency(?int $freq) |
|
286 | - { |
|
287 | - $this->redrawFreq = null !== $freq ? max(1, $freq) : null; |
|
288 | - } |
|
289 | - |
|
290 | - public function minSecondsBetweenRedraws(float $seconds): void |
|
291 | - { |
|
292 | - $this->minSecondsBetweenRedraws = $seconds; |
|
293 | - } |
|
294 | - |
|
295 | - public function maxSecondsBetweenRedraws(float $seconds): void |
|
296 | - { |
|
297 | - $this->maxSecondsBetweenRedraws = $seconds; |
|
298 | - } |
|
299 | - |
|
300 | - /** |
|
301 | - * Returns an iterator that will automatically update the progress bar when iterated. |
|
302 | - * |
|
303 | - * @param int|null $max Number of steps to complete the bar (0 if indeterminate), if null it will be inferred from $iterable |
|
304 | - */ |
|
305 | - public function iterate(iterable $iterable, int $max = null): iterable |
|
306 | - { |
|
307 | - $this->start($max ?? (is_countable($iterable) ? \count($iterable) : 0)); |
|
308 | - |
|
309 | - foreach ($iterable as $key => $value) { |
|
310 | - yield $key => $value; |
|
311 | - |
|
312 | - $this->advance(); |
|
313 | - } |
|
314 | - |
|
315 | - $this->finish(); |
|
316 | - } |
|
317 | - |
|
318 | - /** |
|
319 | - * Starts the progress output. |
|
320 | - * |
|
321 | - * @param int|null $max Number of steps to complete the bar (0 if indeterminate), null to leave unchanged |
|
322 | - */ |
|
323 | - public function start(int $max = null) |
|
324 | - { |
|
325 | - $this->startTime = time(); |
|
326 | - $this->step = 0; |
|
327 | - $this->percent = 0.0; |
|
328 | - |
|
329 | - if (null !== $max) { |
|
330 | - $this->setMaxSteps($max); |
|
331 | - } |
|
332 | - |
|
333 | - $this->display(); |
|
334 | - } |
|
335 | - |
|
336 | - /** |
|
337 | - * Advances the progress output X steps. |
|
338 | - * |
|
339 | - * @param int $step Number of steps to advance |
|
340 | - */ |
|
341 | - public function advance(int $step = 1) |
|
342 | - { |
|
343 | - $this->setProgress($this->step + $step); |
|
344 | - } |
|
345 | - |
|
346 | - /** |
|
347 | - * Sets whether to overwrite the progressbar, false for new line. |
|
348 | - */ |
|
349 | - public function setOverwrite(bool $overwrite) |
|
350 | - { |
|
351 | - $this->overwrite = $overwrite; |
|
352 | - } |
|
353 | - |
|
354 | - public function setProgress(int $step) |
|
355 | - { |
|
356 | - if ($this->max && $step > $this->max) { |
|
357 | - $this->max = $step; |
|
358 | - } elseif ($step < 0) { |
|
359 | - $step = 0; |
|
360 | - } |
|
361 | - |
|
362 | - $redrawFreq = $this->redrawFreq ?? (($this->max ?: 10) / 10); |
|
363 | - $prevPeriod = (int) ($this->step / $redrawFreq); |
|
364 | - $currPeriod = (int) ($step / $redrawFreq); |
|
365 | - $this->step = $step; |
|
366 | - $this->percent = $this->max ? (float) $this->step / $this->max : 0; |
|
367 | - $timeInterval = microtime(true) - $this->lastWriteTime; |
|
368 | - |
|
369 | - // Draw regardless of other limits |
|
370 | - if ($this->max === $step) { |
|
371 | - $this->display(); |
|
372 | - |
|
373 | - return; |
|
374 | - } |
|
375 | - |
|
376 | - // Throttling |
|
377 | - if ($timeInterval < $this->minSecondsBetweenRedraws) { |
|
378 | - return; |
|
379 | - } |
|
380 | - |
|
381 | - // Draw each step period, but not too late |
|
382 | - if ($prevPeriod !== $currPeriod || $timeInterval >= $this->maxSecondsBetweenRedraws) { |
|
383 | - $this->display(); |
|
384 | - } |
|
385 | - } |
|
386 | - |
|
387 | - public function setMaxSteps(int $max) |
|
388 | - { |
|
389 | - $this->format = null; |
|
390 | - $this->max = max(0, $max); |
|
391 | - $this->stepWidth = $this->max ? Helper::width((string) $this->max) : 4; |
|
392 | - } |
|
393 | - |
|
394 | - /** |
|
395 | - * Finishes the progress output. |
|
396 | - */ |
|
397 | - public function finish(): void |
|
398 | - { |
|
399 | - if (!$this->max) { |
|
400 | - $this->max = $this->step; |
|
401 | - } |
|
402 | - |
|
403 | - if ($this->step === $this->max && !$this->overwrite) { |
|
404 | - // prevent double 100% output |
|
405 | - return; |
|
406 | - } |
|
407 | - |
|
408 | - $this->setProgress($this->max); |
|
409 | - } |
|
410 | - |
|
411 | - /** |
|
412 | - * Outputs the current progress string. |
|
413 | - */ |
|
414 | - public function display(): void |
|
415 | - { |
|
416 | - if (OutputInterface::VERBOSITY_QUIET === $this->output->getVerbosity()) { |
|
417 | - return; |
|
418 | - } |
|
419 | - |
|
420 | - if (null === $this->format) { |
|
421 | - $this->setRealFormat($this->internalFormat ?: $this->determineBestFormat()); |
|
422 | - } |
|
423 | - |
|
424 | - $this->overwrite($this->buildLine()); |
|
425 | - } |
|
426 | - |
|
427 | - /** |
|
428 | - * Removes the progress bar from the current line. |
|
429 | - * |
|
430 | - * This is useful if you wish to write some output |
|
431 | - * while a progress bar is running. |
|
432 | - * Call display() to show the progress bar again. |
|
433 | - */ |
|
434 | - public function clear(): void |
|
435 | - { |
|
436 | - if (!$this->overwrite) { |
|
437 | - return; |
|
438 | - } |
|
439 | - |
|
440 | - if (null === $this->format) { |
|
441 | - $this->setRealFormat($this->internalFormat ?: $this->determineBestFormat()); |
|
442 | - } |
|
443 | - |
|
444 | - $this->overwrite(''); |
|
445 | - } |
|
446 | - |
|
447 | - private function setRealFormat(string $format) |
|
448 | - { |
|
449 | - // try to use the _nomax variant if available |
|
450 | - if (!$this->max && null !== self::getFormatDefinition($format.'_nomax')) { |
|
451 | - $this->format = self::getFormatDefinition($format.'_nomax'); |
|
452 | - } elseif (null !== self::getFormatDefinition($format)) { |
|
453 | - $this->format = self::getFormatDefinition($format); |
|
454 | - } else { |
|
455 | - $this->format = $format; |
|
456 | - } |
|
457 | - |
|
458 | - $this->formatLineCount = substr_count($this->format, "\n"); |
|
459 | - } |
|
460 | - |
|
461 | - /** |
|
462 | - * Overwrites a previous message to the output. |
|
463 | - */ |
|
464 | - private function overwrite(string $message): void |
|
465 | - { |
|
466 | - if ($this->previousMessage === $message) { |
|
467 | - return; |
|
468 | - } |
|
469 | - |
|
470 | - $originalMessage = $message; |
|
471 | - |
|
472 | - if ($this->overwrite) { |
|
473 | - if (null !== $this->previousMessage) { |
|
474 | - if ($this->output instanceof ConsoleSectionOutput) { |
|
475 | - $messageLines = explode("\n", $message); |
|
476 | - $lineCount = \count($messageLines); |
|
477 | - foreach ($messageLines as $messageLine) { |
|
478 | - $messageLineLength = Helper::width(Helper::removeDecoration($this->output->getFormatter(), $messageLine)); |
|
479 | - if ($messageLineLength > $this->terminal->getWidth()) { |
|
480 | - $lineCount += floor($messageLineLength / $this->terminal->getWidth()); |
|
481 | - } |
|
482 | - } |
|
483 | - $this->output->clear($lineCount); |
|
484 | - } else { |
|
485 | - for ($i = 0; $i < $this->formatLineCount; ++$i) { |
|
486 | - $this->cursor->moveToColumn(1); |
|
487 | - $this->cursor->clearLine(); |
|
488 | - $this->cursor->moveUp(); |
|
489 | - } |
|
490 | - |
|
491 | - $this->cursor->moveToColumn(1); |
|
492 | - $this->cursor->clearLine(); |
|
493 | - } |
|
494 | - } |
|
495 | - } elseif ($this->step > 0) { |
|
496 | - $message = \PHP_EOL.$message; |
|
497 | - } |
|
498 | - |
|
499 | - $this->previousMessage = $originalMessage; |
|
500 | - $this->lastWriteTime = microtime(true); |
|
501 | - |
|
502 | - $this->output->write($message); |
|
503 | - ++$this->writeCount; |
|
504 | - } |
|
505 | - |
|
506 | - private function determineBestFormat(): string |
|
507 | - { |
|
508 | - switch ($this->output->getVerbosity()) { |
|
509 | - // OutputInterface::VERBOSITY_QUIET: display is disabled anyway |
|
510 | - case OutputInterface::VERBOSITY_VERBOSE: |
|
511 | - return $this->max ? self::FORMAT_VERBOSE : self::FORMAT_VERBOSE_NOMAX; |
|
512 | - case OutputInterface::VERBOSITY_VERY_VERBOSE: |
|
513 | - return $this->max ? self::FORMAT_VERY_VERBOSE : self::FORMAT_VERY_VERBOSE_NOMAX; |
|
514 | - case OutputInterface::VERBOSITY_DEBUG: |
|
515 | - return $this->max ? self::FORMAT_DEBUG : self::FORMAT_DEBUG_NOMAX; |
|
516 | - default: |
|
517 | - return $this->max ? self::FORMAT_NORMAL : self::FORMAT_NORMAL_NOMAX; |
|
518 | - } |
|
519 | - } |
|
520 | - |
|
521 | - private static function initPlaceholderFormatters(): array |
|
522 | - { |
|
523 | - return [ |
|
524 | - 'bar' => function (self $bar, OutputInterface $output) { |
|
525 | - $completeBars = $bar->getBarOffset(); |
|
526 | - $display = str_repeat($bar->getBarCharacter(), $completeBars); |
|
527 | - if ($completeBars < $bar->getBarWidth()) { |
|
528 | - $emptyBars = $bar->getBarWidth() - $completeBars - Helper::length(Helper::removeDecoration($output->getFormatter(), $bar->getProgressCharacter())); |
|
529 | - $display .= $bar->getProgressCharacter().str_repeat($bar->getEmptyBarCharacter(), $emptyBars); |
|
530 | - } |
|
531 | - |
|
532 | - return $display; |
|
533 | - }, |
|
534 | - 'elapsed' => function (self $bar) { |
|
535 | - return Helper::formatTime(time() - $bar->getStartTime()); |
|
536 | - }, |
|
537 | - 'remaining' => function (self $bar) { |
|
538 | - if (!$bar->getMaxSteps()) { |
|
539 | - throw new LogicException('Unable to display the remaining time if the maximum number of steps is not set.'); |
|
540 | - } |
|
541 | - |
|
542 | - return Helper::formatTime($bar->getRemaining()); |
|
543 | - }, |
|
544 | - 'estimated' => function (self $bar) { |
|
545 | - if (!$bar->getMaxSteps()) { |
|
546 | - throw new LogicException('Unable to display the estimated time if the maximum number of steps is not set.'); |
|
547 | - } |
|
548 | - |
|
549 | - return Helper::formatTime($bar->getEstimated()); |
|
550 | - }, |
|
551 | - 'memory' => function (self $bar) { |
|
552 | - return Helper::formatMemory(memory_get_usage(true)); |
|
553 | - }, |
|
554 | - 'current' => function (self $bar) { |
|
555 | - return str_pad($bar->getProgress(), $bar->getStepWidth(), ' ', \STR_PAD_LEFT); |
|
556 | - }, |
|
557 | - 'max' => function (self $bar) { |
|
558 | - return $bar->getMaxSteps(); |
|
559 | - }, |
|
560 | - 'percent' => function (self $bar) { |
|
561 | - return floor($bar->getProgressPercent() * 100); |
|
562 | - }, |
|
563 | - ]; |
|
564 | - } |
|
565 | - |
|
566 | - private static function initFormats(): array |
|
567 | - { |
|
568 | - return [ |
|
569 | - self::FORMAT_NORMAL => ' %current%/%max% [%bar%] %percent:3s%%', |
|
570 | - self::FORMAT_NORMAL_NOMAX => ' %current% [%bar%]', |
|
571 | - |
|
572 | - self::FORMAT_VERBOSE => ' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%', |
|
573 | - self::FORMAT_VERBOSE_NOMAX => ' %current% [%bar%] %elapsed:6s%', |
|
574 | - |
|
575 | - self::FORMAT_VERY_VERBOSE => ' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s%', |
|
576 | - self::FORMAT_VERY_VERBOSE_NOMAX => ' %current% [%bar%] %elapsed:6s%', |
|
577 | - |
|
578 | - self::FORMAT_DEBUG => ' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%', |
|
579 | - self::FORMAT_DEBUG_NOMAX => ' %current% [%bar%] %elapsed:6s% %memory:6s%', |
|
580 | - ]; |
|
581 | - } |
|
582 | - |
|
583 | - private function buildLine(): string |
|
584 | - { |
|
585 | - $regex = "{%([a-z\-_]+)(?:\:([^%]+))?%}i"; |
|
586 | - $callback = function ($matches) { |
|
587 | - if ($formatter = $this::getPlaceholderFormatterDefinition($matches[1])) { |
|
588 | - $text = $formatter($this, $this->output); |
|
589 | - } elseif (isset($this->messages[$matches[1]])) { |
|
590 | - $text = $this->messages[$matches[1]]; |
|
591 | - } else { |
|
592 | - return $matches[0]; |
|
593 | - } |
|
594 | - |
|
595 | - if (isset($matches[2])) { |
|
596 | - $text = sprintf('%'.$matches[2], $text); |
|
597 | - } |
|
598 | - |
|
599 | - return $text; |
|
600 | - }; |
|
601 | - $line = preg_replace_callback($regex, $callback, $this->format); |
|
602 | - |
|
603 | - // gets string length for each sub line with multiline format |
|
604 | - $linesLength = array_map(function ($subLine) { |
|
605 | - return Helper::width(Helper::removeDecoration($this->output->getFormatter(), rtrim($subLine, "\r"))); |
|
606 | - }, explode("\n", $line)); |
|
607 | - |
|
608 | - $linesWidth = max($linesLength); |
|
609 | - |
|
610 | - $terminalWidth = $this->terminal->getWidth(); |
|
611 | - if ($linesWidth <= $terminalWidth) { |
|
612 | - return $line; |
|
613 | - } |
|
614 | - |
|
615 | - $this->setBarWidth($this->barWidth - $linesWidth + $terminalWidth); |
|
616 | - |
|
617 | - return preg_replace_callback($regex, $callback, $this->format); |
|
618 | - } |
|
29 | + public const FORMAT_VERBOSE = 'verbose'; |
|
30 | + public const FORMAT_VERY_VERBOSE = 'very_verbose'; |
|
31 | + public const FORMAT_DEBUG = 'debug'; |
|
32 | + public const FORMAT_NORMAL = 'normal'; |
|
33 | + |
|
34 | + private const FORMAT_VERBOSE_NOMAX = 'verbose_nomax'; |
|
35 | + private const FORMAT_VERY_VERBOSE_NOMAX = 'very_verbose_nomax'; |
|
36 | + private const FORMAT_DEBUG_NOMAX = 'debug_nomax'; |
|
37 | + private const FORMAT_NORMAL_NOMAX = 'normal_nomax'; |
|
38 | + |
|
39 | + private $barWidth = 28; |
|
40 | + private $barChar; |
|
41 | + private $emptyBarChar = '-'; |
|
42 | + private $progressChar = '>'; |
|
43 | + private $format; |
|
44 | + private $internalFormat; |
|
45 | + private $redrawFreq = 1; |
|
46 | + private $writeCount; |
|
47 | + private $lastWriteTime; |
|
48 | + private $minSecondsBetweenRedraws = 0; |
|
49 | + private $maxSecondsBetweenRedraws = 1; |
|
50 | + private $output; |
|
51 | + private $step = 0; |
|
52 | + private $max; |
|
53 | + private $startTime; |
|
54 | + private $stepWidth; |
|
55 | + private $percent = 0.0; |
|
56 | + private $formatLineCount; |
|
57 | + private $messages = []; |
|
58 | + private $overwrite = true; |
|
59 | + private $terminal; |
|
60 | + private $previousMessage; |
|
61 | + private $cursor; |
|
62 | + |
|
63 | + private static $formatters; |
|
64 | + private static $formats; |
|
65 | + |
|
66 | + /** |
|
67 | + * @param int $max Maximum steps (0 if unknown) |
|
68 | + */ |
|
69 | + public function __construct(OutputInterface $output, int $max = 0, float $minSecondsBetweenRedraws = 1 / 25) |
|
70 | + { |
|
71 | + if ($output instanceof ConsoleOutputInterface) { |
|
72 | + $output = $output->getErrorOutput(); |
|
73 | + } |
|
74 | + |
|
75 | + $this->output = $output; |
|
76 | + $this->setMaxSteps($max); |
|
77 | + $this->terminal = new Terminal(); |
|
78 | + |
|
79 | + if (0 < $minSecondsBetweenRedraws) { |
|
80 | + $this->redrawFreq = null; |
|
81 | + $this->minSecondsBetweenRedraws = $minSecondsBetweenRedraws; |
|
82 | + } |
|
83 | + |
|
84 | + if (!$this->output->isDecorated()) { |
|
85 | + // disable overwrite when output does not support ANSI codes. |
|
86 | + $this->overwrite = false; |
|
87 | + |
|
88 | + // set a reasonable redraw frequency so output isn't flooded |
|
89 | + $this->redrawFreq = null; |
|
90 | + } |
|
91 | + |
|
92 | + $this->startTime = time(); |
|
93 | + $this->cursor = new Cursor($output); |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Sets a placeholder formatter for a given name. |
|
98 | + * |
|
99 | + * This method also allow you to override an existing placeholder. |
|
100 | + * |
|
101 | + * @param string $name The placeholder name (including the delimiter char like %) |
|
102 | + * @param callable $callable A PHP callable |
|
103 | + */ |
|
104 | + public static function setPlaceholderFormatterDefinition(string $name, callable $callable): void |
|
105 | + { |
|
106 | + if (!self::$formatters) { |
|
107 | + self::$formatters = self::initPlaceholderFormatters(); |
|
108 | + } |
|
109 | + |
|
110 | + self::$formatters[$name] = $callable; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Gets the placeholder formatter for a given name. |
|
115 | + * |
|
116 | + * @param string $name The placeholder name (including the delimiter char like %) |
|
117 | + * |
|
118 | + * @return callable|null A PHP callable |
|
119 | + */ |
|
120 | + public static function getPlaceholderFormatterDefinition(string $name): ?callable |
|
121 | + { |
|
122 | + if (!self::$formatters) { |
|
123 | + self::$formatters = self::initPlaceholderFormatters(); |
|
124 | + } |
|
125 | + |
|
126 | + return self::$formatters[$name] ?? null; |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * Sets a format for a given name. |
|
131 | + * |
|
132 | + * This method also allow you to override an existing format. |
|
133 | + * |
|
134 | + * @param string $name The format name |
|
135 | + * @param string $format A format string |
|
136 | + */ |
|
137 | + public static function setFormatDefinition(string $name, string $format): void |
|
138 | + { |
|
139 | + if (!self::$formats) { |
|
140 | + self::$formats = self::initFormats(); |
|
141 | + } |
|
142 | + |
|
143 | + self::$formats[$name] = $format; |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * Gets the format for a given name. |
|
148 | + * |
|
149 | + * @param string $name The format name |
|
150 | + * |
|
151 | + * @return string|null A format string |
|
152 | + */ |
|
153 | + public static function getFormatDefinition(string $name): ?string |
|
154 | + { |
|
155 | + if (!self::$formats) { |
|
156 | + self::$formats = self::initFormats(); |
|
157 | + } |
|
158 | + |
|
159 | + return self::$formats[$name] ?? null; |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * Associates a text with a named placeholder. |
|
164 | + * |
|
165 | + * The text is displayed when the progress bar is rendered but only |
|
166 | + * when the corresponding placeholder is part of the custom format line |
|
167 | + * (by wrapping the name with %). |
|
168 | + * |
|
169 | + * @param string $message The text to associate with the placeholder |
|
170 | + * @param string $name The name of the placeholder |
|
171 | + */ |
|
172 | + public function setMessage(string $message, string $name = 'message') |
|
173 | + { |
|
174 | + $this->messages[$name] = $message; |
|
175 | + } |
|
176 | + |
|
177 | + public function getMessage(string $name = 'message') |
|
178 | + { |
|
179 | + return $this->messages[$name]; |
|
180 | + } |
|
181 | + |
|
182 | + public function getStartTime(): int |
|
183 | + { |
|
184 | + return $this->startTime; |
|
185 | + } |
|
186 | + |
|
187 | + public function getMaxSteps(): int |
|
188 | + { |
|
189 | + return $this->max; |
|
190 | + } |
|
191 | + |
|
192 | + public function getProgress(): int |
|
193 | + { |
|
194 | + return $this->step; |
|
195 | + } |
|
196 | + |
|
197 | + private function getStepWidth(): int |
|
198 | + { |
|
199 | + return $this->stepWidth; |
|
200 | + } |
|
201 | + |
|
202 | + public function getProgressPercent(): float |
|
203 | + { |
|
204 | + return $this->percent; |
|
205 | + } |
|
206 | + |
|
207 | + public function getBarOffset(): float |
|
208 | + { |
|
209 | + return floor($this->max ? $this->percent * $this->barWidth : (null === $this->redrawFreq ? (int) (min(5, $this->barWidth / 15) * $this->writeCount) : $this->step) % $this->barWidth); |
|
210 | + } |
|
211 | + |
|
212 | + public function getEstimated(): float |
|
213 | + { |
|
214 | + if (!$this->step) { |
|
215 | + return 0; |
|
216 | + } |
|
217 | + |
|
218 | + return round((time() - $this->startTime) / $this->step * $this->max); |
|
219 | + } |
|
220 | + |
|
221 | + public function getRemaining(): float |
|
222 | + { |
|
223 | + if (!$this->step) { |
|
224 | + return 0; |
|
225 | + } |
|
226 | + |
|
227 | + return round((time() - $this->startTime) / $this->step * ($this->max - $this->step)); |
|
228 | + } |
|
229 | + |
|
230 | + public function setBarWidth(int $size) |
|
231 | + { |
|
232 | + $this->barWidth = max(1, $size); |
|
233 | + } |
|
234 | + |
|
235 | + public function getBarWidth(): int |
|
236 | + { |
|
237 | + return $this->barWidth; |
|
238 | + } |
|
239 | + |
|
240 | + public function setBarCharacter(string $char) |
|
241 | + { |
|
242 | + $this->barChar = $char; |
|
243 | + } |
|
244 | + |
|
245 | + public function getBarCharacter(): string |
|
246 | + { |
|
247 | + if (null === $this->barChar) { |
|
248 | + return $this->max ? '=' : $this->emptyBarChar; |
|
249 | + } |
|
250 | + |
|
251 | + return $this->barChar; |
|
252 | + } |
|
253 | + |
|
254 | + public function setEmptyBarCharacter(string $char) |
|
255 | + { |
|
256 | + $this->emptyBarChar = $char; |
|
257 | + } |
|
258 | + |
|
259 | + public function getEmptyBarCharacter(): string |
|
260 | + { |
|
261 | + return $this->emptyBarChar; |
|
262 | + } |
|
263 | + |
|
264 | + public function setProgressCharacter(string $char) |
|
265 | + { |
|
266 | + $this->progressChar = $char; |
|
267 | + } |
|
268 | + |
|
269 | + public function getProgressCharacter(): string |
|
270 | + { |
|
271 | + return $this->progressChar; |
|
272 | + } |
|
273 | + |
|
274 | + public function setFormat(string $format) |
|
275 | + { |
|
276 | + $this->format = null; |
|
277 | + $this->internalFormat = $format; |
|
278 | + } |
|
279 | + |
|
280 | + /** |
|
281 | + * Sets the redraw frequency. |
|
282 | + * |
|
283 | + * @param int|null $freq The frequency in steps |
|
284 | + */ |
|
285 | + public function setRedrawFrequency(?int $freq) |
|
286 | + { |
|
287 | + $this->redrawFreq = null !== $freq ? max(1, $freq) : null; |
|
288 | + } |
|
289 | + |
|
290 | + public function minSecondsBetweenRedraws(float $seconds): void |
|
291 | + { |
|
292 | + $this->minSecondsBetweenRedraws = $seconds; |
|
293 | + } |
|
294 | + |
|
295 | + public function maxSecondsBetweenRedraws(float $seconds): void |
|
296 | + { |
|
297 | + $this->maxSecondsBetweenRedraws = $seconds; |
|
298 | + } |
|
299 | + |
|
300 | + /** |
|
301 | + * Returns an iterator that will automatically update the progress bar when iterated. |
|
302 | + * |
|
303 | + * @param int|null $max Number of steps to complete the bar (0 if indeterminate), if null it will be inferred from $iterable |
|
304 | + */ |
|
305 | + public function iterate(iterable $iterable, int $max = null): iterable |
|
306 | + { |
|
307 | + $this->start($max ?? (is_countable($iterable) ? \count($iterable) : 0)); |
|
308 | + |
|
309 | + foreach ($iterable as $key => $value) { |
|
310 | + yield $key => $value; |
|
311 | + |
|
312 | + $this->advance(); |
|
313 | + } |
|
314 | + |
|
315 | + $this->finish(); |
|
316 | + } |
|
317 | + |
|
318 | + /** |
|
319 | + * Starts the progress output. |
|
320 | + * |
|
321 | + * @param int|null $max Number of steps to complete the bar (0 if indeterminate), null to leave unchanged |
|
322 | + */ |
|
323 | + public function start(int $max = null) |
|
324 | + { |
|
325 | + $this->startTime = time(); |
|
326 | + $this->step = 0; |
|
327 | + $this->percent = 0.0; |
|
328 | + |
|
329 | + if (null !== $max) { |
|
330 | + $this->setMaxSteps($max); |
|
331 | + } |
|
332 | + |
|
333 | + $this->display(); |
|
334 | + } |
|
335 | + |
|
336 | + /** |
|
337 | + * Advances the progress output X steps. |
|
338 | + * |
|
339 | + * @param int $step Number of steps to advance |
|
340 | + */ |
|
341 | + public function advance(int $step = 1) |
|
342 | + { |
|
343 | + $this->setProgress($this->step + $step); |
|
344 | + } |
|
345 | + |
|
346 | + /** |
|
347 | + * Sets whether to overwrite the progressbar, false for new line. |
|
348 | + */ |
|
349 | + public function setOverwrite(bool $overwrite) |
|
350 | + { |
|
351 | + $this->overwrite = $overwrite; |
|
352 | + } |
|
353 | + |
|
354 | + public function setProgress(int $step) |
|
355 | + { |
|
356 | + if ($this->max && $step > $this->max) { |
|
357 | + $this->max = $step; |
|
358 | + } elseif ($step < 0) { |
|
359 | + $step = 0; |
|
360 | + } |
|
361 | + |
|
362 | + $redrawFreq = $this->redrawFreq ?? (($this->max ?: 10) / 10); |
|
363 | + $prevPeriod = (int) ($this->step / $redrawFreq); |
|
364 | + $currPeriod = (int) ($step / $redrawFreq); |
|
365 | + $this->step = $step; |
|
366 | + $this->percent = $this->max ? (float) $this->step / $this->max : 0; |
|
367 | + $timeInterval = microtime(true) - $this->lastWriteTime; |
|
368 | + |
|
369 | + // Draw regardless of other limits |
|
370 | + if ($this->max === $step) { |
|
371 | + $this->display(); |
|
372 | + |
|
373 | + return; |
|
374 | + } |
|
375 | + |
|
376 | + // Throttling |
|
377 | + if ($timeInterval < $this->minSecondsBetweenRedraws) { |
|
378 | + return; |
|
379 | + } |
|
380 | + |
|
381 | + // Draw each step period, but not too late |
|
382 | + if ($prevPeriod !== $currPeriod || $timeInterval >= $this->maxSecondsBetweenRedraws) { |
|
383 | + $this->display(); |
|
384 | + } |
|
385 | + } |
|
386 | + |
|
387 | + public function setMaxSteps(int $max) |
|
388 | + { |
|
389 | + $this->format = null; |
|
390 | + $this->max = max(0, $max); |
|
391 | + $this->stepWidth = $this->max ? Helper::width((string) $this->max) : 4; |
|
392 | + } |
|
393 | + |
|
394 | + /** |
|
395 | + * Finishes the progress output. |
|
396 | + */ |
|
397 | + public function finish(): void |
|
398 | + { |
|
399 | + if (!$this->max) { |
|
400 | + $this->max = $this->step; |
|
401 | + } |
|
402 | + |
|
403 | + if ($this->step === $this->max && !$this->overwrite) { |
|
404 | + // prevent double 100% output |
|
405 | + return; |
|
406 | + } |
|
407 | + |
|
408 | + $this->setProgress($this->max); |
|
409 | + } |
|
410 | + |
|
411 | + /** |
|
412 | + * Outputs the current progress string. |
|
413 | + */ |
|
414 | + public function display(): void |
|
415 | + { |
|
416 | + if (OutputInterface::VERBOSITY_QUIET === $this->output->getVerbosity()) { |
|
417 | + return; |
|
418 | + } |
|
419 | + |
|
420 | + if (null === $this->format) { |
|
421 | + $this->setRealFormat($this->internalFormat ?: $this->determineBestFormat()); |
|
422 | + } |
|
423 | + |
|
424 | + $this->overwrite($this->buildLine()); |
|
425 | + } |
|
426 | + |
|
427 | + /** |
|
428 | + * Removes the progress bar from the current line. |
|
429 | + * |
|
430 | + * This is useful if you wish to write some output |
|
431 | + * while a progress bar is running. |
|
432 | + * Call display() to show the progress bar again. |
|
433 | + */ |
|
434 | + public function clear(): void |
|
435 | + { |
|
436 | + if (!$this->overwrite) { |
|
437 | + return; |
|
438 | + } |
|
439 | + |
|
440 | + if (null === $this->format) { |
|
441 | + $this->setRealFormat($this->internalFormat ?: $this->determineBestFormat()); |
|
442 | + } |
|
443 | + |
|
444 | + $this->overwrite(''); |
|
445 | + } |
|
446 | + |
|
447 | + private function setRealFormat(string $format) |
|
448 | + { |
|
449 | + // try to use the _nomax variant if available |
|
450 | + if (!$this->max && null !== self::getFormatDefinition($format.'_nomax')) { |
|
451 | + $this->format = self::getFormatDefinition($format.'_nomax'); |
|
452 | + } elseif (null !== self::getFormatDefinition($format)) { |
|
453 | + $this->format = self::getFormatDefinition($format); |
|
454 | + } else { |
|
455 | + $this->format = $format; |
|
456 | + } |
|
457 | + |
|
458 | + $this->formatLineCount = substr_count($this->format, "\n"); |
|
459 | + } |
|
460 | + |
|
461 | + /** |
|
462 | + * Overwrites a previous message to the output. |
|
463 | + */ |
|
464 | + private function overwrite(string $message): void |
|
465 | + { |
|
466 | + if ($this->previousMessage === $message) { |
|
467 | + return; |
|
468 | + } |
|
469 | + |
|
470 | + $originalMessage = $message; |
|
471 | + |
|
472 | + if ($this->overwrite) { |
|
473 | + if (null !== $this->previousMessage) { |
|
474 | + if ($this->output instanceof ConsoleSectionOutput) { |
|
475 | + $messageLines = explode("\n", $message); |
|
476 | + $lineCount = \count($messageLines); |
|
477 | + foreach ($messageLines as $messageLine) { |
|
478 | + $messageLineLength = Helper::width(Helper::removeDecoration($this->output->getFormatter(), $messageLine)); |
|
479 | + if ($messageLineLength > $this->terminal->getWidth()) { |
|
480 | + $lineCount += floor($messageLineLength / $this->terminal->getWidth()); |
|
481 | + } |
|
482 | + } |
|
483 | + $this->output->clear($lineCount); |
|
484 | + } else { |
|
485 | + for ($i = 0; $i < $this->formatLineCount; ++$i) { |
|
486 | + $this->cursor->moveToColumn(1); |
|
487 | + $this->cursor->clearLine(); |
|
488 | + $this->cursor->moveUp(); |
|
489 | + } |
|
490 | + |
|
491 | + $this->cursor->moveToColumn(1); |
|
492 | + $this->cursor->clearLine(); |
|
493 | + } |
|
494 | + } |
|
495 | + } elseif ($this->step > 0) { |
|
496 | + $message = \PHP_EOL.$message; |
|
497 | + } |
|
498 | + |
|
499 | + $this->previousMessage = $originalMessage; |
|
500 | + $this->lastWriteTime = microtime(true); |
|
501 | + |
|
502 | + $this->output->write($message); |
|
503 | + ++$this->writeCount; |
|
504 | + } |
|
505 | + |
|
506 | + private function determineBestFormat(): string |
|
507 | + { |
|
508 | + switch ($this->output->getVerbosity()) { |
|
509 | + // OutputInterface::VERBOSITY_QUIET: display is disabled anyway |
|
510 | + case OutputInterface::VERBOSITY_VERBOSE: |
|
511 | + return $this->max ? self::FORMAT_VERBOSE : self::FORMAT_VERBOSE_NOMAX; |
|
512 | + case OutputInterface::VERBOSITY_VERY_VERBOSE: |
|
513 | + return $this->max ? self::FORMAT_VERY_VERBOSE : self::FORMAT_VERY_VERBOSE_NOMAX; |
|
514 | + case OutputInterface::VERBOSITY_DEBUG: |
|
515 | + return $this->max ? self::FORMAT_DEBUG : self::FORMAT_DEBUG_NOMAX; |
|
516 | + default: |
|
517 | + return $this->max ? self::FORMAT_NORMAL : self::FORMAT_NORMAL_NOMAX; |
|
518 | + } |
|
519 | + } |
|
520 | + |
|
521 | + private static function initPlaceholderFormatters(): array |
|
522 | + { |
|
523 | + return [ |
|
524 | + 'bar' => function (self $bar, OutputInterface $output) { |
|
525 | + $completeBars = $bar->getBarOffset(); |
|
526 | + $display = str_repeat($bar->getBarCharacter(), $completeBars); |
|
527 | + if ($completeBars < $bar->getBarWidth()) { |
|
528 | + $emptyBars = $bar->getBarWidth() - $completeBars - Helper::length(Helper::removeDecoration($output->getFormatter(), $bar->getProgressCharacter())); |
|
529 | + $display .= $bar->getProgressCharacter().str_repeat($bar->getEmptyBarCharacter(), $emptyBars); |
|
530 | + } |
|
531 | + |
|
532 | + return $display; |
|
533 | + }, |
|
534 | + 'elapsed' => function (self $bar) { |
|
535 | + return Helper::formatTime(time() - $bar->getStartTime()); |
|
536 | + }, |
|
537 | + 'remaining' => function (self $bar) { |
|
538 | + if (!$bar->getMaxSteps()) { |
|
539 | + throw new LogicException('Unable to display the remaining time if the maximum number of steps is not set.'); |
|
540 | + } |
|
541 | + |
|
542 | + return Helper::formatTime($bar->getRemaining()); |
|
543 | + }, |
|
544 | + 'estimated' => function (self $bar) { |
|
545 | + if (!$bar->getMaxSteps()) { |
|
546 | + throw new LogicException('Unable to display the estimated time if the maximum number of steps is not set.'); |
|
547 | + } |
|
548 | + |
|
549 | + return Helper::formatTime($bar->getEstimated()); |
|
550 | + }, |
|
551 | + 'memory' => function (self $bar) { |
|
552 | + return Helper::formatMemory(memory_get_usage(true)); |
|
553 | + }, |
|
554 | + 'current' => function (self $bar) { |
|
555 | + return str_pad($bar->getProgress(), $bar->getStepWidth(), ' ', \STR_PAD_LEFT); |
|
556 | + }, |
|
557 | + 'max' => function (self $bar) { |
|
558 | + return $bar->getMaxSteps(); |
|
559 | + }, |
|
560 | + 'percent' => function (self $bar) { |
|
561 | + return floor($bar->getProgressPercent() * 100); |
|
562 | + }, |
|
563 | + ]; |
|
564 | + } |
|
565 | + |
|
566 | + private static function initFormats(): array |
|
567 | + { |
|
568 | + return [ |
|
569 | + self::FORMAT_NORMAL => ' %current%/%max% [%bar%] %percent:3s%%', |
|
570 | + self::FORMAT_NORMAL_NOMAX => ' %current% [%bar%]', |
|
571 | + |
|
572 | + self::FORMAT_VERBOSE => ' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%', |
|
573 | + self::FORMAT_VERBOSE_NOMAX => ' %current% [%bar%] %elapsed:6s%', |
|
574 | + |
|
575 | + self::FORMAT_VERY_VERBOSE => ' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s%', |
|
576 | + self::FORMAT_VERY_VERBOSE_NOMAX => ' %current% [%bar%] %elapsed:6s%', |
|
577 | + |
|
578 | + self::FORMAT_DEBUG => ' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%', |
|
579 | + self::FORMAT_DEBUG_NOMAX => ' %current% [%bar%] %elapsed:6s% %memory:6s%', |
|
580 | + ]; |
|
581 | + } |
|
582 | + |
|
583 | + private function buildLine(): string |
|
584 | + { |
|
585 | + $regex = "{%([a-z\-_]+)(?:\:([^%]+))?%}i"; |
|
586 | + $callback = function ($matches) { |
|
587 | + if ($formatter = $this::getPlaceholderFormatterDefinition($matches[1])) { |
|
588 | + $text = $formatter($this, $this->output); |
|
589 | + } elseif (isset($this->messages[$matches[1]])) { |
|
590 | + $text = $this->messages[$matches[1]]; |
|
591 | + } else { |
|
592 | + return $matches[0]; |
|
593 | + } |
|
594 | + |
|
595 | + if (isset($matches[2])) { |
|
596 | + $text = sprintf('%'.$matches[2], $text); |
|
597 | + } |
|
598 | + |
|
599 | + return $text; |
|
600 | + }; |
|
601 | + $line = preg_replace_callback($regex, $callback, $this->format); |
|
602 | + |
|
603 | + // gets string length for each sub line with multiline format |
|
604 | + $linesLength = array_map(function ($subLine) { |
|
605 | + return Helper::width(Helper::removeDecoration($this->output->getFormatter(), rtrim($subLine, "\r"))); |
|
606 | + }, explode("\n", $line)); |
|
607 | + |
|
608 | + $linesWidth = max($linesLength); |
|
609 | + |
|
610 | + $terminalWidth = $this->terminal->getWidth(); |
|
611 | + if ($linesWidth <= $terminalWidth) { |
|
612 | + return $line; |
|
613 | + } |
|
614 | + |
|
615 | + $this->setBarWidth($this->barWidth - $linesWidth + $terminalWidth); |
|
616 | + |
|
617 | + return preg_replace_callback($regex, $callback, $this->format); |
|
618 | + } |
|
619 | 619 | } |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | private $stepWidth; |
55 | 55 | private $percent = 0.0; |
56 | 56 | private $formatLineCount; |
57 | - private $messages = []; |
|
57 | + private $messages = [ ]; |
|
58 | 58 | private $overwrite = true; |
59 | 59 | private $terminal; |
60 | 60 | private $previousMessage; |
@@ -66,22 +66,22 @@ discard block |
||
66 | 66 | /** |
67 | 67 | * @param int $max Maximum steps (0 if unknown) |
68 | 68 | */ |
69 | - public function __construct(OutputInterface $output, int $max = 0, float $minSecondsBetweenRedraws = 1 / 25) |
|
69 | + public function __construct( OutputInterface $output, int $max = 0, float $minSecondsBetweenRedraws = 1 / 25 ) |
|
70 | 70 | { |
71 | - if ($output instanceof ConsoleOutputInterface) { |
|
71 | + if ( $output instanceof ConsoleOutputInterface ) { |
|
72 | 72 | $output = $output->getErrorOutput(); |
73 | 73 | } |
74 | 74 | |
75 | 75 | $this->output = $output; |
76 | - $this->setMaxSteps($max); |
|
76 | + $this->setMaxSteps( $max ); |
|
77 | 77 | $this->terminal = new Terminal(); |
78 | 78 | |
79 | - if (0 < $minSecondsBetweenRedraws) { |
|
79 | + if ( 0 < $minSecondsBetweenRedraws ) { |
|
80 | 80 | $this->redrawFreq = null; |
81 | 81 | $this->minSecondsBetweenRedraws = $minSecondsBetweenRedraws; |
82 | 82 | } |
83 | 83 | |
84 | - if (!$this->output->isDecorated()) { |
|
84 | + if ( ! $this->output->isDecorated() ) { |
|
85 | 85 | // disable overwrite when output does not support ANSI codes. |
86 | 86 | $this->overwrite = false; |
87 | 87 | |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | } |
91 | 91 | |
92 | 92 | $this->startTime = time(); |
93 | - $this->cursor = new Cursor($output); |
|
93 | + $this->cursor = new Cursor( $output ); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
@@ -101,13 +101,13 @@ discard block |
||
101 | 101 | * @param string $name The placeholder name (including the delimiter char like %) |
102 | 102 | * @param callable $callable A PHP callable |
103 | 103 | */ |
104 | - public static function setPlaceholderFormatterDefinition(string $name, callable $callable): void |
|
104 | + public static function setPlaceholderFormatterDefinition( string $name, callable $callable ): void |
|
105 | 105 | { |
106 | - if (!self::$formatters) { |
|
106 | + if ( ! self::$formatters ) { |
|
107 | 107 | self::$formatters = self::initPlaceholderFormatters(); |
108 | 108 | } |
109 | 109 | |
110 | - self::$formatters[$name] = $callable; |
|
110 | + self::$formatters[ $name ] = $callable; |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -117,13 +117,13 @@ discard block |
||
117 | 117 | * |
118 | 118 | * @return callable|null A PHP callable |
119 | 119 | */ |
120 | - public static function getPlaceholderFormatterDefinition(string $name): ?callable |
|
120 | + public static function getPlaceholderFormatterDefinition( string $name ): ?callable |
|
121 | 121 | { |
122 | - if (!self::$formatters) { |
|
122 | + if ( ! self::$formatters ) { |
|
123 | 123 | self::$formatters = self::initPlaceholderFormatters(); |
124 | 124 | } |
125 | 125 | |
126 | - return self::$formatters[$name] ?? null; |
|
126 | + return self::$formatters[ $name ] ?? null; |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
@@ -134,13 +134,13 @@ discard block |
||
134 | 134 | * @param string $name The format name |
135 | 135 | * @param string $format A format string |
136 | 136 | */ |
137 | - public static function setFormatDefinition(string $name, string $format): void |
|
137 | + public static function setFormatDefinition( string $name, string $format ): void |
|
138 | 138 | { |
139 | - if (!self::$formats) { |
|
139 | + if ( ! self::$formats ) { |
|
140 | 140 | self::$formats = self::initFormats(); |
141 | 141 | } |
142 | 142 | |
143 | - self::$formats[$name] = $format; |
|
143 | + self::$formats[ $name ] = $format; |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -150,13 +150,13 @@ discard block |
||
150 | 150 | * |
151 | 151 | * @return string|null A format string |
152 | 152 | */ |
153 | - public static function getFormatDefinition(string $name): ?string |
|
153 | + public static function getFormatDefinition( string $name ): ?string |
|
154 | 154 | { |
155 | - if (!self::$formats) { |
|
155 | + if ( ! self::$formats ) { |
|
156 | 156 | self::$formats = self::initFormats(); |
157 | 157 | } |
158 | 158 | |
159 | - return self::$formats[$name] ?? null; |
|
159 | + return self::$formats[ $name ] ?? null; |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | /** |
@@ -169,14 +169,14 @@ discard block |
||
169 | 169 | * @param string $message The text to associate with the placeholder |
170 | 170 | * @param string $name The name of the placeholder |
171 | 171 | */ |
172 | - public function setMessage(string $message, string $name = 'message') |
|
172 | + public function setMessage( string $message, string $name = 'message' ) |
|
173 | 173 | { |
174 | - $this->messages[$name] = $message; |
|
174 | + $this->messages[ $name ] = $message; |
|
175 | 175 | } |
176 | 176 | |
177 | - public function getMessage(string $name = 'message') |
|
177 | + public function getMessage( string $name = 'message' ) |
|
178 | 178 | { |
179 | - return $this->messages[$name]; |
|
179 | + return $this->messages[ $name ]; |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | public function getStartTime(): int |
@@ -206,30 +206,30 @@ discard block |
||
206 | 206 | |
207 | 207 | public function getBarOffset(): float |
208 | 208 | { |
209 | - return floor($this->max ? $this->percent * $this->barWidth : (null === $this->redrawFreq ? (int) (min(5, $this->barWidth / 15) * $this->writeCount) : $this->step) % $this->barWidth); |
|
209 | + return floor( $this->max ? $this->percent * $this->barWidth : ( null === $this->redrawFreq ? (int)( min( 5, $this->barWidth / 15 ) * $this->writeCount ) : $this->step ) % $this->barWidth ); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | public function getEstimated(): float |
213 | 213 | { |
214 | - if (!$this->step) { |
|
214 | + if ( ! $this->step ) { |
|
215 | 215 | return 0; |
216 | 216 | } |
217 | 217 | |
218 | - return round((time() - $this->startTime) / $this->step * $this->max); |
|
218 | + return round( ( time() - $this->startTime ) / $this->step * $this->max ); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | public function getRemaining(): float |
222 | 222 | { |
223 | - if (!$this->step) { |
|
223 | + if ( ! $this->step ) { |
|
224 | 224 | return 0; |
225 | 225 | } |
226 | 226 | |
227 | - return round((time() - $this->startTime) / $this->step * ($this->max - $this->step)); |
|
227 | + return round( ( time() - $this->startTime ) / $this->step * ( $this->max - $this->step ) ); |
|
228 | 228 | } |
229 | 229 | |
230 | - public function setBarWidth(int $size) |
|
230 | + public function setBarWidth( int $size ) |
|
231 | 231 | { |
232 | - $this->barWidth = max(1, $size); |
|
232 | + $this->barWidth = max( 1, $size ); |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | public function getBarWidth(): int |
@@ -237,21 +237,21 @@ discard block |
||
237 | 237 | return $this->barWidth; |
238 | 238 | } |
239 | 239 | |
240 | - public function setBarCharacter(string $char) |
|
240 | + public function setBarCharacter( string $char ) |
|
241 | 241 | { |
242 | 242 | $this->barChar = $char; |
243 | 243 | } |
244 | 244 | |
245 | 245 | public function getBarCharacter(): string |
246 | 246 | { |
247 | - if (null === $this->barChar) { |
|
247 | + if ( null === $this->barChar ) { |
|
248 | 248 | return $this->max ? '=' : $this->emptyBarChar; |
249 | 249 | } |
250 | 250 | |
251 | 251 | return $this->barChar; |
252 | 252 | } |
253 | 253 | |
254 | - public function setEmptyBarCharacter(string $char) |
|
254 | + public function setEmptyBarCharacter( string $char ) |
|
255 | 255 | { |
256 | 256 | $this->emptyBarChar = $char; |
257 | 257 | } |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | return $this->emptyBarChar; |
262 | 262 | } |
263 | 263 | |
264 | - public function setProgressCharacter(string $char) |
|
264 | + public function setProgressCharacter( string $char ) |
|
265 | 265 | { |
266 | 266 | $this->progressChar = $char; |
267 | 267 | } |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | return $this->progressChar; |
272 | 272 | } |
273 | 273 | |
274 | - public function setFormat(string $format) |
|
274 | + public function setFormat( string $format ) |
|
275 | 275 | { |
276 | 276 | $this->format = null; |
277 | 277 | $this->internalFormat = $format; |
@@ -282,17 +282,17 @@ discard block |
||
282 | 282 | * |
283 | 283 | * @param int|null $freq The frequency in steps |
284 | 284 | */ |
285 | - public function setRedrawFrequency(?int $freq) |
|
285 | + public function setRedrawFrequency( ?int $freq ) |
|
286 | 286 | { |
287 | - $this->redrawFreq = null !== $freq ? max(1, $freq) : null; |
|
287 | + $this->redrawFreq = null !== $freq ? max( 1, $freq ) : null; |
|
288 | 288 | } |
289 | 289 | |
290 | - public function minSecondsBetweenRedraws(float $seconds): void |
|
290 | + public function minSecondsBetweenRedraws( float $seconds ): void |
|
291 | 291 | { |
292 | 292 | $this->minSecondsBetweenRedraws = $seconds; |
293 | 293 | } |
294 | 294 | |
295 | - public function maxSecondsBetweenRedraws(float $seconds): void |
|
295 | + public function maxSecondsBetweenRedraws( float $seconds ): void |
|
296 | 296 | { |
297 | 297 | $this->maxSecondsBetweenRedraws = $seconds; |
298 | 298 | } |
@@ -302,11 +302,11 @@ discard block |
||
302 | 302 | * |
303 | 303 | * @param int|null $max Number of steps to complete the bar (0 if indeterminate), if null it will be inferred from $iterable |
304 | 304 | */ |
305 | - public function iterate(iterable $iterable, int $max = null): iterable |
|
305 | + public function iterate( iterable $iterable, int $max = null ): iterable |
|
306 | 306 | { |
307 | - $this->start($max ?? (is_countable($iterable) ? \count($iterable) : 0)); |
|
307 | + $this->start( $max ?? ( is_countable( $iterable ) ? \count( $iterable ) : 0 ) ); |
|
308 | 308 | |
309 | - foreach ($iterable as $key => $value) { |
|
309 | + foreach ( $iterable as $key => $value ) { |
|
310 | 310 | yield $key => $value; |
311 | 311 | |
312 | 312 | $this->advance(); |
@@ -320,14 +320,14 @@ discard block |
||
320 | 320 | * |
321 | 321 | * @param int|null $max Number of steps to complete the bar (0 if indeterminate), null to leave unchanged |
322 | 322 | */ |
323 | - public function start(int $max = null) |
|
323 | + public function start( int $max = null ) |
|
324 | 324 | { |
325 | 325 | $this->startTime = time(); |
326 | 326 | $this->step = 0; |
327 | 327 | $this->percent = 0.0; |
328 | 328 | |
329 | - if (null !== $max) { |
|
330 | - $this->setMaxSteps($max); |
|
329 | + if ( null !== $max ) { |
|
330 | + $this->setMaxSteps( $max ); |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | $this->display(); |
@@ -338,57 +338,57 @@ discard block |
||
338 | 338 | * |
339 | 339 | * @param int $step Number of steps to advance |
340 | 340 | */ |
341 | - public function advance(int $step = 1) |
|
341 | + public function advance( int $step = 1 ) |
|
342 | 342 | { |
343 | - $this->setProgress($this->step + $step); |
|
343 | + $this->setProgress( $this->step + $step ); |
|
344 | 344 | } |
345 | 345 | |
346 | 346 | /** |
347 | 347 | * Sets whether to overwrite the progressbar, false for new line. |
348 | 348 | */ |
349 | - public function setOverwrite(bool $overwrite) |
|
349 | + public function setOverwrite( bool $overwrite ) |
|
350 | 350 | { |
351 | 351 | $this->overwrite = $overwrite; |
352 | 352 | } |
353 | 353 | |
354 | - public function setProgress(int $step) |
|
354 | + public function setProgress( int $step ) |
|
355 | 355 | { |
356 | - if ($this->max && $step > $this->max) { |
|
356 | + if ( $this->max && $step > $this->max ) { |
|
357 | 357 | $this->max = $step; |
358 | - } elseif ($step < 0) { |
|
358 | + } elseif ( $step < 0 ) { |
|
359 | 359 | $step = 0; |
360 | 360 | } |
361 | 361 | |
362 | - $redrawFreq = $this->redrawFreq ?? (($this->max ?: 10) / 10); |
|
363 | - $prevPeriod = (int) ($this->step / $redrawFreq); |
|
364 | - $currPeriod = (int) ($step / $redrawFreq); |
|
362 | + $redrawFreq = $this->redrawFreq ?? ( ( $this->max ?: 10 ) / 10 ); |
|
363 | + $prevPeriod = (int)( $this->step / $redrawFreq ); |
|
364 | + $currPeriod = (int)( $step / $redrawFreq ); |
|
365 | 365 | $this->step = $step; |
366 | - $this->percent = $this->max ? (float) $this->step / $this->max : 0; |
|
367 | - $timeInterval = microtime(true) - $this->lastWriteTime; |
|
366 | + $this->percent = $this->max ? (float)$this->step / $this->max : 0; |
|
367 | + $timeInterval = microtime( true ) - $this->lastWriteTime; |
|
368 | 368 | |
369 | 369 | // Draw regardless of other limits |
370 | - if ($this->max === $step) { |
|
370 | + if ( $this->max === $step ) { |
|
371 | 371 | $this->display(); |
372 | 372 | |
373 | 373 | return; |
374 | 374 | } |
375 | 375 | |
376 | 376 | // Throttling |
377 | - if ($timeInterval < $this->minSecondsBetweenRedraws) { |
|
377 | + if ( $timeInterval < $this->minSecondsBetweenRedraws ) { |
|
378 | 378 | return; |
379 | 379 | } |
380 | 380 | |
381 | 381 | // Draw each step period, but not too late |
382 | - if ($prevPeriod !== $currPeriod || $timeInterval >= $this->maxSecondsBetweenRedraws) { |
|
382 | + if ( $prevPeriod !== $currPeriod || $timeInterval >= $this->maxSecondsBetweenRedraws ) { |
|
383 | 383 | $this->display(); |
384 | 384 | } |
385 | 385 | } |
386 | 386 | |
387 | - public function setMaxSteps(int $max) |
|
387 | + public function setMaxSteps( int $max ) |
|
388 | 388 | { |
389 | 389 | $this->format = null; |
390 | - $this->max = max(0, $max); |
|
391 | - $this->stepWidth = $this->max ? Helper::width((string) $this->max) : 4; |
|
390 | + $this->max = max( 0, $max ); |
|
391 | + $this->stepWidth = $this->max ? Helper::width( (string)$this->max ) : 4; |
|
392 | 392 | } |
393 | 393 | |
394 | 394 | /** |
@@ -396,16 +396,16 @@ discard block |
||
396 | 396 | */ |
397 | 397 | public function finish(): void |
398 | 398 | { |
399 | - if (!$this->max) { |
|
399 | + if ( ! $this->max ) { |
|
400 | 400 | $this->max = $this->step; |
401 | 401 | } |
402 | 402 | |
403 | - if ($this->step === $this->max && !$this->overwrite) { |
|
403 | + if ( $this->step === $this->max && ! $this->overwrite ) { |
|
404 | 404 | // prevent double 100% output |
405 | 405 | return; |
406 | 406 | } |
407 | 407 | |
408 | - $this->setProgress($this->max); |
|
408 | + $this->setProgress( $this->max ); |
|
409 | 409 | } |
410 | 410 | |
411 | 411 | /** |
@@ -413,15 +413,15 @@ discard block |
||
413 | 413 | */ |
414 | 414 | public function display(): void |
415 | 415 | { |
416 | - if (OutputInterface::VERBOSITY_QUIET === $this->output->getVerbosity()) { |
|
416 | + if ( OutputInterface::VERBOSITY_QUIET === $this->output->getVerbosity() ) { |
|
417 | 417 | return; |
418 | 418 | } |
419 | 419 | |
420 | - if (null === $this->format) { |
|
421 | - $this->setRealFormat($this->internalFormat ?: $this->determineBestFormat()); |
|
420 | + if ( null === $this->format ) { |
|
421 | + $this->setRealFormat( $this->internalFormat ?: $this->determineBestFormat() ); |
|
422 | 422 | } |
423 | 423 | |
424 | - $this->overwrite($this->buildLine()); |
|
424 | + $this->overwrite( $this->buildLine() ); |
|
425 | 425 | } |
426 | 426 | |
427 | 427 | /** |
@@ -433,79 +433,79 @@ discard block |
||
433 | 433 | */ |
434 | 434 | public function clear(): void |
435 | 435 | { |
436 | - if (!$this->overwrite) { |
|
436 | + if ( ! $this->overwrite ) { |
|
437 | 437 | return; |
438 | 438 | } |
439 | 439 | |
440 | - if (null === $this->format) { |
|
441 | - $this->setRealFormat($this->internalFormat ?: $this->determineBestFormat()); |
|
440 | + if ( null === $this->format ) { |
|
441 | + $this->setRealFormat( $this->internalFormat ?: $this->determineBestFormat() ); |
|
442 | 442 | } |
443 | 443 | |
444 | - $this->overwrite(''); |
|
444 | + $this->overwrite( '' ); |
|
445 | 445 | } |
446 | 446 | |
447 | - private function setRealFormat(string $format) |
|
447 | + private function setRealFormat( string $format ) |
|
448 | 448 | { |
449 | 449 | // try to use the _nomax variant if available |
450 | - if (!$this->max && null !== self::getFormatDefinition($format.'_nomax')) { |
|
451 | - $this->format = self::getFormatDefinition($format.'_nomax'); |
|
452 | - } elseif (null !== self::getFormatDefinition($format)) { |
|
453 | - $this->format = self::getFormatDefinition($format); |
|
450 | + if ( ! $this->max && null !== self::getFormatDefinition( $format . '_nomax' ) ) { |
|
451 | + $this->format = self::getFormatDefinition( $format . '_nomax' ); |
|
452 | + } elseif ( null !== self::getFormatDefinition( $format ) ) { |
|
453 | + $this->format = self::getFormatDefinition( $format ); |
|
454 | 454 | } else { |
455 | 455 | $this->format = $format; |
456 | 456 | } |
457 | 457 | |
458 | - $this->formatLineCount = substr_count($this->format, "\n"); |
|
458 | + $this->formatLineCount = substr_count( $this->format, "\n" ); |
|
459 | 459 | } |
460 | 460 | |
461 | 461 | /** |
462 | 462 | * Overwrites a previous message to the output. |
463 | 463 | */ |
464 | - private function overwrite(string $message): void |
|
464 | + private function overwrite( string $message ): void |
|
465 | 465 | { |
466 | - if ($this->previousMessage === $message) { |
|
466 | + if ( $this->previousMessage === $message ) { |
|
467 | 467 | return; |
468 | 468 | } |
469 | 469 | |
470 | 470 | $originalMessage = $message; |
471 | 471 | |
472 | - if ($this->overwrite) { |
|
473 | - if (null !== $this->previousMessage) { |
|
474 | - if ($this->output instanceof ConsoleSectionOutput) { |
|
475 | - $messageLines = explode("\n", $message); |
|
476 | - $lineCount = \count($messageLines); |
|
477 | - foreach ($messageLines as $messageLine) { |
|
478 | - $messageLineLength = Helper::width(Helper::removeDecoration($this->output->getFormatter(), $messageLine)); |
|
479 | - if ($messageLineLength > $this->terminal->getWidth()) { |
|
480 | - $lineCount += floor($messageLineLength / $this->terminal->getWidth()); |
|
472 | + if ( $this->overwrite ) { |
|
473 | + if ( null !== $this->previousMessage ) { |
|
474 | + if ( $this->output instanceof ConsoleSectionOutput ) { |
|
475 | + $messageLines = explode( "\n", $message ); |
|
476 | + $lineCount = \count( $messageLines ); |
|
477 | + foreach ( $messageLines as $messageLine ) { |
|
478 | + $messageLineLength = Helper::width( Helper::removeDecoration( $this->output->getFormatter(), $messageLine ) ); |
|
479 | + if ( $messageLineLength > $this->terminal->getWidth() ) { |
|
480 | + $lineCount += floor( $messageLineLength / $this->terminal->getWidth() ); |
|
481 | 481 | } |
482 | 482 | } |
483 | - $this->output->clear($lineCount); |
|
483 | + $this->output->clear( $lineCount ); |
|
484 | 484 | } else { |
485 | - for ($i = 0; $i < $this->formatLineCount; ++$i) { |
|
486 | - $this->cursor->moveToColumn(1); |
|
485 | + for ( $i = 0; $i < $this->formatLineCount; ++$i ) { |
|
486 | + $this->cursor->moveToColumn( 1 ); |
|
487 | 487 | $this->cursor->clearLine(); |
488 | 488 | $this->cursor->moveUp(); |
489 | 489 | } |
490 | 490 | |
491 | - $this->cursor->moveToColumn(1); |
|
491 | + $this->cursor->moveToColumn( 1 ); |
|
492 | 492 | $this->cursor->clearLine(); |
493 | 493 | } |
494 | 494 | } |
495 | - } elseif ($this->step > 0) { |
|
496 | - $message = \PHP_EOL.$message; |
|
495 | + } elseif ( $this->step > 0 ) { |
|
496 | + $message = \PHP_EOL . $message; |
|
497 | 497 | } |
498 | 498 | |
499 | 499 | $this->previousMessage = $originalMessage; |
500 | - $this->lastWriteTime = microtime(true); |
|
500 | + $this->lastWriteTime = microtime( true ); |
|
501 | 501 | |
502 | - $this->output->write($message); |
|
502 | + $this->output->write( $message ); |
|
503 | 503 | ++$this->writeCount; |
504 | 504 | } |
505 | 505 | |
506 | 506 | private function determineBestFormat(): string |
507 | 507 | { |
508 | - switch ($this->output->getVerbosity()) { |
|
508 | + switch ( $this->output->getVerbosity() ) { |
|
509 | 509 | // OutputInterface::VERBOSITY_QUIET: display is disabled anyway |
510 | 510 | case OutputInterface::VERBOSITY_VERBOSE: |
511 | 511 | return $this->max ? self::FORMAT_VERBOSE : self::FORMAT_VERBOSE_NOMAX; |
@@ -521,44 +521,44 @@ discard block |
||
521 | 521 | private static function initPlaceholderFormatters(): array |
522 | 522 | { |
523 | 523 | return [ |
524 | - 'bar' => function (self $bar, OutputInterface $output) { |
|
524 | + 'bar' => function( self $bar, OutputInterface $output ) { |
|
525 | 525 | $completeBars = $bar->getBarOffset(); |
526 | - $display = str_repeat($bar->getBarCharacter(), $completeBars); |
|
527 | - if ($completeBars < $bar->getBarWidth()) { |
|
528 | - $emptyBars = $bar->getBarWidth() - $completeBars - Helper::length(Helper::removeDecoration($output->getFormatter(), $bar->getProgressCharacter())); |
|
529 | - $display .= $bar->getProgressCharacter().str_repeat($bar->getEmptyBarCharacter(), $emptyBars); |
|
526 | + $display = str_repeat( $bar->getBarCharacter(), $completeBars ); |
|
527 | + if ( $completeBars < $bar->getBarWidth() ) { |
|
528 | + $emptyBars = $bar->getBarWidth() - $completeBars - Helper::length( Helper::removeDecoration( $output->getFormatter(), $bar->getProgressCharacter() ) ); |
|
529 | + $display .= $bar->getProgressCharacter() . str_repeat( $bar->getEmptyBarCharacter(), $emptyBars ); |
|
530 | 530 | } |
531 | 531 | |
532 | 532 | return $display; |
533 | 533 | }, |
534 | - 'elapsed' => function (self $bar) { |
|
535 | - return Helper::formatTime(time() - $bar->getStartTime()); |
|
534 | + 'elapsed' => function( self $bar ) { |
|
535 | + return Helper::formatTime( time() - $bar->getStartTime() ); |
|
536 | 536 | }, |
537 | - 'remaining' => function (self $bar) { |
|
538 | - if (!$bar->getMaxSteps()) { |
|
539 | - throw new LogicException('Unable to display the remaining time if the maximum number of steps is not set.'); |
|
537 | + 'remaining' => function( self $bar ) { |
|
538 | + if ( ! $bar->getMaxSteps() ) { |
|
539 | + throw new LogicException( 'Unable to display the remaining time if the maximum number of steps is not set.' ); |
|
540 | 540 | } |
541 | 541 | |
542 | - return Helper::formatTime($bar->getRemaining()); |
|
542 | + return Helper::formatTime( $bar->getRemaining() ); |
|
543 | 543 | }, |
544 | - 'estimated' => function (self $bar) { |
|
545 | - if (!$bar->getMaxSteps()) { |
|
546 | - throw new LogicException('Unable to display the estimated time if the maximum number of steps is not set.'); |
|
544 | + 'estimated' => function( self $bar ) { |
|
545 | + if ( ! $bar->getMaxSteps() ) { |
|
546 | + throw new LogicException( 'Unable to display the estimated time if the maximum number of steps is not set.' ); |
|
547 | 547 | } |
548 | 548 | |
549 | - return Helper::formatTime($bar->getEstimated()); |
|
549 | + return Helper::formatTime( $bar->getEstimated() ); |
|
550 | 550 | }, |
551 | - 'memory' => function (self $bar) { |
|
552 | - return Helper::formatMemory(memory_get_usage(true)); |
|
551 | + 'memory' => function( self $bar ) { |
|
552 | + return Helper::formatMemory( memory_get_usage( true ) ); |
|
553 | 553 | }, |
554 | - 'current' => function (self $bar) { |
|
555 | - return str_pad($bar->getProgress(), $bar->getStepWidth(), ' ', \STR_PAD_LEFT); |
|
554 | + 'current' => function( self $bar ) { |
|
555 | + return str_pad( $bar->getProgress(), $bar->getStepWidth(), ' ', \STR_PAD_LEFT ); |
|
556 | 556 | }, |
557 | - 'max' => function (self $bar) { |
|
557 | + 'max' => function( self $bar ) { |
|
558 | 558 | return $bar->getMaxSteps(); |
559 | 559 | }, |
560 | - 'percent' => function (self $bar) { |
|
561 | - return floor($bar->getProgressPercent() * 100); |
|
560 | + 'percent' => function( self $bar ) { |
|
561 | + return floor( $bar->getProgressPercent() * 100 ); |
|
562 | 562 | }, |
563 | 563 | ]; |
564 | 564 | } |
@@ -583,37 +583,37 @@ discard block |
||
583 | 583 | private function buildLine(): string |
584 | 584 | { |
585 | 585 | $regex = "{%([a-z\-_]+)(?:\:([^%]+))?%}i"; |
586 | - $callback = function ($matches) { |
|
587 | - if ($formatter = $this::getPlaceholderFormatterDefinition($matches[1])) { |
|
588 | - $text = $formatter($this, $this->output); |
|
589 | - } elseif (isset($this->messages[$matches[1]])) { |
|
590 | - $text = $this->messages[$matches[1]]; |
|
586 | + $callback = function( $matches ) { |
|
587 | + if ( $formatter = $this::getPlaceholderFormatterDefinition( $matches[ 1 ] ) ) { |
|
588 | + $text = $formatter( $this, $this->output ); |
|
589 | + } elseif ( isset( $this->messages[ $matches[ 1 ] ] ) ) { |
|
590 | + $text = $this->messages[ $matches[ 1 ] ]; |
|
591 | 591 | } else { |
592 | - return $matches[0]; |
|
592 | + return $matches[ 0 ]; |
|
593 | 593 | } |
594 | 594 | |
595 | - if (isset($matches[2])) { |
|
596 | - $text = sprintf('%'.$matches[2], $text); |
|
595 | + if ( isset( $matches[ 2 ] ) ) { |
|
596 | + $text = sprintf( '%' . $matches[ 2 ], $text ); |
|
597 | 597 | } |
598 | 598 | |
599 | 599 | return $text; |
600 | 600 | }; |
601 | - $line = preg_replace_callback($regex, $callback, $this->format); |
|
601 | + $line = preg_replace_callback( $regex, $callback, $this->format ); |
|
602 | 602 | |
603 | 603 | // gets string length for each sub line with multiline format |
604 | - $linesLength = array_map(function ($subLine) { |
|
605 | - return Helper::width(Helper::removeDecoration($this->output->getFormatter(), rtrim($subLine, "\r"))); |
|
606 | - }, explode("\n", $line)); |
|
604 | + $linesLength = array_map( function( $subLine ) { |
|
605 | + return Helper::width( Helper::removeDecoration( $this->output->getFormatter(), rtrim( $subLine, "\r" ) ) ); |
|
606 | + }, explode( "\n", $line ) ); |
|
607 | 607 | |
608 | - $linesWidth = max($linesLength); |
|
608 | + $linesWidth = max( $linesLength ); |
|
609 | 609 | |
610 | 610 | $terminalWidth = $this->terminal->getWidth(); |
611 | - if ($linesWidth <= $terminalWidth) { |
|
611 | + if ( $linesWidth <= $terminalWidth ) { |
|
612 | 612 | return $line; |
613 | 613 | } |
614 | 614 | |
615 | - $this->setBarWidth($this->barWidth - $linesWidth + $terminalWidth); |
|
615 | + $this->setBarWidth( $this->barWidth - $linesWidth + $terminalWidth ); |
|
616 | 616 | |
617 | - return preg_replace_callback($regex, $callback, $this->format); |
|
617 | + return preg_replace_callback( $regex, $callback, $this->format ); |
|
618 | 618 | } |
619 | 619 | } |
@@ -24,8 +24,7 @@ discard block |
||
24 | 24 | * @author Fabien Potencier <[email protected]> |
25 | 25 | * @author Chris Jones <[email protected]> |
26 | 26 | */ |
27 | -final class ProgressBar |
|
28 | -{ |
|
27 | +final class ProgressBar { |
|
29 | 28 | public const FORMAT_VERBOSE = 'verbose'; |
30 | 29 | public const FORMAT_VERY_VERBOSE = 'very_verbose'; |
31 | 30 | public const FORMAT_DEBUG = 'debug'; |
@@ -66,8 +65,7 @@ discard block |
||
66 | 65 | /** |
67 | 66 | * @param int $max Maximum steps (0 if unknown) |
68 | 67 | */ |
69 | - public function __construct(OutputInterface $output, int $max = 0, float $minSecondsBetweenRedraws = 1 / 25) |
|
70 | - { |
|
68 | + public function __construct(OutputInterface $output, int $max = 0, float $minSecondsBetweenRedraws = 1 / 25) { |
|
71 | 69 | if ($output instanceof ConsoleOutputInterface) { |
72 | 70 | $output = $output->getErrorOutput(); |
73 | 71 | } |
@@ -169,13 +167,11 @@ discard block |
||
169 | 167 | * @param string $message The text to associate with the placeholder |
170 | 168 | * @param string $name The name of the placeholder |
171 | 169 | */ |
172 | - public function setMessage(string $message, string $name = 'message') |
|
173 | - { |
|
170 | + public function setMessage(string $message, string $name = 'message') { |
|
174 | 171 | $this->messages[$name] = $message; |
175 | 172 | } |
176 | 173 | |
177 | - public function getMessage(string $name = 'message') |
|
178 | - { |
|
174 | + public function getMessage(string $name = 'message') { |
|
179 | 175 | return $this->messages[$name]; |
180 | 176 | } |
181 | 177 | |
@@ -227,8 +223,7 @@ discard block |
||
227 | 223 | return round((time() - $this->startTime) / $this->step * ($this->max - $this->step)); |
228 | 224 | } |
229 | 225 | |
230 | - public function setBarWidth(int $size) |
|
231 | - { |
|
226 | + public function setBarWidth(int $size) { |
|
232 | 227 | $this->barWidth = max(1, $size); |
233 | 228 | } |
234 | 229 | |
@@ -237,8 +232,7 @@ discard block |
||
237 | 232 | return $this->barWidth; |
238 | 233 | } |
239 | 234 | |
240 | - public function setBarCharacter(string $char) |
|
241 | - { |
|
235 | + public function setBarCharacter(string $char) { |
|
242 | 236 | $this->barChar = $char; |
243 | 237 | } |
244 | 238 | |
@@ -251,8 +245,7 @@ discard block |
||
251 | 245 | return $this->barChar; |
252 | 246 | } |
253 | 247 | |
254 | - public function setEmptyBarCharacter(string $char) |
|
255 | - { |
|
248 | + public function setEmptyBarCharacter(string $char) { |
|
256 | 249 | $this->emptyBarChar = $char; |
257 | 250 | } |
258 | 251 | |
@@ -261,8 +254,7 @@ discard block |
||
261 | 254 | return $this->emptyBarChar; |
262 | 255 | } |
263 | 256 | |
264 | - public function setProgressCharacter(string $char) |
|
265 | - { |
|
257 | + public function setProgressCharacter(string $char) { |
|
266 | 258 | $this->progressChar = $char; |
267 | 259 | } |
268 | 260 | |
@@ -271,8 +263,7 @@ discard block |
||
271 | 263 | return $this->progressChar; |
272 | 264 | } |
273 | 265 | |
274 | - public function setFormat(string $format) |
|
275 | - { |
|
266 | + public function setFormat(string $format) { |
|
276 | 267 | $this->format = null; |
277 | 268 | $this->internalFormat = $format; |
278 | 269 | } |
@@ -282,8 +273,7 @@ discard block |
||
282 | 273 | * |
283 | 274 | * @param int|null $freq The frequency in steps |
284 | 275 | */ |
285 | - public function setRedrawFrequency(?int $freq) |
|
286 | - { |
|
276 | + public function setRedrawFrequency(?int $freq) { |
|
287 | 277 | $this->redrawFreq = null !== $freq ? max(1, $freq) : null; |
288 | 278 | } |
289 | 279 | |
@@ -320,8 +310,7 @@ discard block |
||
320 | 310 | * |
321 | 311 | * @param int|null $max Number of steps to complete the bar (0 if indeterminate), null to leave unchanged |
322 | 312 | */ |
323 | - public function start(int $max = null) |
|
324 | - { |
|
313 | + public function start(int $max = null) { |
|
325 | 314 | $this->startTime = time(); |
326 | 315 | $this->step = 0; |
327 | 316 | $this->percent = 0.0; |
@@ -338,21 +327,18 @@ discard block |
||
338 | 327 | * |
339 | 328 | * @param int $step Number of steps to advance |
340 | 329 | */ |
341 | - public function advance(int $step = 1) |
|
342 | - { |
|
330 | + public function advance(int $step = 1) { |
|
343 | 331 | $this->setProgress($this->step + $step); |
344 | 332 | } |
345 | 333 | |
346 | 334 | /** |
347 | 335 | * Sets whether to overwrite the progressbar, false for new line. |
348 | 336 | */ |
349 | - public function setOverwrite(bool $overwrite) |
|
350 | - { |
|
337 | + public function setOverwrite(bool $overwrite) { |
|
351 | 338 | $this->overwrite = $overwrite; |
352 | 339 | } |
353 | 340 | |
354 | - public function setProgress(int $step) |
|
355 | - { |
|
341 | + public function setProgress(int $step) { |
|
356 | 342 | if ($this->max && $step > $this->max) { |
357 | 343 | $this->max = $step; |
358 | 344 | } elseif ($step < 0) { |
@@ -384,8 +370,7 @@ discard block |
||
384 | 370 | } |
385 | 371 | } |
386 | 372 | |
387 | - public function setMaxSteps(int $max) |
|
388 | - { |
|
373 | + public function setMaxSteps(int $max) { |
|
389 | 374 | $this->format = null; |
390 | 375 | $this->max = max(0, $max); |
391 | 376 | $this->stepWidth = $this->max ? Helper::width((string) $this->max) : 4; |
@@ -444,8 +429,7 @@ discard block |
||
444 | 429 | $this->overwrite(''); |
445 | 430 | } |
446 | 431 | |
447 | - private function setRealFormat(string $format) |
|
448 | - { |
|
432 | + private function setRealFormat(string $format) { |
|
449 | 433 | // try to use the _nomax variant if available |
450 | 434 | if (!$this->max && null !== self::getFormatDefinition($format.'_nomax')) { |
451 | 435 | $this->format = self::getFormatDefinition($format.'_nomax'); |
@@ -18,69 +18,69 @@ |
||
18 | 18 | */ |
19 | 19 | class TableCellStyle |
20 | 20 | { |
21 | - public const DEFAULT_ALIGN = 'left'; |
|
21 | + public const DEFAULT_ALIGN = 'left'; |
|
22 | 22 | |
23 | - private $options = [ |
|
24 | - 'fg' => 'default', |
|
25 | - 'bg' => 'default', |
|
26 | - 'options' => null, |
|
27 | - 'align' => self::DEFAULT_ALIGN, |
|
28 | - 'cellFormat' => null, |
|
29 | - ]; |
|
23 | + private $options = [ |
|
24 | + 'fg' => 'default', |
|
25 | + 'bg' => 'default', |
|
26 | + 'options' => null, |
|
27 | + 'align' => self::DEFAULT_ALIGN, |
|
28 | + 'cellFormat' => null, |
|
29 | + ]; |
|
30 | 30 | |
31 | - private $tagOptions = [ |
|
32 | - 'fg', |
|
33 | - 'bg', |
|
34 | - 'options', |
|
35 | - ]; |
|
31 | + private $tagOptions = [ |
|
32 | + 'fg', |
|
33 | + 'bg', |
|
34 | + 'options', |
|
35 | + ]; |
|
36 | 36 | |
37 | - private $alignMap = [ |
|
38 | - 'left' => \STR_PAD_RIGHT, |
|
39 | - 'center' => \STR_PAD_BOTH, |
|
40 | - 'right' => \STR_PAD_LEFT, |
|
41 | - ]; |
|
37 | + private $alignMap = [ |
|
38 | + 'left' => \STR_PAD_RIGHT, |
|
39 | + 'center' => \STR_PAD_BOTH, |
|
40 | + 'right' => \STR_PAD_LEFT, |
|
41 | + ]; |
|
42 | 42 | |
43 | - public function __construct(array $options = []) |
|
44 | - { |
|
45 | - if ($diff = array_diff(array_keys($options), array_keys($this->options))) { |
|
46 | - throw new InvalidArgumentException(sprintf('The TableCellStyle does not support the following options: \'%s\'.', implode('\', \'', $diff))); |
|
47 | - } |
|
43 | + public function __construct(array $options = []) |
|
44 | + { |
|
45 | + if ($diff = array_diff(array_keys($options), array_keys($this->options))) { |
|
46 | + throw new InvalidArgumentException(sprintf('The TableCellStyle does not support the following options: \'%s\'.', implode('\', \'', $diff))); |
|
47 | + } |
|
48 | 48 | |
49 | - if (isset($options['align']) && !\array_key_exists($options['align'], $this->alignMap)) { |
|
50 | - throw new InvalidArgumentException(sprintf('Wrong align value. Value must be following: \'%s\'.', implode('\', \'', array_keys($this->alignMap)))); |
|
51 | - } |
|
49 | + if (isset($options['align']) && !\array_key_exists($options['align'], $this->alignMap)) { |
|
50 | + throw new InvalidArgumentException(sprintf('Wrong align value. Value must be following: \'%s\'.', implode('\', \'', array_keys($this->alignMap)))); |
|
51 | + } |
|
52 | 52 | |
53 | - $this->options = array_merge($this->options, $options); |
|
54 | - } |
|
53 | + $this->options = array_merge($this->options, $options); |
|
54 | + } |
|
55 | 55 | |
56 | - public function getOptions(): array |
|
57 | - { |
|
58 | - return $this->options; |
|
59 | - } |
|
56 | + public function getOptions(): array |
|
57 | + { |
|
58 | + return $this->options; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * Gets options we need for tag for example fg, bg. |
|
63 | - * |
|
64 | - * @return string[] |
|
65 | - */ |
|
66 | - public function getTagOptions() |
|
67 | - { |
|
68 | - return array_filter( |
|
69 | - $this->getOptions(), |
|
70 | - function ($key) { |
|
71 | - return \in_array($key, $this->tagOptions) && isset($this->options[$key]); |
|
72 | - }, |
|
73 | - \ARRAY_FILTER_USE_KEY |
|
74 | - ); |
|
75 | - } |
|
61 | + /** |
|
62 | + * Gets options we need for tag for example fg, bg. |
|
63 | + * |
|
64 | + * @return string[] |
|
65 | + */ |
|
66 | + public function getTagOptions() |
|
67 | + { |
|
68 | + return array_filter( |
|
69 | + $this->getOptions(), |
|
70 | + function ($key) { |
|
71 | + return \in_array($key, $this->tagOptions) && isset($this->options[$key]); |
|
72 | + }, |
|
73 | + \ARRAY_FILTER_USE_KEY |
|
74 | + ); |
|
75 | + } |
|
76 | 76 | |
77 | - public function getPadByAlign() |
|
78 | - { |
|
79 | - return $this->alignMap[$this->getOptions()['align']]; |
|
80 | - } |
|
77 | + public function getPadByAlign() |
|
78 | + { |
|
79 | + return $this->alignMap[$this->getOptions()['align']]; |
|
80 | + } |
|
81 | 81 | |
82 | - public function getCellFormat(): ?string |
|
83 | - { |
|
84 | - return $this->getOptions()['cellFormat']; |
|
85 | - } |
|
82 | + public function getCellFormat(): ?string |
|
83 | + { |
|
84 | + return $this->getOptions()['cellFormat']; |
|
85 | + } |
|
86 | 86 | } |
@@ -40,17 +40,17 @@ discard block |
||
40 | 40 | 'right' => \STR_PAD_LEFT, |
41 | 41 | ]; |
42 | 42 | |
43 | - public function __construct(array $options = []) |
|
43 | + public function __construct( array $options = [ ] ) |
|
44 | 44 | { |
45 | - if ($diff = array_diff(array_keys($options), array_keys($this->options))) { |
|
46 | - throw new InvalidArgumentException(sprintf('The TableCellStyle does not support the following options: \'%s\'.', implode('\', \'', $diff))); |
|
45 | + if ( $diff = array_diff( array_keys( $options ), array_keys( $this->options ) ) ) { |
|
46 | + throw new InvalidArgumentException( sprintf( 'The TableCellStyle does not support the following options: \'%s\'.', implode( '\', \'', $diff ) ) ); |
|
47 | 47 | } |
48 | 48 | |
49 | - if (isset($options['align']) && !\array_key_exists($options['align'], $this->alignMap)) { |
|
50 | - throw new InvalidArgumentException(sprintf('Wrong align value. Value must be following: \'%s\'.', implode('\', \'', array_keys($this->alignMap)))); |
|
49 | + if ( isset( $options[ 'align' ] ) && ! \array_key_exists( $options[ 'align' ], $this->alignMap ) ) { |
|
50 | + throw new InvalidArgumentException( sprintf( 'Wrong align value. Value must be following: \'%s\'.', implode( '\', \'', array_keys( $this->alignMap ) ) ) ); |
|
51 | 51 | } |
52 | 52 | |
53 | - $this->options = array_merge($this->options, $options); |
|
53 | + $this->options = array_merge( $this->options, $options ); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | public function getOptions(): array |
@@ -67,8 +67,8 @@ discard block |
||
67 | 67 | { |
68 | 68 | return array_filter( |
69 | 69 | $this->getOptions(), |
70 | - function ($key) { |
|
71 | - return \in_array($key, $this->tagOptions) && isset($this->options[$key]); |
|
70 | + function( $key ) { |
|
71 | + return \in_array( $key, $this->tagOptions ) && isset( $this->options[ $key ] ); |
|
72 | 72 | }, |
73 | 73 | \ARRAY_FILTER_USE_KEY |
74 | 74 | ); |
@@ -76,11 +76,11 @@ discard block |
||
76 | 76 | |
77 | 77 | public function getPadByAlign() |
78 | 78 | { |
79 | - return $this->alignMap[$this->getOptions()['align']]; |
|
79 | + return $this->alignMap[ $this->getOptions()[ 'align' ] ]; |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | public function getCellFormat(): ?string |
83 | 83 | { |
84 | - return $this->getOptions()['cellFormat']; |
|
84 | + return $this->getOptions()[ 'cellFormat' ]; |
|
85 | 85 | } |
86 | 86 | } |
@@ -16,8 +16,7 @@ discard block |
||
16 | 16 | /** |
17 | 17 | * @author Yewhen Khoptynskyi <[email protected]> |
18 | 18 | */ |
19 | -class TableCellStyle |
|
20 | -{ |
|
19 | +class TableCellStyle { |
|
21 | 20 | public const DEFAULT_ALIGN = 'left'; |
22 | 21 | |
23 | 22 | private $options = [ |
@@ -40,8 +39,7 @@ discard block |
||
40 | 39 | 'right' => \STR_PAD_LEFT, |
41 | 40 | ]; |
42 | 41 | |
43 | - public function __construct(array $options = []) |
|
44 | - { |
|
42 | + public function __construct(array $options = []) { |
|
45 | 43 | if ($diff = array_diff(array_keys($options), array_keys($this->options))) { |
46 | 44 | throw new InvalidArgumentException(sprintf('The TableCellStyle does not support the following options: \'%s\'.', implode('\', \'', $diff))); |
47 | 45 | } |
@@ -63,8 +61,7 @@ discard block |
||
63 | 61 | * |
64 | 62 | * @return string[] |
65 | 63 | */ |
66 | - public function getTagOptions() |
|
67 | - { |
|
64 | + public function getTagOptions() { |
|
68 | 65 | return array_filter( |
69 | 66 | $this->getOptions(), |
70 | 67 | function ($key) { |
@@ -74,8 +71,7 @@ discard block |
||
74 | 71 | ); |
75 | 72 | } |
76 | 73 | |
77 | - public function getPadByAlign() |
|
78 | - { |
|
74 | + public function getPadByAlign() { |
|
79 | 75 | return $this->alignMap[$this->getOptions()['align']]; |
80 | 76 | } |
81 | 77 |
@@ -23,342 +23,342 @@ |
||
23 | 23 | */ |
24 | 24 | class TableStyle |
25 | 25 | { |
26 | - private $paddingChar = ' '; |
|
27 | - private $horizontalOutsideBorderChar = '-'; |
|
28 | - private $horizontalInsideBorderChar = '-'; |
|
29 | - private $verticalOutsideBorderChar = '|'; |
|
30 | - private $verticalInsideBorderChar = '|'; |
|
31 | - private $crossingChar = '+'; |
|
32 | - private $crossingTopRightChar = '+'; |
|
33 | - private $crossingTopMidChar = '+'; |
|
34 | - private $crossingTopLeftChar = '+'; |
|
35 | - private $crossingMidRightChar = '+'; |
|
36 | - private $crossingBottomRightChar = '+'; |
|
37 | - private $crossingBottomMidChar = '+'; |
|
38 | - private $crossingBottomLeftChar = '+'; |
|
39 | - private $crossingMidLeftChar = '+'; |
|
40 | - private $crossingTopLeftBottomChar = '+'; |
|
41 | - private $crossingTopMidBottomChar = '+'; |
|
42 | - private $crossingTopRightBottomChar = '+'; |
|
43 | - private $headerTitleFormat = '<fg=black;bg=white;options=bold> %s </>'; |
|
44 | - private $footerTitleFormat = '<fg=black;bg=white;options=bold> %s </>'; |
|
45 | - private $cellHeaderFormat = '<info>%s</info>'; |
|
46 | - private $cellRowFormat = '%s'; |
|
47 | - private $cellRowContentFormat = ' %s '; |
|
48 | - private $borderFormat = '%s'; |
|
49 | - private $padType = \STR_PAD_RIGHT; |
|
50 | - |
|
51 | - /** |
|
52 | - * Sets padding character, used for cell padding. |
|
53 | - * |
|
54 | - * @return $this |
|
55 | - */ |
|
56 | - public function setPaddingChar(string $paddingChar) |
|
57 | - { |
|
58 | - if (!$paddingChar) { |
|
59 | - throw new LogicException('The padding char must not be empty.'); |
|
60 | - } |
|
61 | - |
|
62 | - $this->paddingChar = $paddingChar; |
|
63 | - |
|
64 | - return $this; |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * Gets padding character, used for cell padding. |
|
69 | - * |
|
70 | - * @return string |
|
71 | - */ |
|
72 | - public function getPaddingChar() |
|
73 | - { |
|
74 | - return $this->paddingChar; |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Sets horizontal border characters. |
|
79 | - * |
|
80 | - * <code> |
|
81 | - * ╔═══════════════╤══════════════════════════╤══════════════════╗ |
|
82 | - * 1 ISBN 2 Title │ Author ║ |
|
83 | - * ╠═══════════════╪══════════════════════════╪══════════════════╣ |
|
84 | - * ║ 99921-58-10-7 │ Divine Comedy │ Dante Alighieri ║ |
|
85 | - * ║ 9971-5-0210-0 │ A Tale of Two Cities │ Charles Dickens ║ |
|
86 | - * ║ 960-425-059-0 │ The Lord of the Rings │ J. R. R. Tolkien ║ |
|
87 | - * ║ 80-902734-1-6 │ And Then There Were None │ Agatha Christie ║ |
|
88 | - * ╚═══════════════╧══════════════════════════╧══════════════════╝ |
|
89 | - * </code> |
|
90 | - */ |
|
91 | - public function setHorizontalBorderChars(string $outside, string $inside = null): self |
|
92 | - { |
|
93 | - $this->horizontalOutsideBorderChar = $outside; |
|
94 | - $this->horizontalInsideBorderChar = $inside ?? $outside; |
|
95 | - |
|
96 | - return $this; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Sets vertical border characters. |
|
101 | - * |
|
102 | - * <code> |
|
103 | - * ╔═══════════════╤══════════════════════════╤══════════════════╗ |
|
104 | - * ║ ISBN │ Title │ Author ║ |
|
105 | - * ╠═══════1═══════╪══════════════════════════╪══════════════════╣ |
|
106 | - * ║ 99921-58-10-7 │ Divine Comedy │ Dante Alighieri ║ |
|
107 | - * ║ 9971-5-0210-0 │ A Tale of Two Cities │ Charles Dickens ║ |
|
108 | - * ╟───────2───────┼──────────────────────────┼──────────────────╢ |
|
109 | - * ║ 960-425-059-0 │ The Lord of the Rings │ J. R. R. Tolkien ║ |
|
110 | - * ║ 80-902734-1-6 │ And Then There Were None │ Agatha Christie ║ |
|
111 | - * ╚═══════════════╧══════════════════════════╧══════════════════╝ |
|
112 | - * </code> |
|
113 | - */ |
|
114 | - public function setVerticalBorderChars(string $outside, string $inside = null): self |
|
115 | - { |
|
116 | - $this->verticalOutsideBorderChar = $outside; |
|
117 | - $this->verticalInsideBorderChar = $inside ?? $outside; |
|
118 | - |
|
119 | - return $this; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Gets border characters. |
|
124 | - * |
|
125 | - * @internal |
|
126 | - */ |
|
127 | - public function getBorderChars(): array |
|
128 | - { |
|
129 | - return [ |
|
130 | - $this->horizontalOutsideBorderChar, |
|
131 | - $this->verticalOutsideBorderChar, |
|
132 | - $this->horizontalInsideBorderChar, |
|
133 | - $this->verticalInsideBorderChar, |
|
134 | - ]; |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Sets crossing characters. |
|
139 | - * |
|
140 | - * Example: |
|
141 | - * <code> |
|
142 | - * 1═══════════════2══════════════════════════2══════════════════3 |
|
143 | - * ║ ISBN │ Title │ Author ║ |
|
144 | - * 8'══════════════0'═════════════════════════0'═════════════════4' |
|
145 | - * ║ 99921-58-10-7 │ Divine Comedy │ Dante Alighieri ║ |
|
146 | - * ║ 9971-5-0210-0 │ A Tale of Two Cities │ Charles Dickens ║ |
|
147 | - * 8───────────────0──────────────────────────0──────────────────4 |
|
148 | - * ║ 960-425-059-0 │ The Lord of the Rings │ J. R. R. Tolkien ║ |
|
149 | - * ║ 80-902734-1-6 │ And Then There Were None │ Agatha Christie ║ |
|
150 | - * 7═══════════════6══════════════════════════6══════════════════5 |
|
151 | - * </code> |
|
152 | - * |
|
153 | - * @param string $cross Crossing char (see #0 of example) |
|
154 | - * @param string $topLeft Top left char (see #1 of example) |
|
155 | - * @param string $topMid Top mid char (see #2 of example) |
|
156 | - * @param string $topRight Top right char (see #3 of example) |
|
157 | - * @param string $midRight Mid right char (see #4 of example) |
|
158 | - * @param string $bottomRight Bottom right char (see #5 of example) |
|
159 | - * @param string $bottomMid Bottom mid char (see #6 of example) |
|
160 | - * @param string $bottomLeft Bottom left char (see #7 of example) |
|
161 | - * @param string $midLeft Mid left char (see #8 of example) |
|
162 | - * @param string|null $topLeftBottom Top left bottom char (see #8' of example), equals to $midLeft if null |
|
163 | - * @param string|null $topMidBottom Top mid bottom char (see #0' of example), equals to $cross if null |
|
164 | - * @param string|null $topRightBottom Top right bottom char (see #4' of example), equals to $midRight if null |
|
165 | - */ |
|
166 | - public function setCrossingChars(string $cross, string $topLeft, string $topMid, string $topRight, string $midRight, string $bottomRight, string $bottomMid, string $bottomLeft, string $midLeft, string $topLeftBottom = null, string $topMidBottom = null, string $topRightBottom = null): self |
|
167 | - { |
|
168 | - $this->crossingChar = $cross; |
|
169 | - $this->crossingTopLeftChar = $topLeft; |
|
170 | - $this->crossingTopMidChar = $topMid; |
|
171 | - $this->crossingTopRightChar = $topRight; |
|
172 | - $this->crossingMidRightChar = $midRight; |
|
173 | - $this->crossingBottomRightChar = $bottomRight; |
|
174 | - $this->crossingBottomMidChar = $bottomMid; |
|
175 | - $this->crossingBottomLeftChar = $bottomLeft; |
|
176 | - $this->crossingMidLeftChar = $midLeft; |
|
177 | - $this->crossingTopLeftBottomChar = $topLeftBottom ?? $midLeft; |
|
178 | - $this->crossingTopMidBottomChar = $topMidBottom ?? $cross; |
|
179 | - $this->crossingTopRightBottomChar = $topRightBottom ?? $midRight; |
|
180 | - |
|
181 | - return $this; |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * Sets default crossing character used for each cross. |
|
186 | - * |
|
187 | - * @see {@link setCrossingChars()} for setting each crossing individually. |
|
188 | - */ |
|
189 | - public function setDefaultCrossingChar(string $char): self |
|
190 | - { |
|
191 | - return $this->setCrossingChars($char, $char, $char, $char, $char, $char, $char, $char, $char); |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * Gets crossing character. |
|
196 | - * |
|
197 | - * @return string |
|
198 | - */ |
|
199 | - public function getCrossingChar() |
|
200 | - { |
|
201 | - return $this->crossingChar; |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * Gets crossing characters. |
|
206 | - * |
|
207 | - * @internal |
|
208 | - */ |
|
209 | - public function getCrossingChars(): array |
|
210 | - { |
|
211 | - return [ |
|
212 | - $this->crossingChar, |
|
213 | - $this->crossingTopLeftChar, |
|
214 | - $this->crossingTopMidChar, |
|
215 | - $this->crossingTopRightChar, |
|
216 | - $this->crossingMidRightChar, |
|
217 | - $this->crossingBottomRightChar, |
|
218 | - $this->crossingBottomMidChar, |
|
219 | - $this->crossingBottomLeftChar, |
|
220 | - $this->crossingMidLeftChar, |
|
221 | - $this->crossingTopLeftBottomChar, |
|
222 | - $this->crossingTopMidBottomChar, |
|
223 | - $this->crossingTopRightBottomChar, |
|
224 | - ]; |
|
225 | - } |
|
226 | - |
|
227 | - /** |
|
228 | - * Sets header cell format. |
|
229 | - * |
|
230 | - * @return $this |
|
231 | - */ |
|
232 | - public function setCellHeaderFormat(string $cellHeaderFormat) |
|
233 | - { |
|
234 | - $this->cellHeaderFormat = $cellHeaderFormat; |
|
235 | - |
|
236 | - return $this; |
|
237 | - } |
|
238 | - |
|
239 | - /** |
|
240 | - * Gets header cell format. |
|
241 | - * |
|
242 | - * @return string |
|
243 | - */ |
|
244 | - public function getCellHeaderFormat() |
|
245 | - { |
|
246 | - return $this->cellHeaderFormat; |
|
247 | - } |
|
248 | - |
|
249 | - /** |
|
250 | - * Sets row cell format. |
|
251 | - * |
|
252 | - * @return $this |
|
253 | - */ |
|
254 | - public function setCellRowFormat(string $cellRowFormat) |
|
255 | - { |
|
256 | - $this->cellRowFormat = $cellRowFormat; |
|
257 | - |
|
258 | - return $this; |
|
259 | - } |
|
260 | - |
|
261 | - /** |
|
262 | - * Gets row cell format. |
|
263 | - * |
|
264 | - * @return string |
|
265 | - */ |
|
266 | - public function getCellRowFormat() |
|
267 | - { |
|
268 | - return $this->cellRowFormat; |
|
269 | - } |
|
270 | - |
|
271 | - /** |
|
272 | - * Sets row cell content format. |
|
273 | - * |
|
274 | - * @return $this |
|
275 | - */ |
|
276 | - public function setCellRowContentFormat(string $cellRowContentFormat) |
|
277 | - { |
|
278 | - $this->cellRowContentFormat = $cellRowContentFormat; |
|
279 | - |
|
280 | - return $this; |
|
281 | - } |
|
282 | - |
|
283 | - /** |
|
284 | - * Gets row cell content format. |
|
285 | - * |
|
286 | - * @return string |
|
287 | - */ |
|
288 | - public function getCellRowContentFormat() |
|
289 | - { |
|
290 | - return $this->cellRowContentFormat; |
|
291 | - } |
|
292 | - |
|
293 | - /** |
|
294 | - * Sets table border format. |
|
295 | - * |
|
296 | - * @return $this |
|
297 | - */ |
|
298 | - public function setBorderFormat(string $borderFormat) |
|
299 | - { |
|
300 | - $this->borderFormat = $borderFormat; |
|
301 | - |
|
302 | - return $this; |
|
303 | - } |
|
304 | - |
|
305 | - /** |
|
306 | - * Gets table border format. |
|
307 | - * |
|
308 | - * @return string |
|
309 | - */ |
|
310 | - public function getBorderFormat() |
|
311 | - { |
|
312 | - return $this->borderFormat; |
|
313 | - } |
|
314 | - |
|
315 | - /** |
|
316 | - * Sets cell padding type. |
|
317 | - * |
|
318 | - * @return $this |
|
319 | - */ |
|
320 | - public function setPadType(int $padType) |
|
321 | - { |
|
322 | - if (!\in_array($padType, [\STR_PAD_LEFT, \STR_PAD_RIGHT, \STR_PAD_BOTH], true)) { |
|
323 | - throw new InvalidArgumentException('Invalid padding type. Expected one of (STR_PAD_LEFT, STR_PAD_RIGHT, STR_PAD_BOTH).'); |
|
324 | - } |
|
325 | - |
|
326 | - $this->padType = $padType; |
|
327 | - |
|
328 | - return $this; |
|
329 | - } |
|
330 | - |
|
331 | - /** |
|
332 | - * Gets cell padding type. |
|
333 | - * |
|
334 | - * @return int |
|
335 | - */ |
|
336 | - public function getPadType() |
|
337 | - { |
|
338 | - return $this->padType; |
|
339 | - } |
|
340 | - |
|
341 | - public function getHeaderTitleFormat(): string |
|
342 | - { |
|
343 | - return $this->headerTitleFormat; |
|
344 | - } |
|
345 | - |
|
346 | - public function setHeaderTitleFormat(string $format): self |
|
347 | - { |
|
348 | - $this->headerTitleFormat = $format; |
|
349 | - |
|
350 | - return $this; |
|
351 | - } |
|
352 | - |
|
353 | - public function getFooterTitleFormat(): string |
|
354 | - { |
|
355 | - return $this->footerTitleFormat; |
|
356 | - } |
|
357 | - |
|
358 | - public function setFooterTitleFormat(string $format): self |
|
359 | - { |
|
360 | - $this->footerTitleFormat = $format; |
|
361 | - |
|
362 | - return $this; |
|
363 | - } |
|
26 | + private $paddingChar = ' '; |
|
27 | + private $horizontalOutsideBorderChar = '-'; |
|
28 | + private $horizontalInsideBorderChar = '-'; |
|
29 | + private $verticalOutsideBorderChar = '|'; |
|
30 | + private $verticalInsideBorderChar = '|'; |
|
31 | + private $crossingChar = '+'; |
|
32 | + private $crossingTopRightChar = '+'; |
|
33 | + private $crossingTopMidChar = '+'; |
|
34 | + private $crossingTopLeftChar = '+'; |
|
35 | + private $crossingMidRightChar = '+'; |
|
36 | + private $crossingBottomRightChar = '+'; |
|
37 | + private $crossingBottomMidChar = '+'; |
|
38 | + private $crossingBottomLeftChar = '+'; |
|
39 | + private $crossingMidLeftChar = '+'; |
|
40 | + private $crossingTopLeftBottomChar = '+'; |
|
41 | + private $crossingTopMidBottomChar = '+'; |
|
42 | + private $crossingTopRightBottomChar = '+'; |
|
43 | + private $headerTitleFormat = '<fg=black;bg=white;options=bold> %s </>'; |
|
44 | + private $footerTitleFormat = '<fg=black;bg=white;options=bold> %s </>'; |
|
45 | + private $cellHeaderFormat = '<info>%s</info>'; |
|
46 | + private $cellRowFormat = '%s'; |
|
47 | + private $cellRowContentFormat = ' %s '; |
|
48 | + private $borderFormat = '%s'; |
|
49 | + private $padType = \STR_PAD_RIGHT; |
|
50 | + |
|
51 | + /** |
|
52 | + * Sets padding character, used for cell padding. |
|
53 | + * |
|
54 | + * @return $this |
|
55 | + */ |
|
56 | + public function setPaddingChar(string $paddingChar) |
|
57 | + { |
|
58 | + if (!$paddingChar) { |
|
59 | + throw new LogicException('The padding char must not be empty.'); |
|
60 | + } |
|
61 | + |
|
62 | + $this->paddingChar = $paddingChar; |
|
63 | + |
|
64 | + return $this; |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * Gets padding character, used for cell padding. |
|
69 | + * |
|
70 | + * @return string |
|
71 | + */ |
|
72 | + public function getPaddingChar() |
|
73 | + { |
|
74 | + return $this->paddingChar; |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Sets horizontal border characters. |
|
79 | + * |
|
80 | + * <code> |
|
81 | + * ╔═══════════════╤══════════════════════════╤══════════════════╗ |
|
82 | + * 1 ISBN 2 Title │ Author ║ |
|
83 | + * ╠═══════════════╪══════════════════════════╪══════════════════╣ |
|
84 | + * ║ 99921-58-10-7 │ Divine Comedy │ Dante Alighieri ║ |
|
85 | + * ║ 9971-5-0210-0 │ A Tale of Two Cities │ Charles Dickens ║ |
|
86 | + * ║ 960-425-059-0 │ The Lord of the Rings │ J. R. R. Tolkien ║ |
|
87 | + * ║ 80-902734-1-6 │ And Then There Were None │ Agatha Christie ║ |
|
88 | + * ╚═══════════════╧══════════════════════════╧══════════════════╝ |
|
89 | + * </code> |
|
90 | + */ |
|
91 | + public function setHorizontalBorderChars(string $outside, string $inside = null): self |
|
92 | + { |
|
93 | + $this->horizontalOutsideBorderChar = $outside; |
|
94 | + $this->horizontalInsideBorderChar = $inside ?? $outside; |
|
95 | + |
|
96 | + return $this; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Sets vertical border characters. |
|
101 | + * |
|
102 | + * <code> |
|
103 | + * ╔═══════════════╤══════════════════════════╤══════════════════╗ |
|
104 | + * ║ ISBN │ Title │ Author ║ |
|
105 | + * ╠═══════1═══════╪══════════════════════════╪══════════════════╣ |
|
106 | + * ║ 99921-58-10-7 │ Divine Comedy │ Dante Alighieri ║ |
|
107 | + * ║ 9971-5-0210-0 │ A Tale of Two Cities │ Charles Dickens ║ |
|
108 | + * ╟───────2───────┼──────────────────────────┼──────────────────╢ |
|
109 | + * ║ 960-425-059-0 │ The Lord of the Rings │ J. R. R. Tolkien ║ |
|
110 | + * ║ 80-902734-1-6 │ And Then There Were None │ Agatha Christie ║ |
|
111 | + * ╚═══════════════╧══════════════════════════╧══════════════════╝ |
|
112 | + * </code> |
|
113 | + */ |
|
114 | + public function setVerticalBorderChars(string $outside, string $inside = null): self |
|
115 | + { |
|
116 | + $this->verticalOutsideBorderChar = $outside; |
|
117 | + $this->verticalInsideBorderChar = $inside ?? $outside; |
|
118 | + |
|
119 | + return $this; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Gets border characters. |
|
124 | + * |
|
125 | + * @internal |
|
126 | + */ |
|
127 | + public function getBorderChars(): array |
|
128 | + { |
|
129 | + return [ |
|
130 | + $this->horizontalOutsideBorderChar, |
|
131 | + $this->verticalOutsideBorderChar, |
|
132 | + $this->horizontalInsideBorderChar, |
|
133 | + $this->verticalInsideBorderChar, |
|
134 | + ]; |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * Sets crossing characters. |
|
139 | + * |
|
140 | + * Example: |
|
141 | + * <code> |
|
142 | + * 1═══════════════2══════════════════════════2══════════════════3 |
|
143 | + * ║ ISBN │ Title │ Author ║ |
|
144 | + * 8'══════════════0'═════════════════════════0'═════════════════4' |
|
145 | + * ║ 99921-58-10-7 │ Divine Comedy │ Dante Alighieri ║ |
|
146 | + * ║ 9971-5-0210-0 │ A Tale of Two Cities │ Charles Dickens ║ |
|
147 | + * 8───────────────0──────────────────────────0──────────────────4 |
|
148 | + * ║ 960-425-059-0 │ The Lord of the Rings │ J. R. R. Tolkien ║ |
|
149 | + * ║ 80-902734-1-6 │ And Then There Were None │ Agatha Christie ║ |
|
150 | + * 7═══════════════6══════════════════════════6══════════════════5 |
|
151 | + * </code> |
|
152 | + * |
|
153 | + * @param string $cross Crossing char (see #0 of example) |
|
154 | + * @param string $topLeft Top left char (see #1 of example) |
|
155 | + * @param string $topMid Top mid char (see #2 of example) |
|
156 | + * @param string $topRight Top right char (see #3 of example) |
|
157 | + * @param string $midRight Mid right char (see #4 of example) |
|
158 | + * @param string $bottomRight Bottom right char (see #5 of example) |
|
159 | + * @param string $bottomMid Bottom mid char (see #6 of example) |
|
160 | + * @param string $bottomLeft Bottom left char (see #7 of example) |
|
161 | + * @param string $midLeft Mid left char (see #8 of example) |
|
162 | + * @param string|null $topLeftBottom Top left bottom char (see #8' of example), equals to $midLeft if null |
|
163 | + * @param string|null $topMidBottom Top mid bottom char (see #0' of example), equals to $cross if null |
|
164 | + * @param string|null $topRightBottom Top right bottom char (see #4' of example), equals to $midRight if null |
|
165 | + */ |
|
166 | + public function setCrossingChars(string $cross, string $topLeft, string $topMid, string $topRight, string $midRight, string $bottomRight, string $bottomMid, string $bottomLeft, string $midLeft, string $topLeftBottom = null, string $topMidBottom = null, string $topRightBottom = null): self |
|
167 | + { |
|
168 | + $this->crossingChar = $cross; |
|
169 | + $this->crossingTopLeftChar = $topLeft; |
|
170 | + $this->crossingTopMidChar = $topMid; |
|
171 | + $this->crossingTopRightChar = $topRight; |
|
172 | + $this->crossingMidRightChar = $midRight; |
|
173 | + $this->crossingBottomRightChar = $bottomRight; |
|
174 | + $this->crossingBottomMidChar = $bottomMid; |
|
175 | + $this->crossingBottomLeftChar = $bottomLeft; |
|
176 | + $this->crossingMidLeftChar = $midLeft; |
|
177 | + $this->crossingTopLeftBottomChar = $topLeftBottom ?? $midLeft; |
|
178 | + $this->crossingTopMidBottomChar = $topMidBottom ?? $cross; |
|
179 | + $this->crossingTopRightBottomChar = $topRightBottom ?? $midRight; |
|
180 | + |
|
181 | + return $this; |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * Sets default crossing character used for each cross. |
|
186 | + * |
|
187 | + * @see {@link setCrossingChars()} for setting each crossing individually. |
|
188 | + */ |
|
189 | + public function setDefaultCrossingChar(string $char): self |
|
190 | + { |
|
191 | + return $this->setCrossingChars($char, $char, $char, $char, $char, $char, $char, $char, $char); |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * Gets crossing character. |
|
196 | + * |
|
197 | + * @return string |
|
198 | + */ |
|
199 | + public function getCrossingChar() |
|
200 | + { |
|
201 | + return $this->crossingChar; |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Gets crossing characters. |
|
206 | + * |
|
207 | + * @internal |
|
208 | + */ |
|
209 | + public function getCrossingChars(): array |
|
210 | + { |
|
211 | + return [ |
|
212 | + $this->crossingChar, |
|
213 | + $this->crossingTopLeftChar, |
|
214 | + $this->crossingTopMidChar, |
|
215 | + $this->crossingTopRightChar, |
|
216 | + $this->crossingMidRightChar, |
|
217 | + $this->crossingBottomRightChar, |
|
218 | + $this->crossingBottomMidChar, |
|
219 | + $this->crossingBottomLeftChar, |
|
220 | + $this->crossingMidLeftChar, |
|
221 | + $this->crossingTopLeftBottomChar, |
|
222 | + $this->crossingTopMidBottomChar, |
|
223 | + $this->crossingTopRightBottomChar, |
|
224 | + ]; |
|
225 | + } |
|
226 | + |
|
227 | + /** |
|
228 | + * Sets header cell format. |
|
229 | + * |
|
230 | + * @return $this |
|
231 | + */ |
|
232 | + public function setCellHeaderFormat(string $cellHeaderFormat) |
|
233 | + { |
|
234 | + $this->cellHeaderFormat = $cellHeaderFormat; |
|
235 | + |
|
236 | + return $this; |
|
237 | + } |
|
238 | + |
|
239 | + /** |
|
240 | + * Gets header cell format. |
|
241 | + * |
|
242 | + * @return string |
|
243 | + */ |
|
244 | + public function getCellHeaderFormat() |
|
245 | + { |
|
246 | + return $this->cellHeaderFormat; |
|
247 | + } |
|
248 | + |
|
249 | + /** |
|
250 | + * Sets row cell format. |
|
251 | + * |
|
252 | + * @return $this |
|
253 | + */ |
|
254 | + public function setCellRowFormat(string $cellRowFormat) |
|
255 | + { |
|
256 | + $this->cellRowFormat = $cellRowFormat; |
|
257 | + |
|
258 | + return $this; |
|
259 | + } |
|
260 | + |
|
261 | + /** |
|
262 | + * Gets row cell format. |
|
263 | + * |
|
264 | + * @return string |
|
265 | + */ |
|
266 | + public function getCellRowFormat() |
|
267 | + { |
|
268 | + return $this->cellRowFormat; |
|
269 | + } |
|
270 | + |
|
271 | + /** |
|
272 | + * Sets row cell content format. |
|
273 | + * |
|
274 | + * @return $this |
|
275 | + */ |
|
276 | + public function setCellRowContentFormat(string $cellRowContentFormat) |
|
277 | + { |
|
278 | + $this->cellRowContentFormat = $cellRowContentFormat; |
|
279 | + |
|
280 | + return $this; |
|
281 | + } |
|
282 | + |
|
283 | + /** |
|
284 | + * Gets row cell content format. |
|
285 | + * |
|
286 | + * @return string |
|
287 | + */ |
|
288 | + public function getCellRowContentFormat() |
|
289 | + { |
|
290 | + return $this->cellRowContentFormat; |
|
291 | + } |
|
292 | + |
|
293 | + /** |
|
294 | + * Sets table border format. |
|
295 | + * |
|
296 | + * @return $this |
|
297 | + */ |
|
298 | + public function setBorderFormat(string $borderFormat) |
|
299 | + { |
|
300 | + $this->borderFormat = $borderFormat; |
|
301 | + |
|
302 | + return $this; |
|
303 | + } |
|
304 | + |
|
305 | + /** |
|
306 | + * Gets table border format. |
|
307 | + * |
|
308 | + * @return string |
|
309 | + */ |
|
310 | + public function getBorderFormat() |
|
311 | + { |
|
312 | + return $this->borderFormat; |
|
313 | + } |
|
314 | + |
|
315 | + /** |
|
316 | + * Sets cell padding type. |
|
317 | + * |
|
318 | + * @return $this |
|
319 | + */ |
|
320 | + public function setPadType(int $padType) |
|
321 | + { |
|
322 | + if (!\in_array($padType, [\STR_PAD_LEFT, \STR_PAD_RIGHT, \STR_PAD_BOTH], true)) { |
|
323 | + throw new InvalidArgumentException('Invalid padding type. Expected one of (STR_PAD_LEFT, STR_PAD_RIGHT, STR_PAD_BOTH).'); |
|
324 | + } |
|
325 | + |
|
326 | + $this->padType = $padType; |
|
327 | + |
|
328 | + return $this; |
|
329 | + } |
|
330 | + |
|
331 | + /** |
|
332 | + * Gets cell padding type. |
|
333 | + * |
|
334 | + * @return int |
|
335 | + */ |
|
336 | + public function getPadType() |
|
337 | + { |
|
338 | + return $this->padType; |
|
339 | + } |
|
340 | + |
|
341 | + public function getHeaderTitleFormat(): string |
|
342 | + { |
|
343 | + return $this->headerTitleFormat; |
|
344 | + } |
|
345 | + |
|
346 | + public function setHeaderTitleFormat(string $format): self |
|
347 | + { |
|
348 | + $this->headerTitleFormat = $format; |
|
349 | + |
|
350 | + return $this; |
|
351 | + } |
|
352 | + |
|
353 | + public function getFooterTitleFormat(): string |
|
354 | + { |
|
355 | + return $this->footerTitleFormat; |
|
356 | + } |
|
357 | + |
|
358 | + public function setFooterTitleFormat(string $format): self |
|
359 | + { |
|
360 | + $this->footerTitleFormat = $format; |
|
361 | + |
|
362 | + return $this; |
|
363 | + } |
|
364 | 364 | } |
@@ -53,10 +53,10 @@ discard block |
||
53 | 53 | * |
54 | 54 | * @return $this |
55 | 55 | */ |
56 | - public function setPaddingChar(string $paddingChar) |
|
56 | + public function setPaddingChar( string $paddingChar ) |
|
57 | 57 | { |
58 | - if (!$paddingChar) { |
|
59 | - throw new LogicException('The padding char must not be empty.'); |
|
58 | + if ( ! $paddingChar ) { |
|
59 | + throw new LogicException( 'The padding char must not be empty.' ); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | $this->paddingChar = $paddingChar; |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | * ╚═══════════════╧══════════════════════════╧══════════════════╝ |
89 | 89 | * </code> |
90 | 90 | */ |
91 | - public function setHorizontalBorderChars(string $outside, string $inside = null): self |
|
91 | + public function setHorizontalBorderChars( string $outside, string $inside = null ): self |
|
92 | 92 | { |
93 | 93 | $this->horizontalOutsideBorderChar = $outside; |
94 | 94 | $this->horizontalInsideBorderChar = $inside ?? $outside; |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | * ╚═══════════════╧══════════════════════════╧══════════════════╝ |
112 | 112 | * </code> |
113 | 113 | */ |
114 | - public function setVerticalBorderChars(string $outside, string $inside = null): self |
|
114 | + public function setVerticalBorderChars( string $outside, string $inside = null ): self |
|
115 | 115 | { |
116 | 116 | $this->verticalOutsideBorderChar = $outside; |
117 | 117 | $this->verticalInsideBorderChar = $inside ?? $outside; |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | * @param string|null $topMidBottom Top mid bottom char (see #0' of example), equals to $cross if null |
164 | 164 | * @param string|null $topRightBottom Top right bottom char (see #4' of example), equals to $midRight if null |
165 | 165 | */ |
166 | - public function setCrossingChars(string $cross, string $topLeft, string $topMid, string $topRight, string $midRight, string $bottomRight, string $bottomMid, string $bottomLeft, string $midLeft, string $topLeftBottom = null, string $topMidBottom = null, string $topRightBottom = null): self |
|
166 | + public function setCrossingChars( string $cross, string $topLeft, string $topMid, string $topRight, string $midRight, string $bottomRight, string $bottomMid, string $bottomLeft, string $midLeft, string $topLeftBottom = null, string $topMidBottom = null, string $topRightBottom = null ): self |
|
167 | 167 | { |
168 | 168 | $this->crossingChar = $cross; |
169 | 169 | $this->crossingTopLeftChar = $topLeft; |
@@ -186,9 +186,9 @@ discard block |
||
186 | 186 | * |
187 | 187 | * @see {@link setCrossingChars()} for setting each crossing individually. |
188 | 188 | */ |
189 | - public function setDefaultCrossingChar(string $char): self |
|
189 | + public function setDefaultCrossingChar( string $char ): self |
|
190 | 190 | { |
191 | - return $this->setCrossingChars($char, $char, $char, $char, $char, $char, $char, $char, $char); |
|
191 | + return $this->setCrossingChars( $char, $char, $char, $char, $char, $char, $char, $char, $char ); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | * |
230 | 230 | * @return $this |
231 | 231 | */ |
232 | - public function setCellHeaderFormat(string $cellHeaderFormat) |
|
232 | + public function setCellHeaderFormat( string $cellHeaderFormat ) |
|
233 | 233 | { |
234 | 234 | $this->cellHeaderFormat = $cellHeaderFormat; |
235 | 235 | |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | * |
252 | 252 | * @return $this |
253 | 253 | */ |
254 | - public function setCellRowFormat(string $cellRowFormat) |
|
254 | + public function setCellRowFormat( string $cellRowFormat ) |
|
255 | 255 | { |
256 | 256 | $this->cellRowFormat = $cellRowFormat; |
257 | 257 | |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | * |
274 | 274 | * @return $this |
275 | 275 | */ |
276 | - public function setCellRowContentFormat(string $cellRowContentFormat) |
|
276 | + public function setCellRowContentFormat( string $cellRowContentFormat ) |
|
277 | 277 | { |
278 | 278 | $this->cellRowContentFormat = $cellRowContentFormat; |
279 | 279 | |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | * |
296 | 296 | * @return $this |
297 | 297 | */ |
298 | - public function setBorderFormat(string $borderFormat) |
|
298 | + public function setBorderFormat( string $borderFormat ) |
|
299 | 299 | { |
300 | 300 | $this->borderFormat = $borderFormat; |
301 | 301 | |
@@ -317,10 +317,10 @@ discard block |
||
317 | 317 | * |
318 | 318 | * @return $this |
319 | 319 | */ |
320 | - public function setPadType(int $padType) |
|
320 | + public function setPadType( int $padType ) |
|
321 | 321 | { |
322 | - if (!\in_array($padType, [\STR_PAD_LEFT, \STR_PAD_RIGHT, \STR_PAD_BOTH], true)) { |
|
323 | - throw new InvalidArgumentException('Invalid padding type. Expected one of (STR_PAD_LEFT, STR_PAD_RIGHT, STR_PAD_BOTH).'); |
|
322 | + if ( ! \in_array( $padType, [ \STR_PAD_LEFT, \STR_PAD_RIGHT, \STR_PAD_BOTH ], true ) ) { |
|
323 | + throw new InvalidArgumentException( 'Invalid padding type. Expected one of (STR_PAD_LEFT, STR_PAD_RIGHT, STR_PAD_BOTH).' ); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | $this->padType = $padType; |
@@ -343,7 +343,7 @@ discard block |
||
343 | 343 | return $this->headerTitleFormat; |
344 | 344 | } |
345 | 345 | |
346 | - public function setHeaderTitleFormat(string $format): self |
|
346 | + public function setHeaderTitleFormat( string $format ): self |
|
347 | 347 | { |
348 | 348 | $this->headerTitleFormat = $format; |
349 | 349 | |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | return $this->footerTitleFormat; |
356 | 356 | } |
357 | 357 | |
358 | - public function setFooterTitleFormat(string $format): self |
|
358 | + public function setFooterTitleFormat( string $format ): self |
|
359 | 359 | { |
360 | 360 | $this->footerTitleFormat = $format; |
361 | 361 |
@@ -21,8 +21,7 @@ discard block |
||
21 | 21 | * @author Саша Стаменковић <[email protected]> |
22 | 22 | * @author Dany Maillard <[email protected]> |
23 | 23 | */ |
24 | -class TableStyle |
|
25 | -{ |
|
24 | +class TableStyle { |
|
26 | 25 | private $paddingChar = ' '; |
27 | 26 | private $horizontalOutsideBorderChar = '-'; |
28 | 27 | private $horizontalInsideBorderChar = '-'; |
@@ -53,8 +52,7 @@ discard block |
||
53 | 52 | * |
54 | 53 | * @return $this |
55 | 54 | */ |
56 | - public function setPaddingChar(string $paddingChar) |
|
57 | - { |
|
55 | + public function setPaddingChar(string $paddingChar) { |
|
58 | 56 | if (!$paddingChar) { |
59 | 57 | throw new LogicException('The padding char must not be empty.'); |
60 | 58 | } |
@@ -69,8 +67,7 @@ discard block |
||
69 | 67 | * |
70 | 68 | * @return string |
71 | 69 | */ |
72 | - public function getPaddingChar() |
|
73 | - { |
|
70 | + public function getPaddingChar() { |
|
74 | 71 | return $this->paddingChar; |
75 | 72 | } |
76 | 73 | |
@@ -196,8 +193,7 @@ discard block |
||
196 | 193 | * |
197 | 194 | * @return string |
198 | 195 | */ |
199 | - public function getCrossingChar() |
|
200 | - { |
|
196 | + public function getCrossingChar() { |
|
201 | 197 | return $this->crossingChar; |
202 | 198 | } |
203 | 199 | |
@@ -229,8 +225,7 @@ discard block |
||
229 | 225 | * |
230 | 226 | * @return $this |
231 | 227 | */ |
232 | - public function setCellHeaderFormat(string $cellHeaderFormat) |
|
233 | - { |
|
228 | + public function setCellHeaderFormat(string $cellHeaderFormat) { |
|
234 | 229 | $this->cellHeaderFormat = $cellHeaderFormat; |
235 | 230 | |
236 | 231 | return $this; |
@@ -241,8 +236,7 @@ discard block |
||
241 | 236 | * |
242 | 237 | * @return string |
243 | 238 | */ |
244 | - public function getCellHeaderFormat() |
|
245 | - { |
|
239 | + public function getCellHeaderFormat() { |
|
246 | 240 | return $this->cellHeaderFormat; |
247 | 241 | } |
248 | 242 | |
@@ -251,8 +245,7 @@ discard block |
||
251 | 245 | * |
252 | 246 | * @return $this |
253 | 247 | */ |
254 | - public function setCellRowFormat(string $cellRowFormat) |
|
255 | - { |
|
248 | + public function setCellRowFormat(string $cellRowFormat) { |
|
256 | 249 | $this->cellRowFormat = $cellRowFormat; |
257 | 250 | |
258 | 251 | return $this; |
@@ -263,8 +256,7 @@ discard block |
||
263 | 256 | * |
264 | 257 | * @return string |
265 | 258 | */ |
266 | - public function getCellRowFormat() |
|
267 | - { |
|
259 | + public function getCellRowFormat() { |
|
268 | 260 | return $this->cellRowFormat; |
269 | 261 | } |
270 | 262 | |
@@ -273,8 +265,7 @@ discard block |
||
273 | 265 | * |
274 | 266 | * @return $this |
275 | 267 | */ |
276 | - public function setCellRowContentFormat(string $cellRowContentFormat) |
|
277 | - { |
|
268 | + public function setCellRowContentFormat(string $cellRowContentFormat) { |
|
278 | 269 | $this->cellRowContentFormat = $cellRowContentFormat; |
279 | 270 | |
280 | 271 | return $this; |
@@ -285,8 +276,7 @@ discard block |
||
285 | 276 | * |
286 | 277 | * @return string |
287 | 278 | */ |
288 | - public function getCellRowContentFormat() |
|
289 | - { |
|
279 | + public function getCellRowContentFormat() { |
|
290 | 280 | return $this->cellRowContentFormat; |
291 | 281 | } |
292 | 282 | |
@@ -295,8 +285,7 @@ discard block |
||
295 | 285 | * |
296 | 286 | * @return $this |
297 | 287 | */ |
298 | - public function setBorderFormat(string $borderFormat) |
|
299 | - { |
|
288 | + public function setBorderFormat(string $borderFormat) { |
|
300 | 289 | $this->borderFormat = $borderFormat; |
301 | 290 | |
302 | 291 | return $this; |
@@ -307,8 +296,7 @@ discard block |
||
307 | 296 | * |
308 | 297 | * @return string |
309 | 298 | */ |
310 | - public function getBorderFormat() |
|
311 | - { |
|
299 | + public function getBorderFormat() { |
|
312 | 300 | return $this->borderFormat; |
313 | 301 | } |
314 | 302 | |
@@ -317,8 +305,7 @@ discard block |
||
317 | 305 | * |
318 | 306 | * @return $this |
319 | 307 | */ |
320 | - public function setPadType(int $padType) |
|
321 | - { |
|
308 | + public function setPadType(int $padType) { |
|
322 | 309 | if (!\in_array($padType, [\STR_PAD_LEFT, \STR_PAD_RIGHT, \STR_PAD_BOTH], true)) { |
323 | 310 | throw new InvalidArgumentException('Invalid padding type. Expected one of (STR_PAD_LEFT, STR_PAD_RIGHT, STR_PAD_BOTH).'); |
324 | 311 | } |
@@ -333,8 +320,7 @@ discard block |
||
333 | 320 | * |
334 | 321 | * @return int |
335 | 322 | */ |
336 | - public function getPadType() |
|
337 | - { |
|
323 | + public function getPadType() { |
|
338 | 324 | return $this->padType; |
339 | 325 | } |
340 | 326 |