Vim Code specification Tool Php-cs-fixer.phar
(Refer to Https://github.com/FriendsOfPHP/PHP-CS-Fixer)
INSTALL
curl http://get.sensiolabs.org/php-cs-fixer.phar -o php-cs-fixer sudo chmod a+x php-cs-fixer sudo mv php-cs-fixer /usr/local/bin/php-cs-fixer
At this point, you can format the code directly with Php-cs-fixer.
USAGE
(Currently supported level is PSR0, PSR1, Psr2,symfony,contrib)
php-cs-fixer fix test.--level=psr2 php-cs-fixer./--level=psr2
It's not enough to satisfy a vimer little soul.
Vim-php-cs-fixer
INSTALL
'stephpy/vim-php-cs-fixer
CONFIGURE
. VIMRC (Reference: Https://github.com/stephpy/vim-php-cs-fixer)
"If Php-cs-fixer is in $PATH and you don ' t need to define line below" LetG:php_cs_fixer_path ="~/php-cs-fixer.phar""Define the path to the Php-cs-fixer.pharlet G:php_cs_fixer_level ="Psr2" "which level? (Psr0, PSR1, PSR2, Symfony) LetG:php_cs_fixer_config ="Default""Configurationlet G:php_cs_fixer_php_path ="Php" "Path toPhp"If you want to define specific fixers:" LetG:php_cs_fixer_fixers_list ="Linefeed,short_tag,indentation" LetG:php_cs_fixer_enable_default_mapping =1"Enable the mapping By default (
PCD) Let G:php_cs_fixer_dry_run = 0"
Call command withDry-runoption LetG:php_cs_fixer_verbose =0Return The output of command if 1, else an inline information.
The above configuration we found
let g:php_cs_fixer_enable_default_mapping = 1 " Enable the mapping by default (
pcd)
This configuration shortcut key for \PCD actual operation will find extremely error-prone, and too long
. Vim/bundle/vim-php-cs-fixer/plugin/php-cs-fixer.vim
if(g:php_cs_fixer_enable_default_mapping == 1) <silent><leader>pcd :call PhpCsFixerFixDirectory()<CR> <silent><leader>pcf :call PhpCsFixerFixFile()<CR>endif
can find
PCD is a formatted directory
PCF is a format file
Now you can replace PCD, and PCF with your favorite shortcut keys.
PS: Is the nomal mode, is a shortcut key prefix default is \, can be used in vim with the map command to view
Appendix
Psr0 [psr-0] Classes must beinchA path thatMatches their namespace, be atLeast one namespace deep, and theclassnameShould match thefilename. Encoding [psr-1] PHP code must use only utf-8withoutBOM (remove BOM). Short_tag [psr-1] PHP code must use theLong
Tagsor theShort-echo
TagsitMust notUse theOther tag variations.braces [psr-2] The body ofEach structure must is enclosed byBraces. Braces should be properly placed. Body ofBraces should be properly indented.elseif [psr-2] The keyword ElseIf should be usedinstead ofElseifSo thatAll control keywords lookswords. eof_ending [psr-2] AfileMust alwaysEnd withA single empty line feed.function_call_space [psr-2] When making a methodorfunction call, there must isn't be aSpacebetween theMethodorfunctionname and theOpening Parenthesis.function_declaration [psr-2] Spaces should be properly placedinchA function declaration.indentation [psr-2] Code must use of an indent of4Spaces andMust not use tabs forIndenting.line_after_namespace [psr-2] There must is one blank line After thenamespace declaration.linefeed[psr-2] All PHP files must use theUnix LF (linefeed) Line Ending.lowercase_constants [psr-2] The PHP constantstrue,false, andNull must beinchLower Case.lowercase_keywords [psr-2] PHP keywords must beinchLower Case.method_argument_space [psr-2] in method arguments andMethod call, there must isn't be aSpacebeforeEach comma andThere must be oneSpace AfterEach comma.multiple_use [psr-2] There must is one use keyword per declaration.parenthesis [psr-2] There must not be aSpace After theOpening parenthesis. There must not be aSpacebefore theClosing Parenthesis.php_closing_tag [psr-2] The closing?> tag must be omitted fromFiles containing only php.single_line_after_imports [psr-2] Each namespace use must go on itsOwn line andThere must be one blank line After theUse statements block.trailing_spaces [psr-2] Remove trailing whitespace at theEnd ofNon-blank lines.visibility [psr-2] Visibility must be declared onAll Properties andMethods Abstract andFinal must be declaredbefore theVisibility Static must be declared After theVisibility.blankline_after_open_tag [Symfony] ensure there isNo code on theSame line as thePHP Open Tag andit isFollowed byA blankline.concat_without_spaces [symfony] concatenation should be usedwithoutspaces.double_arrow_multiline_whitespaces [Symfony] Operator = should notBe arounded byMulti-line Whitespaces.duplicate_semicolon [symfony] Remove duplicated Semicolons.empty_return [Symfony] AreturnStatement wishing toreturnNothing should be simply"Return". extra_empty_lines [Symfony] Removes extra empty lines.include [Symfony] Include andfilePath should be divided withA singleSpace. File Path should notbe placed under Brackets.join_function [Symfony] implode function should be usedinstead ofJoin Function.list_commas [Symfony] Remove trailing commasinchListfunction Calls.multiline_array_trailing_comma [symfony] PHP multi-line arrays should have a trailing comma.namespace_no_ Leading_whitespace [Symfony] the namespace declaration line shouldn ' tcontainLeading whitespace.new_with_braces [Symfony] all instances created withNew keyword must be followed bybraces.no_blank_lines_after_class_opening [Symfony] There should be no empty lines AfterclassOpening Brace.no_empty_lines_after_phpdocs [Symfony] there should notbe Blank LinesbetweenDocBlock and theDocumented Element.object_operator [Symfony] there should notBeSpacebeforeor AfterObject t_object_operator.operators_spaces [Symfony] Binary operators should be arounded by atleast oneSpace. phpdoc_indent [Symfony] docblocks should has theSame indentation as theDocumented subject.phpdoc_no_access [symfony] @access annotations should be omitted fromPhpdocs.phpdoc_no_empty_return [Symfony] @returnvoid and@returnNull annotations should be omitted fromPhpdocs.phpdoc_no_package [Symfony] @package and@subpackage annotations should be omitted fromPhpdocs.phpdoc_params [Symfony] All items of the@param, @throws, @return, @var, and@type Phpdoc tags must be aligned vertically.phpdoc_scalar [symfony] scalar types should all be writteninch theSame form."int", not"integer";"BOOL", not"Boolean";"Float", not"Real"or"Double". phpdoc_separation [Symfony] AnnotationsinchPhpdocs should is grouped together so thatAnnotations of theSame type immediately follow each other, andAnnotations ofA different type is separated byA single blank line.phpdoc_short_description [Symfony] Phpdocs short descriptions shouldEndinchEither a full stop, exclamation mark,orQuestion Mark.phpdoc_to_comment [Symfony] docblocks should only be used onStructural Elements.phpdoc_trim [Symfony] Phpdocs should start andEnd withContent, excluding theVery First and LastLine of theDocblocks.phpdoc_type_to_var [Symfony] @type should always be written as@var. phpdoc_var_without_name [Symfony] @var and@type annotations should notcontain theVariablename. pre_increment [Symfony] pre incrementation/decrementation should be usedifPossible.remove_leading_slash_use [Symfony] Remove leading slashesinchUse clauses.remove_lines_between_uses [symfony] removes line breaksbetweenUse statements.return[Symfony] An empty line feed should precede areturnStatement.self_accessor [Symfony] Inside a classy element"Self"should be preferred to theclassnameItself.single_array_no_trailing_comma [Symfony] PHP single-line arrays should nothas trailing comma.single_blank_line_before_namespace [symfony] There should be exactly one blank linebeforeA namespace declaration.single_quote [Symfony] Convert double quotes toSingle quotes forSimple Strings.spaces_before_semicolon [symfony] single-line whitespacebeforeClosing semicolon is prohibited.spaces_cast [Symfony] A singleSpaceshould bebetweenCast andvariable.standardize_not_equal [Symfony] Replace all <> with!=.ternary_spaces [Symfony] standardize spacesaroundTernary operator.trim_array_spaces [Symfony] Arrays should is formatted like function/method arguments,withoutLeadingorTrailing single lineSpace. unalign_double_arrow [Symfony] Unalign double arrow symbols.unalign_equals [Symfony] Unalignequalssymbols.unary_operators_spaces [symfony] unary operators should be placed adjacent toTheir operands.unused_use [symfony] Unused use statements must is Removed.whitespacy_lines [Symfony] Remove trailing white Space at theEnd ofBlank Lines.align_double_arrow [contrib] align double arrow symbolsinchConsecutive lines.align_equals [contrib] AlignequalsSymbolsinchConsecutive lines.concat_with_spaces [contrib] concatenation should be used with atleast one whitespacearound. ereg_to_preg [Contrib] Replace deprecated ereg Regular expression functions withPreg. warning! This could change code behavior.header_comment [contrib] Add, replaceorRemove header comment.long_array_syntax [contrib] Arrays should use theLong Syntax.multiline_spaces_before_semicolon [contrib] multi-line whitespacebeforeClosing semicolon is prohibited.newline_after_open_tag [contrib] ensure there isNo code on theSame line as thePHP open Tag.no_blank_lines_before_namespace [contrib] There should be no blank linesbeforeA namespace declaration.ordered_use [contrib] ordering use Statements.php4_constructor [contrib] Convert Php4-style Constructors to__construct. warning! This could change code behavior.phpdoc_order [contrib] AnnotationsinchPhpdocs should is ordered so thatparam annotations Come First, ThenThrows Annotations, ThenreturnAnnotations.phpdoc_var_to_type [contrib] @var should always be written as@type. Short_array_syntax [contrib] PHP arrays should use thePhp5.4Short-syntax.short_echo_tag [contrib] Replace Short-echo
WithLong format
With$strict param. warning! This could change code behavior.
The above describes the vim PHP code specification, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.