PHP 5.4 sprawdzanie kompatybilności kodu

Mamy aplikację napisaną w starym klimacie i chcemy przejść na php 5.4 a nie jesteśmy pewni czy wszystko będzie działać poprawnie? Ręcznie sprawdzać co jest grane to przy większej ilości kodu proszenie się o problemy, dlatego fajnie zautomatyzować proces.

Opcja 1

Wykorzystać crawler’a i przeglądać logi z błędami. Jasne, zadziała zakładając, że mamy dobrego crawler’a (trzeba pamiętać o obsłudze JS’a, jeżeli crawl’er jest napisany w php to musimy się pobawić  SpiderMonkey – opis biblioteki znajdziecie na DevZone)

Opcja 2

Za pomocą pear’a instalujemy sobie PHP_CodeSniffer. Po poprawnej instalacji musimy odszukać katalog, w którym zainstalował się CodeSniffer, u mnie wygląda to tak:

ls -l `php-config –prefix`/lib/php/PHP/CodeSniffer

Za pomocą komendy php-config –prefix uzyskujemy katalog w którym znajdują się źródła PHP.

Output powyższej komendy na moim latopie:


13:43:12-paramah@lobo:~$ ls -l `php-config --prefix`/lib/php/PHP/CodeSniffer
total 336
-rw-r--r-- 1 root admin 26715 1 lip 04:06 CLI.php
drwxr-xr-x 13 root admin 442 1 lip 04:06 CommentParser
drwxr-xr-x 5 root admin 170 1 lip 04:06 DocGenerators
-rw-r--r-- 1 root admin 1009 1 lip 04:06 Exception.php
-rw-r--r-- 1 root admin 101016 1 lip 04:06 File.php
-rw-r--r-- 1 root admin 1433 1 lip 04:06 MultiFileSniff.php
-rw-r--r-- 1 root admin 1443 1 lip 04:06 Report.php
-rw-r--r-- 1 root admin 7712 1 lip 04:06 Reporting.php
drwxr-xr-x 13 root admin 442 1 lip 04:06 Reports
-rw-r--r-- 1 root admin 3074 1 lip 04:06 Sniff.php
drwxr-xr-x 13 root admin 442 9 sie 13:06 Standards
drwxr-xr-x 5 root admin 170 1 lip 04:06 Tokenizers
-rw-r--r-- 1 root admin 15821 1 lip 04:06 Tokens.php

Katalog z CodeSniffer’em jest dla nas o tyle istotny, bo musimy dograć do niego wzór standardu kodowania, na którym nam zależy. Standard o którym mowa znajdziecie na GitHub. Klonujemy repozytorium do katalogu Standards:


13:43:17-paramah@lobo:~$ ls -l `php-config --prefix`/lib/php/PHP/CodeSniffer/Standards
total 112
-rw-r--r-- 1 root admin 35839 1 lip 04:06 AbstractPatternSniff.php
-rw-r--r-- 1 root admin 6472 1 lip 04:06 AbstractScopeSniff.php
-rw-r--r-- 1 root admin 7976 1 lip 04:06 AbstractVariableSniff.php
drwxr-xr-x 5 root admin 170 1 lip 04:06 Generic
-rw-r--r-- 1 root admin 1090 1 lip 04:06 IncorrectPatternException.php
drwxr-xr-x 4 root admin 136 1 lip 04:06 MySource
drwxr-xr-x 5 root admin 170 1 lip 04:06 PEAR
drwxr-xr-x 3 root admin 102 1 lip 04:06 PHPCS
drwxr-xr-x 6 root admin 204 9 sie 13:06 PHPCompatibility
drwxr-xr-x 5 root admin 170 1 lip 04:06 Squiz
drwxr-xr-x 4 root admin 136 1 lip 04:06 Zend

Po wszystkim powinno to wyglądać tak jak powyżej ;-)

Teraz prosta komenda:

phpcs –standard=PHPCompatibility <ścieżka_do_kodu> –report-file=report.txt

