Antevenio/safe-url-validator

View on GitHub
src/Validator/ValidUrl.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace Antevenio\SafeUrl\Validator;

use Antevenio\SafeUrl\Validator;

class ValidUrl implements Validator
{
    protected function schemeIsHttp($scheme) {
        return $scheme == 'http' || $scheme == 'https';
    }
    public function isValid($url)
    {
        $url = strtolower($url);
        $validUrl = (bool)filter_var($url, FILTER_VALIDATE_URL);
        if ($validUrl) {
            $parsedUrl = parse_url($url);
            if ($parsedUrl) {
                return $this->schemeIsHttp($parsedUrl["scheme"]);
            }
        }
        return false;
    }
}