Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP-CS-Fixer の導入 #996

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Conversation

nanasess
Copy link
Contributor

@nanasess nanasess commented Sep 5, 2024

  • strlen($val) で null チェックしているのを修正するのが主目的
    • 未定義変数や連想配列での扱いに副作用があるため除外
  • その他、統一した方が良さそうなルールを適用
  • PHP8.3で以下のコマンドを実行
    PHP_CS_FIXER_IGNORE_ENV=1 data/vendor/bin/php-cs-fixer fix  --allow-risky=yes
    

Copy link

codecov bot commented Sep 5, 2024

Codecov Report

Attention: Patch coverage is 45.87459% with 820 lines in your changes missing coverage. Please review.

Project coverage is 56.23%. Comparing base (74eaa0a) to head (20138d0).

Files with missing lines Patch % Lines
data/class/helper/SC_Helper_Customer.php 7.19% 129 Missing ⚠️
data/class/helper/SC_Helper_CSV.php 0.00% 105 Missing ⚠️
data/class/helper/SC_Helper_Transform.php 0.00% 59 Missing ⚠️
data/class/SC_Image.php 2.50% 39 Missing ⚠️
data/class/SC_Fpdf.php 11.76% 30 Missing ⚠️
data/class/api/SC_Api_Operation.php 0.00% 30 Missing ⚠️
data/class/api/SC_Api_Utils.php 0.00% 29 Missing ⚠️
data/class/helper/SC_Helper_PageLayout.php 25.64% 29 Missing ⚠️
data/class/api/operations/ItemLookup.php 0.00% 28 Missing ⚠️
data/class/SC_Initial.php 0.00% 27 Missing ⚠️
... and 44 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #996      +/-   ##
==========================================
- Coverage   56.29%   56.23%   -0.07%     
==========================================
  Files          75       75              
  Lines        8917     9046     +129     
==========================================
+ Hits         5020     5087      +67     
- Misses       3897     3959      +62     
Flag Coverage Δ
tests 56.23% <45.87%> (-0.07%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@seasoftjapan
Copy link
Contributor

6f20c7d は、全て PHP-CS-Fixer による変更ですか?

ローカルで bfc9f5d から実行を試したのですが、結果が異なる様子でして。

$ data/vendor/bin/php-cs-fixer fix --allow-risky=yes --dry-run
Loaded config default from "****/.php-cs-fixer.dist.php".
   1) data/class/SC_Customer.php
   2) data/class/helper/SC_Helper_TaxRule.php
   3) data/class/helper/SC_Helper_CSV.php
   4) data/class/SC_Fpdf.php
   5) data/class/pages/guide/LC_Page_Guide_Kiyaku.php
   6) data/class/pages/shopping/LC_Page_Shopping.php
   7) data/class/pages/products/LC_Page_Products_List.php
   8) data/class/pages/admin/contents/LC_Page_Admin_Contents_Recommend.php
   9) data/class/pages/admin/contents/LC_Page_Admin_Contents_RecommendSearch.php
  10) data/class/pages/admin/mail/LC_Page_Admin_Mail_Preview.php
  11) data/class/pages/admin/design/LC_Page_Admin_Design.php
  12) data/class/pages/admin/design/LC_Page_Admin_Design_MainEdit.php
  13) data/class/pages/admin/order/LC_Page_Admin_Order_Mail.php
  14) data/class/pages/admin/order/LC_Page_Admin_Order_Edit.php
  15) data/class/pages/admin/order/LC_Page_Admin_Order_Disp.php
  16) data/class/pages/admin/order/LC_Page_Admin_Order_ProductSelect.php
  17) data/class/pages/admin/products/LC_Page_Admin_Products_Product.php
  18) data/class/pages/mypage/LC_Page_Mypage_Favorite.php
  19) data/module/HTTP/Request.php

Checked all files in 20.817 seconds, 24.000 MB memory used

正しい実行手順を教えていただけますと幸いです。

@nanasess
Copy link
Contributor Author

nanasess commented Sep 5, 2024

@seasoftjapan
そのままだと composer.json の config.platform.php: 7.4.0 が有効になっていて、PHP8.0以降のルールが適用されないようです。
以下でいかがでしょうか?

PHP_CS_FIXER_IGNORE_ENV=1 data/vendor/bin/php-cs-fixer fix --allow-risky=yes

また、 --diff オプションをつけていただくと、原因がわかりやすいです

@nanasess
Copy link
Contributor Author

nanasess commented Sep 5, 2024

