Skip to content

phpstan error because  #17

@hassifmohd

Description

@hassifmohd

Problem

when i do my code like below

$token = $this->Examples->Tokens->find()->first()
return $token->foreign_data['vendor_email']

then i got errors during phpstan

> phpstan analyse --memory-limit=512M
Note: Using configuration file /var/www/html/phpstan.neon.
 145/145 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

 ------ -------------------------------------------
  Line   src/Controller/ExamplesController.php
 ------ -------------------------------------------
  11     Cannot assign offset 'string' to string.
 ------ -------------------------------------------

 [ERROR] Found 1 error

Script phpstan analyse --memory-limit=512M handling the stan event returned with error code 1
Script @stan was called via check

Investigation

foreign_data currently is a string
https://github.com/UseMuffin/Tokenize/blob/master/src/Model/Entity/Token.php#L16

foreign_data should be an array because setColumnType=json
https://github.com/UseMuffin/Tokenize/blob/master/src/Model/Table/TokensTable.php#L118

Proposal

to put the correct properties
also to put other properties such as expired, created and modified

 * @property array $foreign_data
 * @property \Cake\I18n\FrozenTime $expired
 * @property \Cake\I18n\FrozenTime $created
 * @property \Cake\I18n\FrozenTime $modified

some example i would like to use for the expired property is

$token = $this->Examples->Tokens->find()->first()
return $token->expired->isPast()

Others

composer.json

...
"muffin/tokenize": "dev-cake-4.x",
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions