This file is indexed.

/usr/share/php/ApiGen/Reflection/Extractors/AnnotationMethodExtractor.php is in php-apigen 4.1.2-1ubuntu2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php

/**
 * This file is part of the ApiGen (http://apigen.org)
 *
 * For the full copyright and license information, please view
 * the file license.md that was distributed with this source code.
 */

namespace ApiGen\Reflection\Extractors;

use ApiGen\Reflection\ReflectionClass;
use ApiGen\Reflection\ReflectionMethodMagic;
use ApiGen\Reflection\TokenReflection\ReflectionFactory;


class AnnotationMethodExtractor
{

	const PATTERN_METHOD = '~^(?:([\\w\\\\]+(?:\\|[\\w\\\\]+)*)\\s+)?(&)?\\s*(\\w+)\\s*\\(\\s*(.*)\\s*\\)\\s*(.*|$)~s';
	const PATTERN_PARAMETER = '~^(?:([\\w\\\\]+(?:\\|[\\w\\\\]+)*)\\s+)?(&)?\\s*\\$(\\w+)(?:\\s*=\\s*(.*))?($)~s';

	/**
	 * @var ReflectionFactory
	 */
	private $reflectionFactory;

	/**
	 * @var ReflectionClass
	 */
	private $reflectionClass;


	public function __construct(ReflectionFactory $reflectionFactory)
	{
		$this->reflectionFactory = $reflectionFactory;
	}


	/**
	 * @param ReflectionClass $reflectionClass
	 * @return ReflectionMethodMagic[]|array
	 */
	public function extractFromReflection(ReflectionClass $reflectionClass)
	{
		$this->reflectionClass = $reflectionClass;

		$methods = [];
		if ($reflectionClass->hasAnnotation('method')) {
			foreach ($reflectionClass->getAnnotation('method') as $annotation) {
				$methods += $this->processMagicMethodAnnotation($annotation);
			};
		}

		return $methods;
	}


	/**
	 * @param string $annotation
	 * @return ReflectionMethodMagic[]|array
	 */
	private function processMagicMethodAnnotation($annotation)
	{
		if ( ! preg_match(self::PATTERN_METHOD, $annotation, $matches)) {
			return [];
		}

		list(, $returnTypeHint, $returnsReference, $name, $args, $shortDescription) = $matches;

		$startLine = $this->getStartLine($annotation);
		$endLine = $startLine + substr_count($annotation, "\n");

		$methods = [];
		$methods[$name] = $method = $this->reflectionFactory->createMethodMagic([
			'name' => $name,
			'shortDescription' => str_replace("\n", ' ', $shortDescription),
			'startLine' => $startLine,
			'endLine' => $endLine,
			'returnsReference' => ($returnsReference === '&'),
			'declaringClass' => $this->reflectionClass,
			'annotations' => ['return' => [0 => $returnTypeHint]]
		]);
		$this->attachMethodParameters($method, $args);
		return $methods;
	}


	/**
	 * @param string $annotation
	 * @return int
	 */
	private function getStartLine($annotation)
	{
		$doc = $this->reflectionClass->getDocComment();
		$tmp = $annotation;
		if ($delimiter = strpos($annotation, "\n")) {
			$tmp = substr($annotation, 0, $delimiter);
		}
		return $this->reflectionClass->getStartLine() + substr_count(substr($doc, 0, strpos($doc, $tmp)), "\n");
	}


	/**
	 * @param ReflectionMethodMagic $method
	 * @param string $args
	 */
	private function attachMethodParameters(ReflectionMethodMagic $method, $args)
	{
		$parameters = [];
		foreach (array_filter(preg_split('~\\s*,\\s*~', $args)) as $position => $arg) {
			if ( ! preg_match(self::PATTERN_PARAMETER, $arg, $matches)) {
				// Wrong annotation format
				continue;
			}

			list(, $typeHint, $passedByReference, $name, $defaultValueDefinition) = $matches;

			$parameters[$name] = $this->reflectionFactory->createParameterMagic([
				'name' => $name,
				'position' => $position,
				'typeHint' => $typeHint,
				'defaultValueDefinition' => $defaultValueDefinition,
				'unlimited' => FALSE,
				'passedByReference' => ($passedByReference === '&'),
				'declaringFunction' => $method
			]);
			$method->addAnnotation('param', ltrim(sprintf('%s $%s', $typeHint, $name)));
		}
		$method->setParameters($parameters);
	}

}