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

PPTX
Code igniter unittest-part1
PPTX
CodeIgniter Ant Scripting
PPT
Functional Testing Swing Applications with Frankenstein
PPTX
Cse 241
PPTX
Controlling multiple VMs with the power of Python
ODP
Os Cook
PDF
Writing multi-language documentation using Sphinx
PPTX
Getting started with PHPUnit
Code igniter unittest-part1
CodeIgniter Ant Scripting
Functional Testing Swing Applications with Frankenstein
Cse 241
Controlling multiple VMs with the power of Python
Os Cook
Writing multi-language documentation using Sphinx
Getting started with PHPUnit

What's hot (20)

ODP
Perl ides
PPTX
Bsides tampa
PPTX
Denial of service attack part 2
PDF
Introduction to ida python
PDF
What's new on Laravel 5.5
PDF
Static Analysis of PHP Code – IPC Berlin 2016
PDF
Flask With Server-Sent Event
PPTX
Getting Started With PowerShell Scripting
PDF
Unit testing symfony plugins with php unit
RTF
appledoc_style
PPTX
Php psr standard 2014 01-22
PDF
Using OTP and gen_server Effectively
PPT
Write book in markdown
PPTX
Installing and updating software packages [autosaved]
ODP
PhpSpec: practical introduction
PDF
Python tools for testing web services over HTTP
PPTX
Implement server push in flask framework
PPT
Assurer - a pluggable server testing/monitoring framework
PDF
PHP-VCR behat case study
DOCX
CodeShip
Perl ides
Bsides tampa
Denial of service attack part 2
Introduction to ida python
What's new on Laravel 5.5
Static Analysis of PHP Code – IPC Berlin 2016
Flask With Server-Sent Event
Getting Started With PowerShell Scripting
Unit testing symfony plugins with php unit
appledoc_style
Php psr standard 2014 01-22
Using OTP and gen_server Effectively
Write book in markdown
Installing and updating software packages [autosaved]
PhpSpec: practical introduction
Python tools for testing web services over HTTP
Implement server push in flask framework
Assurer - a pluggable server testing/monitoring framework
PHP-VCR behat case study
CodeShip
Ad

Similar to Code Igniter Code Sniffer (20)

PPTX
PHPCS (PHP Code Sniffer)
KEY
Php|tek '12 It's More Than Just Style
PPTX
Code analysis tools (for PHP)
PPTX
Listen afup 2010
PPT
Php Best Practices
PPT
Php Best Practices
ODP
PHP Code Quality
PDF
Continuous Quality Assurance
PPTX
Listen and look at your PHP code
PDF
Enter Cookbook: refactoring under a microscope
PDF
SVN Hook
PDF
Joomla Code Quality Control and Automation Testing
KEY
Improving QA on PHP projects - confoo 2011
ODP
The why and how of moving to php 5.4
KEY
Php Power Tools
PPTX
Standards: Don't pee in the pool
PDF
The why and how of moving to php 8
PDF
20 PHP Static Analysis and Documentation Generators #burningkeyboards
ODP
The why and how of moving to PHP 5.4/5.5
PDF
Your (coding) standards matter
PHPCS (PHP Code Sniffer)
Php|tek '12 It's More Than Just Style
Code analysis tools (for PHP)
Listen afup 2010
Php Best Practices
Php Best Practices
PHP Code Quality
Continuous Quality Assurance
Listen and look at your PHP code
Enter Cookbook: refactoring under a microscope
SVN Hook
Joomla Code Quality Control and Automation Testing
Improving QA on PHP projects - confoo 2011
The why and how of moving to php 5.4
Php Power Tools
Standards: Don't pee in the pool
The why and how of moving to php 8
20 PHP Static Analysis and Documentation Generators #burningkeyboards
The why and how of moving to PHP 5.4/5.5
Your (coding) standards matter
Ad

Recently uploaded (20)

PDF
Machine learning based COVID-19 study performance prediction
PDF
Encapsulation theory and applications.pdf
PPTX
sap open course for s4hana steps from ECC to s4
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Approach and Philosophy of On baking technology
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
cuic standard and advanced reporting.pdf
Machine learning based COVID-19 study performance prediction
Encapsulation theory and applications.pdf
sap open course for s4hana steps from ECC to s4
The Rise and Fall of 3GPP – Time for a Sabbatical?
Dropbox Q2 2025 Financial Results & Investor Presentation
Approach and Philosophy of On baking technology
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Programs and apps: productivity, graphics, security and other tools
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Unlocking AI with Model Context Protocol (MCP)
The AUB Centre for AI in Media Proposal.docx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Building Integrated photovoltaic BIPV_UPV.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
20250228 LYD VKU AI Blended-Learning.pptx
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
cuic standard and advanced reporting.pdf

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: albert@albert-rosa.comAIM: albertrosa2000Meetup: www.meetup.com/codeigniter/Rokkan: www.rokkan.com