wataridori / framgia-php-codesniffer

The Coding Standard package for Code Sniffer to check whether your codes satisfy the Framgia Standard or not.
MIT License
13 stars 13 forks source link

phpcbf wrong fix #4

Open tuanpht opened 6 years ago

tuanpht commented 6 years ago

Giả sử em có đoạn code như thế này:

<?php

$relation = null;
if($condition) {
    $model = Model::where('id', $uuid)->with(['relation' => function($query){
        $query->fromSelf()->includePrices()->includeSomething()->orderBy('updated_at', 'desc');
    }])->first();
    $relation = $model->relation;
} else if($otherCondition) {
    $relation = Relation::where('model_id', $uuid)->fromSelf()->includePrices()->includeSomething()->orderBy('updated_at', 'desc')->get();
}

Sau khi chạy lệnh phpcbf --standard=Framgia -n test.php --suffix=.fixed, thì được file mới:

<?php

$relation = null;
if ($condition) {
    $model = Model::where('id', $uuid)->with(['relation' => function ($query) {
        $query->fromSelf()->includePrices()->includeSomething()->orderBy('updated_at', 'desc');
    },
    ])->first();,
    $relation = $model->relation;
} else if ($otherCondition) {
    $relation = Relation::where('model_id', $uuid)->fromSelf()->includePrices()->includeSomething()->orderBy('updated_at', 'desc')->get();
}

Diff:

4,5c4,5
< if($condition) {
<     $model = Model::where('id', $uuid)->with(['relation' => function($query){
---
> if ($condition) {
>     $model = Model::where('id', $uuid)->with(['relation' => function ($query) {
7c7,8
<     }])->first();
---
>     },
>     ])->first();,
9c10
< } else if($otherCondition) {
---
> } else if ($otherCondition) {

Em chưa fix được nên để tạm issue ở đây

dangminhtruong commented 5 years ago

@tuanpht phpcbf fix xong minhfphair review lại cơ. Nhiều khi nó thêm dấu , không đúng chỗ làm lỗi tùm lum

tuanpt-0634 commented 5 years ago

@dangminhtruong uhm, không tin tưởng phpcbf lắm, nên mình chỉ dùng php-cs-fixer :))