Url   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
c 2
b 0
f 0
lcom 1
cbo 1
dl 28
loc 28
ccs 6
cts 6
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A validates() 8 8 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/**
4
 * This file is part of slick/validator package
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Slick\Validator;
11
12
/**
13
 * Url validator
14
 *
15
 * @package Slick\Validator
16
 * @author  Filipe Silva <[email protected]>
17
 */
18 View Code Duplication
class Url extends AbstractValidator implements ValidatorInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

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.

Loading history...
19
{
20
21
    /**
22
     * @var array Message templates
23
     */
24
    protected $messageTemplate = 'The value is not a valid URL.';
25
26
    /**
27
     * Returns true if and only if $value meets the validation requirements
28
     *
29
     * The context specified can be used in the validation process so that
30
     * the same value can be valid or invalid depending on that data.
31
     *
32
     * @param mixed $value
33
     * @param array|mixed $context
34
     *
35
     * @return bool
36
     */
37 10
    public function validates($value, $context = [])
38
    {
39 10
        $result = (boolean) filter_var($value, FILTER_VALIDATE_URL);
40 10
        if (!$result) {
41 6
            $this->addMessage($this->messageTemplate, $value);
42 6
        }
43 10
        return $result;
44
    }
45
}