Completed
Push — master ( 2076b7...2510e5 )
by Afshin
02:23
created

getImageFileName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 3
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
function getDirFiles($path)
4
{
5
    $dir = scandir($path);
6
    $ex_folders = array('..', '.');
7
8
    return array_diff($dir,$ex_folders);
9
}
10
11
/*folder*/
12
function getImageDirName($photoid, $type = 'user_photo' ,$collectionNum =1000)
13
{
14
    $folderName = null;
15
    switch ($type) {
16
        case 'user_photo':
17
            $folderName = (int) ($photoid / $collectionNum);
18
            $folderName++;
19
            $dir = 'user_photo/'.$folderName.'/';
20
            break;
21
    }
22
23
    if ($folderName) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $folderName of type null|integer is loosely compared to true; this is ambiguous if the integer can be 0. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
24
        $folderName = $dir;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $dir does not seem to be defined for all execution paths leading up to this point.
Loading history...
25
    }
26
27
    return $folderName;
28
}
29
30
function getImageFileName($photoid,$fileType='l',$type='user_photo')
31
{
32
    $fileName = null;
33
34
    switch ($type) {
35
        case 'user_photo':
36
            $fileName = 'user'.(int)$photoid.'-'.$fileType;
37
        break;
38
    }
39
40
41
    return $fileName;
42
}