GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ValidatorClassNameMethodName   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 79
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 3
dl 79
loc 79
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 6 6 1
A validate() 4 4 2
A validateResultKeys() 7 7 3
A getMapping() 18 18 1
A getValidationInfo() 4 4 1
A getValidationTag() 4 4 1
A __toString() 4 4 1

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
namespace DF\PHPCoverFish\Validator;
4
5
use DF\PHPCoverFish\Common\CoverFishMapping;
6
use DF\PHPCoverFish\Common\CoverFishPHPUnitFile;
7
use DF\PHPCoverFish\Validator\Base\BaseCoverFishValidator;
8
9
/**
10
 * Class ValidatorClassNameMethodName, validate that the annotated test method covers the specified method (Class::Method)
11
 *
12
 * @package   DF\PHPCoverFish
13
 * @author    Patrick Paechnatz <[email protected]>
14
 * @copyright 2015 Patrick Paechnatz <[email protected]>
15
 * @license   http://www.opensource.org/licenses/MIT
16
 * @link      http://github.com/dunkelfrosch/phpcoverfish/tree
17
 * @since     class available since Release 0.9.0
18
 * @version   0.9.4
19
 */
20 View Code Duplication
class ValidatorClassNameMethodName extends BaseCoverFishValidator
21
{
22
    /**
23
     * @return array
24
     */
25
    private function execute()
26
    {
27
        preg_match_all('/^(?P<class>(^(([\\\\])|([A-Z]))([A-Za-z0-9_\\\\]+)))(?P<sep>::{1})((?P<method>[\w]+))$/', $this->coversToken, $this->result, PREG_SET_ORDER);
28
29
        return $this->result;
30
    }
31
32
    /**
33
     * @return bool
34
     */
35
    public function validate()
36
    {
37
        return (count($this->execute()) > 0) && $this->validateResultKeys();
38
    }
39
40
    /**
41
     * @return bool
42
     */
43
    public function validateResultKeys()
44
    {
45
        return array_key_exists('class', $this->getResult())
46
            && array_key_exists('sep', $this->getResult())
47
            && array_key_exists('method', $this->getResult()
48
        );
49
    }
50
51
    /**
52
     * @param CoverFishPHPUnitFile $phpUnitFile
53
     *
54
     * @return CoverFishMapping
55
     */
56
    public function getMapping(CoverFishPHPUnitFile $phpUnitFile)
57
    {
58
        $method = $this->getResult()['method'];
59
        $class = $this->getResult()['class'];
60
        $classFQN = $this->coverFishHelper->getClassFromUse($class, $phpUnitFile->getUsedClasses());
61
62
        $mappingOptions = array(
63
            'coverToken' => $this->coversToken,
64
            'coverMethod' => $method,
65
            'coverAccessor' => null,
66
            'coverClass' => $class,
67
            'coverClassFQN' => $classFQN,
68
            'validatorMatch' => $this->getValidationTag(),
69
            'validatorClass' => get_class($this)
70
        );
71
72
        return $this->setMapping($mappingOptions);
73
    }
74
75
    /**
76
     * @return string
77
     */
78
    public function getValidationInfo()
79
    {
80
        return 'Specifies that the annotated test method covers the specified method.';
81
    }
82
83
    /**
84
     * @return string
85
     */
86
    public function getValidationTag()
87
    {
88
        return 'ClassName::methodName';
89
    }
90
91
    /**
92
     * @return string
93
     */
94
    public function __toString()
95
    {
96
        return get_class($this);
97
    }
98
}