MaxFolderSizeValidator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 4
Bugs 0 Features 2
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 27
rs 10
c 4
b 0
f 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validateMaxSize() 0 9 1
A getDirSize() 0 9 2
1
<?php namespace Modules\Media\Validators;
2
3
use Illuminate\Validation\Validator;
4
use RecursiveDirectoryIterator;
5
use RecursiveIteratorIterator;
6
use Symfony\Component\HttpFoundation\File\UploadedFile;
7
8
class MaxFolderSizeValidator extends Validator
9
{
10
    public function validateMaxSize($attribute, UploadedFile $value, $parameters)
0 ignored issues
show
Unused Code introduced by
The parameter $attribute is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $parameters is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
11
    {
12
        $mediaPath = public_path(config('asgard.media.config.files-path'));
13
        $folderSize = $this->getDirSize($mediaPath);
14
15
        preg_match('/([0-9]+)/', $folderSize, $match);
16
17
        return ($match[0] + $value->getSize()) < config('asgard.media.config.max-total-size');
18
    }
19
20
    /**
21
    * Get the directory size
22
    * @param string $directory
23
    * @return int
24
    */
25
    public function getDirSize($directory)
26
    {
27
        $size = 0;
28
        foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)) as $file) {
29
            $size += $file->getSize();
30
        }
31
32
        return $size;
33
    }
34
}
35