generate.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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);