質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.47%
PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

Q&A

解決済

1回答

4872閲覧

php-cs-fixer: Files that were not fixed due to errors reported during linting before fixing エラー

ucan-lab

総合スコア888

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

0グッド

1クリップ

投稿2020/11/23 06:00

環境

  • PHP: 7.4.6
  • PHP CS Fixer: 2.13.0

実行したコマンド

$ docker run --rm --volume `pwd`:/project herloct/php-cs-fixer fix --diff --diff-format udiff --verbose . Loaded config default from "/project/./.php_cs.dist". Using cache file ".php_cs.cache". Paths from configuration file have been overridden by paths provided as command arguments. SISIISIS Legend: ?-unknown, I-invalid file syntax, file ignored, S-Skipped, .-no changes, F-fixed, E-error Checked all files in 0.044 seconds, 10.000 MB memory used Files that were not fixed due to errors reported during linting before fixing: 1) /project/src/App/Hoge.php

Hoge.php のプロパティ型指定を外すとこのエラーが発生しなくなります。

// protected Foo $foo; // Error protected $foo; // OK

プロパティの型指定は付けていきたいので、このエラーをどうやったら直せるのかを知りたいです...。

補足: .php_cs.dist

使用しているルールはこちらです。
(ちなみに全部のルールをコメントアウトしても結果は同じでした...)

php

1<?php declare(strict_types=1); 2 3return PhpCsFixer\Config::create() 4 ->setRiskyAllowed(true) 5 ->setRules([ 6 '@PSR2' => true, 7 'align_multiline_comment' => true, 8 'array_syntax' => ['syntax' => 'short'], 9 'binary_operator_spaces' => [ 10 'align_double_arrow' => false, 11 'align_equals' => false, 12 ], 13 'blank_line_after_opening_tag' => false, 14 'blank_line_before_statement' => [ 15 'statements' => [ 16 'do', 17 'for', 18 'foreach', 19 'if', 20 'switch', 21 'try', 22 ], 23 ], 24 'cast_spaces' => true, 25 'class_attributes_separation' => false, 26 'combine_consecutive_issets' => true, 27 'combine_consecutive_unsets' => true, 28 'compact_nullable_typehint' => true, 29 'concat_space' => ['spacing' => 'one'], 30 'declare_equal_normalize' => true, 31 'declare_strict_types' => true, 32 'dir_constant' => true, 33 'ereg_to_preg' => true, 34 'escape_implicit_backslashes' => true, 35 'explicit_indirect_variable' => true, 36 'explicit_string_variable' => true, 37 'final_internal_class' => true, 38 'function_to_constant' => true, 39 'function_typehint_space' => true, 40 'general_phpdoc_annotation_remove' => [ 41 'annotations' => [ 42 'class', 43 'package', 44 'author' 45 ], 46 ], 47 'hash_to_slash_comment' => true, 48 'heredoc_to_nowdoc' => true, 49 'include' => true, 50 'is_null' => ['use_yoda_style' => false], 51 'linebreak_after_opening_tag' => false, 52 'list_syntax' => [ 53 'syntax' => 'short' 54 ], 55 'lowercase_cast' => true, 56 'magic_constant_casing' => true, 57 'method_chaining_indentation' => true, 58 'method_separation' => true, 59 'modernize_types_casting' => true, 60 'native_function_casing' => true, 61 'no_alias_functions' => true, 62 'no_blank_lines_after_class_opening' => true, 63 'no_blank_lines_after_phpdoc' => true, 64 'no_empty_comment' => true, 65 'no_empty_phpdoc' => true, 66 'no_empty_statement' => true, 67 'no_extra_consecutive_blank_lines' => [ 68 'tokens' => [ 69 'break', 70 'continue', 71 'extra', 72 'return', 73 'throw', 74 'use', 75 'parenthesis_brace_block', 76 'square_brace_block', 77 'curly_brace_block' 78 ], 79 ], 80 'no_homoglyph_names' => true, 81 'no_leading_import_slash' => true, 82 'no_leading_namespace_whitespace' => true, 83 'no_mixed_echo_print' => true, 84 'no_multiline_whitespace_around_double_arrow' => true, 85 'no_multiline_whitespace_before_semicolons' => true, 86 'no_null_property_initialization' => true, 87 'no_php4_constructor' => true, 88 'no_short_bool_cast' => true, 89 'no_singleline_whitespace_before_semicolons' => true, 90 'no_spaces_around_offset' => true, 91 'no_trailing_comma_in_list_call' => true, 92 'no_trailing_comma_in_singleline_array' => true, 93 'no_unneeded_control_parentheses' => true, 94 'no_unneeded_curly_braces' => true, 95 'no_unneeded_final_method' => true, 96 'no_unreachable_default_argument_value' => true, 97 'no_unused_imports' => true, 98 'no_useless_else' => true, 99 'no_useless_return' => true, 100 'no_whitespace_before_comma_in_array' => true, 101 'no_whitespace_in_blank_line' => true, 102 'normalize_index_brace' => true, 103 'object_operator_without_whitespace' => true, 104 'ordered_class_elements' => true, 105 'ordered_imports' => true, 106 'php_unit_construct' => true, 107 'php_unit_dedicate_assert' => true, 108 'php_unit_mock' => true, 109 'php_unit_namespaced' => true, 110 'phpdoc_add_missing_param_annotation' => ['only_untyped' => false], 111 'phpdoc_align' => ['align' => 'left'], 112 'phpdoc_annotation_without_dot' => true, 113 'phpdoc_indent' => true, 114 'phpdoc_inline_tag' => true, 115 'phpdoc_no_access' => true, 116 'phpdoc_no_empty_return' => true, 117 'phpdoc_no_package' => true, 118 'phpdoc_order' => false, 119 'phpdoc_return_self_reference' => true, 120 'phpdoc_scalar' => true, 121 'phpdoc_single_line_var_spacing' => true, 122 'phpdoc_summary' => false, 123 'phpdoc_to_comment' => true, 124 'phpdoc_trim' => true, 125 'phpdoc_types' => true, 126 'phpdoc_types_order' => [ 127 'null_adjustment' => 'always_last', 128 'sort_algorithm' => 'none', 129 ], 130 'phpdoc_var_without_name' => true, 131 'pow_to_exponentiation' => true, 132 'protected_to_private' => true, 133 'random_api_migration' => true, 134 'return_type_declaration' => true, 135 'self_accessor' => true, 136 'semicolon_after_instruction' => true, 137 'short_scalar_cast' => true, 138 'simplified_null_return' => true, 139 'single_blank_line_before_namespace' => true, 140 'single_line_comment_style' => true, 141 'single_quote' => true, 142 'space_after_semicolon' => ['remove_in_empty_for_expressions' => true], 143 'standardize_not_equals' => true, 144 'ternary_operator_spaces' => true, 145 'ternary_to_null_coalescing' => true, 146 'trailing_comma_in_multiline_array' => true, 147 'trim_array_spaces' => true, 148 'unary_operator_spaces' => true, 149 'void_return' => true, 150 'whitespace_after_comma_in_array' => true, 151 'yoda_style' => [ 152 'equal' => false, 153 'identical' => false, 154 ], 155 ]) 156 ->setFinder(PhpCsFixer\Finder::create() 157 ->exclude('vendor') 158 ->in(__DIR__) 159 ) 160;

