laminas-validator icon indicating copy to clipboard operation
laminas-validator copied to clipboard

Documentation for GpsPoint is missing

Open FabianKoestring opened this issue 3 years ago • 1 comments

Feature Request

Q A
New Feature yes
RFC no
BC Break no

Summary

It seems like the Documentation for Laminas\Validator\GpsPoint is missing. I never knew that there is a validator for this. 🤯

FabianKoestring avatar Sep 10 '20 12:09 FabianKoestring

I believe this validator should either be rewritten or removed entirely as it will return true for the input "foo, bar"

It expects a string as input in the form "latitude, longitude" :

    public function isValid($value)
    {
        if (strpos($value, ',') === false) {
            $this->error(self::INCOMPLETE_COORDINATE, $value);
            return false;
        }

        [$lat, $long] = explode(',', $value);

but the isValidCoordinate() method blindly casts the supposed lat or long to a double:

        $doubleLatitude = (double) $value;

        if ($doubleLatitude <= $maxBoundary && $doubleLatitude >= $maxBoundary * -1) {
            return true;
        }

which results in a 0 value in the case of non-numerical strings, which then passes validation as a valid lat/long.

At the very least it should have explicit comments stating that the expected input is in a very particular format already.

ajgale avatar Jun 21 '22 20:06 ajgale