Completed
Push — master ( 86db96...a2faf8 )
by Nicolas
08:49
created

AnnotationReaderFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A getAnnotationReader() 0 19 3
1
<?php
2
3
namespace Nikoms\PhpUnit;
4
5
use Doctrine\Common\Annotations\AnnotationReader;
6
use Doctrine\Common\Annotations\DocParser;
7
8
/**
9
 * Class AnnotationReaderFactory
10
 * @package Nikoms\PhpUnit
11
 */
12
class AnnotationReaderFactory
13
{
14
    /**
15
     * @var AnnotationReader
16
     */
17
    private static $annotationReader;
18
19
    /**
20
     * @var array
21
     */
22
    private static $ignoredAnnotationNames = array(
23
        //All known phpunit annotations
24
        'author',
25
        'after',
26
        'afterClass',
27
        'backupGlobals',
28
        'backupStaticAttributes',
29
        'before',
30
        'beforeClass',
31
        'codeCoverageIgnore',
32
        'codeCoverageIgnoreStart',
33
        'codeCoverageIgnoreEnd',
34
        'covers',
35
        'coversDefaultClass',
36
        'coversNothing',
37
        'dataProvider',
38
        'depends',
39
        'expectedException',
40
        'expectedExceptionCode',
41
        'expectedExceptionMessage',
42
        'expectedExceptionMessageRegExp',
43
        'group',
44
        'large',
45
        'medium',
46
        'preserveGlobalState',
47
        'requires',
48
        'runTestsInSeparateProcesses',
49
        'runInSeparateProcess',
50
        'small',
51
        'test',
52
        'testdox',
53
        'ticket',
54
        'uses',
55
    );
56
57
    /**
58
     * @return AnnotationReader
59
     */
60
    public static function getAnnotationReader()
61
    {
62
        if (self::$annotationReader !== null) {
63
            return self::$annotationReader;
64
        }
65
66
        //For old AnnotationReader (<=1.2.7)
67
        //For new (>1.2.7) version of AnnotationReader, we can give a DocParser since a3c2928912eeb5dc5678352f22c378173def16b6
68
        $parser = new DocParser();
69
        $parser->setIgnoreNotImportedAnnotations(true);
70
        self::$annotationReader = new AnnotationReader($parser);
0 ignored issues
show
Unused Code introduced by
The call to AnnotationReader::__construct() has too many arguments starting with $parser.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
71
72
        //For old version of AnnotationReader (<=1.2.7) , we have to specify manually all ignored annotations
73
        foreach (self::$ignoredAnnotationNames as $ignoredAnnotationName) {
74
            self::$annotationReader->addGlobalIgnoredName($ignoredAnnotationName);
75
        }
76
77
        return self::$annotationReader;
78
    }
79
}