Failed Conditions
Push — master ( 830d2d...99bc8c )
by Alexander
02:52
created

SizeHelper::formatSize()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 27
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 21
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 27
ccs 21
cts 21
cp 1
rs 8.439
cc 5
eloc 18
nc 5
nop 1
crap 5
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 SizeHelper extends Helper
17
{
18
19
	/**
20
	 * {@inheritdoc}
1 ignored issue
show
introduced by
Doc comment short description must start with a capital letter
Loading history...
21
	 */
1 ignored issue
show
introduced by
Missing @return tag in function comment
Loading history...
22 1
	public function getName()
23
	{
24 1
		return 'size';
25
	}
26
27
	/**
28
	 * Formats file/memory size in nice way
29
	 *
30
	 * @param integer $bytes Bytes.
31
	 *
32
	 * @return string
33
	 */
34 5
	public function formatSize($bytes)
35
	{
36 5
		if ( $bytes >= 1099511627776 ) {
37 1
			$return = round($bytes / 1024 / 1024 / 1024 / 1024, 2);
38 1
			$suffix = 'TB';
39 1
		}
40 4
		elseif ( $bytes >= 1073741824 ) {
41 1
			$return = round($bytes / 1024 / 1024 / 1024, 2);
42 1
			$suffix = 'GB';
43 1
		}
44 3
		elseif ( $bytes >= 1048576 ) {
45 1
			$return = round($bytes / 1024 / 1024, 2);
46 1
			$suffix = 'MB';
47 1
		}
48 2
		elseif ( $bytes >= 1024 ) {
49 1
			$return = round($bytes / 1024, 2);
50 1
			$suffix = 'KB';
51 1
		}
52
		else {
53 1
			$return = $bytes;
54 1
			$suffix = 'Byte';
55
		}
56
57 5
		$return .= ' ' . $suffix;
58
59 5
		return $return;
60
	}
61
62
}
63