SlideShare a Scribd company logo
CodeIgniterCode Sniffer
TopicCode SnifferThe ins and out of making sure your code is up to a standard of your choosing.
Code Igniter  Code Sniffer
INTRODUCTIONIn our days we have come to code to our own way. Many of us have preferences of tabs to spaces, how we name public and private variables. Whether to use CamelCases or Underscores.  I myself have been a more code as I code and go back to clean up later, be it with documentation, notes, and how my code is presented.Many like myself want to make sure that All of our codebase is the same format, but we don't want to manually run through them. That could be so tedious and repetitive that one can take a whole other development cycle to just review the code they have written.Luckily there is a pear package we can use to alleviate the stress, this package is called PhpCodeSniffer.
INSTALLING PHP CODE SNIFFER To Install PhpCodeSniffer, follow these steps:Go to your command line and enter the following:pear install PHP_CodeSnifferThen enterPhpcs –ito see the installed Coding Standards
ABOUT CODE SNIFFERCode Sniffer is used by many Open Source and Private development teams.  Code Sniffer can sniff any file or directory you wish.  Once it has finished Sniffing you will find a detailed report on all the files you have tested.  Also CodeSniffer comes with the prepackaged coding standards (PEAR, Squiz, PHPCS and Zend	), I personally follow the Zend Coding Standards, but you can also customize and create your own coding standard taking bits from all over.
CODE SNIFFER RESPONSEBellow is a typical report for a CodeSniff.FILE: /home/lorna/phpcs/recipe.class.php--------------------------------------------------------------------------------FOUND 3 ERROR(S) AND 0 WARNING(S) AFFECTING 3 LINE(S)--------------------------------------------------------------------------------10 | ERROR | Variable "prep_time" is not in valid camel caps format13 | ERROR | Spaces must be used to indent lines; tabs are not allowed17 | ERROR | A closing tag is not permitted at the end of a PHP file--------------------------------------------------------------------------------
HOW TO USE CODE SNIFFERCode Sniffer is run via command line, so if needed please shell into your server. At times it is best to know the path to the directory/project you want to sniff. Personally I create a reports folder within the project so All my files related to that project are together.  I also want the full report to be printed / displayed.Here is the line I use to generate the Reports from within the project reports folder:phpcs /full/path/to/project --standard=Zend --report=full -n >> projectName.sniffer.txtnow we target just specific files as follows:phpcs /full/path/to/project/ext/fileW.extension --standard=Zend --report=full -n >> projectName.sniffer.txtnow I use >> to pipe the results into a file but you can remove the the piping to render the results within the terminal/console.
I GOT MY REPORT NOW WHATNow that you have the report in which ever format you decided as a file or on screen, just follow it's instructions, clear out all the errors and run the command again until there is nothing to report or you are satisfied with the current errors being defined.
Something to NoteCode Sniffer does not catch all the errors on first pass especially if there are errors, on many cases once some errors clear up another set of errors become apparent and noticeable. It's good use to make sure you run code sniffer a couple of times to validate that your sniffer code is properly sniffed.
THANKSThanks go to Adil and Rokkan for providing us with the Conference space.
Next Months TopicVote at: www.meetup.com/codeigniter/PhpUnit and Code Igniter with PHP 5.3Code Sniffer Creating Custom StandardsAnything More important than testing and keeping that code clean.
General InfoMy Email: albert@albert-rosa.comAIM: albertrosa2000Meetup: www.meetup.com/codeigniter/Rokkan: www.rokkan.com

More Related Content

What's hot (20)

ODP
Perl ides
Naim Shafiev
 
PPTX
Bsides tampa
Octavio Paguaga
 
PPTX
Denial of service attack part 2
Kaustubh Padwad
 
PDF
Introduction to ida python
geeksec80
 
PDF
What's new on Laravel 5.5
Glend Maatita
 
PDF
Static Analysis of PHP Code – IPC Berlin 2016
Rouven Weßling
 
PDF
Flask With Server-Sent Event
Tencent
 
PPTX
Getting Started With PowerShell Scripting
Ravikanth Chaganti
 
PDF
Unit testing symfony plugins with php unit
Christian Schaefer
 
RTF
appledoc_style
Ziku Spartan
 
