Skip to content

Commit ad0e6ab

Browse files
committed
[dev] function-info command
I'm trying to figure out why some functions claim to take a `resource` when they actually take a `FTP\Connection` or a `GdImage` -- this CLI command helps with debugging. ### Example: ```php $ php ./generator/safe.php function-info ftp_alloc Params: ftp ParameterType: FTP\Connection SignatureType: DocBlockType: resource size ParameterType: int SignatureType: int DocBlockType: int response ParameterType: string SignatureType: ?string DocBlockType: string|null /** * Sends an ALLO command to the remote FTP server to * allocate space for a file to be uploaded. * * @param resource $ftp An FTP\Connection instance. * @param int $size The number of bytes to allocate. * @param string|null $response A textual representation of the servers response will be returned by * reference in response if a variable is provided. * @throws FtpException * */ function ftp_alloc($ftp, int $size, ?string &$response = null): void { error_clear_last(); $safeResult = \ftp_alloc($ftp, $size, $response); if ($safeResult === false) { throw FtpException::createFromPhpError(); } } ```
1 parent 0dd499f commit ad0e6ab

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

generator/safe.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66

77
use Safe\GenerateCommand;
88
use Safe\ScanObjectsCommand;
9+
use Safe\FunctionInfoCommand;
910
use Symfony\Component\Console\Application;
1011

1112
$application = new Application();
1213
$application->addCommands([new GenerateCommand()]);
1314
$application->addCommands([new ScanObjectsCommand()]);
15+
$application->addCommands([new FunctionInfoCommand()]);
1416

1517
$application->run();

generator/src/FunctionInfoCommand.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Safe;
6+
7+
use Symfony\Component\Console\Command\Command;
8+
use Symfony\Component\Console\Input\InputInterface;
9+
use Symfony\Component\Console\Input\InputArgument;
10+
use Symfony\Component\Console\Output\OutputInterface;
11+
12+
class FunctionInfoCommand extends Command
13+
{
14+
protected function configure(): void
15+
{
16+
$this
17+
->setName('function-info')
18+
->setDescription('Displays parsed info about a function.')
19+
->addArgument('function', InputArgument::REQUIRED, 'The function name to display info about.')
20+
;
21+
}
22+
23+
protected function execute(InputInterface $input, OutputInterface $output): int
24+
{
25+
$scanner = new Scanner(__DIR__ . '/../doc/doc-en/en/reference/');
26+
$res = $scanner->getMethods($scanner->getFunctionsPaths(), $output);
27+
28+
foreach ($res->methods as $function) {
29+
$name = $function->getFunctionName();
30+
if ($name == $input->getArgument("function")) {
31+
$output->writeln("Params: ");
32+
foreach ($function->getParams() as $param) {
33+
$output->writeln(" " . $param->getParameterName());
34+
$output->writeln(" ParameterType: " . $param->getParameterType());
35+
$output->writeln(" SignatureType: " . $param->getSignatureType());
36+
$output->writeln(" DocBlockType: " . $param->getDocBlockType());
37+
}
38+
$writePhpFunction = new WritePhpFunction($function);
39+
$output->writeln($writePhpFunction->getPhpFunctionalFunction());
40+
break;
41+
}
42+
}
43+
44+
return 0;
45+
}
46+
}

0 commit comments

Comments
 (0)