PageRenderTime 63ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/phpdocumentor/phpdocumentor/src/phpDocumentor/Descriptor/FileDescriptor.php

https://gitlab.com/faisaliqbal/mytripsorter
PHP | 379 lines | 157 code | 48 blank | 174 comment | 7 complexity | 836ae72f5b7b95e83567f99b1a517ccd MD5 | raw file
  1. <?php
  2. /**
  3. * phpDocumentor
  4. *
  5. * PHP Version 5.3
  6. *
  7. * @copyright 2010-2014 Mike van Riel / Naenius (http://www.naenius.com)
  8. * @license http://www.opensource.org/licenses/mit-license.php MIT
  9. * @link http://phpdoc.org
  10. */
  11. namespace phpDocumentor\Descriptor;
  12. /**
  13. * Represents a file in the project.
  14. */
  15. class FileDescriptor extends DescriptorAbstract implements Interfaces\FileInterface
  16. {
  17. /** @var string $hash */
  18. protected $hash;
  19. /** @var string $path */
  20. protected $path = '';
  21. /** @var string|null $source */
  22. protected $source = null;
  23. /** @var Collection $namespaceAliases */
  24. protected $namespaceAliases;
  25. /** @var Collection $includes */
  26. protected $includes;
  27. /** @var Collection $constants */
  28. protected $constants;
  29. /** @var Collection $functions */
  30. protected $functions;
  31. /** @var Collection $classes */
  32. protected $classes;
  33. /** @var Collection $interfaces */
  34. protected $interfaces;
  35. /** @var Collection $traits */
  36. protected $traits;
  37. /** @var Collection $markers */
  38. protected $markers;
  39. /**
  40. * Initializes a new file descriptor with the given hash of its contents.
  41. *
  42. * @param string $hash An MD5 hash of the contents if this file.
  43. */
  44. public function __construct($hash)
  45. {
  46. parent::__construct();
  47. $this->setHash($hash);
  48. $this->setNamespaceAliases(new Collection());
  49. $this->setIncludes(new Collection());
  50. $this->setConstants(new Collection());
  51. $this->setFunctions(new Collection());
  52. $this->setClasses(new Collection());
  53. $this->setInterfaces(new Collection());
  54. $this->setTraits(new Collection());
  55. $this->setMarkers(new Collection());
  56. }
  57. /**
  58. * Returns the hash of the contents for this file.
  59. *
  60. * @return string
  61. */
  62. public function getHash()
  63. {
  64. return $this->hash;
  65. }
  66. /**
  67. * Sets the hash of the contents for this file.
  68. *
  69. * @param string $hash
  70. *
  71. * @return void
  72. */
  73. protected function setHash($hash)
  74. {
  75. $this->hash = $hash;
  76. }
  77. /**
  78. * Retrieves the contents of this file.
  79. *
  80. * @return string|null
  81. */
  82. public function getSource()
  83. {
  84. return $this->source;
  85. }
  86. /**
  87. * Sets the source contents for this file.
  88. *
  89. * @param string|null $source
  90. *
  91. * @return void
  92. */
  93. public function setSource($source)
  94. {
  95. $this->source = $source;
  96. }
  97. /**
  98. * Returns the namespace aliases that have been defined in this file.
  99. *
  100. * @return Collection
  101. */
  102. public function getNamespaceAliases()
  103. {
  104. return $this->namespaceAliases;
  105. }
  106. /**
  107. * Sets the collection of namespace aliases for this file.
  108. *
  109. * @param Collection $namespaceAliases
  110. *
  111. * @return void
  112. */
  113. public function setNamespaceAliases(Collection $namespaceAliases)
  114. {
  115. $this->namespaceAliases = $namespaceAliases;
  116. }
  117. /**
  118. * Returns a list of all includes that have been declared in this file.
  119. *
  120. * @return Collection
  121. */
  122. public function getIncludes()
  123. {
  124. return $this->includes;
  125. }
  126. /**
  127. * Sets a list of all includes that have been declared in this file.
  128. *
  129. * @param Collection $includes
  130. *
  131. * @return void
  132. */
  133. public function setIncludes(Collection $includes)
  134. {
  135. $this->includes = $includes;
  136. }
  137. /**
  138. * Returns a list of constant descriptors contained in this file.
  139. *
  140. * @return Collection
  141. */
  142. public function getConstants()
  143. {
  144. return $this->constants;
  145. }
  146. /**
  147. * Sets a list of constant descriptors contained in this file.
  148. *
  149. * @param Collection $constants
  150. *
  151. * @return void
  152. */
  153. public function setConstants(Collection $constants)
  154. {
  155. $this->constants = $constants;
  156. }
  157. /**
  158. * Returns a list of function descriptors contained in this file.
  159. *
  160. * @return Collection|FunctionInterface[]
  161. */
  162. public function getFunctions()
  163. {
  164. return $this->functions;
  165. }
  166. /**
  167. * Sets a list of function descriptors contained in this file.
  168. *
  169. * @param Collection $functions
  170. *
  171. * @return void
  172. */
  173. public function setFunctions(Collection $functions)
  174. {
  175. $this->functions = $functions;
  176. }
  177. /**
  178. * Returns a list of class descriptors contained in this file.
  179. *
  180. * @return Collection|ClassInterface[]
  181. */
  182. public function getClasses()
  183. {
  184. return $this->classes;
  185. }
  186. /**
  187. * Sets a list of class descriptors contained in this file.
  188. *
  189. * @param Collection $classes
  190. *
  191. * @return void
  192. */
  193. public function setClasses(Collection $classes)
  194. {
  195. $this->classes = $classes;
  196. }
  197. /**
  198. * Returns a list of interface descriptors contained in this file.
  199. *
  200. * @return Collection|InterfaceInterface[]
  201. */
  202. public function getInterfaces()
  203. {
  204. return $this->interfaces;
  205. }
  206. /**
  207. * Sets a list of interface descriptors contained in this file.
  208. *
  209. * @param Collection $interfaces
  210. *
  211. * @return void
  212. */
  213. public function setInterfaces(Collection $interfaces)
  214. {
  215. $this->interfaces = $interfaces;
  216. }
  217. /**
  218. * Returns a list of trait descriptors contained in this file.
  219. *
  220. * @return Collection|TraitInterface[]
  221. */
  222. public function getTraits()
  223. {
  224. return $this->traits;
  225. }
  226. /**
  227. * Sets a list of trait descriptors contained in this file.
  228. *
  229. * @param Collection $traits
  230. *
  231. * @return void
  232. */
  233. public function setTraits(Collection $traits)
  234. {
  235. $this->traits = $traits;
  236. }
  237. /**
  238. * Returns a series of markers contained in this file.
  239. *
  240. * A marker is a special inline comment that starts with a keyword and is followed by a single line description.
  241. *
  242. * Example:
  243. * ```
  244. * // TODO: This is an item that needs to be done.
  245. * ```
  246. *
  247. * @return Collection
  248. */
  249. public function getMarkers()
  250. {
  251. return $this->markers;
  252. }
  253. /**
  254. * Sets a series of markers contained in this file.
  255. *
  256. * @param Collection $markers
  257. *
  258. * @see getMarkers() for more information on markers.
  259. *
  260. * @return void
  261. */
  262. public function setMarkers(Collection $markers)
  263. {
  264. $this->markers = $markers;
  265. }
  266. /**
  267. * Returns a list of all errors in this file and all its child elements.
  268. *
  269. * @return Collection
  270. */
  271. public function getAllErrors()
  272. {
  273. $errors = $this->getErrors();
  274. $types = $this->getClasses()->merge($this->getInterfaces())->merge($this->getTraits());
  275. $elements = $this->getFunctions()->merge($this->getConstants())->merge($types);
  276. foreach ($elements as $element) {
  277. if (!$element) {
  278. continue;
  279. }
  280. $errors = $errors->merge($element->getErrors());
  281. }
  282. foreach ($types as $element) {
  283. if (!$element) {
  284. continue;
  285. }
  286. foreach ($element->getMethods() as $item) {
  287. if (!$item) {
  288. continue;
  289. }
  290. $errors = $errors->merge($item->getErrors());
  291. }
  292. if (method_exists($element, 'getConstants')) {
  293. foreach ($element->getConstants() as $item) {
  294. if (!$item) {
  295. continue;
  296. }
  297. $errors = $errors->merge($item->getErrors());
  298. }
  299. }
  300. if (method_exists($element, 'getProperties')) {
  301. foreach ($element->getProperties() as $item) {
  302. if (!$item) {
  303. continue;
  304. }
  305. $errors = $errors->merge($item->getErrors());
  306. }
  307. }
  308. }
  309. return $errors;
  310. }
  311. /**
  312. * Sets the file path for this file relative to the project's root.
  313. *
  314. * @param string $path
  315. *
  316. * @return void
  317. */
  318. public function setPath($path)
  319. {
  320. $this->path = $path;
  321. }
  322. /**
  323. * Returns the file path relative to the project's root.
  324. *
  325. * @return string
  326. */
  327. public function getPath()
  328. {
  329. return $this->path;
  330. }
  331. }