Failed Conditions
Push — master ( c1c7d6...c5e998 )
by Alexander
03:04
created

OutputHelper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 41
ccs 14
cts 14
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
A formatArray() 0 19 4
1
<?php
2
/**
3
 * This file is part of the SVN-Buddy library.
4
 * For the full copyright and license information, please view
5
 * the LICENSE file that was distributed with this source code.
6
 *
7
 * @copyright Alexander Obuhovich <[email protected]>
8
 * @link      https://github.com/console-helpers/svn-buddy
9
 */
10
11
namespace ConsoleHelpers\SVNBuddy\Helper;
12
13
14
use Symfony\Component\Console\Helper\Helper;
15
16
class OutputHelper extends Helper
17
{
18
19
	/**
20
	 * {@inheritdoc}
0 ignored issues
show
introduced by
Doc comment short description must start with a capital letter
Loading history...
21
	 */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
22 1
	public function getName()
23
	{
24 1
		return 'output';
25
	}
26
27
	/**
28
	 * Returns formatted list of records.
29
	 *
30
	 * @param array       $items         List of items.
31
	 * @param integer     $items_per_row Number of bugs displayed per row.
32
	 * @param string|null $color         Color.
33
	 *
34
	 * @return string
35
	 */
36 6
	public function formatArray(array $items, $items_per_row, $color = null)
37
	{
38 6
		$items_chunks = array_chunk($items, $items_per_row);
39
40 6
		$ret = array();
41
42 6
		if ( isset($color) ) {
43 3
			foreach ( $items_chunks as $item_chunk ) {
44 3
				$ret[] = '<fg=' . $color . '>' . implode('</>, <fg=' . $color . '>', $item_chunk) . '</>';
45 3
			}
46 3
		}
47
		else {
48 3
			foreach ( $items_chunks as $item_chunk ) {
49 3
				$ret[] = implode(', ', $item_chunk);
50 3
			}
51
		}
52
53 6
		return implode(',' . PHP_EOL, $ret);
54
	}
55
56
}
57