Completed
Push — v5 ( 9120d0...3fd0ee )
by Georges
02:35
created

Directory::dirSize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 2
eloc 5
c 1
b 1
f 0
nc 2
nop 1
dl 0
loc 9
rs 9.6666
1
<?php
2
/**
3
 *
4
 * This file is part of phpFastCache.
5
 *
6
 * @license MIT License (MIT)
7
 *
8
 * For full copyright and license information, please see the docs/CREDITS.txt file.
9
 *
10
 * @author Khoa Bui (khoaofgod)  <[email protected]> http://www.phpfastcache.com
11
 * @author Georges.L (Geolim4)  <[email protected]>
12
 *
13
 */
14
namespace phpFastCache\Util;
15
16
17
class Directory
18
{
19
    /**
20
     * Get the directory size
21
     * @param string $directory
22
     * @return integer
23
     */
24
    public static function dirSize($directory)
25
    {
26
        $size = 0;
27
        foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory)) as $file) {
28
            $size += $file->getSize();
29
        }
30
31
        return $size;
32
    }
33
34
    /**
35
     * @param string $path
36
     * @return int
37
     */
38
    public static function getFileCount($path)
39
    {
40
        $count = 0;
41
        $objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path), \RecursiveIteratorIterator::SELF_FIRST);
42
        foreach($objects as $name => $object){
43
            /**
44
             * @var \SplFileInfo $object
45
             */
46
            if($object->isFile())
47
            {
48
                $count++;
49
            }
50
        }
51
        return $count;
52
    }
53
}