SlideShare a Scribd company logo
Some tips to improve 
developer experience 
with Symfony 
by Artem Kolesnikov (@tyomo4ka) 
1
Common 
recommendations 
2
Code style 
• Symfony uses PSR-1 and PSR-2 
• Symfony extends PSRs with Symfony Coding 
Standards 
• PHP CS Fixer supports PSRs and Symfony 
• Broken windows theory 
3
Prefer clean naming to 
comments 
• "Every time you write a comment, you should 
grimace and feel the failure of your ability of 
expression." © Robert C. Martin "Clean code" 
• Always comment complex and not obvious logic 
• Remove obsolete comments 
• Never commit commented unused code 
4
Avoid business logic in 
controllers 
• Fat stupid ugly controllers (FSUC) 
// FSUC 
public function updateUserAction(User $user, $userData) 
{ 
$user->updateFromArray($userData); 
$this->getDoctrine()->getManager()->flush($user); 
} 
// OK 
public function updateUserAction(User $user, $userData) 
{ 
$this->get('user_manager')->update($user, $userData); 
} 
5
Use PHP Storm IDE 
• Code analysis 
• Great Symfony2 plugin 
• Plugins for Behat, composer 
• And much, much more 
6
Use PHP syntax sugar and 
new features 
• Short syntax for arrays 
• Other syntactic sugar 
• Traits 
$options = ['yes', 'no']; 
$user = (new User())->setEmail('tyomo4ka@gmail.com'); 
$headers = $this->getRequest()['headers']; 
return $result ?: []; 
7
Don't use interfaces when 
you don't need it 
• Dependency on abstract class works as well 
• Introduce interface is much simpler than remove 
• Interfaces for everything... 
8
Symfony specific 
recommendations 
9
Don't inject service container 
in business logic services 
/** Service which does not depend on Container */ 
class UserManager 
{ 
private $em; 
public function __construct(EntityManager $em) 
{ 
$this->em = $em; 
} 
} 
/** Service which depends on Container */ 
class UserManager 
{ 
private $container; 
public function __construct(ContainerInterface $container) 
{ 
$this->container = $container; 
} 
} 
10
Use one bundle for 
application 
• Recommendation from 
"Official Symfony Best 
Practices" 
• AppBundle vs App 
• use AppEntityUser; 
11
Always use param 
converters 
• Param convert works using request attributes 
public function someAction(ContextEntity $entity) {} 
• Don't write action like this 
public function deleteTagAction() 
{ 
$this->get('xxx.tag_manager')->deleteTagFromStream( 
$this->getRequest()->get('stream_id'), 
$this->getRequest()->get('tag_id') 
); 
} 
• This looks much cleaner 
public function deleteTagAction(Stream $stream, Tag $tag) 
{ 
$this->get('xxx.tag_manager') 
->deleteTagFromStream($stream, $tag) 
; 
} 
12
Prefer security voters to ACL 
• Each ACL check requires requests to DB 
• Voters are simple 
interface VoterInterface 
{ 
function supportsAttribute($attribute); 
function supportsClass($class); 
function vote(TokenInterface $token, $object, array $attributes); 
} 
• Abstract voter (Symfony 2.6+) 
abstract class AbstractVoter implements VoterInterface 
{ 
abstract protected function getSupportedClasses(); 
abstract protected function getSupportedAttributes(); 
abstract protected function isGranted($attribute, $object, $user = null); 
} 
13
Prefer Grunt or Gulp to Assetic 
if you have reach front-end 
• Assetic is good if you don't have too much 
assets 
• Cool like a Frontend Developer: Grunt, 
RequireJS, Bower and other Tools by Ryan 
Weaver (slides and video) 
14
Recommendations from 
"Official Symfony Best 
Practices" 
15
Always use Composer 
to install Symfony 
16
Configuration management 
• Use constants to define configuration options 
that rarely change 
• Don't define a semantic dependency injection 
configuration for your bundles 
17
Services definitions 
• The name of your application's services should be 
as short as possible, ideally just one simple word 
• Use the YAML format to define your own services 
• Don't define parameters for the classes of your 
services 
<parameter key="jms_serializer.metadata.file_locator.class"> 
MetadataDriverFileLocator 
</parameter> 
18
Configuration format 
• Use annotations to define the mapping 
information of the Doctrine entities 
• Use annotations to configure routing, caching 
and security whenever possible 
• Don't use the @Template() annotation to 
configure the template used by the controller 
19
Templating 
• Use Twig templating format for your templates 
• PHP templating engine will be removed in the 
future 
• Store all your application's templates in app/ 
Resources/views/ directory 
20
Some other official recommendations 
• Define your forms as PHP classes 
• Always use keys for translations instead of 
content strings 
{{ 'project_name' |trans }} // Good 
{{ 'Project name' |trans }} // Not good 
21
Some services to improve 
quality of your projects 
22
Codeship CI 
http://codeship.io 
23
Travis CI 
https://travis-ci.org/ 
24
SensioLabs Insight 
https://insight.sensiolabs.com/ 
25
Scrutinizer CI 
https://scrutinizer-ci.com 
26
Check new bundles while 
your drinking your morning coffee 
Check new bundles while your drinking 
your morning coffee 
http://knpbundles.com/ 
27
And finally my favorite 
joke about developers :) 
28
The first year 
29
The second year 
30
The third year 
31
The fifth year 
32
The tens year 
33
Thanks! 
34

