0

I realize this goes against proper coding standards but I don't care.

I want my migration files checked by PHPCS.

I removed the following line from my phpcs.xml file.

<exclude-pattern>*/migrations/*</exclude-pattern>

I then formatted the following migration file to see if it was working.

<?php

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




class MigrationExampleClass extends Migration





{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('agreements', function (Blueprint $table) {
            $table->unsignedInteger('subject_id')->nullable()->change();
            $table->string('subject_type')->nullable()->change();
            $table->dropUnique('agreements_type_user_id_subject_id_version_uniqueso;jfgjdfjgisdgjdfidfgjddfifgbjfgnidfbjdfbjfgnjdfbjdfvjdfbjdfbj');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('agreements', function (Blueprint $table) {
            $table->string('subject_id')->change();
            $table->string('subject_type')->change();

            $table->unique(['type', 'user_id', 'subject_id', 'version']);
        });
    }
}

This would get flagged by PHPCS if this were a normal php file but it isn't.

Is there something else I have to do to get my migration files checked?

Evan Lalo
  • 1,209
  • 1
  • 14
  • 34
  • If it's a `.php` file, it will get checked by PHPCS if you've pointed to the correct directory. Try running PHPCS over the file directly (`phpcs /path/to/migrations/...php`) and making sure you get errors. If you do, run PHPCS as normal, but with the `-v` command line argument to you can see which files are being checked. – Greg Sherwood Oct 19 '19 at 05:43
  • I've run phpcs referencing the file explicitly but it did not find any errors. Any thoughts? – Evan Lalo Oct 22 '19 at 17:55
  • Is the file extension `.php`? If not, PHPCS may just be skipping it because it doesn't know that it's a PHP file. If that's the case, try running PHPCS with the `--extensions` CLI argument. For example, `phpcs /path/to/file.foo --extensions=foo` – Greg Sherwood Oct 23 '19 at 20:42

0 Answers0