Passed
Push — master ( 1a3693...31c150 )
by Jonathan
10:52
created

Culture   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 49
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A isValid() 22 22 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
 * ReportingCloud PHP Wrapper
5
 *
6
 * PHP wrapper for ReportingCloud Web API. Authored and supported by Text Control GmbH.
7
 *
8
 * @link      http://www.reporting.cloud to learn more about ReportingCloud
9
 * @link      https://github.com/TextControl/txtextcontrol-reportingcloud-php for the canonical source repository
10
 * @license   https://raw.githubusercontent.com/TextControl/txtextcontrol-reportingcloud-php/master/LICENSE.md
11
 * @copyright © 2017 Text Control GmbH
12
 */
13
14
namespace TxTextControl\ReportingCloud\Validator;
15
16
/**
17
 * Culture validator
18
 *
19
 * @package TxTextControl\ReportingCloud
20
 * @author  Jonathan Maron (@JonathanMaron)
21
 */
22 View Code Duplication
class Culture extends AbstractValidator
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...
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 3
    public function isValid($value)
49
    {
50 3
        $this->setValue($value);
51
52 3
        $filename = realpath(__DIR__ . DIRECTORY_SEPARATOR . self::FILENAME);
53
54 3
        $values = include $filename;
55
56 3
        if (!in_array($value, $values)) {
57
58 1
            $message = sprintf("'%s' is not a valid culture value. Valid values are: '%s'"
59 1
                , $value
60 1
                , implode("', '", $values));
61
62 1
            $this->setMessage($message, self::INVALID_CULTURE);
63 1
            $this->error(self::INVALID_CULTURE);
64
65 1
            return false;
66
        }
67
68 2
        return true;
69
    }
70
}