mac Atom php静态代码检查phpcs,phpmd

首先 你的mac 得安装atom

你的mac有PHP环境

linter-phpcs 主要检查格式 linter-phpmd主要检查语法

1、sudo  pear install PHP_CodeSniffer

如果一切正常的话,你执行phpcs --version可以看到版本号了。
执行phpcs -i可以看到它已经预先安装好一些标准了:

The installed coding standards are MySource, PEAR, PHPCS, PSR1, PSR2, Squiz, Zend

一般第一次会遇到


Warning: include_once(PHP/CodeSniffer/CLI.php): failed to open stream: No such file or directory in /usr/local/bin/phpcs on line 21

Warning: include_once(): Failed opening 'PHP/CodeSniffer/CLI.php' for inclusion (include_path='.:') in /usr/local/bin/phpcs on line 21

Fatal error: Class 'PHP_CodeSniffer_CLI' not found in /usr/local/bin/phpcs on line 24

用以下命令找出路径

pear config-get php_dir

我的执行结果是:‘/usr/lib/php/pear’

然后修改php.ini,添加或修改一行

include_path = ".:/usr/lib/php/pear"

再执行phpcs -i 就正常了。

 

配置文件: /usr/lib/php/pear/data/PHP_CodeSniffer/CodeSniffer.conf

这样PHP_CodeSniffer就安装好了 。

接下来就是配置Atom 插件了。

安装linter-phpcs 插件。启用  这样就可以用了 。(无需配置)

系统中安装phpmd

composer global require phpmd/phpmd

系统中安装linter-phpmd插件

apm install linter-phpmd

安装完后来测试可以看到系统中。有了phpmd命令。
这时再Atom中编辑php文件就会自动检查了。

在linter-phpmd安装的过程中我的出现了如下故障:

[Linter] Error running PHPMD Error: Failed to spawn command `phpmd`. Make sure `phpmd` is installed and on your PATH(…)

解决方法:

找到本地phpmd 的安装路径:我的/Users/eric/.composer/vendor/bin

然后 

也可以直接编辑  ~/.atom/init.coffee这个文件。

 

最终效果

 

phpstorm 上安装这些插件参考:http://confluence.jetbrains.com/display/PhpStorm/PHP+Mess+Detector+in+PhpStorm#PHPMessDetectorinPhpStorm-1.EnablePHPMessDetectorintegrationinPhpStorm

编辑自定义规则参考:http://www.kancloud.cn/bajiao/phpmd/128478

28 thoughts on “mac Atom php静态代码检查phpcs,phpmd

  1. Free Stuff

    After I initially commented I clicked the -Notify me when new feedback are added- checkbox and now each time a comment is added I get four emails with the same comment. Is there any way you’ll be able to take away me from that service? Thanks!

  2. belajar pemrograman php dari dasar

    Hiya, I am really glad I have found this information. Nowadays bloggers publish just about gossip and net stuff and this is actually frustrating. A good website with exciting content, that is what I need. Thank you for making this website, and I will be visiting again. Do you do newsletters by email?

  3. golden goose

    A lot of thanks for each of your efforts on this site. Debby really likes doing investigation and it’s really easy to see why. My partner and i notice all regarding the powerful method you present practical strategies on the blog and as well as increase response from people on that content while our favorite simple princess is now discovering a whole lot. Enjoy the remaining portion of the new year. You’re the one doing a great job.

  4. quick high protein breakfast

    Hiya, I am really glad I’ve found this information. Nowadays bloggers publish just about gossip and web stuff and this is really frustrating. A good web site with interesting content, that’s what I need. Thanks for making this website, and I’ll be visiting again. Do you do newsletters by email?

  5. situs judi qq online

    Hiya, I’m really glad I’ve found this info. Nowadays bloggers publish just about gossip and net stuff and this is really annoying. A good web site with interesting content, this is what I need. Thanks for making this web-site, and I will be visiting again. Do you do newsletters by email?

  6. kobe 11

    I’m also commenting to make you be aware of what a awesome discovery my friend’s princess found viewing your site. She noticed some pieces, not to mention what it’s like to have a marvelous helping heart to get the others without hassle fully grasp a variety of multifaceted topics. You truly did more than my expected results. Many thanks for supplying those warm and helpful, dependable, informative as well as unique tips about that topic to Sandra.

  7. depo qq

    Awesome write-up. I am a normal visitor of your website and appreciate you taking the time to maintain the nice site. I will be a frequent visitor for a long time.

  8. jordan shoes

    I actually wanted to type a small comment to express gratitude to you for all the stunning concepts you are giving here. My prolonged internet investigation has at the end of the day been rewarded with incredibly good strategies to share with my family and friends. I would believe that we visitors actually are rather lucky to live in a remarkable place with many wonderful individuals with good principles. I feel truly privileged to have encountered the web pages and look forward to so many more fun times reading here. Thank you again for a lot of things.

  9. satta king

    I simply could not depart your web site before suggesting that I extremely enjoyed the standard info a person supply for your visitors? Is gonna be back regularly to inspect new posts

  10. Agen Judi

    Hello there. I discovered your website by means of Google even as searching for a similar subject, your site came up. It appears to be good. I have bookmarked it in my google bookmarks to visit then.

  11. Data Hk

    Hiya, I am really glad I’ve found this info. Nowadays bloggers publish just about gossip and net stuff and this is actually frustrating. A good website with interesting content, that’s what I need. Thanks for making this web-site, and I’ll be visiting again. Do you do newsletters by email?

  12. totobet hk

    Hiya, I am really glad I’ve found this information. Today bloggers publish just about gossip and net stuff and this is really frustrating. A good website with interesting content, this is what I need. Thank you for making this site, and I’ll be visiting again. Do you do newsletters by email?

  13. timberlands

    I want to express thanks to you for bailing me out of this type of circumstance. As a result of looking through the internet and getting opinions which are not beneficial, I assumed my life was done. Living without the presence of strategies to the issues you have solved all through this short article is a crucial case, as well as the ones that might have negatively damaged my entire career if I hadn’t noticed your web page. Your good training and kindness in controlling every part was excellent. I don’t know what I would’ve done if I hadn’t discovered such a point like this. I can also at this moment look forward to my future. Thanks a lot so much for the professional and sensible help. I will not think twice to recommend the website to anyone who requires recommendations on this subject matter.

  14. Furniture Unique Jepara

    Hiya, I’m really glad I have found this info. Nowadays bloggers publish just about gossip and net stuff and this is actually irritating. A good site with exciting content, this is what I need. Thanks for making this web site, and I will be visiting again. Do you do newsletters by email?

  15. ratu poker 88

    Hi there. I discovered your blog by way of Google while looking for a related subject, your web site got here up. It seems good. I’ve bookmarked it in my google bookmarks to come back then.

  16. ratupoker88.com

    Hiya, I am really glad I’ve found this info. Today bloggers publish only about gossip and internet stuff and this is actually annoying. A good web site with exciting content, this is what I need. Thank you for making this web-site, and I will be visiting again. Do you do newsletters by email?

  17. Super Bowl 2020

    Thank you, I have just been looking for information approximately this topic for a while and yours is the best I’ve discovered till now. But, what about the conclusion? Are you positive in regards to the supply?