SlideShare a Scribd company logo
PSR-2:
Coding Style Guide
PSR-2's purpose is to have a single
style guide for PHP code that
results in uniformly formatted
shared code.
● PSR-2 is a coding style agreed upon by many
PHP framework developers
● It’s an extension of the original PSR-1,
which basically has 3 main conventions.
● The benefit of PSR-2 is not in the rules
themselves, but in the sharing of those
rules.
3 Main Conventions of PSR-1
● Classes are upper CamelCase.
● Methods are lower camelCase.
● Constants are written in caps like
VERSION_NUMBER.
Some other rules of PSR-1
● Files MUST use only <?php and <?= tags.
● Files MUST use only UTF-8 without BOM for
PHP code.
● Class names MUST be declared in StudlyCaps
(text notation in which the capitalization of letters
varies by some pattern, or arbitrarily, usually also
omitting spaces between words and often omitting some
letters).
etc...
PSR-2 expands PSR-1 by using these
standards:
● Indents are 4 spaces instead of tabs.
● All PHP files MUST end with a single blank line.
● The closing ?> tag MUST be omitted from files
containing only PHP.
● Keep line lengths at 80 characters. Soft limit of
120 characters.
● Use one blank line after a namespace declaration.
● Use a blank line after a group of declarations.
● There MUST NOT be trailing whitespace at the end of
non-blank lines.
● The `extends` and `implements` keywords MUST be
declared on the same line as the class name.
● Visibility MUST be declared on all methods.
● In the argument list, there MUST NOT be a space before
each comma, and there MUST be one space after each
comma.
● Opening braces for classes MUST go on the next line.
Closing brace must be on its own line.
● Opening braces for methods must go on the next line,
and a separate line for the closing brace.
● Closures must have a space after the function keyword.
● Never use the var keyword, this is used with
JavaScript and would cause some confusion.
● Control structures, like IF, WHICH, FOR, and FOREACH
must have one space before the condition parenthesis.
● The case keywords should be indented from the switch
keyword.
● Keywords, like true, false, and null should be in
lowercase.
Examples
that show how to
use PSR-2
CLASS
METHOD
PROPERTYWrong
Right
METHOD ARGUMENTS
CONTROL:
one space before the condition parenthesis
SWITCH
WHILE, DO WHILE
KEYWORD
PHP Mess Detector
(PHPMD)
What PHPMD does?
It takes a given PHP source code
base and look for several potential
problems within that source.
● PHPMD works through Rules – specific sets of
instructions on what to look for in source code
● There’s a wide variety of prepared rules and
users can write their own
● PHPMD can be installed globally via composer by
running
composer global require 'phpmd/phpmd=*'
Potential Problems within
the Source:
● Possible bugs
● Suboptimal code
● Overcomplicated expressions
● Unused parameters, methods, properties
etc.
Some examples of rules:
● Clean Code Rules: enforce a clean code base.
● Naming Rules: about names - too long, too short,
and so forth
● Unused Code Rules: finds unused code.
● ElseExpression: An if expression with an else
branch is never necessary. You can rewrite the
conditions in a way that the else is not necessary
and the code becomes simpler to read. To achieve
this use early return statements.
● ExcessiveMethodLength: Try to reduce the method
size by creating helper methods and removing
any copy/pasted code.
● ExcessiveClassLength: Try to break it down, and
reduce the size to something manageable.
● ExcessiveParameterList: Long parameter lists
can indicate that a new object should be
created to wrap the numerous parameters.
● ExcessivePublicCount: A large number of public
methods and attributes declared in a class can
indicate the class may need to be broken up.
● CamelCaseClassName: It is considered best practice
to use the CamelCase notation to name classes.
● CamelCasePropertyName: use the camelCase notation
to name attributes.
● CamelCaseMethodName: use the camelCase notation to
name methods.
● CamelCaseParameterName: use the camelCase notation
to name parameters.
● CamelCaseVariableName: use the camelCase notation
to name variables.
● NumberOfChildren: A class with an excessive number of
children is an indicator for an unbalanced class
hierarchy. You should consider to refactor this class
hierarchy.
● DepthOfInheritance: A class with many parents is an
indicator for an unbalanced and wrong class hierarchy.
● ShortVariable: Detects when a field, local, or
parameter has a very short name.
● LongVariable: Detects when a field, formal or local
variable is declared with a long name.
● ShortMethodName: Detects when very short method names
are used.
● ConstantNamingConventions: Class/Interface constant
names should always be defined in uppercase.

More Related Content

What's hot

Dart ppt
Dart pptDart ppt
Dart ppt
Krishna Teja
 
TypeScript VS JavaScript.pptx
TypeScript VS JavaScript.pptxTypeScript VS JavaScript.pptx
TypeScript VS JavaScript.pptx
Albiorix Technology
 
Coding standard
Coding standardCoding standard
Coding standard
FAROOK Samath
 
Secure Infrastructure Provisioning with Terraform Cloud, Vault + GitLab CI
Secure Infrastructure Provisioning with Terraform Cloud, Vault + GitLab CISecure Infrastructure Provisioning with Terraform Cloud, Vault + GitLab CI
Secure Infrastructure Provisioning with Terraform Cloud, Vault + GitLab CI
Mitchell Pronschinske
 
CNIT 141 7. Keyed Hashing
CNIT 141 7. Keyed HashingCNIT 141 7. Keyed Hashing
CNIT 141 7. Keyed Hashing
Sam Bowne
 
TypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painTypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the pain
Sander Mak (@Sander_Mak)
 
Redux and context api with react native app introduction, use cases, implemen...
Redux and context api with react native app introduction, use cases, implemen...Redux and context api with react native app introduction, use cases, implemen...
Redux and context api with react native app introduction, use cases, implemen...
Katy Slemon
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
Rob O'Doherty
 
Vertx
VertxVertx
Java vs JavaScript | Edureka
Java vs JavaScript | EdurekaJava vs JavaScript | Edureka
Java vs JavaScript | Edureka
Edureka!
 
JAVA SCRIPT
JAVA SCRIPTJAVA SCRIPT
JAVA SCRIPT
Go4Guru
 
Job schedulers android
Job schedulers androidJob schedulers android
Job schedulers android
Deesha Vora
 
Load-testing 101 for Startups with Artillery.io
Load-testing 101 for Startups with Artillery.ioLoad-testing 101 for Startups with Artillery.io
Load-testing 101 for Startups with Artillery.io
Hassy Veldstra
 
Coding standard and coding guideline
Coding standard and coding guidelineCoding standard and coding guideline
Coding standard and coding guideline
Dhananjaysinh Jhala
 
Introduction to Drools
Introduction to DroolsIntroduction to Drools
Introduction to Droolsgiurca
 
오픈소스가이드 win,c++
오픈소스가이드 win,c++오픈소스가이드 win,c++
오픈소스가이드 win,c++
jdo
 
Java byte code & virtual machine
Java byte code & virtual machineJava byte code & virtual machine
Java byte code & virtual machine
Laxman Puri
 
Docker 101: An Introduction
Docker 101: An IntroductionDocker 101: An Introduction
Docker 101: An Introduction
POSSCON
 
JavaScript - Chapter 4 - Types and Statements
 JavaScript - Chapter 4 - Types and Statements JavaScript - Chapter 4 - Types and Statements
JavaScript - Chapter 4 - Types and Statements
WebStackAcademy
 

What's hot (20)

Ide
IdeIde
Ide
 
Dart ppt
Dart pptDart ppt
Dart ppt
 
TypeScript VS JavaScript.pptx
TypeScript VS JavaScript.pptxTypeScript VS JavaScript.pptx
TypeScript VS JavaScript.pptx
 
Coding standard
Coding standardCoding standard
Coding standard
 
Secure Infrastructure Provisioning with Terraform Cloud, Vault + GitLab CI
Secure Infrastructure Provisioning with Terraform Cloud, Vault + GitLab CISecure Infrastructure Provisioning with Terraform Cloud, Vault + GitLab CI
Secure Infrastructure Provisioning with Terraform Cloud, Vault + GitLab CI
 
