SlideShare uma empresa Scribd logo
1 de 25
Let’s PHP in a better way!
Coding Recommendations.
Leekas Shep
/Leekas
1
Sneak Peek
● Coding Standards
● Coding Principles
● Design Patterns
We’ll be walking through..
.. and we’ll keep it short and sane
/Leekas
2
Hand-
Picked
Hai There..
● PHP programmer
● Working in collaboration
● Values quality codebase
● Develops scalable applications
● Most importantly, a love for coding
You can benefit the most out of this session,
if you are..
/Leekas
3
No one never ever gonna
touch my code..
Scaling and maintenance
is not even in my wildest
dreams..
And I’ve no love for
coding.. Yes, I hate my
life...
Then, you are in the
wrong place mate! Run!
Coding Standards - Hand-Picked!
● PEAR Coding Standards
● Zend Coding Standards
● PSR Coding Standards
Some of the well known and widely accepted coding standards..
/Leekas
4
PEAR Coding Standards
● One of the first proposed and
widely accepted standards
● Adheres to most of the old-
school practices
(PHP Extension and Application Repository)
/Leekas
5
Zend Coding Standards
● Follows the PEAR standards for
the most part
● No closing tag ( ?> )
● Abstract classes and Interfaces
should have postfixes in the
name - Optional in latest
standards.
/Leekas
6
PSR Coding Standards
● Published by the PHP Framework Interop Group (PHP-FIG)
● Similar to Java Specification Request for Java
(PHP Standard Recommendation)
/Leekas
7
● PSR-1 : Basic Coding Standard
● PSR-2 : Coding Style Guide
● PSR-4 : Autoloader Specifications
PSR-4 Basically deals with
namespaces and file-
directory structure
conventions..
PSR-1 : Basic Coding Standard
● Files MUST use only <?php and <?= tags.
● Files MUST use only UTF-8 without BOM for PHP
code.
● Files SHOULD either declare symbols (classes,
functions, constants, etc.) or cause side-effects
(e.g. generate output, change .ini settings, etc.)
but SHOULD NOT do both.
● Namespaces and classes MUST follow an
"autoloading" PSR: [PSR-0, PSR-4].
● Class names MUST be declared in StudlyCaps.
● Class constants MUST be declared in all upper
case with underscore separators.
● Method names MUST be declared in camelCase.
/Leekas
8
PSR-2 : Coding Style Guide
● Code MUST follow a "coding style guide" PSR [PSR-1].
● Code MUST use 4 spaces for indenting, not tabs.
● There MUST NOT be a hard limit on line length; the soft limit MUST be 120 characters;
lines SHOULD be 80 characters or less.
● There MUST be one blank line after the namespace declaration, and there MUST be one
blank line after the block of use declarations.
● Opening braces for classes MUST go on the next line, and closing braces MUST go on
the next line after the body.
● Opening braces for methods MUST go on the next line, and closing braces MUST go on
the next line after the body.
● Visibility MUST be declared on all properties and methods; abstract and final MUST be
declared before the visibility; static MUST be declared after the visibility.
● Control structure keywords MUST have one space after them; method and function calls
MUST NOT.
● Opening braces for control structures MUST go on the same line, and closing braces
MUST go on the next line after the body.
● Opening parentheses for control structures MUST NOT have a space after them, and
closing parentheses for control structures MUST NOT have a space before.
/Leekas
9
PSR-2 : Coding Style Guide
/Leekas
10
The SOLID Agile Principles
● Single Responsibility Principle
● Open/Closed Principle
● Liskov Substitution Principle
● Interface Segregation Principle
● Dependency Inversion Principle
/Leekas
11
Single Responsibility Principle
/Leekas
12
A class should have only
one reason to change.
Open/Closed Principle
/Leekas
13
Software entities
(classes, modules,
functions, etc.) should
be open for extension,
but closed for
modification.
Hmm.. Those
dependency
injection
trickies.. Luv it!
Those were the
days!
Liskov Substitution Principle
/Leekas
14
Child classes should
never break the parent
class' type definitions.
Coz,
you’ll
never
know!!
Interface Segregation Principle
/Leekas
15
The interface-segregation
principle (ISP) states that no
client should be forced to
depend on methods it does
not use.
Dependency Inversion Principle
/Leekas
16
1. High-level modules should
not depend on low-level
modules. Both should depend
on abstractions.
2. Abstractions should not
depend upon details. Details
should depend upon
abstractions.
The Dependency Inversion Principle is one
that leads or helps us respect all the other
principles.
Design Patterns - Hand-Picked!
● Strategy Pattern
● Facade Pattern
● Decorator Pattern
/Leekas
17
Strategy Pattern
/Leekas
18
● Identify an algorithm (i.e. a
behavior) that the client would
prefer to access through a "flex
point".
● Specify the signature for that
algorithm in an interface.
● Bury the alternative
implementation details in
derived classes.
● Clients of the algorithm couple
themselves to the interface.
Strategy Pattern
/Leekas
19
Facade Pattern
/Leekas
20
Facade Pattern
/Leekas
21
Decorator Pattern
/Leekas
22
Decorator Pattern
/Leekas
23
YES!!
Any questions?
Hook ‘em up!
/Leekas
24
Thank You!!
“Love your code.. Embrace your craft.. Do better..”
Leekas Shep
/Leekas
25

Mais conteúdo relacionado

Mais procurados

Java generics(Under The Hood Of The Compiler) by Harmeet singh
Java generics(Under The Hood Of The Compiler) by Harmeet singhJava generics(Under The Hood Of The Compiler) by Harmeet singh
Java generics(Under The Hood Of The Compiler) by Harmeet singhHarmeet Singh(Taara)
 
(6) c sharp introduction_advanced_features_part_i
(6) c sharp introduction_advanced_features_part_i(6) c sharp introduction_advanced_features_part_i
(6) c sharp introduction_advanced_features_part_iNico Ludwig
 
Decision properties of reular languages
Decision properties of reular languagesDecision properties of reular languages
Decision properties of reular languagesSOMNATHMORE2
 
Decision properties of reular languages
Decision properties of reular languagesDecision properties of reular languages
Decision properties of reular languagesSOMNATHMORE2
 
I Know Kung Fu - Juggling Java Bytecode
I Know Kung Fu - Juggling Java BytecodeI Know Kung Fu - Juggling Java Bytecode
I Know Kung Fu - Juggling Java BytecodeAlexander Shopov
 
Single responsibility principle
Single responsibility principleSingle responsibility principle
Single responsibility principleRadu Iscu
 
Lifting The Veil - Reading Java Bytecode During Lunchtime
Lifting The Veil - Reading Java Bytecode During LunchtimeLifting The Veil - Reading Java Bytecode During Lunchtime
Lifting The Veil - Reading Java Bytecode During LunchtimeAlexander Shopov
 
Lifting The Veil - Reading Java Bytecode
Lifting The Veil - Reading Java BytecodeLifting The Veil - Reading Java Bytecode
Lifting The Veil - Reading Java BytecodeAlexander Shopov
 

Mais procurados (12)

C++ c#
C++ c#C++ c#
C++ c#
 
Finite Automata
Finite AutomataFinite Automata
Finite Automata
 
Java generics(Under The Hood Of The Compiler) by Harmeet singh
Java generics(Under The Hood Of The Compiler) by Harmeet singhJava generics(Under The Hood Of The Compiler) by Harmeet singh
Java generics(Under The Hood Of The Compiler) by Harmeet singh
 
(6) c sharp introduction_advanced_features_part_i
(6) c sharp introduction_advanced_features_part_i(6) c sharp introduction_advanced_features_part_i
(6) c sharp introduction_advanced_features_part_i
 
Decision properties of reular languages
Decision properties of reular languagesDecision properties of reular languages
Decision properties of reular languages
 
Decision properties of reular languages
Decision properties of reular languagesDecision properties of reular languages
Decision properties of reular languages
 
Asynchronous PHP. Myth? Reality!
Asynchronous PHP. Myth? Reality!Asynchronous PHP. Myth? Reality!
Asynchronous PHP. Myth? Reality!
 
I Know Kung Fu - Juggling Java Bytecode
I Know Kung Fu - Juggling Java BytecodeI Know Kung Fu - Juggling Java Bytecode
I Know Kung Fu - Juggling Java Bytecode
 
Single responsibility principle
Single responsibility principleSingle responsibility principle
Single responsibility principle
 
Lifting The Veil - Reading Java Bytecode During Lunchtime
Lifting The Veil - Reading Java Bytecode During LunchtimeLifting The Veil - Reading Java Bytecode During Lunchtime
Lifting The Veil - Reading Java Bytecode During Lunchtime
 
Lifting The Veil - Reading Java Bytecode
Lifting The Veil - Reading Java BytecodeLifting The Veil - Reading Java Bytecode
Lifting The Veil - Reading Java Bytecode
 
Python decision making
Python   decision makingPython   decision making
Python decision making
 

Semelhante a Let's PHP in a better way! - Coding Recommendations.

Software Craftmanship - Cours Polytech
Software Craftmanship - Cours PolytechSoftware Craftmanship - Cours Polytech
Software Craftmanship - Cours Polytechyannick grenzinger
 
Psr 2 coding style guide - Tidepool Labs
Psr 2   coding style guide - Tidepool LabsPsr 2   coding style guide - Tidepool Labs
Psr 2 coding style guide - Tidepool LabsHarutyun Abgaryan
 
Solid principles
Solid principlesSolid principles
Solid principlesNhan Nguyen
 
Clean Code - Part 2
Clean Code - Part 2Clean Code - Part 2
Clean Code - Part 2Knoldus Inc.
 
JDT embraces lambda expressions
JDT embraces lambda expressionsJDT embraces lambda expressions
JDT embraces lambda expressionsEclipse Day India
 
PHP Standards Recommendations - PHP-FIG
PHP Standards Recommendations - PHP-FIGPHP Standards Recommendations - PHP-FIG
PHP Standards Recommendations - PHP-FIGAkshay Khale
 
Principled And Clean Coding
Principled And Clean CodingPrincipled And Clean Coding
Principled And Clean CodingMetin Ogurlu
 
Basics of writing clean code
Basics of writing clean codeBasics of writing clean code
Basics of writing clean codeKnoldus Inc.
 
FRONTEND BOOTCAMP Session 2.pptx
FRONTEND BOOTCAMP Session 2.pptxFRONTEND BOOTCAMP Session 2.pptx
FRONTEND BOOTCAMP Session 2.pptxEhtesham46
 
(3) c sharp introduction_basics_part_ii
(3) c sharp introduction_basics_part_ii(3) c sharp introduction_basics_part_ii
(3) c sharp introduction_basics_part_iiNico Ludwig
 
Web development basics (Part-4)
Web development basics (Part-4)Web development basics (Part-4)
Web development basics (Part-4)Rajat Pratap Singh
 
C STANDARDS (C17).pptx
C STANDARDS (C17).pptxC STANDARDS (C17).pptx
C STANDARDS (C17).pptxSKUP1
 
C STANDARDS (C17) (1).pptx
C STANDARDS (C17) (1).pptxC STANDARDS (C17) (1).pptx
C STANDARDS (C17) (1).pptxSKUP ACADEMY
 
C STANDARDS (C17) (1).pptx
C STANDARDS (C17) (1).pptxC STANDARDS (C17) (1).pptx
C STANDARDS (C17) (1).pptxSKUP ACADEMY
 
C STANDARDS (C17).pptx
C STANDARDS (C17).pptxC STANDARDS (C17).pptx
C STANDARDS (C17).pptxLECO9
 
Psr - php standards recommendations
Psr - php standards recommendationsPsr - php standards recommendations
Psr - php standards recommendationsHà Anh Sơn
 
New c sharp3_features_(linq)_part_ii
New c sharp3_features_(linq)_part_iiNew c sharp3_features_(linq)_part_ii
New c sharp3_features_(linq)_part_iiNico Ludwig
 

Semelhante a Let's PHP in a better way! - Coding Recommendations. (20)

Software Craftmanship - Cours Polytech
Software Craftmanship - Cours PolytechSoftware Craftmanship - Cours Polytech
Software Craftmanship - Cours Polytech
 
Psr 2 coding style guide - Tidepool Labs
Psr 2   coding style guide - Tidepool LabsPsr 2   coding style guide - Tidepool Labs
Psr 2 coding style guide - Tidepool Labs
 
Solid principles
Solid principlesSolid principles
Solid principles
 
Solid principles
Solid principlesSolid principles
Solid principles
 
Clean Code - Part 2
Clean Code - Part 2Clean Code - Part 2
Clean Code - Part 2
 
JDT embraces lambda expressions
JDT embraces lambda expressionsJDT embraces lambda expressions
JDT embraces lambda expressions
 
PHP Standards Recommendations - PHP-FIG
PHP Standards Recommendations - PHP-FIGPHP Standards Recommendations - PHP-FIG
PHP Standards Recommendations - PHP-FIG
 
Principled And Clean Coding
Principled And Clean CodingPrincipled And Clean Coding
Principled And Clean Coding
 
Solid principes
Solid principesSolid principes
Solid principes
 
Basics of writing clean code
Basics of writing clean codeBasics of writing clean code
Basics of writing clean code
 
FRONTEND BOOTCAMP Session 2.pptx
FRONTEND BOOTCAMP Session 2.pptxFRONTEND BOOTCAMP Session 2.pptx
FRONTEND BOOTCAMP Session 2.pptx
 
(3) c sharp introduction_basics_part_ii
(3) c sharp introduction_basics_part_ii(3) c sharp introduction_basics_part_ii
(3) c sharp introduction_basics_part_ii
 
Web development basics (Part-4)
Web development basics (Part-4)Web development basics (Part-4)
Web development basics (Part-4)
 
C STANDARDS (C17).pptx
C STANDARDS (C17).pptxC STANDARDS (C17).pptx
C STANDARDS (C17).pptx
 
C STANDARDS (C17) (1).pptx
C STANDARDS (C17) (1).pptxC STANDARDS (C17) (1).pptx
C STANDARDS (C17) (1).pptx
 
C STANDARDS (C17) (1).pptx
C STANDARDS (C17) (1).pptxC STANDARDS (C17) (1).pptx
C STANDARDS (C17) (1).pptx
 
C STANDARDS (C17).pptx
C STANDARDS (C17).pptxC STANDARDS (C17).pptx
C STANDARDS (C17).pptx
 
Coding conventions
Coding conventionsCoding conventions
Coding conventions
 
Psr - php standards recommendations
Psr - php standards recommendationsPsr - php standards recommendations
Psr - php standards recommendations
 
New c sharp3_features_(linq)_part_ii
New c sharp3_features_(linq)_part_iiNew c sharp3_features_(linq)_part_ii
New c sharp3_features_(linq)_part_ii
 

Último

Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...Skynet Technologies
 
Introduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxIntroduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxFIDO Alliance
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...ScyllaDB
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfSrushith Repakula
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...panagenda
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfFIDO Alliance
 
Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxFIDO Alliance
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxFIDO Alliance
 
TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024Stephen Perrenod
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessUXDXConf
 
Microsoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - QuestionnaireMicrosoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - QuestionnaireExakis Nelite
 
Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftshyamraj55
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?Mark Billinghurst
 
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The InsideCollecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The InsideStefan Dietze
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform EngineeringMarcus Vechiato
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераMark Opanasiuk
 
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...FIDO Alliance
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGDSC PJATK
 
Using IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandUsing IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandIES VE
 

Último (20)

Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
 
Introduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxIntroduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptx
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptx
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptx
 
TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 
Microsoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - QuestionnaireMicrosoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - Questionnaire
 
Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoft
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The InsideCollecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 Warsaw
 
Using IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandUsing IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & Ireland
 

Let's PHP in a better way! - Coding Recommendations.

  • 1. Let’s PHP in a better way! Coding Recommendations. Leekas Shep /Leekas 1
  • 2. Sneak Peek ● Coding Standards ● Coding Principles ● Design Patterns We’ll be walking through.. .. and we’ll keep it short and sane /Leekas 2 Hand- Picked
  • 3. Hai There.. ● PHP programmer ● Working in collaboration ● Values quality codebase ● Develops scalable applications ● Most importantly, a love for coding You can benefit the most out of this session, if you are.. /Leekas 3 No one never ever gonna touch my code.. Scaling and maintenance is not even in my wildest dreams.. And I’ve no love for coding.. Yes, I hate my life... Then, you are in the wrong place mate! Run!
  • 4. Coding Standards - Hand-Picked! ● PEAR Coding Standards ● Zend Coding Standards ● PSR Coding Standards Some of the well known and widely accepted coding standards.. /Leekas 4
  • 5. PEAR Coding Standards ● One of the first proposed and widely accepted standards ● Adheres to most of the old- school practices (PHP Extension and Application Repository) /Leekas 5
  • 6. Zend Coding Standards ● Follows the PEAR standards for the most part ● No closing tag ( ?> ) ● Abstract classes and Interfaces should have postfixes in the name - Optional in latest standards. /Leekas 6
  • 7. PSR Coding Standards ● Published by the PHP Framework Interop Group (PHP-FIG) ● Similar to Java Specification Request for Java (PHP Standard Recommendation) /Leekas 7 ● PSR-1 : Basic Coding Standard ● PSR-2 : Coding Style Guide ● PSR-4 : Autoloader Specifications PSR-4 Basically deals with namespaces and file- directory structure conventions..
  • 8. PSR-1 : Basic Coding Standard ● Files MUST use only <?php and <?= tags. ● Files MUST use only UTF-8 without BOM for PHP code. ● Files SHOULD either declare symbols (classes, functions, constants, etc.) or cause side-effects (e.g. generate output, change .ini settings, etc.) but SHOULD NOT do both. ● Namespaces and classes MUST follow an "autoloading" PSR: [PSR-0, PSR-4]. ● Class names MUST be declared in StudlyCaps. ● Class constants MUST be declared in all upper case with underscore separators. ● Method names MUST be declared in camelCase. /Leekas 8
  • 9. PSR-2 : Coding Style Guide ● Code MUST follow a "coding style guide" PSR [PSR-1]. ● Code MUST use 4 spaces for indenting, not tabs. ● There MUST NOT be a hard limit on line length; the soft limit MUST be 120 characters; lines SHOULD be 80 characters or less. ● There MUST be one blank line after the namespace declaration, and there MUST be one blank line after the block of use declarations. ● Opening braces for classes MUST go on the next line, and closing braces MUST go on the next line after the body. ● Opening braces for methods MUST go on the next line, and closing braces MUST go on the next line after the body. ● Visibility MUST be declared on all properties and methods; abstract and final MUST be declared before the visibility; static MUST be declared after the visibility. ● Control structure keywords MUST have one space after them; method and function calls MUST NOT. ● Opening braces for control structures MUST go on the same line, and closing braces MUST go on the next line after the body. ● Opening parentheses for control structures MUST NOT have a space after them, and closing parentheses for control structures MUST NOT have a space before. /Leekas 9
  • 10. PSR-2 : Coding Style Guide /Leekas 10
  • 11. The SOLID Agile Principles ● Single Responsibility Principle ● Open/Closed Principle ● Liskov Substitution Principle ● Interface Segregation Principle ● Dependency Inversion Principle /Leekas 11
  • 12. Single Responsibility Principle /Leekas 12 A class should have only one reason to change.
  • 13. Open/Closed Principle /Leekas 13 Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification. Hmm.. Those dependency injection trickies.. Luv it! Those were the days!
  • 14. Liskov Substitution Principle /Leekas 14 Child classes should never break the parent class' type definitions. Coz, you’ll never know!!
  • 15. Interface Segregation Principle /Leekas 15 The interface-segregation principle (ISP) states that no client should be forced to depend on methods it does not use.
  • 16. Dependency Inversion Principle /Leekas 16 1. High-level modules should not depend on low-level modules. Both should depend on abstractions. 2. Abstractions should not depend upon details. Details should depend upon abstractions. The Dependency Inversion Principle is one that leads or helps us respect all the other principles.
  • 17. Design Patterns - Hand-Picked! ● Strategy Pattern ● Facade Pattern ● Decorator Pattern /Leekas 17
  • 18. Strategy Pattern /Leekas 18 ● Identify an algorithm (i.e. a behavior) that the client would prefer to access through a "flex point". ● Specify the signature for that algorithm in an interface. ● Bury the alternative implementation details in derived classes. ● Clients of the algorithm couple themselves to the interface.
  • 25. Thank You!! “Love your code.. Embrace your craft.. Do better..” Leekas Shep /Leekas 25