More Related Content

What's hot

Hello World on Slim Framework 3.x
Hello World on Slim Framework 3.xHello World on Slim Framework 3.x
Hello World on Slim Framework 3.x
Ryan Szrama
 
Elefrant [ng-Poznan]
Elefrant [ng-Poznan]Elefrant [ng-Poznan]
Elefrant [ng-Poznan]
Marcos Latorre
 
Working with oro crm entities
Working with oro crm entitiesWorking with oro crm entities
Working with oro crm entities
Oro Inc.
 
Rack
RackRack
Laravel 5 In Depth
Laravel 5 In DepthLaravel 5 In Depth
Laravel 5 In Depth
Kirk Bushell
 
Phoenix demysitify, with fun
Phoenix demysitify, with funPhoenix demysitify, with fun
Phoenix demysitify, with fun
Tai An Su
 
Web services with laravel
Web services with laravelWeb services with laravel
Web services with laravel
Confiz
 
Javascript laravel's friend
Javascript laravel's friendJavascript laravel's friend
Javascript laravel's friend
Bart Van Den Brande
 
Resting with OroCRM Webinar
Resting with OroCRM WebinarResting with OroCRM Webinar
Resting with OroCRM Webinar
Oro Inc.
 
Adventurous Merb
Adventurous MerbAdventurous Merb
Adventurous Merb
Matt Todd
 
Laravel Design Patterns
Laravel Design PatternsLaravel Design Patterns
Laravel Design Patterns
Bobby Bouwmann
 
Lecture6
Lecture6Lecture6
OroCRM Partner Technical Training: September 2015
OroCRM Partner Technical Training: September 2015OroCRM Partner Technical Training: September 2015
OroCRM Partner Technical Training: September 2015
Oro Inc.
 
REST APIs in Laravel 101
REST APIs in Laravel 101REST APIs in Laravel 101
REST APIs in Laravel 101
Samantha Geitz
 
Oro Workflows
Oro WorkflowsOro Workflows
Oro Workflows
Yevhen Shyshkin
 
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra  SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
Sencha
 
Cocoa on-rails-3rd
Cocoa on-rails-3rdCocoa on-rails-3rd
Cocoa on-rails-3rd
Xiaochun Shen
 
Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5
Elena Kolevska
 
Workshop 3: JavaScript build tools
Workshop 3: JavaScript build toolsWorkshop 3: JavaScript build tools
Workshop 3: JavaScript build tools
Visual Engineering
 
Magento - a Zend Framework Application
Magento - a Zend Framework ApplicationMagento - a Zend Framework Application
Magento - a Zend Framework Application
ZendCon
 

What's hot (20)

Hello World on Slim Framework 3.x
Hello World on Slim Framework 3.xHello World on Slim Framework 3.x
Hello World on Slim Framework 3.x
 
Elefrant [ng-Poznan]
Elefrant [ng-Poznan]Elefrant [ng-Poznan]
Elefrant [ng-Poznan]
 
Working with oro crm entities
Working with oro crm entitiesWorking with oro crm entities
Working with oro crm entities
 
Rack
RackRack
Rack
 
Laravel 5 In Depth
Laravel 5 In DepthLaravel 5 In Depth
Laravel 5 In Depth
 
Phoenix demysitify, with fun
Phoenix demysitify, with funPhoenix demysitify, with fun
Phoenix demysitify, with fun
 
Web services with laravel
Web services with laravelWeb services with laravel
Web services with laravel
 
Javascript laravel's friend
Javascript laravel's friendJavascript laravel's friend
Javascript laravel's friend
 
Resting with OroCRM Webinar
Resting with OroCRM WebinarResting with OroCRM Webinar
Resting with OroCRM Webinar
 