CNIT 141 7. Keyed Hashing
CNIT 141 7. Keyed HashingCNIT 141 7. Keyed Hashing
CNIT 141 7. Keyed Hashing
 
TypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painTypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the pain
 
Redux and context api with react native app introduction, use cases, implemen...
Redux and context api with react native app introduction, use cases, implemen...Redux and context api with react native app introduction, use cases, implemen...
Redux and context api with react native app introduction, use cases, implemen...
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Vertx
VertxVertx
Vertx
 
Java vs JavaScript | Edureka
Java vs JavaScript | EdurekaJava vs JavaScript | Edureka
Java vs JavaScript | Edureka
 
JAVA SCRIPT
JAVA SCRIPTJAVA SCRIPT
JAVA SCRIPT
 
Job schedulers android
Job schedulers androidJob schedulers android
Job schedulers android
 
Load-testing 101 for Startups with Artillery.io
Load-testing 101 for Startups with Artillery.ioLoad-testing 101 for Startups with Artillery.io
Load-testing 101 for Startups with Artillery.io
 
Coding standard and coding guideline
Coding standard and coding guidelineCoding standard and coding guideline
Coding standard and coding guideline
 
Introduction to Drools
Introduction to DroolsIntroduction to Drools
Introduction to Drools
 
오픈소스가이드 win,c++
오픈소스가이드 win,c++오픈소스가이드 win,c++
오픈소스가이드 win,c++
 
Java byte code & virtual machine
Java byte code & virtual machineJava byte code & virtual machine
Java byte code & virtual machine
 
Docker 101: An Introduction
Docker 101: An IntroductionDocker 101: An Introduction
Docker 101: An Introduction
 
JavaScript - Chapter 4 - Types and Statements
 JavaScript - Chapter 4 - Types and Statements JavaScript - Chapter 4 - Types and Statements
JavaScript - Chapter 4 - Types and Statements
 

Similar to Psr 2 coding style guide - Tidepool Labs

Let's PHP in a better way! - Coding Recommendations.
Let's PHP in a better way! - Coding Recommendations.Let's PHP in a better way! - Coding Recommendations.
Let's PHP in a better way! - Coding Recommendations.
Leekas Shep
 
Perfomatix - iOS swift coding standards
Perfomatix - iOS swift coding standardsPerfomatix - iOS swift coding standards
Perfomatix - iOS swift coding standards
Perfomatix Solutions
 
PHP Standards Recommendations - PHP-FIG
PHP Standards Recommendations - PHP-FIGPHP Standards Recommendations - PHP-FIG
PHP Standards Recommendations - PHP-FIG
Akshay Khale
 
introduction to server-side scripting
introduction to server-side scriptingintroduction to server-side scripting
introduction to server-side scripting
Amirul Shafeeq
 
Md06 advance class features
Md06 advance class featuresMd06 advance class features
Md06 advance class featuresRakesh Madugula
 
c-coding-standards-and-best-programming-practices.ppt
c-coding-standards-and-best-programming-practices.pptc-coding-standards-and-best-programming-practices.ppt
c-coding-standards-and-best-programming-practices.ppt
VinayakHospet1
 
Presentation
PresentationPresentation
Presentationbugway
 
Hsc IT 5. Server-Side Scripting (PHP).pdf
Hsc IT 5. Server-Side Scripting (PHP).pdfHsc IT 5. Server-Side Scripting (PHP).pdf
Hsc IT 5. Server-Side Scripting (PHP).pdf
AAFREEN SHAIKH
 
Lambdas in Java 8
Lambdas in Java 8Lambdas in Java 8
Lambdas in Java 8
Tobias Coetzee
 
An intro to php standards recommendation (psr)
An intro to php standards recommendation (psr)An intro to php standards recommendation (psr)
An intro to php standards recommendation (psr)
valuebound
 
Server Scripting Language -PHP
Server Scripting Language -PHPServer Scripting Language -PHP
Server Scripting Language -PHP
Deo Shao
 
Symbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code GenerationSymbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code Generation
Akhil Kaushik
 