PPTX
Php psr standard 2014 01-22
Võ Duy Tuấn
 
PDF
Using OTP and gen_server Effectively
Ken Pratt
 
PPT
Write book in markdown
Larry Cai
 
PPTX
Installing and updating software packages [autosaved]
ANIMESHKUMARSINHA2
 
ODP
PhpSpec: practical introduction
Dave Hulbert
 
PDF
Python tools for testing web services over HTTP
Mykhailo Kolesnyk
 
PPTX
Implement server push in flask framework
Chi-Chia Huang
 
PPT
Assurer - a pluggable server testing/monitoring framework
Gosuke Miyashita
 
PDF
PHP-VCR behat case study
Pascal Thormeier
 
DOCX
CodeShip
Bryan Reinbolt
 
Perl ides
Naim Shafiev
 
Bsides tampa
Octavio Paguaga
 
Denial of service attack part 2
Kaustubh Padwad
 
Introduction to ida python
geeksec80
 
What's new on Laravel 5.5
Glend Maatita
 
Static Analysis of PHP Code – IPC Berlin 2016
Rouven Weßling
 
Flask With Server-Sent Event
Tencent
 
Getting Started With PowerShell Scripting
Ravikanth Chaganti
 
Unit testing symfony plugins with php unit
Christian Schaefer
 
appledoc_style
Ziku Spartan
 
Php psr standard 2014 01-22
Võ Duy Tuấn
 
Using OTP and gen_server Effectively
Ken Pratt
 
Write book in markdown
Larry Cai
 
Installing and updating software packages [autosaved]
ANIMESHKUMARSINHA2
 
PhpSpec: practical introduction
Dave Hulbert
 
Python tools for testing web services over HTTP
Mykhailo Kolesnyk
 
Implement server push in flask framework
Chi-Chia Huang
 
Assurer - a pluggable server testing/monitoring framework
Gosuke Miyashita
 
PHP-VCR behat case study
Pascal Thormeier
 
CodeShip
Bryan Reinbolt
 

Similar to Code Igniter Code Sniffer (20)

PPTX
PHPCS (PHP Code Sniffer)
Oleksii Prohonnyi
 
KEY
Php|tek '12 It's More Than Just Style
LB Denker
 
PPTX
Code analysis tools (for PHP)
Karlen Kishmiryan
 
PPTX
Listen afup 2010
Gabriele Santini
 
PPT
Php Best Practices
Ansar Ahmed
 
PPT
Php Best Practices
Ansar Ahmed
 
ODP
PHP Code Quality
Usman Zafar
 
PDF
Continuous Quality Assurance
Michelangelo van Dam
 
PPTX
Listen and look at your PHP code
Gabriele Santini
 
PDF
Enter Cookbook: refactoring under a microscope
Kamil Samigullin
 
PDF
SVN Hook
Thomas Weinert
 
PDF
Joomla Code Quality Control and Automation Testing
Shyam Sunder Verma
 
KEY
Improving QA on PHP projects - confoo 2011
Michelangelo van Dam
 
ODP
The why and how of moving to php 5.4
Wim Godden
 
KEY
Php Power Tools
Michelangelo van Dam
 
PPTX
Standards: Don't pee in the pool
David Yell
 
PDF
The why and how of moving to php 8
Wim Godden
 
PDF
20 PHP Static Analysis and Documentation Generators #burningkeyboards
Denis Ristic
 
ODP
The why and how of moving to PHP 5.4/5.5
Wim Godden
 
PDF
Your (coding) standards matter
Edorian
 
PHPCS (PHP Code Sniffer)
Oleksii Prohonnyi
 
Php|tek '12 It's More Than Just Style
LB Denker
 
Code analysis tools (for PHP)
Karlen Kishmiryan
 
Listen afup 2010
Gabriele Santini
 
Php Best Practices
Ansar Ahmed
 
Php Best Practices
Ansar Ahmed
 
PHP Code Quality
Usman Zafar
 
Continuous Quality Assurance
Michelangelo van Dam
 
Listen and look at your PHP code
Gabriele Santini
 
Enter Cookbook: refactoring under a microscope
Kamil Samigullin
 
SVN Hook
Thomas Weinert
 
Joomla Code Quality Control and Automation Testing
Shyam Sunder Verma
 
