GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

FileModifiedChecker::__construct()   B
last analyzed

Complexity

Conditions 10
Paths 27

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 24.1991

Importance

Changes 0
Metric Value
cc 10
nc 27
nop 1
dl 0
loc 27
ccs 11
cts 23
cp 0.4783
crap 24.1991
rs 7.6666
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
namespace PhpBoot\Cache;
3
4
/**
5
 * 检查文件是否过期
6
 * @author caoym
7
 */
8
class FileModifiedChecker
9
{
10
    /**
11
     * @param string|array $fileName 文件的绝对路径
12
     */
13 21
    function __construct($fileName){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
14 21
        $fileNames = array();
15 21
        if(is_string($fileName)){
16
            $fileNames[]=$fileName;
17
        }else{
18 21
            is_array($fileName) or \PhpBoot\abort(new \InvalidArgumentException("string or array is required by param 0"));
19 21
            $fileNames = $fileName;
20
        }
21 21
        foreach ($fileNames as $fileName){
22 21
            if(is_file($fileName)){
23 21
                $this->fileName[$fileName] = @filemtime($fileName);
24 21
            }else {
25
                $this->fileName[$fileName] = @filemtime($fileName);
26
                if(!is_dir($fileName)){
27
                    continue;
28
                }
29
                $files = @dir($fileName) or \PhpBoot\abort("open dir $fileName failed");
30
                while (!!($file = $files->read())){
31
                    if($file == '.' || $file == '..') {
32
                        continue;
33
                    }
34
                    $this->fileName[$fileName.'/'.$file] = @filemtime($fileName.'/'.$file);
35
                }
36
                $files->close();
37
            }
38 21
        }
39 21
    }
40
    /**
41
     * 判断是否过期
42
     * @param mixed $data 从缓存中得到的数据
43
     * @param int $createdTime
44
     * @return boolean
45
     */
46 74
    public function __invoke($data, $createdTime){
47 74
        foreach ($this->fileName as $name => $time){
48 74
            if(@filemtime($name) != $time){
49
                return false;
50
            }
51 74
        }
52 74
        return true;
53
    }
54
    private $fileName=[]; //文件全路径
55
}
56