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)

PPTX
Symfony Best Practices
PDF
Symfony War Stories
PDF
C:\fake path\askeet 1.0-en
PPT
Workshop: Symfony2 Intruduction: (Controller, Routing, Model)
PDF
Osiąganie mądrej architektury z Symfony2
PDF
Symfony metabook 2.0
PPTX
Symfony2 for legacy app rejuvenation: the eZ Publish case study
PPTX
SOA with PHP and Symfony
PPT
Software Engineering in PHP
KEY
Confoo
PDF
Jobeet 1.4-doctrine-en
PDF
How Kris Writes Symfony Apps
PDF
When e-commerce meets Symfony
PDF
Build powerfull and smart web applications with Symfony2
PDF
Symfony 2 & e-commerce ecosystem - Now in english !
PDF
The Naked Bundle - Symfony Usergroup Belgium
PDF
The Naked Bundle - Symfony Barcelona
ODP
An introduction to Symfony 2 for symfony 1 developers
PPTX
Freelance symfony framework
PDF
Code decoupling from Symfony (and others frameworks) - PHP Conference Brasil ...
Symfony Best Practices
Symfony War Stories
C:\fake path\askeet 1.0-en
Workshop: Symfony2 Intruduction: (Controller, Routing, Model)
Osiąganie mądrej architektury z Symfony2
Symfony metabook 2.0
Symfony2 for legacy app rejuvenation: the eZ Publish case study
SOA with PHP and Symfony
Software Engineering in PHP
Confoo
Jobeet 1.4-doctrine-en
How Kris Writes Symfony Apps
When e-commerce meets Symfony
Build powerfull and smart web applications with Symfony2
Symfony 2 & e-commerce ecosystem - Now in english !
The Naked Bundle - Symfony Usergroup Belgium
The Naked Bundle - Symfony Barcelona
An introduction to Symfony 2 for symfony 1 developers
Freelance symfony framework
Code decoupling from Symfony (and others frameworks) - PHP Conference Brasil ...
Ad

Recently uploaded (20)

PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PPTX
Transform Your Business with a Software ERP System
PPTX
L1 - Introduction to python Backend.pptx
PDF
Digital Systems & Binary Numbers (comprehensive )
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
System and Network Administration Chapter 2
PDF
Digital Strategies for Manufacturing Companies
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
ai tools demonstartion for schools and inter college
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
medical staffing services at VALiNTRY
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
Designing Intelligence for the Shop Floor.pdf
Which alternative to Crystal Reports is best for small or large businesses.pdf
Transform Your Business with a Software ERP System
L1 - Introduction to python Backend.pptx
Digital Systems & Binary Numbers (comprehensive )
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
System and Network Administration Chapter 2
Digital Strategies for Manufacturing Companies
How to Choose the Right IT Partner for Your Business in Malaysia
Upgrade and Innovation Strategies for SAP ERP Customers
CHAPTER 2 - PM Management and IT Context
Softaken Excel to vCard Converter Software.pdf
ai tools demonstartion for schools and inter college
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Adobe Illustrator 28.6 Crack My Vision of Vector Design
medical staffing services at VALiNTRY
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
How to Migrate SBCGlobal Email to Yahoo Easily
Designing Intelligence for the Shop Floor.pdf

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('[email protected]'); $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