In-Depth Guide On WordPress Coding Standards For PHP & HTML
In-Depth Guide On WordPress Coding Standards For PHP & HTMLIn-Depth Guide On WordPress Coding Standards For PHP & HTML
In-Depth Guide On WordPress Coding Standards For PHP & HTML
eSparkBiz
 
Java
JavaJava
Software Craftmanship - Cours Polytech
Software Craftmanship - Cours PolytechSoftware Craftmanship - Cours Polytech
Software Craftmanship - Cours Polytech
yannick grenzinger
 
overview of c#
overview of c#overview of c#
overview of c#
Kandreo Gotro
 
Annotations
AnnotationsAnnotations
Annotations
Knoldus Inc.
 

Similar to Psr 2 coding style guide - Tidepool Labs (20)

Coding conventions
Coding conventionsCoding conventions
Coding conventions
 
Let's PHP in a better way! - Coding Recommendations.
Let's PHP in a better way! - Coding Recommendations.Let's PHP in a better way! - Coding Recommendations.
Let's PHP in a better way! - Coding Recommendations.
 
Perfomatix - iOS swift coding standards
Perfomatix - iOS swift coding standardsPerfomatix - iOS swift coding standards
Perfomatix - iOS swift coding standards
 
PHP Standards Recommendations - PHP-FIG
PHP Standards Recommendations - PHP-FIGPHP Standards Recommendations - PHP-FIG
PHP Standards Recommendations - PHP-FIG
 
PPT 19.pptx
PPT 19.pptxPPT 19.pptx
PPT 19.pptx
 
introduction to server-side scripting
introduction to server-side scriptingintroduction to server-side scripting
introduction to server-side scripting
 
Introduction to C#
Introduction to C#Introduction to C#
Introduction to C#
 
Md06 advance class features
Md06 advance class featuresMd06 advance class features
Md06 advance class features
 
c-coding-standards-and-best-programming-practices.ppt
c-coding-standards-and-best-programming-practices.pptc-coding-standards-and-best-programming-practices.ppt
c-coding-standards-and-best-programming-practices.ppt
 
Presentation
PresentationPresentation
Presentation
 
Hsc IT 5. Server-Side Scripting (PHP).pdf
Hsc IT 5. Server-Side Scripting (PHP).pdfHsc IT 5. Server-Side Scripting (PHP).pdf
Hsc IT 5. Server-Side Scripting (PHP).pdf
 
Lambdas in Java 8
Lambdas in Java 8Lambdas in Java 8
Lambdas in Java 8
 
An intro to php standards recommendation (psr)
An intro to php standards recommendation (psr)An intro to php standards recommendation (psr)
An intro to php standards recommendation (psr)
 
Server Scripting Language -PHP
Server Scripting Language -PHPServer Scripting Language -PHP
Server Scripting Language -PHP
 
Symbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code GenerationSymbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code Generation
 
In-Depth Guide On WordPress Coding Standards For PHP & HTML
In-Depth Guide On WordPress Coding Standards For PHP & HTMLIn-Depth Guide On WordPress Coding Standards For PHP & HTML
In-Depth Guide On WordPress Coding Standards For PHP & HTML
 
Java
JavaJava
Java
 
Software Craftmanship - Cours Polytech
Software Craftmanship - Cours PolytechSoftware Craftmanship - Cours Polytech
Software Craftmanship - Cours Polytech
 
overview of c#
overview of c#overview of c#
overview of c#
 
Annotations
AnnotationsAnnotations
Annotations
 

Recently uploaded

Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
BrazilAccount1
 
Runway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptxRunway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptx
SupreethSP4
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
BrazilAccount1
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
TeeVichai
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 

Recently uploaded (20)

Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
 
Runway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptxRunway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptx
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 