Po chwili (w przypadku dużej ilości kodu może to potrwać deko długo) otrzymamy raport z  przeprowadzonego testu, wszystkie informacje będą się znajdować w pliku określonym przez parametr –report-file

0 thoughts on “PHP 5.4 sprawdzanie kompatybilności kodu

  1. What i do not realize is actually how you are not really a lot more well-favored than you may be now. You are very intelligent. You realize therefore considerably relating to this subject, made me in my view believe it from a lot of varied angles. Its like women and men are not interested until it is one thing to accomplish with Girl gaga! Your own stuffs nice. All the time take care of it up!

  2. I am really loving the theme/design of your weblog. Do you come across any web browser compatibility situations? Some of the site audience have complained regarding my vshare download ios blog not working the right way in Internet Explorer though seems excellent in Safari. Do you have any kind of advice to assist correct this problem?

  3. I’m curious to know what site system you have been utilizing? I’m having some minor security issues with our most recent site on intercom system installation NY and I would like to find one thing far more secure. Have you got any strategies?

  4. I would like to thank you for the efforts you have put in writing this site. I am hoping the same high-grade site post from you in the upcoming also. Actually your creative writing skills has encouraged me to get my own web site now. Actually the blogging is spreading its wings quickly. Your write up is a good example of it.

  5. I am really enjoying the theme/design of your site. Do you ever run into any kind of internet browser interface problems? Quite a few of the website visitors have lamented regarding my firestarter apk site not working the right way in Internet Explorer but seems very good in Firefox. Are there any ideas to assist repair this problem?

  6. I actually arrived over here from some other website about insta followers and considered I might check out this page. I really like the things I see so now I am following you. Looking forward to going over your website back again.

  7. I was talking to a good friend of mine around this and about pokemon go app store too. I feel you made a lot of great points in this case, we’re also looking forward to keep reading information from you.

  8. Appreciating the persistence you put into the website and thorough info you provide. It is wonderful to discover a blogging site occasionally that isn’t the similar out of date re-written information. Wonderful read! We have saved your website and I’m including your RSS feeds to my how to buy ethereum web page.

  9. That is the suitable blog for anybody who wants to search out out about this topic. You understand a lot its virtually laborious to argue with you (not that I actually would need…HaHa). You positively put a new spin on a subject thats been written about for years. Great stuff, simply great!

  10. I was quite pleased to find this website. I wanted to thanks for your time for this great read!! I unquestionably enjoying every single little bit of it and I have you bookmarked to check out new stuff you blog post.

  11. Viagra Generika Rezept Homeopathic Amoxicillin For Pets http://costofcial.com – generic cialis Usonline Viagra Spironolactone Buy Without Perscription Cialis Meno Effetti Collaterali Del Viagra cheap cialis 40 Pills For 99.00 Cephalexin For Penicillin Allergic Patients Buy Prednisolone On Line Zithromax Make You Sleepy Cialis 20mg Tunisie http://costofcial.com – cialis price Kamagra Oral Jelly 5mg Propecia How To Apply Forum site achat cialis

  12. My brother suggested I might like this website. He was entirely right. This post actually made my day. You cann’t imagine simply how much time I had spent for this information! Thanks!

  13. We’re a group of volunteers and starting a new scheme in our community. Your web site provided us with useful info to paintings on. You have performed a formidable task and our entire group might be thankful to you.

  14. You’re entirely correct. I liked reading through this article and I will come back for more as quick as possible. My internet site is about more insta followers, you could take a peek if you happen to be still interested in that.

  15. You are completely right! I loved reading this info and I will return for more straight away. My own site is on the subject of commercial real estate financing, you could take a glance if you’re still interested in that.

  16. I personally arrived over here via some other web page related to robot trading and imagined I may as well look into this. I enjoy the things I see thus now I”m following you. Looking forward to looking over your site yet again.

  17. Hey, you are definitely right. I constantly go through your site content attentively. I am furthermore focused on conservation land management traineeship, you might discuss that occasionally. Have a good day.

Leave a Reply

Your email address will not be published. Required fields are marked *