StdinFileInfo.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of PHP CS Fixer.
  5. *
  6. * (c) Fabien Potencier <fabien@symfony.com>
  7. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  8. *
  9. * This source file is subject to the MIT license that is bundled
  10. * with this source code in the file LICENSE.
  11. */
  12. namespace PhpCsFixer;
  13. /**
  14. * @author Davi Koscianski Vidal <davividal@gmail.com>
  15. *
  16. * @internal
  17. */
  18. final class StdinFileInfo extends \SplFileInfo
  19. {
  20. public function __construct()
  21. {
  22. }
  23. public function __toString(): string
  24. {
  25. return $this->getRealPath();
  26. }
  27. public function getRealPath(): string
  28. {
  29. // So file_get_contents & friends will work.
  30. // Warning - this stream is not seekable, so `file_get_contents` will work only once! Consider using `FileReader`.
  31. return 'php://stdin';
  32. }
  33. public function getATime(): int
  34. {
  35. return 0;
  36. }
  37. public function getBasename($suffix = null): string
  38. {
  39. return $this->getFilename();
  40. }
  41. public function getCTime(): int
  42. {
  43. return 0;
  44. }
  45. public function getExtension(): string
  46. {
  47. return '.php';
  48. }
  49. public function getFileInfo($className = null): \SplFileInfo
  50. {
  51. throw new \BadMethodCallException(sprintf('Method "%s" is not implemented.', __METHOD__));
  52. }
  53. public function getFilename(): string
  54. {
  55. /*
  56. * Useful so fixers depending on PHP-only files still work.
  57. *
  58. * The idea to use STDIN is to parse PHP-only files, so we can
  59. * assume that there will be always a PHP file out there.
  60. */
  61. return 'stdin.php';
  62. }
  63. public function getGroup(): int
  64. {
  65. return 0;
  66. }
  67. public function getInode(): int
  68. {
  69. return 0;
  70. }
  71. public function getLinkTarget(): string
  72. {
  73. return '';
  74. }
  75. public function getMTime(): int
  76. {
  77. return 0;
  78. }
  79. public function getOwner(): int
  80. {
  81. return 0;
  82. }
  83. public function getPath(): string
  84. {
  85. return '';
  86. }
  87. public function getPathInfo($className = null): \SplFileInfo
  88. {
  89. throw new \BadMethodCallException(sprintf('Method "%s" is not implemented.', __METHOD__));
  90. }
  91. public function getPathname(): string
  92. {
  93. return $this->getFilename();
  94. }
  95. public function getPerms(): int
  96. {
  97. return 0;
  98. }
  99. public function getSize(): int
  100. {
  101. return 0;
  102. }
  103. public function getType(): string
  104. {
  105. return 'file';
  106. }
  107. public function isDir(): bool
  108. {
  109. return false;
  110. }
  111. public function isExecutable(): bool
  112. {
  113. return false;
  114. }
  115. public function isFile(): bool
  116. {
  117. return true;
  118. }
  119. public function isLink(): bool
  120. {
  121. return false;
  122. }
  123. public function isReadable(): bool
  124. {
  125. return true;
  126. }
  127. public function isWritable(): bool
  128. {
  129. return false;
  130. }
  131. public function openFile($openMode = 'r', $useIncludePath = false, $context = null): \SplFileObject
  132. {
  133. throw new \BadMethodCallException(sprintf('Method "%s" is not implemented.', __METHOD__));
  134. }
  135. public function setFileClass($className = null): void
  136. {
  137. }
  138. public function setInfoClass($className = null): void
  139. {
  140. }
  141. }