Adventurous Merb
Adventurous MerbAdventurous Merb
Adventurous Merb
 
Laravel Design Patterns
Laravel Design PatternsLaravel Design Patterns
Laravel Design Patterns
 
Lecture6
Lecture6Lecture6
Lecture6
 
OroCRM Partner Technical Training: September 2015
OroCRM Partner Technical Training: September 2015OroCRM Partner Technical Training: September 2015
OroCRM Partner Technical Training: September 2015
 
REST APIs in Laravel 101
REST APIs in Laravel 101REST APIs in Laravel 101
REST APIs in Laravel 101
 
Oro Workflows
Oro WorkflowsOro Workflows
Oro Workflows
 
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra  SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
 
Cocoa on-rails-3rd
Cocoa on-rails-3rdCocoa on-rails-3rd
Cocoa on-rails-3rd
 
Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5
 
Workshop 3: JavaScript build tools
Workshop 3: JavaScript build toolsWorkshop 3: JavaScript build tools
Workshop 3: JavaScript build tools
 
Magento - a Zend Framework Application
Magento - a Zend Framework ApplicationMagento - a Zend Framework Application
Magento - a Zend Framework Application
 

Similar to Some tips to improve developer experience with Symfony

Código Saudável => Programador Feliz - Rs on Rails 2010
Código Saudável => Programador Feliz - Rs on Rails 2010Código Saudável => Programador Feliz - Rs on Rails 2010
Código Saudável => Programador Feliz - Rs on Rails 2010
Plataformatec
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenches
Lukas Smith
 
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
James Titcumb
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5
Darren Craig
 
Symfony2 from the Trenches
Symfony2 from the TrenchesSymfony2 from the Trenches
Symfony2 from the Trenches
Jonathan Wage
 
Red5 - PHUG Workshops
Red5 - PHUG WorkshopsRed5 - PHUG Workshops
Red5 - PHUG Workshops
Brendan Sera-Shriar
 
Working With The Symfony Admin Generator
Working With The Symfony Admin GeneratorWorking With The Symfony Admin Generator
Working With The Symfony Admin Generator
John Cleveley
 
The Naked Bundle - Tryout
The Naked Bundle - TryoutThe Naked Bundle - Tryout
The Naked Bundle - Tryout
Matthias Noback
 
AD102 - Break out of the Box
AD102 - Break out of the BoxAD102 - Break out of the Box
AD102 - Break out of the Box
Karl-Henry Martinsson
 
Speed up your developments with Symfony2
Speed up your developments with Symfony2Speed up your developments with Symfony2
Speed up your developments with Symfony2
Hugo Hamon
 
Workshop: Symfony2 Intruduction: (Controller, Routing, Model)
Workshop: Symfony2 Intruduction: (Controller, Routing, Model)Workshop: Symfony2 Intruduction: (Controller, Routing, Model)
Workshop: Symfony2 Intruduction: (Controller, Routing, Model)
Antonio Peric-Mazar
 
Developing Lightning Components for Communities.pptx
Developing Lightning Components for Communities.pptxDeveloping Lightning Components for Communities.pptx
Developing Lightning Components for Communities.pptx
Dmitry Vinnik
 
Code decoupling from Symfony (and others frameworks) - PHP Conference Brasil ...
Code decoupling from Symfony (and others frameworks) - PHP Conference Brasil ...Code decoupling from Symfony (and others frameworks) - PHP Conference Brasil ...
Code decoupling from Symfony (and others frameworks) - PHP Conference Brasil ...
Miguel Gallardo
 
Creating a modern web application using Symfony API Platform, ReactJS and Red...
Creating a modern web application using Symfony API Platform, ReactJS and Red...Creating a modern web application using Symfony API Platform, ReactJS and Red...
Creating a modern web application using Symfony API Platform, ReactJS and Red...
Jesus Manuel Olivas
 
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
James Titcumb
 
Simplify your professional web development with symfony
Simplify your professional web development with symfonySimplify your professional web development with symfony
Simplify your professional web development with symfony
Francois Zaninotto
 
6 tips for improving ruby performance
6 tips for improving ruby performance6 tips for improving ruby performance
6 tips for improving ruby performance
Engine Yard
 
The Naked Bundle - Symfony Live London 2014
The Naked Bundle - Symfony Live London 2014The Naked Bundle - Symfony Live London 2014
The Naked Bundle - Symfony Live London 2014
Matthias Noback
 
Hexagonal architecture
Hexagonal architectureHexagonal architecture
Hexagonal architecture
Alessandro Minoccheri
 
Overview of MVC Framework - by software outsourcing company india
Overview of MVC Framework - by software outsourcing company indiaOverview of MVC Framework - by software outsourcing company india
Overview of MVC Framework - by software outsourcing company india
Jignesh Aakoliya
 

Similar to Some tips to improve developer experience with Symfony (20)

Código Saudável => Programador Feliz - Rs on Rails 2010
Código Saudável => Programador Feliz - Rs on Rails 2010Código Saudável => Programador Feliz - Rs on Rails 2010
Código Saudável => Programador Feliz - Rs on Rails 2010
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenches
 
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5
 
Symfony2 from the Trenches
Symfony2 from the TrenchesSymfony2 from the Trenches
Symfony2 from the Trenches
 
Red5 - PHUG Workshops
Red5 - PHUG WorkshopsRed5 - PHUG Workshops
Red5 - PHUG Workshops
 
Working With The Symfony Admin Generator
Working With The Symfony Admin GeneratorWorking With The Symfony Admin Generator
Working With The Symfony Admin Generator
 
The Naked Bundle - Tryout
The Naked Bundle - TryoutThe Naked Bundle - Tryout
The Naked Bundle - Tryout
 
AD102 - Break out of the Box
AD102 - Break out of the BoxAD102 - Break out of the Box
AD102 - Break out of the Box
 
Speed up your developments with Symfony2
Speed up your developments with Symfony2Speed up your developments with Symfony2
Speed up your developments with Symfony2
 
Workshop: Symfony2 Intruduction: (Controller, Routing, Model)
Workshop: Symfony2 Intruduction: (Controller, Routing, Model)Workshop: Symfony2 Intruduction: (Controller, Routing, Model)
Workshop: Symfony2 Intruduction: (Controller, Routing, Model)
 
Developing Lightning Components for Communities.pptx
Developing Lightning Components for Communities.pptxDeveloping Lightning Components for Communities.pptx
Developing Lightning Components for Communities.pptx
 
Code decoupling from Symfony (and others frameworks) - PHP Conference Brasil ...
Code decoupling from Symfony (and others frameworks) - PHP Conference Brasil ...Code decoupling from Symfony (and others frameworks) - PHP Conference Brasil ...
Code decoupling from Symfony (and others frameworks) - PHP Conference Brasil ...
 
Creating a modern web application using Symfony API Platform, ReactJS and Red...
Creating a modern web application using Symfony API Platform, ReactJS and Red...Creating a modern web application using Symfony API Platform, ReactJS and Red...
Creating a modern web application using Symfony API Platform, ReactJS and Red...
 
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
 
Simplify your professional web development with symfony
Simplify your professional web development with symfonySimplify your professional web development with symfony
Simplify your professional web development with symfony
 
6 tips for improving ruby performance
6 tips for improving ruby performance6 tips for improving ruby performance
6 tips for improving ruby performance
 
The Naked Bundle - Symfony Live London 2014
The Naked Bundle - Symfony Live London 2014The Naked Bundle - Symfony Live London 2014
The Naked Bundle - Symfony Live London 2014
 
Hexagonal architecture
Hexagonal architectureHexagonal architecture
Hexagonal architecture
 
Overview of MVC Framework - by software outsourcing company india
Overview of MVC Framework - by software outsourcing company indiaOverview of MVC Framework - by software outsourcing company india
Overview of MVC Framework - by software outsourcing company india
 

Recently uploaded

fiscal year variant fiscal year variant.
fiscal year variant fiscal year variant.fiscal year variant fiscal year variant.
fiscal year variant fiscal year variant.
AnkitaPandya11
 
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
gapen1
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
rodomar2
 
SQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure MalaysiaSQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure Malaysia
GohKiangHock
 
Project Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdfProject Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdf
Karya Keeper
 
zOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL DifferenceszOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL Differences
YousufSait3
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
dakas1
 
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
kalichargn70th171
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
ToXSL Technologies
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
Remote DBA Services
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
Sven Peters
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
mz5nrf0n
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
XfilesPro
 
Lecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptxLecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptx
TaghreedAltamimi
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
Rakesh Kumar R
 
14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision
ShulagnaSarkar2
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
Quickdice ERP
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
Peter Muessig
 

Recently uploaded (20)

fiscal year variant fiscal year variant.
fiscal year variant fiscal year variant.fiscal year variant fiscal year variant.
fiscal year variant fiscal year variant.
 
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
 
SQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure MalaysiaSQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure Malaysia
 