テストが落ちているようなので、一旦 Draft に戻します

@nanasess nanasess marked this pull request as draft September 5, 2024 12:34
@nanasess
Copy link
Contributor Author

nanasess commented Sep 6, 2024

未定義変数、連想配列の扱いに難がありそう

data/class/SC_CartSession.php Show resolved Hide resolved
@@ -41,7 +40,7 @@ class API_CartAdd extends SC_Api_Abstract_Ex
public function doAction($arrParam)
{
$this->arrResponse = array(
'Version' => ECCUBE_VERSION);
'Version' => ECCUBE_VERSION, );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

カンマの後、改行してくれるオプションとか無いでしょうか?
いくつか、気持ちの悪い(中途半端な)印象の整形がありました。

Copy link
Contributor Author

@nanasess nanasess Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trailing_comma_in_multiline が有効になっていると、複数行の配列で、末尾は改行しないパターンでこのようになってしまうようです。
複数行を強制するルールは実装されていないようなので、 trailing_comma_in_multiline => false にしたいと思います
https://cs.symfony.com/doc/rules/control_structure/trailing_comma_in_multiline.html

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

気持ち悪いですが、それでも今後の Diff を整えられる全体的なメリットを考えると、ケツカンマの徹底は優先して良いと思います。

とは言え、やはり気持ち悪いし、その箇所は Diff を改善できないので、, ] となる箇所は私が修正しようと思います。どの流れが良いとかありますか?

Copy link
Contributor Author

@nanasess nanasess Oct 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seasoftjapan

本 PR はルールを戻して、, ] となった箇所を別 Issue で修正する。

この対応にしましょうかね。
trailing_comma_in_multiline => false は削除しておきます(@Symfony に含まれているため)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trailing_comma_in_multiline => false は削除して再度 fix しておきました
20138d0

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ありがとうございます。
#1017 登録しました。

@@ -125,27 +125,27 @@ protected function getProductsList($searchCondition, $disp_number, $startno, $li
case 'price':
$objProduct->setProductsOrder('price02', 'dtb_products_class', 'ASC');
break;
// 販売価格が高い順
// 販売価格が高い順
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これ、救えないですかね。case のコメントで、case の真上に欲しいです。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'statement_indentation' => ['stick_comment_to_next_continuous_control_statement' => true] とすることで対応できそうです。
https://cs.symfony.com/doc/rules/whitespace/statement_indentation.html
が、 composer の依存関係の問題で、現在 php-cs-fixer 3.9.5 がインストールされています。
このバージョンでは上記オプションは未実装のため、利用できないようです。
PHPUnit のバージョンを上げることで、上記オプションも利用できるようになりそうなので、別途対応しようと思います。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

以下 PR 作成しました
#1020

.php-cs-fixer.dist.php Outdated Show resolved Hide resolved
.php-cs-fixer.dist.php Outdated Show resolved Hide resolved
.php-cs-fixer.dist.php Outdated Show resolved Hide resolved
.php-cs-fixer.dist.php Show resolved Hide resolved
data/class/SC_Batch.php Show resolved Hide resolved
@nanasess
Copy link
Contributor Author

nanasess commented Sep 9, 2024

@seasoftjapan ありがとうございます!おおむね対応可能だと思いますので、順次対応していきますね

@nanasess
Copy link
Contributor Author

2.13.x のソースに対しても同様のルールを適用できそうなので、これを活用すれば旧バージョンからのマージや PHP8 対応も楽にできそう

- コメント追記
- `single_quote => true` に変更(4系にあわせる)
- `concat_space => ['spacing' => 'none']` に変更(4系にあわせる)
- `array_syntax => true` に変更(4系にあわせる)
- `phpdoc_scalar => true` に変更(phpdoc の int や bool を統一したい)
- `data/smarty_extends` 及び `tests` にも適用
@nanasess
Copy link
Contributor Author

@seasoftjapan
以下のルールを見直してみました

  • single_quote => true に変更(4系にあわせる)
  • concat_space => ['spacing' => 'none'] に変更(4系にあわせる)
  • array_syntax => true に変更(4系にあわせる)
  • phpdoc_scalar => true に変更(phpdoc の int や bool を統一したい)
  • data/smarty_extends 及び tests にも適用

各ルールにコメントも入れておきましたのでご確認お願いいたします🙇‍♂️
94d493c

@nanasess
Copy link
Contributor Author

nanasess commented Oct 3, 2024

GitHub Actions のエラーは以下 PR で解消予定
#1018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants