cakephp-phpstan icon indicating copy to clipboard operation
cakephp-phpstan copied to clipboard

Feature/table methods throws

Open rochamarcelo opened this issue 4 months ago • 3 comments

For https://github.com/CakeDC/cakephp-phpstan/issues/47

I'm not 100% sure if this is the way to handle the issue reported.

@LordSimal Could you please test this.

rochamarcelo avatar Oct 15 '25 21:10 rochamarcelo

Sorry for the late response. I tried this branch, but it doesn't fix my problem. If I remove the phpstan-ignore line from

    public function batnodePorts(NginxConfigUtility $nginxConfigUtility): Response
    {
        $optionsTable = $this->fetchTable('Options');
        try {
            $ports = $optionsTable->get('BatnodePorts');
        /** @phpstan-ignore catch.neverThrown */
        } catch (RecordNotFoundException) {
            $ports = new Option(['alfred_key' => 'BatnodePorts', 'value' => '']);
        }

phpstan complaints again for me with

 ------ -------------------------------------------------------------------------------------------------- 
  Line   plugins/AlfredTools/src/Controller/ToolsController.php                                            
 ------ -------------------------------------------------------------------------------------------------- 
  616    Dead catch - Cake\Datasource\Exception\RecordNotFoundException is never thrown in the try block.  
         🪪  catch.neverThrown                                                                             
         at plugins/AlfredTools/src/Controller/ToolsController.php:616                                     
 ------ -------------------------------------------------------------------------------------------------- 

LordSimal avatar Nov 10 '25 12:11 LordSimal

How does your Tools table compares with MyUsersTable.php ?

rochamarcelo avatar Nov 10 '25 17:11 rochamarcelo

I let that auto generate via the ide helper

/**
 * Options Model
 *
 * @method \App\Model\Entity\Option newEmptyEntity()
 * @method \App\Model\Entity\Option newEntity(array $data, array $options = [])
 * @method array<\App\Model\Entity\Option> newEntities(array $data, array $options = [])
 * @method \App\Model\Entity\Option get(mixed $primaryKey, array|string $finder = 'all', \Psr\SimpleCache\CacheInterface|string|null $cache = null, \Closure|string|null $cacheKey = null, mixed ...$args)
 * @method \App\Model\Entity\Option findOrCreate(\Cake\ORM\Query\SelectQuery|callable|array $search, ?callable $callback = null, array $options = [])
 * @method \App\Model\Entity\Option patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
 * @method array<\App\Model\Entity\Option> patchEntities(iterable $entities, array $data, array $options = [])
 * @method \App\Model\Entity\Option|false save(\Cake\Datasource\EntityInterface $entity, array $options = [])
 * @method \App\Model\Entity\Option saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = [])
 * @method \Cake\Datasource\ResultSetInterface<\App\Model\Entity\Option>|false saveMany(iterable $entities, array $options = [])
 * @method \Cake\Datasource\ResultSetInterface<\App\Model\Entity\Option> saveManyOrFail(iterable $entities, array $options = [])
 * @method \Cake\Datasource\ResultSetInterface<\App\Model\Entity\Option>|false deleteMany(iterable $entities, array $options = [])
 * @method \Cake\Datasource\ResultSetInterface<\App\Model\Entity\Option> deleteManyOrFail(iterable $entities, array $options = [])
 * @mixin \Cake\ORM\Behavior\TimestampBehavior
 * @extends \Cake\ORM\Table<array{Timestamp: \Cake\ORM\Behavior\TimestampBehavior}>
 */

LordSimal avatar Nov 10 '25 17:11 LordSimal