generate.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/env php
  2. <?php declare(strict_types=1);
  3. /*
  4. * This file is part of resource-operations.
  5. *
  6. * (c) Sebastian Bergmann <sebastian@phpunit.de>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. $functions = require __DIR__ . '/FunctionSignatureMap.php';
  12. $resourceFunctions = [];
  13. foreach ($functions as $function => $arguments) {
  14. foreach ($arguments as $argument) {
  15. if (strpos($argument, '?') === 0) {
  16. $argument = substr($argument, 1);
  17. }
  18. if ($argument === 'resource') {
  19. $resourceFunctions[] = explode('\'', $function)[0];
  20. }
  21. }
  22. }
  23. $resourceFunctions = array_unique($resourceFunctions);
  24. sort($resourceFunctions);
  25. $buffer = <<<EOT
  26. <?php declare(strict_types=1);
  27. /*
  28. * This file is part of resource-operations.
  29. *
  30. * (c) Sebastian Bergmann <sebastian@phpunit.de>
  31. *
  32. * For the full copyright and license information, please view the LICENSE
  33. * file that was distributed with this source code.
  34. */
  35. namespace SebastianBergmann\ResourceOperations;
  36. final class ResourceOperations
  37. {
  38. /**
  39. * @return string[]
  40. */
  41. public static function getFunctions(): array
  42. {
  43. return [
  44. EOT;
  45. foreach ($resourceFunctions as $function) {
  46. $buffer .= sprintf(" '%s',\n", $function);
  47. }
  48. $buffer .= <<< EOT
  49. ];
  50. }
  51. }
  52. EOT;
  53. file_put_contents(__DIR__ . '/../src/ResourceOperations.php', $buffer);