Code Duplication    Length = 49-49 lines in 2 locations

src/Validator/Culture.php 1 location

@@ 22-70 (lines=49) @@
19
 * @package TxTextControl\ReportingCloud
20
 * @author  Jonathan Maron (@JonathanMaron)
21
 */
22
class Culture extends AbstractValidator
23
{
24
    const FILENAME = '../../resource/cultures.php';
25
    /**
26
     * Invalid syntax
27
     *
28
     * @const INVALID
29
     */
30
    const INVALID_CULTURE = 'invalidCulture';
31
32
    /**
33
     * Message templates
34
     *
35
     * @var array
36
     */
37
    protected $messageTemplates = [
38
        self::INVALID_CULTURE => '',  // added dynamically
39
    ];
40
41
    /**
42
     * Returns true, if value is valid. False otherwise.
43
     *
44
     * @param mixed $value
45
     *
46
     * @return bool
47
     */
48
    public function isValid($value)
49
    {
50
        $this->setValue($value);
51
52
        $filename = realpath(__DIR__ . DIRECTORY_SEPARATOR . self::FILENAME);
53
54
        $values = include $filename;
55
56
        if (!in_array($value, $values)) {
57
58
            $message = sprintf("'%s' is not a valid culture value. Valid values are: '%s'"
59
                , $value
60
                , implode("', '", $values));
61
62
            $this->setMessage($message, self::INVALID_CULTURE);
63
            $this->error(self::INVALID_CULTURE);
64
65
            return false;
66
        }
67
68
        return true;
69
    }
70
}

src/Validator/Language.php 1 location

@@ 22-70 (lines=49) @@
19
 * @package TxTextControl\ReportingCloud
20
 * @author  Jonathan Maron (@JonathanMaron)
21
 */
22
class Language extends AbstractValidator
23
{
24
    const FILENAME = '../../resource/dictionaries.php';
25
    /**
26
     * Invalid syntax
27
     *
28
     * @const INVALID
29
     */
30
    const INVALID_LANGUAGE = 'invalidLanguage';
31
32
    /**
33
     * Message templates
34
     *
35
     * @var array
36
     */
37
    protected $messageTemplates = [
38
        self::INVALID_LANGUAGE => '',  // added dynamically
39
    ];
40
41
    /**
42
     * Returns true, if value is valid. False otherwise.
43
     *
44
     * @param mixed $value
45
     *
46
     * @return bool
47
     */
48
    public function isValid($value)
49
    {
50
        $this->setValue($value);
51
52
        $filename = realpath(__DIR__ . DIRECTORY_SEPARATOR . self::FILENAME);
53
54
        $values = include $filename;
55
56
        if (!in_array($value, $values)) {
57
58
            $message = sprintf("'%s' is not a valid language value. Valid values are: '%s'"
59
                , $value
60
                , implode("', '", $values));
61
62
            $this->setMessage($message, self::INVALID_LANGUAGE);
63
            $this->error(self::INVALID_LANGUAGE);
64
65
            return false;
66
        }
67
68
        return true;
69
    }
70
}