摘要:在合作開發(fā)時(shí)需要統(tǒng)一下,如給寫時(shí)一些如得按照字母順序來寫,等等。推薦一個(gè),該是作者寫的,質(zhì)量有保證。每一個(gè)的定義可以參考的主頁。
在合作開發(fā)時(shí)需要統(tǒng)一下code style,如給method寫annotation時(shí)一些tag如@params ,@throw,@return得按照字母順序來寫,等等。推薦一個(gè)package:friendsofphp/php-cs-fixer,該package是Symfony作者寫的,質(zhì)量有保證。
安裝下該package:
composer require friendsofphp/php-cs-fixer --dev
然后項(xiàng)目根目錄創(chuàng)建一個(gè)可執(zhí)行文件如.cs文件:
#!/bin/bash vendor/bin/php-cs-fixer fix
以后在項(xiàng)目根目錄只需執(zhí)行./cs就可以自動(dòng)修復(fù)不復(fù)合規(guī)定code style的代碼,code rules的定義在該package packgist的網(wǎng)站上有說明。vendor/bin/php-cs-fixer fix會(huì)讀取.php_cs文件返回的code rules,所以還得定義哪些code rules,同樣在項(xiàng)目根目錄中新建文件.php_cs,然后加上code rules,如:
exclude("bootstrap") ->exclude("database") ->exclude("public") ->exclude("resources") ->exclude("storage") ->exclude("vendor") ->notPath(".phpstorm.meta.php") ->notPath("_ide_helper.php") ->notPath("server.php") ->in(__DIR__); return SymfonyCSConfig::create() ->level(SymfonyCSFixerInterface::PSR2_LEVEL) ->fixers([ // Use all symfony fixers but the following "-"."fixer". // Exclude psr-0 "-psr0", // Concatenation should be used without spaces. "-concat_without_spaces", // A return statement wishing to return nothing should be simply "return". "-empty_return", // Remove useless semicolon statements. "-no_empty_comment", // Binary operators should be surrounded by at least one space. "-operators_spaces", // Phpdocs annotation descriptions should not end with a full stop. "-phpdoc_annotation_without_dot", // @return void and @return null annotations should be omitted from phpdocs. "-phpdoc_no_empty_return", // @package and @subpackage annotations should be omitted from phpdocs. "-phpdoc_no_package", // All items of the @param, @throws, @return, @var, and @type phpdoc tags must be aligned vertically. "-phpdoc_params", // Annotations in phpdocs should be grouped together so that annotations of the same type immediately follow each other, // and annotations of a different type are separated by a single blank line. "-phpdoc_separation", // Phpdocs short descriptions should end in either a full stop, exclamation mark, or question mark. "-phpdoc_short_description", // Docblocks should only be used on structural elements. "-phpdoc_to_comment", // Pre incrementation/decrementation should be used if possible. "-pre_increment", // Unalign double arrow symbols. "-unalign_double_arrow", // Unalign equals symbols. "-unalign_equals", // Use all the following fixers. // Align double arrow symbols in consecutive lines. "align_double_arrow", // Align equals symbols in consecutive lines. "align_equals", // Concatenation should be used with at least one whitespace around. "concat_with_spaces", // Replace deprecated ereg regular expression functions with preg. "ereg_to_preg", // Add, replace or remove header comment. // "header_comment", // Multi-line whitespace before closing semicolon are prohibited. "multiline_spaces_before_semicolon", // Ensure there is no code on the same line as the PHP open tag. "newline_after_open_tag", // There should not be an empty return statement at the end of a function. "no_useless_return", // Ordering use statements. "ordered_use", // Convert PHP4-style constructors to __construct. "php4_constructor", // PHPUnit assertion method calls like "->assertSame(true, $foo)" should be written with dedicated method like "->assertTrue($foo)". "php_unit_construct", // PHPUnit methods like "assertSame" should be used instead of "assertEquals". "php_unit_strict", // Annotations in phpdocs should be ordered so that param annotations come first, // then throws annotations, then return annotations. "phpdoc_order", // PHP arrays should use the PHP 5.4 short-syntax. "short_array_syntax", // Replace short-echo = with long format finder($finder) ->setUsingCache(true);
code rules可以添加或刪除,需要團(tuán)隊(duì)統(tǒng)一,一般至少盡量符合PSR-2的大部分標(biāo)準(zhǔn)。每一個(gè)code rule的定義可以參考package packgist的主頁。
這樣,團(tuán)隊(duì)里以后每次push code前先./cs下:
當(dāng)然,還應(yīng)當(dāng)在PHPStorm IDE里的Preference->Editor->Code Style->PHP里也設(shè)置同樣的code rules,然后導(dǎo)出一個(gè)xml文件,方便在團(tuán)隊(duì)里共享并導(dǎo)入到每個(gè)開發(fā)者的PHPStorm,這樣保證團(tuán)隊(duì)的每一個(gè)Code Style保持相同。
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://www.ezyhdfw.cn/yun/22113.html
摘要:配置需要一個(gè)來用于與虛擬機(jī)進(jìn)行連接,默認(rèn)假定這個(gè)密鑰會(huì)被放在文件夾下。三使用管理項(xiàng)目版本使用可以對(duì)我們的代碼進(jìn)行版本控制,如果萬一誤刪了代碼想回到之前的情況,則可以通過版本控制進(jìn)行回滾。配置選項(xiàng)代表對(duì)進(jìn)行全局設(shè)置。 laravel學(xué)習(xí)筆記,重新梳理知識(shí)點(diǎn)。 一、環(huán)境配置 1、編輯器選用 Atom PHPStorm SublimeText Atom 是由 GitHub 官方在 201...
摘要:中異常處理類主要包含兩個(gè)方法和,其中就是主要用來向第三方發(fā)送異常報(bào)告,這里選擇向這個(gè)神器發(fā)送異常報(bào)告,并使用通知開發(fā)人員。通過也能發(fā)現(xiàn)的執(zhí)行流程。 說明:Laravel學(xué)習(xí)筆記之bootstrap源碼解析中聊異常處理時(shí)提到過Sentry這個(gè)神器,并打算以后聊聊這款神器,本文主要就介紹這款Errors Tracking神器Sentry,Sentry官網(wǎng)有一句話個(gè)人覺得帥呆了: Stop ...
摘要:本節(jié)將學(xué)習(xí)是如何利用形成一套完整的前端工作流模式的。你也可以使用下面命令來強(qiáng)制安裝所有模塊,不管該模塊之前是否安裝過由于國(guó)內(nèi)墻的原因,使用安裝會(huì)非常緩慢,慢到想切,不過還好,我們可以使用淘寶提供的國(guó)內(nèi)鏡像進(jìn)行下載。 本節(jié)將學(xué)習(xí) Laravel 是如何利用 Sass, NPM, Gulp形成一套完整的前端工作流模式的。 一、句法強(qiáng)大的樣式表Sass Sass 是一種可用于編寫CSS的語言...
摘要:總結(jié)本文主要學(xué)習(xí)了啟動(dòng)時(shí)做的七步準(zhǔn)備工作環(huán)境檢測(cè)配置加載日志配置異常處理注冊(cè)注冊(cè)啟動(dòng)。 說明:Laravel在把Request通過管道Pipeline送入中間件Middleware和路由Router之前,還做了程序的啟動(dòng)Bootstrap工作,本文主要學(xué)習(xí)相關(guān)源碼,看看Laravel啟動(dòng)程序做了哪些具體工作,并將個(gè)人的研究心得分享出來,希望對(duì)別人有所幫助。Laravel在入口index...
摘要:根據(jù)我自己的理解,適當(dāng)?shù)恼{(diào)整了順序,對(duì)一些比較常用的功能做一些說明,可結(jié)合文檔學(xué)習(xí)。 根據(jù)我自己的理解,適當(dāng)?shù)恼{(diào)整了順序,對(duì)一些比較常用的功能做一些說明,可結(jié)合文檔學(xué)習(xí)。Learning laravel: 準(zhǔn)備Learning laravel: 創(chuàng)建項(xiàng)目Learning laravel: 路由Learning laravel: URLLearning laravel: 控制器Learn...
閱讀 3845·2021-10-15 09:42
閱讀 2703·2021-09-03 10:50
閱讀 1746·2021-09-03 10:28
閱讀 1909·2019-08-30 15:54
閱讀 2605·2019-08-30 12:46
閱讀 477·2019-08-30 11:06
閱讀 2888·2019-08-30 10:54
閱讀 612·2019-08-29 12:59