Larastan: No support for different data types on primary keys

Created on 25 Mar 2020  ยท  5Comments  ยท  Source: nunomaduro/larastan

  • Larastan Version: ^7
  • --level used: 8

Description

It seems that larastan assumes $id is always an int or doesn't detect scenarios where it isn't, which causes problems when trying to assign/use the id variable. It also doesn't respect the model's docblock

Laravel code where the issue was found

/**
 * @property string $id
 */
class Something extends Model 
{
    protected $keyType = 'uuid';
}
$something = new Something();

// Fails with Property Something::$id (int) does not accept string.
$something->id = Uuid::uuid4()->toString(); 

ref: https://github.com/directus/api-next/runs/532762821

bug

Most helpful comment

It's fixed with #510

I'll release a new version with this fix later today.

All 5 comments

Hi,

Yes, I am aware of this issue. I'll try to fix it today.

It's fixed with #510

I'll release a new version with this fix later today.

Sounds like this hasn't been fixed fur us with #510 รฌn v0.5.5

jo@jofix: fix_linting โ†“2โ†‘5 โœš1 ~/git/directus/api-next $ composer show nunomaduro/larastan
name     : nunomaduro/larastan
descrip. : Larastan - Discover bugs in your code without running it. A phpstan/phpstan wrapper for Laravel
keywords : PHPStan, code analyse, code analysis, larastan, laravel, package, php, static analysis
versions : * v0.5.5
type     : phpstan-extension
license  : MIT License (MIT) (OSI approved) https://spdx.org/licenses/MIT.html#licenseText
homepage : 
source   : [git] https://github.com/nunomaduro/larastan.git 0a24d9c809185b04d00d8b8c1b58a6581cae6c40
dist     : [zip] https://api.github.com/repos/nunomaduro/larastan/zipball/0a24d9c809185b04d00d8b8c1b58a6581cae6c40 0a24d9c809185b04d00d8b8c1b58a6581cae6c40
path     : /var/xgit/directus/api-next/vendor/nunomaduro/larastan
names    : nunomaduro/larastan

autoload
psr-4
NunoMaduro\Larastan\ => src/

requires
composer/composer ^1.0
ext-json *
illuminate/console ^6.0 || ^7.0
illuminate/container ^6.0 || ^7.0
illuminate/contracts ^6.0 || ^7.0
illuminate/database ^6.0 || ^7.0
illuminate/http ^6.0 || ^7.0
illuminate/pipeline ^6.0 || ^7.0
illuminate/support ^6.0 || ^7.0
mockery/mockery ^0.9 || ^1.0
php ^7.2
phpstan/phpstan ^0.12
symfony/process ^4.3 || ^5.0

requires (dev)
orchestra/testbench ^4.0 || ^5.0
phpunit/phpunit ^7.3 || ^8.2

suggests
orchestra/testbench ^4.0 || ^5.0
jo@jofix: fix_linting โ†“2โ†‘5 โœš1 ~/git/directus/api-next $ composer lint                    
> php-cs-fixer --ansi fix --diff --dry-run
Loaded config default from "/var/xgit/directus/api-next/.php_cs".
Using cache file ".php_cs.cache".

Checked all files in 0.004 seconds, 14.000 MB memory used
> phpstan --ansi --memory-limit=2G analyse
Note: Using configuration file /var/xgit/directus/api-next/phpstan.neon.
 46/46 [โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“] 100%

 ------ --------------------------------------------------------------------- 
  Line   src/Database/System/Services/CollectionsService.php                  
 ------ --------------------------------------------------------------------- 
  30     Property Directus\Database\System\Models\Collection::$id (int) does  
         not accept string.                                                   
 ------ --------------------------------------------------------------------- 


 [ERROR] Found 1 error                                                          


Script phpstan --ansi --memory-limit=2G analyse handling the lint:phpstan event returned with error code 1
Script @lint:phpstan was called via lint
jo@jofix: fix_linting โ†“2โ†‘5 โœš1 ~/git/directus/api-next $ 

Are other properties working for you?

The other properties seems to be working fine, but id is still treated as int for some reason.

https://github.com/directus/api-next/blob/master/src/Database/System/Models/Collection.php#L14

Was this page helpful?
0 / 5 - 0 ratings