Improving QA on PHP projects - confoo 2011
Michelangelo van Dam
 
The why and how of moving to php 5.4
Wim Godden
 
Php Power Tools
Michelangelo van Dam
 
Standards: Don't pee in the pool
David Yell
 
The why and how of moving to php 8
Wim Godden
 
20 PHP Static Analysis and Documentation Generators #burningkeyboards
Denis Ristic
 
The why and how of moving to PHP 5.4/5.5
Wim Godden
 
Your (coding) standards matter
Edorian
 
Ad

Recently uploaded (20)

PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
Biography of Daniel Podor.pdf
Daniel Podor
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
Biography of Daniel Podor.pdf
Daniel Podor
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Ad

Code Igniter Code Sniffer

  • 2. TopicCode SnifferThe ins and out of making sure your code is up to a standard of your choosing.
  • 4. INTRODUCTIONIn our days we have come to code to our own way. Many of us have preferences of tabs to spaces, how we name public and private variables. Whether to use CamelCases or Underscores. I myself have been a more code as I code and go back to clean up later, be it with documentation, notes, and how my code is presented.Many like myself want to make sure that All of our codebase is the same format, but we don't want to manually run through them. That could be so tedious and repetitive that one can take a whole other development cycle to just review the code they have written.Luckily there is a pear package we can use to alleviate the stress, this package is called PhpCodeSniffer.
  • 5. INSTALLING PHP CODE SNIFFER To Install PhpCodeSniffer, follow these steps:Go to your command line and enter the following:pear install PHP_CodeSnifferThen enterPhpcs –ito see the installed Coding Standards
  • 6. ABOUT CODE SNIFFERCode Sniffer is used by many Open Source and Private development teams. Code Sniffer can sniff any file or directory you wish. Once it has finished Sniffing you will find a detailed report on all the files you have tested. Also CodeSniffer comes with the prepackaged coding standards (PEAR, Squiz, PHPCS and Zend ), I personally follow the Zend Coding Standards, but you can also customize and create your own coding standard taking bits from all over.
  • 7. CODE SNIFFER RESPONSEBellow is a typical report for a CodeSniff.FILE: /home/lorna/phpcs/recipe.class.php--------------------------------------------------------------------------------FOUND 3 ERROR(S) AND 0 WARNING(S) AFFECTING 3 LINE(S)--------------------------------------------------------------------------------10 | ERROR | Variable "prep_time" is not in valid camel caps format13 | ERROR | Spaces must be used to indent lines; tabs are not allowed17 | ERROR | A closing tag is not permitted at the end of a PHP file--------------------------------------------------------------------------------
  • 8. HOW TO USE CODE SNIFFERCode Sniffer is run via command line, so if needed please shell into your server. At times it is best to know the path to the directory/project you want to sniff. Personally I create a reports folder within the project so All my files related to that project are together. I also want the full report to be printed / displayed.Here is the line I use to generate the Reports from within the project reports folder:phpcs /full/path/to/project --standard=Zend --report=full -n >> projectName.sniffer.txtnow we target just specific files as follows:phpcs /full/path/to/project/ext/fileW.extension --standard=Zend --report=full -n >> projectName.sniffer.txtnow I use >> to pipe the results into a file but you can remove the the piping to render the results within the terminal/console.
  • 9. I GOT MY REPORT NOW WHATNow that you have the report in which ever format you decided as a file or on screen, just follow it's instructions, clear out all the errors and run the command again until there is nothing to report or you are satisfied with the current errors being defined.
  • 10. Something to NoteCode Sniffer does not catch all the errors on first pass especially if there are errors, on many cases once some errors clear up another set of errors become apparent and noticeable. It's good use to make sure you run code sniffer a couple of times to validate that your sniffer code is properly sniffed.
  • 11. THANKSThanks go to Adil and Rokkan for providing us with the Conference space.
  • 12. Next Months TopicVote at: www.meetup.com/codeigniter/PhpUnit and Code Igniter with PHP 5.3Code Sniffer Creating Custom StandardsAnything More important than testing and keeping that code clean.
  • 13. General InfoMy Email: [email protected]: albertrosa2000Meetup: www.meetup.com/codeigniter/Rokkan: www.rokkan.com