Code Duplication    Length = 24-29 lines in 2 locations

src/Rules/Exists.php 1 location

@@ 16-44 (lines=29) @@
13
14
use TheSupportGroup\Common\Validator\Contracts\Rules\RuleInterface;
15
16
class Exists extends BaseRule implements RuleInterface
17
{
18
    public function isValid()
19
    {
20
        if ($this->isNotRequiredAndEmpty()) {
21
            return true;
22
        }
23
24
        $config = $this->getConfig();
25
26
        $field = $this->getParams()[0];
27
        $value = $this->getParams()[1];
28
        $table = $this->getParams()[2];
29
30
        $instance = new $config[BaseRule::CONFIG_ORM]($field, $value, $table);
31
32
        return $instance->isExist();
33
    }
34
35
    /**
36
     * Returns error message from rule.
37
     *
38
     * @return string
39
     */
40
    public function getMessage()
41
    {
42
        return 'Field :field: doesn\'t exist in table';
43
    }
44
}
45

src/Rules/Unique.php 1 location

@@ 16-39 (lines=24) @@
13
14
use TheSupportGroup\Common\Validator\Contracts\Rules\RuleInterface;
15
16
class Unique extends BaseRule implements RuleInterface
17
{
18
    public function isValid()
19
    {
20
        if ($this->isNotRequiredAndEmpty()) {
21
            return true;
22
        }
23
24
        $config = $this->getConfig();
25
26
        $field = $this->getParams()[0];
27
        $value = $this->getParams()[1];
28
        $table = $this->getParams()[2];
29
30
        $instance = new $config[BaseRule::CONFIG_ORM]($field, $value, $table);
31
32
        return $instance->isUnique();
33
    }
34
35
    public function getMessage()
36
    {
37
        return 'Field :field: must be unique';
38
    }
39
}
40