Conditions | 2 |
Paths | 2 |
Total Lines | 14 |
Code Lines | 7 |
Lines | 14 |
Ratio | 100 % |
Tests | 7 |
CRAP Score | 2 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
34 | 25 | View Code Duplication | private function setUrl($url) |
1 ignored issue
–
show
|
|||
35 | { |
||
36 | // remove the whitespace |
||
37 | 25 | $url = trim($url); |
|
38 | |||
39 | // @see https://gist.github.com/dperini/729294 and https://mathiasbynens.be/demo/url-regex |
||
40 | 25 | $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 | 25 | if (!preg_match($urlValidationRegex, $url)) { |
|
42 | 2 | throw new InvalidUrlException(sprintf('The url: "%s" is not a valid url.', $url), 400); |
|
43 | } |
||
44 | 23 | $this->url = $url; |
|
45 | |||
46 | 23 | return $this; |
|
47 | } |
||
48 | |||
65 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.