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

Directory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 37
rs 10
wmc 5
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A dirSize() 0 9 2
A getFileCount() 0 15 3
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
}