This file is indexed.

/usr/share/php/ApiGen/Generator/TemplateGenerators/TreeGenerator.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<?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\Generator\TemplateGenerators;

use ApiGen\Configuration\Configuration;
use ApiGen\Configuration\ConfigurationOptions as CO;
use ApiGen\Configuration\Theme\ThemeConfigOptions as TCO;
use ApiGen\Generator\ConditionalTemplateGenerator;
use ApiGen\Parser\Elements\Elements;
use ApiGen\Parser\ParserResult;
use ApiGen\Reflection\ReflectionClass;
use ApiGen\Templating\TemplateFactory;
use ApiGen\Tree;


class TreeGenerator implements ConditionalTemplateGenerator
{

	/**
	 * @var Configuration
	 */
	private $configuration;

	/**
	 * @var TemplateFactory
	 */
	private $templateFactory;

	/**
	 * @var array
	 */
	private $processed = [];

	/**
	 * @var array[]
	 */
	private $treeStorage = [
		Elements::CLASSES => [],
		Elements::INTERFACES => [],
		Elements::TRAITS => [],
		Elements::EXCEPTIONS => []
	];

	/**
	 * @var ParserResult
	 */
	private $parserResult;


	public function __construct(
		Configuration $configuration,
		TemplateFactory $templateFactory,
		ParserResult $parserResult
	) {
		$this->configuration = $configuration;
		$this->templateFactory = $templateFactory;
		$this->parserResult = $parserResult;
	}


	public function generate()
	{
		$template = $this->templateFactory->createForType(TCO::TREE);

		$classes = $this->parserResult->getClasses();
		foreach ($classes as $className => $reflection) {
			if ($this->canBeProcessed($reflection)) {
				$this->addToTreeByReflection($reflection);
			}
		}

		$this->sortTreeStorageElements();

		$template->setParameters([
			'classTree' => new Tree($this->treeStorage[Elements::CLASSES], $classes),
			'interfaceTree' => new Tree($this->treeStorage[Elements::INTERFACES], $classes),
			'traitTree' => new Tree($this->treeStorage[Elements::TRAITS], $classes),
			'exceptionTree' => new Tree($this->treeStorage[Elements::EXCEPTIONS], $classes)
		]);

		$template->save();
	}


	/**
	 * @return bool
	 */
	public function isAllowed()
	{
		return $this->configuration->getOption(CO::TREE);
	}


	/**
	 * @return bool
	 */
	private function canBeProcessed(ReflectionClass $reflection)
	{
		if ( ! $reflection->isMain()) {
			return FALSE;
		}
		if ( ! $reflection->isDocumented()) {
			return FALSE;
		}
		if (isset($this->processed[$reflection->getName()])) {
			return FALSE;
		}
		return TRUE;
	}


	private function addToTreeByReflection(ReflectionClass $reflection)
	{
		if ($reflection->getParentClassName() === NULL) {
			$type = $this->getTypeByReflection($reflection);
			$this->addToTreeByTypeAndName($type, $reflection->getName());

		} else {
			foreach (array_values(array_reverse($reflection->getParentClasses())) as $level => $parent) {
				$type = NULL;
				if ($level === 0) {
					// The topmost parent decides about the reflection type
					$type = $this->getTypeByReflection($reflection);
				}

				/** @var ReflectionClass $parent */
				$parentName = $parent->getName();
				if ( ! isset($this->treeStorage[$type][$parentName])) {
					$this->addToTreeByTypeAndName($type, $parentName);
				}
			}
		}
	}


	/**
	 * @return string
	 */
	private function getTypeByReflection(ReflectionClass $reflection)
	{
		if ($reflection->isInterface()) {
			return Elements::INTERFACES;

		} elseif ($reflection->isTrait()) {
			return Elements::TRAITS;

		} elseif ($reflection->isException()) {
			return Elements::EXCEPTIONS;

		} else {
			return Elements::CLASSES;
		}
	}


	/**
	 * @param string $type
	 * @param string $name
	 */
	private function addToTreeByTypeAndName($type, $name)
	{
		$this->treeStorage[$type][$name] = [];
		$this->processed[$name] = TRUE;
	}


	private function sortTreeStorageElements()
	{
		foreach ($this->treeStorage as $key => $elements) {
			ksort($elements, SORT_STRING);
			$this->treeStorage[$key] = $elements;
		}
	}

}