Code Duplication    Length = 14-17 lines in 2 locations

src/General/Url.php 1 location

@@ 34-47 (lines=14) @@
31
     *
32
     * @return $this
33
     */
34
    private function setUrl($url)
35
    {
36
        // remove the whitespace
37
        $url = trim($url);
38
39
        // @see https://gist.github.com/dperini/729294 and https://mathiasbynens.be/demo/url-regex
40
        $urlValidationRegex = '_^(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}-\x{ffff}]{2,})))(?::\d{2,5})?(?:/[^\s]*)?$_iuS';
41
        if (!preg_match($urlValidationRegex, $url)) {
42
            throw new InvalidUrlException(sprintf('The url: "%s" is not a valid url.', $url), 400);
43
        }
44
        $this->url = $url;
45
46
        return $this;
47
    }
48
49
    /**
50
     * @return string

src/Slack/Webhook.php 1 location

@@ 58-74 (lines=17) @@
55
     *
56
     * @return self
57
     */
58
    private function setUrl(Url $url)
59
    {
60
        $urlValidationRegex = '_https:\/\/hooks.slack.com\/services\/[\w\/]+$_iuS';
61
        if (!preg_match($urlValidationRegex, (string) $url)) {
62
            throw new InvalidUrlException(
63
                sprintf(
64
                    'The url: "%s" is not a valid url.
65
                     Slack webhook urls should always start with "https://hooks.slack.com/services/"',
66
                    $url
67
                ),
68
                400
69
            );
70
        }
71
        $this->url = $url;
72
73
        return $this;
74
    }
75
76
    /**
77
     * {@inheritdoc}