Psr 2 coding style guide - Tidepool Labs

  • 2. PSR-2's purpose is to have a single style guide for PHP code that results in uniformly formatted shared code.
  • 3. ● PSR-2 is a coding style agreed upon by many PHP framework developers ● It’s an extension of the original PSR-1, which basically has 3 main conventions. ● The benefit of PSR-2 is not in the rules themselves, but in the sharing of those rules.
  • 4. 3 Main Conventions of PSR-1 ● Classes are upper CamelCase. ● Methods are lower camelCase. ● Constants are written in caps like VERSION_NUMBER.
  • 5. Some other rules of PSR-1 ● Files MUST use only <?php and <?= tags. ● Files MUST use only UTF-8 without BOM for PHP code. ● Class names MUST be declared in StudlyCaps (text notation in which the capitalization of letters varies by some pattern, or arbitrarily, usually also omitting spaces between words and often omitting some letters). etc...
  • 6. PSR-2 expands PSR-1 by using these standards: ● Indents are 4 spaces instead of tabs. ● All PHP files MUST end with a single blank line. ● The closing ?> tag MUST be omitted from files containing only PHP. ● Keep line lengths at 80 characters. Soft limit of 120 characters. ● Use one blank line after a namespace declaration. ● Use a blank line after a group of declarations.
  • 7. ● There MUST NOT be trailing whitespace at the end of non-blank lines. ● The `extends` and `implements` keywords MUST be declared on the same line as the class name. ● Visibility MUST be declared on all methods. ● In the argument list, there MUST NOT be a space before each comma, and there MUST be one space after each comma.
  • 8. ● Opening braces for classes MUST go on the next line. Closing brace must be on its own line. ● Opening braces for methods must go on the next line, and a separate line for the closing brace. ● Closures must have a space after the function keyword. ● Never use the var keyword, this is used with JavaScript and would cause some confusion. ● Control structures, like IF, WHICH, FOR, and FOREACH must have one space before the condition parenthesis. ● The case keywords should be indented from the switch keyword. ● Keywords, like true, false, and null should be in lowercase.
  • 9. Examples that show how to use PSR-2
  • 10. CLASS
  • 14. CONTROL: one space before the condition parenthesis
  • 19. What PHPMD does? It takes a given PHP source code base and look for several potential problems within that source.
  • 20. ● PHPMD works through Rules – specific sets of instructions on what to look for in source code ● There’s a wide variety of prepared rules and users can write their own ● PHPMD can be installed globally via composer by running composer global require 'phpmd/phpmd=*'
  • 21. Potential Problems within the Source: ● Possible bugs ● Suboptimal code ● Overcomplicated expressions ● Unused parameters, methods, properties etc.
  • 22. Some examples of rules: ● Clean Code Rules: enforce a clean code base. ● Naming Rules: about names - too long, too short, and so forth ● Unused Code Rules: finds unused code. ● ElseExpression: An if expression with an else branch is never necessary. You can rewrite the conditions in a way that the else is not necessary and the code becomes simpler to read. To achieve this use early return statements.
  • 23. ● ExcessiveMethodLength: Try to reduce the method size by creating helper methods and removing any copy/pasted code. ● ExcessiveClassLength: Try to break it down, and reduce the size to something manageable. ● ExcessiveParameterList: Long parameter lists can indicate that a new object should be created to wrap the numerous parameters. ● ExcessivePublicCount: A large number of public methods and attributes declared in a class can indicate the class may need to be broken up.
  • 24. ● CamelCaseClassName: It is considered best practice to use the CamelCase notation to name classes. ● CamelCasePropertyName: use the camelCase notation to name attributes. ● CamelCaseMethodName: use the camelCase notation to name methods. ● CamelCaseParameterName: use the camelCase notation to name parameters. ● CamelCaseVariableName: use the camelCase notation to name variables.
  • 25. ● NumberOfChildren: A class with an excessive number of children is an indicator for an unbalanced class hierarchy. You should consider to refactor this class hierarchy. ● DepthOfInheritance: A class with many parents is an indicator for an unbalanced and wrong class hierarchy. ● ShortVariable: Detects when a field, local, or parameter has a very short name. ● LongVariable: Detects when a field, formal or local variable is declared with a long name. ● ShortMethodName: Detects when very short method names are used. ● ConstantNamingConventions: Class/Interface constant names should always be defined in uppercase.