Giter Club home page Giter Club logo

Comments (1)

vpratfr avatar vpratfr commented on May 26, 2024

To add a little more information to that issue, as we are having the same one, this is what should be generated:

  • If Attribute::get defined + existing corresponding DB column : @property
  • If Attribute::get defined + no corresponding DB column : @property-read
  • If Attribute::set defined + existing corresponding DB column : @property
  • If Attribute::set defined + no corresponding DB column : @property-write
  • If Attribute::get defined : @property

PHPStan is indeed complaining that we are using a write-only property whereas it used to be fine.

Code to reproduce

class User extends Model {

    // Assuming we have a DB column `name`

    protected function name(): Attribute {
        return Attribute::get(fn($value) => Str::upper($value));
    }

    protected function randomName(): Attribute {
        return Attribute::get(fn() => Str::random());
    }

    public function resetName(): void {
        $this->name = '';
    }
}

In that case, @property-read $name is generated, whereas it should be @property $name.

Note that @property-read $random_name is generated, and that is correct, as no column is there to back it. Hence $user->random_name = 'something' would indeed be incorrect.

from laravel-ide-helper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.