This file is indexed.

/usr/share/php/ApiGen/Parser/Elements/GroupSorter.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
<?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\Parser\Elements;

use ApiGen\Configuration\Configuration;
use ApiGen\Configuration\ConfigurationOptions as CO;


class GroupSorter
{

	/**
	 * @var array
	 */
	private $lowercasedGroupNames;

	/**
	 * @var array
	 */
	private $groups;

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

	/**
	 * @var Elements
	 */
	private $elements;


	public function __construct(Elements $elements, Configuration $configuration)
	{
		$this->elements = $elements;
		$this->configuration = $configuration;
	}


	/**
	 * @return array
	 */
	public function sort(array $groups)
	{
		if ($this->isNoneGroupOnly($groups)) {
			return [];
		}
		$this->groups = $groups;

		$groupNames = array_keys($groups);
		$this->lowercasedGroupNames = $this->convertGroupNamesToLower($groupNames);

		foreach ($groupNames as $groupName) {
			$this->addMissingParentGroups($groupName);
			$this->addMissingElementTypes($groupName);
		}

		uksort($this->groups, function ($one, $two) {
			return $this->compareGroups($one, $two, $this->configuration->getOption(CO::MAIN));
		});

		return $this->groups;
	}


	/**
	 * @return bool
	 */
	private function isNoneGroupOnly(array $groups)
	{
		if (count($groups) === 1 && isset($groups['None'])) {
			return TRUE;
		}
		return FALSE;
	}


	/**
	 * @param array $groupNames
	 * @return array
	 */
	private function convertGroupNamesToLower($groupNames)
	{
		$names = array_map(function ($name) {
			return strtolower($name);
		}, $groupNames);

		return array_flip($names);
	}


	/**
	 * @param string $groupName
	 */
	private function addMissingParentGroups($groupName)
	{
		$parent = '';
		foreach (explode('\\', $groupName) as $part) {
			$parent = ltrim($parent . '\\' . $part, '\\');

			if ( ! isset($this->lowercasedGroupNames[strtolower($parent)])) {
				$this->groups[$parent] = $this->elements->getEmptyList();
			}
		}
	}


	/**
	 * @param string $groupName
	 */
	private function addMissingElementTypes($groupName)
	{
		foreach ($this->elements->getAll() as $type) {
			if ( ! isset($this->groups[$groupName][$type])) {
				$this->groups[$groupName][$type] = [];
			}
		}
	}


	/**
	 * @param string $one
	 * @param string $two
	 * @param string $main
	 * @return int
	 */
	private function compareGroups($one, $two, $main)
	{
		// \ as separator has to be first
		$one = str_replace('\\', ' ', $one);
		$two = str_replace('\\', ' ', $two);

		if ($main) {
			if (strpos($one, $main) === 0 && strpos($two, $main) !== 0) {
				return -1;

			} elseif (strpos($one, $main) !== 0 && strpos($two, $main) === 0) {
				return 1;
			}
		}

		return strcasecmp($one, $two);
	}

}