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

SizeHelper   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 47
ccs 23
cts 23
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
B formatSize() 0 27 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