Passed
Push — master ( 495329...2abeff )
by Daniel
17:26 queued 12s
created

HomeCache::calculateFolderSize()   B

Complexity

Conditions 8
Paths 3

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 8
eloc 6
c 1
b 1
f 0
nc 3
nop 2
dl 0
loc 8
rs 8.4444
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 *
5
 * @author Andreas Fischer <[email protected]>
6
 * @author Björn Schießle <[email protected]>
7
 * @author Christoph Wurst <[email protected]>
8
 * @author Joas Schilling <[email protected]>
9
 * @author Jörn Friedrich Dreyer <[email protected]>
10
 * @author Morris Jobke <[email protected]>
11
 * @author Robin Appelman <[email protected]>
12
 * @author Vincent Petry <[email protected]>
13
 *
14
 * @license AGPL-3.0
15
 *
16
 * This code is free software: you can redistribute it and/or modify
17
 * it under the terms of the GNU Affero General Public License, version 3,
18
 * as published by the Free Software Foundation.
19
 *
20
 * This program is distributed in the hope that it will be useful,
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
 * GNU Affero General Public License for more details.
24
 *
25
 * You should have received a copy of the GNU Affero General Public License, version 3,
26
 * along with this program. If not, see <http://www.gnu.org/licenses/>
27
 *
28
 */
29
namespace OC\Files\Cache;
30
31
use OCP\Files\Cache\ICacheEntry;
32
33
class HomeCache extends Cache {
34
	/**
35
	 * get the size of a folder and set it in the cache
36
	 *
37
	 * @param string $path
38
	 * @param array|null|ICacheEntry $entry (optional) meta data of the folder
39
	 * @return int
40
	 */
41
	public function calculateFolderSize($path, $entry = null) {
42
		if ($path !== '/' and $path !== '' and $path !== 'files' and $path !== 'files_trashbin' and $path !== 'files_versions') {
43
			return parent::calculateFolderSize($path, $entry);
44
		} elseif ($path === '' or $path === '/') {
45
			// since the size of / isn't used (the size of /files is used instead) there is no use in calculating it
46
			return 0;
47
		} else {
48
			return $this->calculateFolderSizeInner($path, $entry, true);
49
		}
50
	}
51
52
	/**
53
	 * @param string $file
54
	 * @return ICacheEntry
55
	 */
56
	public function get($file) {
57
		$data = parent::get($file);
58
		if ($file === '' or $file === '/') {
59
			// only the size of the "files" dir counts
60
			$filesData = parent::get('files');
61
62
			if (isset($filesData['size'])) {
63
				$data['size'] = $filesData['size'];
64
			}
65
		}
66
		return $data;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $data could also return false which is incompatible with the documented return type OCP\Files\Cache\ICacheEntry. Did you maybe forget to handle an error condition?

If the returned type also contains false, it is an indicator that maybe an error condition leading to the specific return statement remains unhandled.

Loading history...
67
	}
68
}
69