StdinFileInfo.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. parent::__construct(__FILE__);
  23. }
  24. public function __toString(): string
  25. {
  26. return $this->getRealPath();
  27. }
  28. public function getRealPath(): string
  29. {
  30. // So file_get_contents & friends will work.
  31. // Warning - this stream is not seekable, so `file_get_contents` will work only once! Consider using `FileReader`.
  32. return 'php://stdin';
  33. }
  34. public function getATime(): int
  35. {
  36. return 0;
  37. }
  38. public function getBasename($suffix = null): string
  39. {
  40. return $this->getFilename();
  41. }
  42. public function getCTime(): int
  43. {
  44. return 0;
  45. }
  46. public function getExtension(): string
  47. {
  48. return '.php';
  49. }
  50. public function getFileInfo($class = null): \SplFileInfo
  51. {
  52. throw new \BadMethodCallException(sprintf('Method "%s" is not implemented.', __METHOD__));
  53. }
  54. public function getFilename(): string
  55. {
  56. /*
  57. * Useful so fixers depending on PHP-only files still work.
  58. *
  59. * The idea to use STDIN is to parse PHP-only files, so we can
  60. * assume that there will be always a PHP file out there.
  61. */
  62. return 'stdin.php';
  63. }
  64. public function getGroup(): int
  65. {
  66. return 0;
  67. }
  68. public function getInode(): int
  69. {
  70. return 0;
  71. }
  72. public function getLinkTarget(): string
  73. {
  74. return '';
  75. }
  76. public function getMTime(): int
  77. {
  78. return 0;
  79. }
  80. public function getOwner(): int
  81. {
  82. return 0;
  83. }
  84. public function getPath(): string
  85. {
  86. return '';
  87. }
  88. public function getPathInfo($class = null): \SplFileInfo
  89. {
  90. throw new \BadMethodCallException(sprintf('Method "%s" is not implemented.', __METHOD__));
  91. }
  92. public function getPathname(): string
  93. {
  94. return $this->getFilename();
  95. }
  96. public function getPerms(): int
  97. {
  98. return 0;
  99. }
  100. public function getSize(): int
  101. {
  102. return 0;
  103. }
  104. public function getType(): string
  105. {
  106. return 'file';
  107. }
  108. public function isDir(): bool
  109. {
  110. return false;
  111. }
  112. public function isExecutable(): bool
  113. {
  114. return false;
  115. }
  116. public function isFile(): bool
  117. {
  118. return true;
  119. }
  120. public function isLink(): bool
  121. {
  122. return false;
  123. }
  124. public function isReadable(): bool
  125. {
  126. return true;
  127. }
  128. public function isWritable(): bool
  129. {
  130. return false;
  131. }
  132. public function openFile($openMode = 'r', $useIncludePath = false, $context = null): \SplFileObject
  133. {
  134. throw new \BadMethodCallException(sprintf('Method "%s" is not implemented.', __METHOD__));
  135. }
  136. public function setFileClass($className = null): void {}
  137. public function setInfoClass($className = null): void {}
  138. }