補足: PHPファイル

src/App/Foo.php

php

1<?php declare(strict_types=1); 2 3namespace App; 4 5class Foo 6{ 7 public function bar(): string 8 { 9 return 'fuga'; 10 } 11}

src/App/Hoge.php

php

1<?php declare(strict_types=1); 2 3namespace App; 4 5class Hoge 6{ 7 protected Foo $foo; 8 9 public function __construct(Foo $foo) 10 { 11 $this->foo = $foo; 12 } 13 14 public function handle(): string 15 { 16 return $this->foo->bar(); 17 } 18}

補足: PHPファイルの動作確認

$ php -a php > require('./src/App/Foo.php'); php > require('./src/App/Hoge.php'); php > echo (new App\Hoge(new App\Foo()))->handle(); fuga

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

手元で確認した結果、Docker内のphp-cs-fixerではなく
2.16のphp-cs-fixerでは通った。
2.13のpharを試したところ、2.13はphp7.4では動かないみたいなので
dockerの内容が怪しい気がします。

https://github.com/herloct/docker-php-cs-fixer/blob/2.13.0/Dockerfile

baseコンテナが7.1になってますね。

投稿2020/11/23 07:35

mikkame

総合スコア5036

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

ucan-lab

2020/11/23 07:37

php-cs-fixerのバージョンが古かったんですね... 公式でメンテされてるのなさそうですし、自分でイメージ作った方が良いかもですね。。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.47%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問