Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug report suggested by phpstan analyzer. #8769

Closed
tjgumis opened this issue Jan 24, 2023 · 4 comments
Closed

Bug report suggested by phpstan analyzer. #8769

tjgumis opened this issue Jan 24, 2023 · 4 comments

Comments

@tjgumis
Copy link

tjgumis commented Jan 24, 2023

Bug report

temporal php_sdk and Symfony console application integration.
The problem appears when phpstan is started with:
vendor/bin/phpstan analyse

     Post the following stack trace to https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md:   
                                                                                                                         
     #0 phar:///home/paneric/Documents/DHOSTING/collector/src/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/ClassReflection.php(1024): PHPStan\Reflection\ClassReflection->getConstructor()                                        
     #1 phar:///home/paneric/Documents/DHOSTING/collector/src/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/ClassReflection.php(1007): PHPStan\Reflection\ClassReflection->findAttributeFlags()                                    
     #2 phar:///home/paneric/Documents/DHOSTING/collector/src/vendor/phpstan/phpstan/phpstan.phar/src/Rules/AttributesCheck.php(54): PHPStan\Reflection\ClassReflection->isAttributeClass()                                             
     #3 phar:///home/paneric/Documents/DHOSTING/collector/src/vendor/phpstan/phpstan/phpstan.phar/src/Rules/Classes/ClassAttributesRule.php(30): PHPStan\Rules\AttributesCheck->check()                                                 
     #4 phar:///home/paneric/Documents/DHOSTING/collector/src/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(106): PHPStan\Rules\Classes\ClassAttributesRule->processNode()                                          
     #5 phar:///home/paneric/Documents/DHOSTING/collector/src/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(415): PHPStan\Analyser\FileAnalyser->PHPStan\Analyser\{closure}()                                  
     #6 phar:///home/paneric/Documents/DHOSTING/collector/src/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(360): PHPStan\Analyser\NodeScopeResolver->processStmtNode()                                        
     #7 phar:///home/paneric/Documents/DHOSTING/collector/src/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(571): PHPStan\Analyser\NodeScopeResolver->processStmtNodes()                                       
     #8 phar:///home/paneric/Documents/DHOSTING/collector/src/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(327): PHPStan\Analyser\NodeScopeResolver->processStmtNode()                                        
     #9 phar:///home/paneric/Documents/DHOSTING/collector/src/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(175): PHPStan\Analyser\NodeScopeResolver->processNodes()                                                
     #10 phar:///home/paneric/Documents/DHOSTING/collector/src/vendor/phpstan/phpstan/phpstan.phar/src/Command/WorkerCommand.php(148): PHPStan\Analyser\FileAnalyser->analyseFile()                                                     
     #11 phar:///home/paneric/Documents/DHOSTING/collector/src/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97): PHPStan\Command\WorkerCommand->PHPStan\Command\{closure}()       
     #12 phar:///home/paneric/Documents/DHOSTING/collector/src/vendor/phpstan/phpstan/phpstan.phar/vendor/clue/ndjson-react/src/Decoder.php(110): _PHPStan_4dd92cd93\Evenement\EventEmitter->emit()                                     
     #13 phar:///home/paneric/Documents/DHOSTING/collector/src/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97): _PHPStan_4dd92cd93\Clue\React\NDJson\Decoder->handleData()       
     #14 phar:///home/paneric/Documents/DHOSTING/collector/src/vendor/phpstan/phpstan/phpstan.phar/vendor/react/stream/src/Util.php(62): _PHPStan_4dd92cd93\Evenement\EventEmitter->emit()                                              
     #15 phar:///home/paneric/Documents/DHOSTING/collector/src/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97):                                                                  
     _PHPStan_4dd92cd93\React\Stream\Util::_PHPStan_4dd92cd93\React\Stream\{closure}()                                                                                                                                                  
     #16 phar:///home/paneric/Documents/DHOSTING/collector/src/vendor/phpstan/phpstan/phpstan.phar/vendor/react/stream/src/DuplexResourceStream.php(154): _PHPStan_4dd92cd93\Evenement\EventEmitter->emit()                             
     #17 phar:///home/paneric/Documents/DHOSTING/collector/src/vendor/phpstan/phpstan/phpstan.phar/vendor/react/event-loop/src/StreamSelectLoop.php(201): _PHPStan_4dd92cd93\React\Stream\DuplexResourceStream->handleData()            
     #18 phar:///home/paneric/Documents/DHOSTING/collector/src/vendor/phpstan/phpstan/phpstan.phar/vendor/react/event-loop/src/StreamSelectLoop.php(173): _PHPStan_4dd92cd93\React\EventLoop\StreamSelectLoop->waitForStreamActivity()  
     #19 phar:///home/paneric/Documents/DHOSTING/collector/src/vendor/phpstan/phpstan/phpstan.phar/src/Command/WorkerCommand.php(108): _PHPStan_4dd92cd93\React\EventLoop\StreamSelectLoop->run()                                       
     #20 phar:///home/paneric/Documents/DHOSTING/collector/src/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Command/Command.php(259): PHPStan\Command\WorkerCommand->execute()                                            
     #21 phar:///home/paneric/Documents/DHOSTING/collector/src/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(870): _PHPStan_4dd92cd93\Symfony\Component\Console\Command\Command->run()                     
     #22 phar:///home/paneric/Documents/DHOSTING/collector/src/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(261): _PHPStan_4dd92cd93\Symfony\Component\Console\Application->doRunCommand()                
     #23 phar:///home/paneric/Documents/DHOSTING/collector/src/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(157): _PHPStan_4dd92cd93\Symfony\Component\Console\Application->doRun()                       
     #24 phar:///home/paneric/Documents/DHOSTING/collector/src/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(124): _PHPStan_4dd92cd93\Symfony\Component\Console\Application->run()                                                    
     #25 phar:///home/paneric/Documents/DHOSTING/collector/src/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(125): _PHPStan_4dd92cd93\{closure}()                                                                                     
     #26 /home/paneric/Documents/DHOSTING/collector/src/vendor/phpstan/phpstan/phpstan(8): require('...')                                                                                                                               
     #27 /home/paneric/Documents/DHOSTING/collector/src/vendor/bin/phpstan(120): include('...')                                                                                                                                         
     #28 {main} 

Internal error: Internal error: Internal error. in file /home/paneric/Documents/DHOSTING/collector/src/src/Command/ImunifyCollector/ExecuteCommand.php  

Code snippet that reproduces the problem

<?php

declare(strict_types=1);

namespace App\Command\ImunifyCollector;

use App\Command\Common\ExecuteCommandTrait;
use App\Command\ImunifyCollector\CollectorWorkflow as ImunifyCollectorWorkflow;
use Carbon\CarbonInterval;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Temporal\Client\WorkflowClientInterface;
use Temporal\Client\WorkflowOptions;

#[AsCommand(
    name: 'app:imunify',
    description: 'Triggers data processing by Imunify Collector'
)]
class ExecuteCommand extends Command
{
    use ExecuteCommandTrait;

    private const BUFFER_ROWS_COUNT = 1000;

    protected string $taskQueue;
    protected string $workflowId;
    protected array $endpointsNames;

    public function __construct(private WorkflowClientInterface $workflowClient)
    {
        $this->workflowId = 'ImunifyMaster';
        $this->taskQueue = 'Security-Queue';
        $this->endpointsNames = [
            'process-threats-count'
        ];

        parent::__construct();
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $bufferRowsCount = (int) $input->getArgument('buffer_rows_count');
        if ($bufferRowsCount < 1 ) {
            $bufferRowsCount = self::BUFFER_ROWS_COUNT;
        }

        $workflowProxy = $this->workflowClient->newWorkflowStub(
            ImunifyCollectorWorkflow::class,
            WorkflowOptions::new()
                ->withTaskQueue($this->taskQueue)
                ->withWorkflowId($this->workflowId)
                ->withCronSchedule('0 */1 * * *')
                // Execution timeout limits total time. Cron will stop executing after this timeout.
//                ->withWorkflowExecutionTimeout(CarbonInterval::minutes(10))
                // Run timeout limits duration of a single workflow invocation.
                ->withWorkflowRunTimeout(CarbonInterval::minute(1760))
        );

        return $this->start($output, $workflowProxy, $bufferRowsCount);
    }
}
<?php

declare(strict_types=1);

namespace App\Command\Common;

use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;
use Temporal\Internal\Client\WorkflowProxy;

trait ExecuteCommandTrait
{
    protected function configure(): void
    {
        $this->addArgument(
            'buffer_rows_count',
            InputArgument::OPTIONAL,
            'Amount of rows per buffer.'
        );
    }

    protected function start(OutputInterface $output, WorkflowProxy $workflowProxy, int $bufferRowsCount): int
    {
        $output->writeln('<comment>' . $this->workflowId . '</comment> processing initiated ... ');

        $workflow = $this->workflowClient->start(
            $workflowProxy,
            $this->endpointsNames,
            $this->taskQueue,
            $this->workflowId,
            $bufferRowsCount
        );

        $output->writeln(
            sprintf(
                'Started: WorkflowID=<fg=magenta>%s</fg=magenta>, RunID=<fg=magenta>%s</fg=magenta>',
                $workflow->getExecution()->getID(),
                $workflow->getExecution()->getRunID(),
            )
        );

        $output->writeln(sprintf(
            'Result:\n<info>%s</info>',
            print_r($workflow->getResult(), true)
        ));

        return self::SUCCESS;
    }
}

Expected output

Just simple test results.

@mergeable
Copy link

mergeable bot commented Jan 24, 2023

This bug report is missing a link to reproduction at phpstan.org/try.

It will most likely be closed after manual review.

@ondrejmirtes
Copy link
Member

Please create a small reproducing repository that shows the error. Thank you.

@ondrejmirtes
Copy link
Member

Most likely fixed with: phpstan/phpstan-src@9334ff3

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants