laravel-idea / plugin

Laravel Idea plugin for PhpStorm
https://laravel-idea.com/
173 stars 7 forks source link

Magick Method Laravel IDE x Qodana #802

Open elvispdosreis opened 1 year ago

elvispdosreis commented 1 year ago

Bug description

i am having alert with magic code generation in laravel IDE and Qodana

image

image

Plugin version

7.2.0.232

Operating system

Windows

Steps to reproduce

No response

Relevant log output

No response

adelf commented 1 year ago

Hello, Elvis. Have you generated a helper code? If yes, could you show the migration code for this field?

elvispdosreis commented 1 year ago

image

Schema::create('safira.sisobra_logs', function (Blueprint $table) {
            $table->id();
            $table->foreignId('usuario_id')->nullable(false)->comment('Usuário')->constrained('geral.usuarios')->onUpdate('cascade')->onDelete('restrict');
            $table->foreignId('documento_id')->nullable(false)->comment('Documento Alvará/Habite-se')->constrained('geral.documentos')->onUpdate('cascade')->onDelete('restrict');
            $table->string('codigo')->default(false)->comment('Código');
            $table->tinyText('descricao')->default(false)->comment('Descrição');
            $table->longText('xml')->default(false)->comment('XML');

            $table->softDeletes()->comment('Excluído Logicamente');
            $table->timestamp('created_at')->useCurrent()->comment('Criado');
            $table->timestamp('updated_at')->useCurrent()->comment('Alterado');
        });
adelf commented 1 year ago

Could you also share a model class? How is the table calculated? $table field?

elvispdosreis commented 1 year ago
<?php

namespace App\Models\Safira;

use App\Models\Contribuinte;
use App\Models\Documento;
use App\Models\Usuario;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
use Illuminate\Database\Eloquent\SoftDeletes;

class SisObraLog extends Model
{
    use SoftDeletes;

    protected $table = 'safira.sisobra_logs';

    public function usuario(): BelongsTo
    {
        return $this->BelongsTo(Usuario::class);
    }

    public function documento(): BelongsTo
    {
        return $this->BelongsTo(Documento::class);
    }

    public function contribuinte(): HasManyThrough
    {
        return $this->hasOneThrough(Contribuinte::class, Usuario::class, 'id', 'id', 'usuario_id', 'contribuinte_id');
    }
}
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('safira.sisobra_logs', function (Blueprint $table) {
            $table->id();
            $table->foreignId('usuario_id')->nullable(false)->comment('Usuário')->constrained('geral.usuarios')->onUpdate('cascade')->onDelete('restrict');
            $table->foreignId('documento_id')->nullable(false)->comment('Documento Alvará/Habite-se')->constrained('geral.documentos')->onUpdate('cascade')->onDelete('restrict');
            $table->string('codigo')->default(false)->comment('Código');
            $table->tinyText('descricao')->default(false)->comment('Descrição');
            $table->longText('xml')->default(false)->comment('XML');

            $table->softDeletes()->comment('Excluído Logicamente');
            $table->timestamp('created_at')->useCurrent()->comment('Criado');
            $table->timestamp('updated_at')->useCurrent()->comment('Alterado');
        });

        DB::unprepared('ALTER TABLE IF EXISTS safira.sisobra_logs OWNER TO safira;');
        DB::unprepared("INSERT INTO safira.tabela_auditadas(tabela, ativo) VALUES ('sisobra_logs', 't');");
    }

    public function down(): void
    {
        Schema::dropIfExists('safira.sisobra_logs');
    }
};
CREATE TABLE "safira"."sisobra_logs" (
  "id" int8 NOT NULL DEFAULT nextval('"safira".sisobra_logs_id_seq'::regclass),
  "usuario_id" int8 NOT NULL,
  "documento_id" int8 NOT NULL,
  "codigo" varchar(255) COLLATE "pg_catalog"."default" NOT NULL DEFAULT '0'::character varying,
  "descricao" varchar(255) COLLATE "pg_catalog"."default" NOT NULL DEFAULT '0'::character varying,
  "xml" text COLLATE "pg_catalog"."default" NOT NULL DEFAULT '0'::text,
  "deleted_at" timestamp(0),
  "created_at" timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  "updated_at" timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  CONSTRAINT "sisobra_logs_pkey" PRIMARY KEY ("id"),
  CONSTRAINT "safira_sisobra_logs_documento_id_foreign" FOREIGN KEY ("documento_id") REFERENCES "geral"."documentos" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
  CONSTRAINT "safira_sisobra_logs_usuario_id_foreign" FOREIGN KEY ("usuario_id") REFERENCES "geral"."usuarios" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
)
;
adelf commented 1 year ago

Thank you. I'll check.

elvispdosreis commented 1 year ago

hi, did you manage to check

adelf commented 1 year ago

Yes. Laravel Idea didn't know about "tinyText" method :( Sorry. It's fixed, and the new version will be released next week, I hope.

elvispdosreis commented 1 year ago

there are some other types of fields inside laravel, depending on the database you use

adelf commented 1 year ago

I know... I have to hard-code them.

elvispdosreis commented 1 year ago

could you check for me this alert

image

image

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Estado extends Model
{

    protected $with = ['pais:id,nome,iso2'];

    protected $table = 'geral.estados';

    protected $fillable = ['nome', 'pais_id'];

    protected $hidden = ['pais_id'];

    public function pais(): BelongsTo
    {
        return $this->belongsTo(Pais::class, 'pais_id', 'id');
    }

    public function cidades(): HasMany
    {
        return $this->hasMany(Cidade::class);
    }

    public static function firstOrCreateEstado($value, Pais $pais): Estado
    {
        return Estado::where('id', '=', $value['estado']['id'] ?? null)->firstOr(function () use ($value, $pais) {
            return Estado::firstOrCreate([
                'nome' => $value['estado']['nome'],
                'pais_id' => $pais->id,
            ]);
        });
    }
}
adelf commented 1 year ago

Laravel Idea suppresses these warnings for PhpStorm. However, Qodana uses its own inspections... maybe later, I could suppress them too.

image