Kint_Object_Representation_SplFileInfo::getMTime()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 0
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
class Kint_Object_Representation_SplFileInfo extends Kint_Object_Representation
0 ignored issues
show
Coding Style introduced by
Kint_Object_Representation_SplFileInfo does not seem to conform to the naming convention (^[A-Z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Coding Style introduced by
The property $is_dir is not named in camelCase.

This check marks property names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
Coding Style introduced by
The property $is_file is not named in camelCase.

This check marks property names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
Coding Style introduced by
The property $is_link is not named in camelCase.

This check marks property names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
4
{
5
    public $perms = null;
6
    public $flags = null;
7
    public $path = null;
8
    public $realpath = null;
9
    public $linktarget = null;
10
    public $size = null;
11
    public $is_dir = false;
0 ignored issues
show
Coding Style introduced by
$is_dir does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
12
    public $is_file = false;
0 ignored issues
show
Coding Style introduced by
$is_file does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
13
    public $is_link = false;
0 ignored issues
show
Coding Style introduced by
$is_link does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
14
    public $owner = null;
15
    public $group = null;
16
    public $ctime = null;
17
    public $mtime = null;
18
    public $typename = 'Unknown file';
19
    public $typeflag = '-';
20
    public $hints = array('fspath');
21
22
    public function __construct(SplFileInfo $fileInfo)
23
    {
24
        if (!file_exists($fileInfo->getPathname())) {
25
            return;
26
        }
27
28
        $this->perms = $fileInfo->getPerms();
29
        $this->size = $fileInfo->getSize();
30
        $this->is_dir = $fileInfo->isDir();
31
        $this->is_file = $fileInfo->isFile();
32
        $this->is_link = $fileInfo->isLink();
33
        $this->owner = $fileInfo->getOwner();
34
        $this->group = $fileInfo->getGroup();
35
        $this->ctime = $fileInfo->getCTime();
36
        $this->mtime = $fileInfo->getMTime();
37
38
        if (($this->perms & 0xC000) === 0xC000) {
39
            $this->typename = 'File socket';
40
            $this->typeflag = 's';
41
        } elseif ($this->is_file) {
42
            if ($this->is_link) {
43
                $this->typename = 'File symlink';
44
                $this->typeflag = 'l';
45
            } else {
46
                $this->typename = 'File';
47
                $this->typeflag = '-';
48
            }
49
        } elseif (($this->perms & 0x6000) === 0x6000) {
50
            $this->typename = 'Block special file';
51
            $this->typeflag = 'b';
52
        } elseif ($this->is_dir) {
53
            if ($this->is_link) {
54
                $this->typename = 'Directory symlink';
55
                $this->typeflag = 'l';
56
            } else {
57
                $this->typename = 'Directory';
58
                $this->typeflag = 'd';
59
            }
60
        } elseif (($this->perms & 0x2000) === 0x2000) {
61
            $this->typename = 'Character special file';
62
            $this->typeflag = 'c';
63
        } elseif (($this->perms & 0x1000) === 0x1000) {
64
            $this->typename = 'FIFO pipe file';
65
            $this->typeflag = 'p';
66
        }
67
68
        parent::__construct('SplFileInfo');
69
70
        $this->path = $fileInfo->getPathname();
71
        $this->realpath = realpath($this->path);
72
73
        if ($this->is_link && method_exists($fileInfo, 'getLinktarget')) {
74
            $this->linktarget = $fileInfo->getLinktarget();
75
        }
76
77
        $this->flags = array($this->typeflag);
78
79
        // User
80
        $this->flags[] = (($this->perms & 0400) ? 'r' : '-');
81
        $this->flags[] = (($this->perms & 0200) ? 'w' : '-');
82
        $this->flags[] = (($this->perms & 0100) ? (($this->perms & 04000) ? 's' : 'x') : (($this->perms & 04000) ? 'S' : '-'));
83
84
        // Group
85
        $this->flags[] = (($this->perms & 0040) ? 'r' : '-');
86
        $this->flags[] = (($this->perms & 0020) ? 'w' : '-');
87
        $this->flags[] = (($this->perms & 0010) ? (($this->perms & 02000) ? 's' : 'x') : (($this->perms & 02000) ? 'S' : '-'));
88
89
        // Other
90
        $this->flags[] = (($this->perms & 0004) ? 'r' : '-');
91
        $this->flags[] = (($this->perms & 0002) ? 'w' : '-');
92
        $this->flags[] = (($this->perms & 0001) ? (($this->perms & 01000) ? 't' : 'x') : (($this->perms & 01000) ? 'T' : '-'));
93
94
        $this->contents = implode($this->flags).' '.$this->owner.' '.$this->group.' '.$this->getSize().' '.$this->getMTime().' ';
0 ignored issues
show
Documentation Bug introduced by
It seems like implode($this->flags) . ...$this->getMTime() . ' ' of type string is incompatible with the declared type array of property $contents.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
95
96
        if ($this->is_link && $this->linktarget) {
97
            $this->contents .= $this->path.' -> '.$this->linktarget;
98
        } elseif (strlen($this->realpath) < strlen($this->path)) {
99
            $this->contents .= $this->realpath;
100
        } else {
101
            $this->contents .= $this->path;
102
        }
103
    }
104
105
    public function getLabel()
106
    {
107
        return $this->typename.' ('.$this->getSize().')';
108
    }
109
110
    public function getSize()
111
    {
112
        static $unit = array('B', 'KB', 'MB', 'GB', 'TB');
113
114
        $size = $this->size;
115
116
        if ($this->size) {
117
            $i = floor(log($this->size, 1024));
118
            $size = round($this->size / pow(1024, $i), 2).$unit[$i];
119
        }
120
121
        return $size;
122
    }
123
124
    public function getMTime()
125
    {
126
        $year = date('Y', $this->mtime);
127
128
        if ($year !== date('Y')) {
129
            return date('M d Y', $this->mtime);
130
        } else {
131
            return date('M d H:i', $this->mtime);
132
        }
133
    }
134
}
135