Conditions | 12 |
Paths | 7 |
Total Lines | 76 |
Code Lines | 51 |
Lines | 22 |
Ratio | 28.95 % |
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 |
||
72 | public function check() |
||
73 | { |
||
74 | $origStage = Versioned::get_reading_mode(); |
||
75 | Versioned::set_reading_mode('Live'); |
||
76 | |||
77 | $files = $this->getFiles(); |
||
78 | if ($files) { |
||
79 | $fileTypeValidateFunc = $this->fileTypeValidateFunc; |
||
80 | if (method_exists($this, $fileTypeValidateFunc)) { |
||
81 | $invalidFiles = array(); |
||
82 | $validFiles = array(); |
||
83 | |||
84 | foreach ($files as $file) { |
||
85 | if ($this->$fileTypeValidateFunc($file)) { |
||
86 | $validFiles[] = $file; |
||
87 | } else { |
||
88 | $invalidFiles[] = $file; |
||
89 | } |
||
90 | } |
||
91 | |||
92 | // If at least one file was valid, count as passed |
||
93 | if ($this->checkType == self::CHECK_SINGLE && count($invalidFiles) < count($files)) { |
||
94 | $validFileList = "\n"; |
||
95 | foreach ($validFiles as $vf) { |
||
96 | $validFileList .= $vf."\n"; |
||
97 | } |
||
98 | View Code Duplication | if ($fileTypeValidateFunc == 'noVidation') { |
|
99 | $checkReturn = array( |
||
100 | EnvironmentCheck::OK, |
||
101 | sprintf('At least these file(s) accessible: %s', $validFileList) |
||
102 | ); |
||
103 | } else { |
||
104 | $checkReturn = array( |
||
105 | EnvironmentCheck::OK, |
||
106 | sprintf('At least these file(s) passed file type validate function "%s": %s', $fileTypeValidateFunc, $validFileList) |
||
107 | ); |
||
108 | } |
||
109 | } else { |
||
110 | if (count($invalidFiles) == 0) { |
||
111 | $checkReturn = array(EnvironmentCheck::OK, 'All files valideted'); |
||
112 | } else { |
||
113 | $invalidFileList = "\n"; |
||
114 | foreach ($invalidFiles as $vf) { |
||
115 | $invalidFileList .= $vf."\n"; |
||
116 | } |
||
117 | |||
118 | View Code Duplication | if ($fileTypeValidateFunc == 'noVidation') { |
|
119 | $checkReturn = array( |
||
120 | EnvironmentCheck::ERROR, |
||
121 | sprintf('File(s) not accessible: %s', $invalidFileList) |
||
122 | ); |
||
123 | } else { |
||
124 | $checkReturn = array( |
||
125 | EnvironmentCheck::ERROR, |
||
126 | sprintf('File(s) not passing the file type validate function "%s": %s', $fileTypeValidateFunc, $invalidFileList) |
||
127 | ); |
||
128 | } |
||
129 | } |
||
130 | } |
||
131 | } else { |
||
132 | $checkReturn = array( |
||
133 | EnvironmentCheck::ERROR, |
||
134 | sprintf("Invalid file type validation method name passed: %s ", $fileTypeValidateFunc) |
||
135 | ); |
||
136 | } |
||
137 | } else { |
||
138 | $checkReturn = array( |
||
139 | EnvironmentCheck::ERROR, |
||
140 | sprintf("No files accessible at path %s", $this->path) |
||
141 | ); |
||
142 | } |
||
143 | |||
144 | Versioned::set_reading_mode($origStage); |
||
145 | |||
146 | return $checkReturn; |
||
147 | } |
||
148 | |||
184 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.