Exists::isValid()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 16
Ratio 100 %
Metric Value
dl 16
loc 16
rs 9.4285
cc 2
eloc 9
nc 2
nop 0
1
<?php
2
3
/**
4
 * @author: Abdul Qureshi. <[email protected]>
5
 * 
6
 * This file has been modified from the original source.
7
 * See original here:
8
 *
9
 * @link: https://github.com/progsmile/request-validator
10
 */
11
12
namespace TheSupportGroup\Common\Validator\Rules;
13
14
use TheSupportGroup\Common\Validator\Contracts\Rules\RuleInterface;
15
16 View Code Duplication
class Exists extends BaseRule implements RuleInterface
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...
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