2
I am developing a class to assist multiple upload using the codeigniter and I decided to analyze my code using some online tools.
One of them was the code Climate; I noticed that when checking reports for code improvement it informs that it is not recommended to use superglobals such as $_FILES
even in specific functions for validation such as;
public function hasFile($key)
{
if (!isset($_FILES[$key]) {
throw new Exception("Não existe o indice $key", 1);
}
return TRUE;
}
I tried to modify this by creating an attribute called key
public $key = 'userFile';
And call you within the duties
if (!isset($_FILES[$this->key]) {.....
But I keep getting the report that this is not a good practice! I also looked in the PHP documentation if there is any type of filter for superglobal $_FILES
using the function filter_input
and I haven’t found.
What would be the best way to validate the superglobal $_FILES
?
print of the report;
In the function in question I do not attribute the super-global to any variable, I only perform the validation as shown above.
Possible duplicate of Get external variable isset vs filter_input
– Jorge B.
@Jorgeb. is not a duplicate, because the context is different, I’m not questioning the use of
isset
orfilter_input
is a method to validate the superglobal$_FILES
which in turn does not have afilter_input
.– RFL
You’re absolutely right. I forgot it doesn’t work for
$_FILES
.– Jorge B.
@rray added.
– RFL
It is the Codeclimate that sends the warning?
– Guilherme Nascimento
@Guillhermenascimento yes.
– RFL
I talked to the bigown and Wallace in the chat today, I think "good practice" is not "rule", it’s more like "tip". Of course this is my opinion :)
– Guilherme Nascimento