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

PPTX
Creating your own framework on top of Symfony2 Components
PDF
RESTful API development in Laravel 4 - Christopher Pecoraro
TXT
Sql procedures
PDF
Adding custom ui controls to your application (1)
PPTX
Zend framework
PPT
Web service with Laravel
PDF
Painless Javascript Unit Testing
PDF
SCR Annotations for Fun and Profit
Creating your own framework on top of Symfony2 Components
RESTful API development in Laravel 4 - Christopher Pecoraro
Sql procedures
Adding custom ui controls to your application (1)
Zend framework
Web service with Laravel
Painless Javascript Unit Testing
SCR Annotations for Fun and Profit

What's hot (20)

PDF
Hello World on Slim Framework 3.x
PPT
Elefrant [ng-Poznan]
PDF
Working with oro crm entities
PDF
Laravel 5 In Depth
PDF
Phoenix demysitify, with fun
PDF
Web services with laravel
ODP
Javascript laravel's friend
PDF
Resting with OroCRM Webinar
PDF
Adventurous Merb
PDF
Laravel Design Patterns
PDF
OroCRM Partner Technical Training: September 2015
PPTX
REST APIs in Laravel 101
ODP
Oro Workflows
PPTX
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
KEY
Cocoa on-rails-3rd
PDF
Bootstrat REST APIs with Laravel 5
PDF
Workshop 3: JavaScript build tools
PPT
Magento - a Zend Framework Application
Hello World on Slim Framework 3.x
Elefrant [ng-Poznan]
Working with oro crm entities
Laravel 5 In Depth
Phoenix demysitify, with fun
Web services with laravel
Javascript laravel's friend
Resting with OroCRM Webinar
Adventurous Merb
Laravel Design Patterns
OroCRM Partner Technical Training: September 2015
REST APIs in Laravel 101
Oro Workflows
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
Cocoa on-rails-3rd
Bootstrat REST APIs with Laravel 5
Workshop 3: JavaScript build tools
Magento - a Zend Framework Application
Ad

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

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

Recently uploaded (20)

PDF
Understanding Forklifts - TECH EHS Solution
PPTX
history of c programming in notes for students .pptx
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
System and Network Administraation Chapter 3
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
System and Network Administration Chapter 2
PPTX
L1 - Introduction to python Backend.pptx
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
ai tools demonstartion for schools and inter college
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Nekopoi APK 2025 free lastest update
Understanding Forklifts - TECH EHS Solution
history of c programming in notes for students .pptx
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Navsoft: AI-Powered Business Solutions & Custom Software Development
How Creative Agencies Leverage Project Management Software.pdf
System and Network Administraation Chapter 3
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
System and Network Administration Chapter 2
L1 - Introduction to python Backend.pptx
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
How to Choose the Right IT Partner for Your Business in Malaysia
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Odoo Companies in India – Driving Business Transformation.pdf
Operating system designcfffgfgggggggvggggggggg
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
ai tools demonstartion for schools and inter college
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Nekopoi APK 2025 free lastest update

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