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

AnnotationReaderFactory::getAnnotationReader()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 19
ccs 0
cts 10
cp 0
rs 9.4285
cc 3
eloc 9
nc 3
nop 0
crap 12
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
}