SlideShare a Scribd company logo
1 of 13
CodeIgniter Code Sniffer
Topic Code Sniffer The ins and out of making sure your code is up to a standard of your choosing.
INTRODUCTION In 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_CodeSniffer Then enter Phpcs –ito see the installed Coding Standards
ABOUT CODE SNIFFER Code 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 RESPONSE Bellow 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 format 13 | ERROR | Spaces must be used to indent lines; tabs are not allowed 17 | ERROR | A closing tag is not permitted at the end of a PHP file --------------------------------------------------------------------------------
HOW TO USE CODE SNIFFER Code 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.txt now we target just specific files as follows: phpcs /full/path/to/project/ext/fileW.extension --standard=Zend --report=full -n >> projectName.sniffer.txt now 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 WHAT Now 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 Note Code 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.
THANKS Thanks go to Adil and Rokkan for providing us with the Conference space.
Next Months Topic Vote at: www.meetup.com/codeigniter/ PhpUnit and Code Igniter with PHP 5.3 Code Sniffer Creating Custom Standards Anything More important than testing and keeping that code clean.
General Info My Email: albert@albert-rosa.com AIM: albertrosa2000 Meetup: www.meetup.com/codeigniter/ Rokkan: www.rokkan.com

More Related Content

What's hot

Introduction to ida python
Introduction to ida pythonIntroduction to ida python
Introduction to ida python
geeksec80
 
Php psr standard 2014 01-22
Php psr standard 2014 01-22Php psr standard 2014 01-22
Php psr standard 2014 01-22
Võ Duy Tuấn
 
Assurer - a pluggable server testing/monitoring framework
Assurer - a pluggable server testing/monitoring frameworkAssurer - a pluggable server testing/monitoring framework
Assurer - a pluggable server testing/monitoring framework
Gosuke Miyashita
 

What's hot (20)

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

Similar to Code Igniter Code Sniffer

Apache Street Smarts Presentation (SANS 99)
Apache Street Smarts Presentation (SANS 99)Apache Street Smarts Presentation (SANS 99)
Apache Street Smarts Presentation (SANS 99)
Michael Dobe, Ph.D.
 

Similar to Code Igniter Code Sniffer (20)

Php
PhpPhp
Php
 
Compliance Automation with Inspec Part 2
Compliance Automation with Inspec Part 2Compliance Automation with Inspec Part 2
Compliance Automation with Inspec Part 2
 
OSDC 2017 | Building Security Into Your Workflow with InSpec by Mandi Walls
OSDC 2017 | Building Security Into Your Workflow with InSpec by Mandi WallsOSDC 2017 | Building Security Into Your Workflow with InSpec by Mandi Walls
OSDC 2017 | Building Security Into Your Workflow with InSpec by Mandi Walls
 
OSDC 2017 - Mandi Walls - Building security into your workflow with inspec
OSDC 2017 - Mandi Walls - Building security into your workflow with inspecOSDC 2017 - Mandi Walls - Building security into your workflow with inspec
OSDC 2017 - Mandi Walls - Building security into your workflow with inspec
 
Adding Security to Your Workflow with InSpec (MAY 2017)
Adding Security to Your Workflow with InSpec (MAY 2017)Adding Security to Your Workflow with InSpec (MAY 2017)
Adding Security to Your Workflow with InSpec (MAY 2017)
 
Comment améliorer le quotidien des Développeurs PHP ?
Comment améliorer le quotidien des Développeurs PHP ?Comment améliorer le quotidien des Développeurs PHP ?
Comment améliorer le quotidien des Développeurs PHP ?
 
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
 
LIGGGHTS installation-guide
LIGGGHTS installation-guideLIGGGHTS installation-guide
LIGGGHTS installation-guide
 
Joomla Code Quality Control and Automation Testing
Joomla Code Quality Control and Automation TestingJoomla Code Quality Control and Automation Testing
Joomla Code Quality Control and Automation Testing
 
DevSec Delight with Compliance as Code - Matt Ray - AgileNZ 2017
DevSec Delight with Compliance as Code - Matt Ray - AgileNZ 2017DevSec Delight with Compliance as Code - Matt Ray - AgileNZ 2017
DevSec Delight with Compliance as Code - Matt Ray - AgileNZ 2017
 
InSpec Workflow for DevOpsDays Riga 2017
InSpec Workflow for DevOpsDays Riga 2017InSpec Workflow for DevOpsDays Riga 2017
InSpec Workflow for DevOpsDays Riga 2017
 
Readme
ReadmeReadme
Readme
 
Mpeg guide
Mpeg  guideMpeg  guide
Mpeg guide
 
5 年後還是新手 - WordPress Plugin 開發大冒險 - GOTY
5 年後還是新手 - WordPress Plugin 開發大冒險 - GOTY5 年後還是新手 - WordPress Plugin 開發大冒險 - GOTY
5 年後還是新手 - WordPress Plugin 開發大冒險 - GOTY
 
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
 
Nike popup compliance workshop
Nike popup compliance workshopNike popup compliance workshop
Nike popup compliance workshop
 
20 PHP Static Analysis and Documentation Generators #burningkeyboards
20 PHP Static Analysis and Documentation Generators #burningkeyboards20 PHP Static Analysis and Documentation Generators #burningkeyboards
20 PHP Static Analysis and Documentation Generators #burningkeyboards
 
Is your code ready for PHP 7 ?
Is your code ready for PHP 7 ?Is your code ready for PHP 7 ?
Is your code ready for PHP 7 ?
 
Apache Street Smarts Presentation (SANS 99)
Apache Street Smarts Presentation (SANS 99)Apache Street Smarts Presentation (SANS 99)
Apache Street Smarts Presentation (SANS 99)
 
DevOpsDaysRiga 2017: Mandi Walls - Building security into your workflow with ...
DevOpsDaysRiga 2017: Mandi Walls - Building security into your workflow with ...DevOpsDaysRiga 2017: Mandi Walls - Building security into your workflow with ...
DevOpsDaysRiga 2017: Mandi Walls - Building security into your workflow with ...
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

Code Igniter Code Sniffer

  • 2. Topic Code Sniffer The ins and out of making sure your code is up to a standard of your choosing.
  • 3.
  • 4. INTRODUCTION In 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_CodeSniffer Then enter Phpcs –ito see the installed Coding Standards
  • 6. ABOUT CODE SNIFFER Code 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 RESPONSE Bellow 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 format 13 | ERROR | Spaces must be used to indent lines; tabs are not allowed 17 | ERROR | A closing tag is not permitted at the end of a PHP file --------------------------------------------------------------------------------
  • 8. HOW TO USE CODE SNIFFER Code 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.txt now we target just specific files as follows: phpcs /full/path/to/project/ext/fileW.extension --standard=Zend --report=full -n >> projectName.sniffer.txt now 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 WHAT Now 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 Note Code 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. THANKS Thanks go to Adil and Rokkan for providing us with the Conference space.
  • 12. Next Months Topic Vote at: www.meetup.com/codeigniter/ PhpUnit and Code Igniter with PHP 5.3 Code Sniffer Creating Custom Standards Anything More important than testing and keeping that code clean.
  • 13. General Info My Email: albert@albert-rosa.com AIM: albertrosa2000 Meetup: www.meetup.com/codeigniter/ Rokkan: www.rokkan.com