Project Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdfProject Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdf
 
zOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL DifferenceszOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL Differences
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
 
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
 
Lecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptxLecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptx
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
 
14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
 

Some tips to improve developer experience with Symfony

  • 1. Some tips to improve developer experience with Symfony by Artem Kolesnikov (@tyomo4ka) 1
  • 3. Code style • Symfony uses PSR-1 and PSR-2 • Symfony extends PSRs with Symfony Coding Standards • PHP CS Fixer supports PSRs and Symfony • Broken windows theory 3
  • 4. Prefer clean naming to comments • "Every time you write a comment, you should grimace and feel the failure of your ability of expression." © Robert C. Martin "Clean code" • Always comment complex and not obvious logic • Remove obsolete comments • Never commit commented unused code 4
  • 5. Avoid business logic in controllers • Fat stupid ugly controllers (FSUC) // FSUC public function updateUserAction(User $user, $userData) { $user->updateFromArray($userData); $this->getDoctrine()->getManager()->flush($user); } // OK public function updateUserAction(User $user, $userData) { $this->get('user_manager')->update($user, $userData); } 5
  • 6. Use PHP Storm IDE • Code analysis • Great Symfony2 plugin • Plugins for Behat, composer • And much, much more 6
  • 7. Use PHP syntax sugar and new features • Short syntax for arrays • Other syntactic sugar • Traits $options = ['yes', 'no']; $user = (new User())->setEmail('tyomo4ka@gmail.com'); $headers = $this->getRequest()['headers']; return $result ?: []; 7
  • 8. Don't use interfaces when you don't need it • Dependency on abstract class works as well • Introduce interface is much simpler than remove • Interfaces for everything... 8
  • 10. Don't inject service container in business logic services /** Service which does not depend on Container */ class UserManager { private $em; public function __construct(EntityManager $em) { $this->em = $em; } } /** Service which depends on Container */ class UserManager { private $container; public function __construct(ContainerInterface $container) { $this->container = $container; } } 10
  • 11. Use one bundle for application • Recommendation from "Official Symfony Best Practices" • AppBundle vs App • use AppEntityUser; 11
  • 12. Always use param converters • Param convert works using request attributes public function someAction(ContextEntity $entity) {} • Don't write action like this public function deleteTagAction() { $this->get('xxx.tag_manager')->deleteTagFromStream( $this->getRequest()->get('stream_id'), $this->getRequest()->get('tag_id') ); } • This looks much cleaner public function deleteTagAction(Stream $stream, Tag $tag) { $this->get('xxx.tag_manager') ->deleteTagFromStream($stream, $tag) ; } 12
  • 13. Prefer security voters to ACL • Each ACL check requires requests to DB • Voters are simple interface VoterInterface { function supportsAttribute($attribute); function supportsClass($class); function vote(TokenInterface $token, $object, array $attributes); } • Abstract voter (Symfony 2.6+) abstract class AbstractVoter implements VoterInterface { abstract protected function getSupportedClasses(); abstract protected function getSupportedAttributes(); abstract protected function isGranted($attribute, $object, $user = null); } 13
  • 14. Prefer Grunt or Gulp to Assetic if you have reach front-end • Assetic is good if you don't have too much assets • Cool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools by Ryan Weaver (slides and video) 14
  • 15. Recommendations from "Official Symfony Best Practices" 15
  • 16. Always use Composer to install Symfony 16
  • 17. Configuration management • Use constants to define configuration options that rarely change • Don't define a semantic dependency injection configuration for your bundles 17
  • 18. Services definitions • The name of your application's services should be as short as possible, ideally just one simple word • Use the YAML format to define your own services • Don't define parameters for the classes of your services <parameter key="jms_serializer.metadata.file_locator.class"> MetadataDriverFileLocator </parameter> 18
  • 19. Configuration format • Use annotations to define the mapping information of the Doctrine entities • Use annotations to configure routing, caching and security whenever possible • Don't use the @Template() annotation to configure the template used by the controller 19
  • 20. Templating • Use Twig templating format for your templates • PHP templating engine will be removed in the future • Store all your application's templates in app/ Resources/views/ directory 20
  • 21. Some other official recommendations • Define your forms as PHP classes • Always use keys for translations instead of content strings {{ 'project_name' |trans }} // Good {{ 'Project name' |trans }} // Not good 21
  • 22. Some services to improve quality of your projects 22
  • 27. Check new bundles while your drinking your morning coffee Check new bundles while your drinking your morning coffee http://knpbundles.com/ 27
  • 28. And finally my favorite joke about developers :) 28