Conditions | 30 |
Paths | > 20000 |
Total Lines | 100 |
Code Lines | 75 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
50 | public function __construct(SplFileInfo $fileInfo) |
||
51 | { |
||
52 | parent::__construct('SplFileInfo'); |
||
53 | |||
54 | if ($fileInfo->getRealPath()) { |
||
55 | $this->realpath = $fileInfo->getRealPath(); |
||
56 | $this->perms = $fileInfo->getPerms(); |
||
57 | $this->size = $fileInfo->getSize(); |
||
58 | $this->owner = $fileInfo->getOwner(); |
||
59 | $this->group = $fileInfo->getGroup(); |
||
60 | $this->ctime = $fileInfo->getCTime(); |
||
61 | $this->mtime = $fileInfo->getMTime(); |
||
62 | } |
||
63 | |||
64 | $this->path = $fileInfo->getPathname(); |
||
65 | |||
66 | $this->is_dir = $fileInfo->isDir(); |
||
67 | $this->is_file = $fileInfo->isFile(); |
||
68 | $this->is_link = $fileInfo->isLink(); |
||
69 | |||
70 | if ($this->is_link) { |
||
71 | $this->linktarget = $fileInfo->getLinkTarget(); |
||
72 | } |
||
73 | |||
74 | switch ($this->perms & 0xF000) { |
||
75 | case 0xC000: |
||
76 | $this->typename = 'Socket'; |
||
77 | $this->typeflag = 's'; |
||
78 | break; |
||
79 | case 0x6000: |
||
80 | $this->typename = 'Block device'; |
||
81 | $this->typeflag = 'b'; |
||
82 | break; |
||
83 | case 0x2000: |
||
84 | $this->typename = 'Character device'; |
||
85 | $this->typeflag = 'c'; |
||
86 | break; |
||
87 | case 0x1000: |
||
88 | $this->typename = 'Named pipe'; |
||
89 | $this->typeflag = 'p'; |
||
90 | break; |
||
91 | default: |
||
92 | if ($this->is_file) { |
||
93 | if ($this->is_link) { |
||
94 | $this->typename = 'File symlink'; |
||
95 | $this->typeflag = 'l'; |
||
96 | } else { |
||
97 | $this->typename = 'File'; |
||
98 | $this->typeflag = '-'; |
||
99 | } |
||
100 | } elseif ($this->is_dir) { |
||
101 | if ($this->is_link) { |
||
102 | $this->typename = 'Directory symlink'; |
||
103 | $this->typeflag = 'l'; |
||
104 | } else { |
||
105 | $this->typename = 'Directory'; |
||
106 | $this->typeflag = 'd'; |
||
107 | } |
||
108 | } |
||
109 | break; |
||
110 | } |
||
111 | |||
112 | $this->flags = array($this->typeflag); |
||
113 | |||
114 | // User |
||
115 | $this->flags[] = (($this->perms & 0400) ? 'r' : '-'); |
||
116 | $this->flags[] = (($this->perms & 0200) ? 'w' : '-'); |
||
117 | if ($this->perms & 0100) { |
||
118 | $this->flags[] = ($this->perms & 04000) ? 's' : 'x'; |
||
119 | } else { |
||
120 | $this->flags[] = ($this->perms & 04000) ? 'S' : '-'; |
||
121 | } |
||
122 | |||
123 | // Group |
||
124 | $this->flags[] = (($this->perms & 0040) ? 'r' : '-'); |
||
125 | $this->flags[] = (($this->perms & 0020) ? 'w' : '-'); |
||
126 | if ($this->perms & 0010) { |
||
127 | $this->flags[] = ($this->perms & 02000) ? 's' : 'x'; |
||
128 | } else { |
||
129 | $this->flags[] = ($this->perms & 02000) ? 'S' : '-'; |
||
130 | } |
||
131 | |||
132 | // Other |
||
133 | $this->flags[] = (($this->perms & 0004) ? 'r' : '-'); |
||
134 | $this->flags[] = (($this->perms & 0002) ? 'w' : '-'); |
||
135 | if ($this->perms & 0001) { |
||
136 | $this->flags[] = ($this->perms & 01000) ? 's' : 'x'; |
||
137 | } else { |
||
138 | $this->flags[] = ($this->perms & 01000) ? 'S' : '-'; |
||
139 | } |
||
140 | |||
141 | $this->contents = \implode($this->flags).' '.$this->owner.' '.$this->group; |
||
142 | $this->contents .= ' '.$this->getSize().' '.$this->getMTime().' '; |
||
143 | |||
144 | if ($this->is_link && $this->linktarget) { |
||
145 | $this->contents .= $this->path.' -> '.$this->linktarget; |
||
146 | } elseif (null !== $this->realpath && \strlen($this->realpath) < \strlen($this->path)) { |
||
147 | $this->contents .= $this->realpath; |
||
148 | } else { |
||
149 | $this->contents .= $this->path; |
||
150 | } |
||
178 |