CoarseChecker   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 45
ccs 10
cts 12
cp 0.8333
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B mightHaveAnnotations() 0 31 6
1
<?php
2
3
/**
4
 * This software package is licensed under AGPL, Commercial license.
5
 *
6
 * @package maslosoft/addendum
7
 * @licence AGPL, Commercial
8
 * @copyright Copyright (c) Piotr Masełkowski <[email protected]> (Meta container, further improvements, bugfixes)
9
 * @copyright Copyright (c) Maslosoft (Meta container, further improvements, bugfixes)
10
 * @copyright Copyright (c) Jan Suchal (Original version, builder, parser)
11
 * @link https://maslosoft.com/addendum/ - maslosoft addendum
12
 * @link https://code.google.com/p/addendum/ - original addendum project
13
 */
14
15
namespace Maslosoft\Addendum\Helpers;
16
17
use ReflectionClass;
18
use ReflectionObject;
19
use Reflector;
20
21
/**
22
 * Coarse check for annotations.
23
 *
24
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
25
 */
26
class CoarseChecker
27
{
28
29
	/**
30
	 * Check if file contains annotations,
31
	 * by checking if it contains @[A-Z] regular expression.
32
	 *
33
	 * It does not ensure that file really contains annotations.
34
	 *
35
	 * @param string|Reflector|object $entity
36
	 * @return bool
37
	 */
38 53
	public static function mightHaveAnnotations($entity)
39
	{
40 53
		if (is_object($entity))
41
		{
42 53
			if ($entity instanceof Reflector)
43
			{
44 53
				if ($entity instanceof ReflectionClass)
45
				{
46 44
					$file = $entity->getFileName();
47
				}
48
				else
49
				{
50 53
					$file = $entity->getDeclaringClass()->getFileName();
51
				}
52
			}
53
			else
54
			{
55 53
				$file = (new ReflectionObject($entity))->getFileName();
56
			}
57
		}
58
		else
59
		{
60
			$file = $entity;
61
		}
62 53
		if (empty($file) || !is_string($file))
63
		{
64
			return false;
65
		}
66 53
		$content = file_get_contents($file);
67 53
		return !!preg_match('~@[A-Z]~', $content);
68
	}
69
70
}
71