plugin icon indicating copy to clipboard operation
plugin copied to clipboard

Magick Method Laravel IDE x Qodana

Open elvispdosreis opened this issue 2 years ago • 11 comments

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

elvispdosreis avatar Aug 05 '23 00:08 elvispdosreis

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

adelf avatar Aug 05 '23 07:08 adelf

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');
        });

elvispdosreis avatar Aug 05 '23 12:08 elvispdosreis

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

adelf avatar Aug 05 '23 12:08 adelf

<?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
)
;

elvispdosreis avatar Aug 05 '23 12:08 elvispdosreis

Thank you. I'll check.

adelf avatar Aug 05 '23 13:08 adelf

hi, did you manage to check

elvispdosreis avatar Aug 18 '23 12:08 elvispdosreis

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

adelf avatar Aug 18 '23 12:08 adelf

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

elvispdosreis avatar Aug 18 '23 15:08 elvispdosreis

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

adelf avatar Aug 18 '23 15:08 adelf

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,
            ]);
        });
    }
}

elvispdosreis avatar Aug 21 '23 12:08 elvispdosreis

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

image

adelf avatar Aug 21 '23 12:08 adelf