MatanYadaev

MatanYadaev

Software Engineer @Showdigs

Member Since 6 years ago

Showdigs, Tel Aviv, Israel

Experience Points
2
follower
Lessons Completed
3
follow
Lessons Completed
38
stars
Best Reply Awards
19
repos

230 contributions in the last year

Pinned
⚡ Laravel Eloquent spatial package.
⚡ A Segment bridge for Laravel.
⚡ Phone number functionality for Laravel 5
⚡ A helper to control the flow of time
⚡ A community-driven content aggregator
⚡ A Postmark adapter for Laravel
Activity
Nov
23
1 week ago
Activity icon
issue

MatanYadaev issue comment pestphp/pest

MatanYadaev
MatanYadaev

Plans for `describe` blocks?

Curious, what are your thoughts about implementing the standard describe blocks?

Ala?

https://jestjs.io/docs/en/api#describename-fn

Example

describe('my block', function() {
  test('is delicious', function() {
    assertTrue(true);
  });
});
MatanYadaev
MatanYadaev

@nunomaduro Any expectation to see this feature in Pest v2? 😊

Nov
22
1 week ago
Activity icon
fork

MatanYadaev forked FakerPHP/Faker

⚡ Faker is a PHP library that generates fake data for you
MatanYadaev MIT License Updated
fork time in 1 week ago
Nov
18
1 week ago
Activity icon
issue

MatanYadaev issue comment nunomaduro/larastan

MatanYadaev
MatanYadaev

There's no option to configure multiple `MorphTo` related models

I have a model with a MorphTo relation to multiple models.

<?php

class Image extends Model
{
  public function imageable(): MorphTo
  {
    return $this->morphTo();
  }
}

class Post extends Model
{
  public function image(): MorphOne
  {
    return $this->morphOne(Image::class, 'imageable');
  }
}

class User extends Model
{
  public function image(): MorphOne
  {
    return $this->morphOne(Image::class, 'imageable');
  }
}

I want to be able to tell PhpStan which models Image is "morphing to", currently there's an option to choose only one model but not multiple models:

<?php

class Image extends Model
{
  /**
   * @return MorphTo<Post, Image>
   */  
  public function imageable(): MorphTo
  {
    return $this->morphTo();
  }
}

This is my expected behavior:

<?php

class Image extends Model
{
  /**
   * @return MorphTo<Post | User, Image>
   */  
  public function imageable(): MorphTo
  {
    return $this->morphTo();
  }
}

// Or

class Image extends Model
{
  /**
   * @return MorphTo<Post, Image> | MorphTo<User, Image>
   */  
  public function imageable(): MorphTo
  {
    return $this->morphTo();
  }
}

Currently when I run one of these two examples, PHPStan throws this error message: Internal error: Internal error: Call to undefined method PHPStan\Type\UnionType::getClassName() in file ...

MatanYadaev
MatanYadaev

@szepeviktor Can we have multiple TRelatedModel? Currently it's limited to only one TRelatedModel.

Activity icon
issue

MatanYadaev issue nunomaduro/larastan

MatanYadaev
MatanYadaev

There's no option to configure multiple `MorphTo` related models

I have a model with a MorphTo relation to multiple models.

<?php

class Image extends Model
{
  public function imageable(): MorphTo
  {
    return $this->morphTo();
  }
}

class Post extends Model
{
  public function image(): MorphOne
  {
    return $this->morphOne(Image::class, 'imageable');
  }
}

class User extends Model
{
  public function image(): MorphOne
  {
    return $this->morphOne(Image::class, 'imageable');
  }
}

I want to be able to tell PhpStan which models Image is "morphing to", currently there's an option to choose only one model but not multiple models:

<?php

class Image extends Model
{
  /**
   * @return MorphTo<Post, Image>
   */  
  public function imageable(): MorphTo
  {
    return $this->morphTo();
  }
}

This is my expected behavior:

<?php

class Image extends Model
{
  /**
   * @return MorphTo<Post | User, Image>
   */  
  public function imageable(): MorphTo
  {
    return $this->morphTo();
  }
}

// Or

class Image extends Model
{
  /**
   * @return MorphTo<Post, Image> | MorphTo<User, Image>
   */  
  public function imageable(): MorphTo
  {
    return $this->morphTo();
  }
}

Currently when I run one of these two examples, PHPStan throws this error message: Internal error: Internal error: Call to undefined method PHPStan\Type\UnionType::getClassName() in file ...

Activity icon
issue

MatanYadaev issue comment nunomaduro/larastan

MatanYadaev
MatanYadaev

Call to an undefined method Illuminate\Database\Eloquent\Relations\MorphTo::withTrashed()

  • Larastan Version: 0.7.12
  • --level used: 4

Description

The issue is similar to #225 and it was mentioned in the comments, but it is still not fixed therefor the new ticket.

Call to an undefined method Illuminate\Database\Eloquent\Relations\MorphTo::withTrashed()

Laravel code where the issue was found

public function loggableUser()
{
     return $this->morphTo()->withTrashed();
}
MatanYadaev
MatanYadaev

@canvural There's an option to define multiple models under the ModelItResolvesTo generic type?

Activity icon
issue

MatanYadaev issue kitloong/laravel-migrations-generator

MatanYadaev
MatanYadaev

Providing `spatialIndex` parameters although it shouldn't receive any parameters

The package generates a migration file with spatial indexes and passes an index name as a parameter, although spatialIndex shouldn't receive any parameters.

<?php

// Current:
$table->point('location')->spatialIndex('properties_location_spatial');

// Should be:
$table->point('location')->spatialIndex();
Activity icon
issue

MatanYadaev issue comment nunomaduro/larastan

MatanYadaev
MatanYadaev

Call to an undefined method Eloquent\Builder::restore

Description

Larastan finds an issue when calling the method Illuminate\Database\Eloquent\Builder::restore of models that have the SoftDeletes trait.

Laravel code where the issue was found

<?php

class User extends Model
{
    use SoftDeletes;

    // ...
}

User::query()->onlyTrashed()->restore(); // Call to an undefined method Illuminate\Database\Eloquent\Builder<App\User>::restore().
Activity icon
issue

MatanYadaev issue phpstan/phpstan

MatanYadaev
MatanYadaev

PHPStan doesn't infer exceptions that are thrown with generics.

Bug report

PHPStan doesn't infer exceptions that are thrown with generics.

Code snippet that reproduces the problem

https://phpstan.org/r/f22aaf48-3d7f-4c6d-a094-fc0b5e66cf83

Expected output

I would expect PHPStan to know that the thrown exception should be \LengthException and not \LogicException and alert that.

Did PHPStan help you today? Did it make you happy in any way?

Love it. It helps me so much.

Activity icon
fork

MatanYadaev forked laravel/framework

⚡ The Laravel Framework.
MatanYadaev MIT License Updated
fork time in 1 week ago
Activity icon
issue

MatanYadaev issue nunomaduro/larastan

MatanYadaev
MatanYadaev

Call to an undefined method Eloquent\Builder::restore

Description

Larastan finds an issue when calling the method Illuminate\Database\Eloquent\Builder::restore of models that have the SoftDeletes trait.

Laravel code where the issue was found

<?php

class User extends Model
{
    use SoftDeletes;
    // ...
}

User::query()->onlyTrashed()->restore(); // Call to an undefined method Illuminate\Database\Eloquent\Builder<App\User>::restore().
Activity icon
created branch

MatanYadaev in MatanYadaev/larastan create branch builder_restore

createdAt 1 week ago
push

MatanYadaev push MatanYadaev/larastan

MatanYadaev
MatanYadaev

refactor: CheckDispatchArgumentTypesCompatibleWithClassConstructorRule can check both Event and Job classes

MatanYadaev
MatanYadaev

fix: groupBy Collection method signature

MatanYadaev
MatanYadaev

Clarified static analysis wording, since Larastan is not static analysis (#1008)

MatanYadaev
MatanYadaev

Revert "feat: update stubs to use non-empty-string"

This reverts commit c5b81cfee07686e2ce0ea557f8e32f2f022d47eb.

MatanYadaev
MatanYadaev
MatanYadaev
MatanYadaev

feat: adds throw types for macros

MatanYadaev
MatanYadaev

update default config to match new highest level

MatanYadaev
MatanYadaev

fix: correct method reflection for magic with* calls on RedirectResponse

MatanYadaev
MatanYadaev

docs(readme): update installation instructions

MatanYadaev
MatanYadaev

feat: improve return types for Collection::first, last, get and pull when default value is given. (#1010)

MatanYadaev
MatanYadaev

fix: macros can have side effects

MatanYadaev
MatanYadaev

fix: Eloquent collection has array-key for the key type (#1027)

MatanYadaev
MatanYadaev

fix: Laravel container can have scalar bindings (#1028)

MatanYadaev
MatanYadaev

fix: the tap helper should not enforce any return type for the callback

commit sha: 19098c78b33fc25ba6289d12538729a58cd60678

push time in 1 week ago
Nov
16
2 weeks ago
Activity icon
issue

MatanYadaev issue comment nunomaduro/larastan

MatanYadaev
MatanYadaev

Missing support for inbound casting

  • Larastan Version: latest
  • --level used: 6

Description

Using inbound casting: https://laravel.com/docs/8.x/eloquent-mutators#inbound-casting.

    protected $casts = [
        'bio' => Markdown::class, // sets the attribute value to a `string`
    ];

Larastan thinks that $model->bio is a Markdown instance instead of a string.

pull request

MatanYadaev pull request MatanYadaev/larastan

MatanYadaev
MatanYadaev

Add custom builder to user model

Nov
14
2 weeks ago
Activity icon
issue

MatanYadaev issue comment barryvdh/laravel-ide-helper

MatanYadaev
MatanYadaev

Improve casts support

Summary

Provides support for all missing types for Model::$casts including decimal:*, custom_datetime, encrypted:*, immutable_date, and immutable_custom_datetime. Resolves #1257

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • Existing tests have been adapted and/or new tests have been added
  • Add a CHANGELOG.md entry
  • [ n/a ] Update the README.md
  • Code style has been fixed via composer fix-style
MatanYadaev
MatanYadaev
Nov
2
4 weeks ago
Activity icon
issue

MatanYadaev issue nunomaduro/larastan

MatanYadaev
MatanYadaev

Custom builders break model methods return type inference

Description

When using custom builders with models, Larastan doesn't infer correctly the model methods' return type, for example, Larastan infers User::first() or User::create($data) return Model instead of User. When you remove the newEloquentBuilder method - this issue is gone. The issue is 100% because of the custom builder.

Laravel code where the issue was found

/**
 * @extends Builder<User>
 */
class UserBuilder extends Builder
{
  //
}
class User extends Model
{
  /**
   * @param  \Illuminate\Database\Query\Builder  $query
   * @return UserBuilder<User>
   */
  public function newEloquentBuilder($query): UserBuilder
  {
    return new UserBuilder($query);
  }

  public function doSomething(): void
  {
    //
  }
}
$user = User::first();
$user->doSomething(); // Call to an undefined method Illuminate\Database\Eloquent\Model::doSomething().
Activity icon
issue

MatanYadaev issue comment nunomaduro/larastan

MatanYadaev
MatanYadaev

Custom builders break model methods return type inference

Description

When using custom builders with models, Larastan doesn't infer correctly the model methods' return type, for example, Larastan infers User::first() or User::create($data) return Model instead of User. When you remove the newEloquentBuilder method - this issue is gone. The issue is 100% because of the custom builder.

Laravel code where the issue was found

/**
 * @extends Builder<User>
 */
class UserBuilder extends Builder
{
  //
}
class User extends Model
{
  /**
   * @param  \Illuminate\Database\Query\Builder  $query
   * @return UserBuilder<User>
   */
  public function newEloquentBuilder($query): UserBuilder
  {
    return new UserBuilder($query);
  }

  public function doSomething(): void
  {
    //
  }
}
$user = User::first();
$user->doSomething(); // Call to an undefined method Illuminate\Database\Eloquent\Model::doSomething().
MatanYadaev
MatanYadaev

NVM. Managed to fix it. This is my final stub:

<?php

namespace Grimzy\LaravelMysqlSpatial\Eloquent;

use Grimzy\LaravelMysqlSpatial\Eloquent\SpatialExpression;
use Grimzy\LaravelMysqlSpatial\Types\GeometryInterface;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;

/**
 * @template TModelClass of \Illuminate\Database\Eloquent\Model
 * @extends EloquentBuilder<TModelClass>
 */
class Builder extends EloquentBuilder
{
}

Thanks for the help!

Activity icon
issue

MatanYadaev issue comment nunomaduro/larastan

MatanYadaev
MatanYadaev

Custom builders break model methods return type inference

Description

When using custom builders with models, Larastan doesn't infer correctly the model methods' return type, for example, Larastan infers User::first() or User::create($data) return Model instead of User. When you remove the newEloquentBuilder method - this issue is gone. The issue is 100% because of the custom builder.

Laravel code where the issue was found

/**
 * @extends Builder<User>
 */
class UserBuilder extends Builder
{
  //
}
class User extends Model
{
  /**
   * @param  \Illuminate\Database\Query\Builder  $query
   * @return UserBuilder<User>
   */
  public function newEloquentBuilder($query): UserBuilder
  {
    return new UserBuilder($query);
  }

  public function doSomething(): void
  {
    //
  }
}
$user = User::first();
$user->doSomething(); // Call to an undefined method Illuminate\Database\Eloquent\Model::doSomething().
MatanYadaev
MatanYadaev

@canvural The package is completely abandoned, so a PR is not a question. About the second option, I added a stub, but it still doesn't work. Maybe I did it wrong? https://github.com/MatanYadaev/larastan/pull/1/files#diff-38519629a21b200bd3a828240670ceab018dca68c0da27e906554053114f3503

Activity icon
issue

MatanYadaev issue comment nunomaduro/larastan

MatanYadaev
MatanYadaev

Custom builders break model methods return type inference

Description

When using custom builders with models, Larastan doesn't infer correctly the model methods' return type, for example, Larastan infers User::first() or User::create($data) return Model instead of User. When you remove the newEloquentBuilder method - this issue is gone. The issue is 100% because of the custom builder.

Laravel code where the issue was found

/**
 * @extends Builder<User>
 */
class UserBuilder extends Builder
{
  //
}
class User extends Model
{
  /**
   * @param  \Illuminate\Database\Query\Builder  $query
   * @return UserBuilder<User>
   */
  public function newEloquentBuilder($query): UserBuilder
  {
    return new UserBuilder($query);
  }

  public function doSomething(): void
  {
    //
  }
}
$user = User::first();
$user->doSomething(); // Call to an undefined method Illuminate\Database\Eloquent\Model::doSomething().
MatanYadaev
MatanYadaev

Hi @szepeviktor, thanks for the super quick response. I read the upgrade guide, it didn't help, but I realize what causes my issue. My custom builder is actually extending another custom builder - I updated my PR so you could check it. My custom builder extends \Grimzy\LaravelMysqlSpatial\Eloquent\Builder.

I encourage you to reach level 4 which is - in Viktor terms - the healthy application. I really wish to reach that, my project is currently on level 1 with a massive amount PHPStan issue, I try to tackle them one by one until I'll reach level 3 or 4. Thanks for the tip.

Activity icon
issue

MatanYadaev issue nunomaduro/larastan

MatanYadaev
MatanYadaev

Custom builders break model methods return type inference

Description

When using custom builders with models, Larastan doesn't infer correctly the return type model methods, for example ->first() or ->create(). It assumes it's Model instead of User (for example). When you remove the newEloquentBuilder method - this issue is gone. The issue is 100% because of the custom builder.

Laravel code where the issue was found

/**
 * @extends Builder<User>
 */
class UserBuilder extends Builder
{
  //
}
class User extends Model
{
  public function newEloquentBuilder($query): UserBuilder
  {
    return new UserBuilder($query);
  }

  public function doSomething(): void
  {
    //
  }
}
$user = User::first();
$user->doSomething(); // Call to an undefined method Illuminate\Database\Eloquent\Model::doSomething().
pull request

MatanYadaev pull request MatanYadaev/larastan

MatanYadaev
MatanYadaev

Add custom builder to user model

Activity icon
created branch

MatanYadaev in MatanYadaev/larastan create branch custom_builders_break_model_method_return_type_inference

createdAt 4 weeks ago
Activity icon
fork

MatanYadaev forked nunomaduro/larastan

⚡ ⚗️ Adds static analysis to Laravel improving developer productivity and code quality.
MatanYadaev MIT License Updated
fork time in 4 weeks ago
Oct
27
1 month ago