riccardo tempesta - the right tools for the right job (or: surviving magento 2 coding)
Post on 06-Apr-2017
68 Views
Preview:
TRANSCRIPT
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO
2 CODING)
#mm17it | Riccardo Tempesta
The daily work of a [Magento 2] developer consists of two main job types
Debugging
existing features
Creating
new features
Your code3rd party’s
(or core) code
A B
We will focus on this
Debugging
existing features
Creating
new features
Your code3rd party’s
(or core) code
A B
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO
2 CODING)
#mm17it | Riccardo Tempesta
A SHORT HINT ON: CREATING FEATURES
You will need these thingies:
PHPStorm IDE
Vagrant (or Docker ?)
GIT
Magicento2
Pestle
MSP CodeMonkey
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO
2 CODING)
#mm17it | Riccardo Tempesta
A SHORT HINT ON: CREATING FEATURES
Pestle, Magicento 2 and MSP CodeMonkey because:
Magento 2 requires a lot of boilerplate code
A typo is always lurking somewhere
Your time is not free
Magento 2 is not always DRY compliant
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO
2 CODING)
#mm17it | Riccardo Tempesta
A SHORT HINT ON: CREATING FEATURES
Example of code complexity: Magento 1 vs. Magento 2
Magento 1 – DB Models:
Model
ResourceModel
Collection
Install / Upgrade scripts
config.xml
Magento 2 – DB Models:
Model
ResourceModel
Collection
Install / Upgrade scripts
Repository
RepositoryInterface
ManagementInterface
DataInterface
Dependency Injection
Getters / Setters in DataInterface
API Preferences
Total involved files: 4-5 Total involved files: 8-9
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO
2 CODING)
#mm17it | Riccardo Tempesta
A SHORT HINT ON: CREATING FEATURES
MSP CodeMonkey can create a whole PSR-2 compliant DB model source code
with API, Interfaces, getters and setters. Just typing:
~$ bin/magento codemonkey:crud My_Module MyModelName my_sql_table
Magicento 2 and Pestle can create controllers, modules, plugins, observers and
lots of other coding entities in few clicks.
Your client does not always understand how complex this job is!
So make it as simple as possible for you because you will not be paid for this!
REMEMBER
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO
2 CODING)
#mm17it | Riccardo Tempesta
DEBUGGING
Your code3rd party’s
(or core) code
DEBUGGING & REVERSE ENGINEERINGare the actual 99% work of a developer
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO
2 CODING)
#mm17it | Riccardo Tempesta
DEBUGGING FEATURES
Common scenario when you’re debugging your code:
You do not know where the broken piece of code may be.
It is very hard to let the client understand that debugging is part
(actually: the most) of developing, so:
You probably do not have any of the project’s budget left;
Plus, you have a very short time to fix it!
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO
2 CODING)
#mm17it | Riccardo Tempesta
DEBUGGING FEATURES
Common scenario when you’re debugging 3rd party’s code:
You have no clue about the how the work’s engineered.
You still do not know where the broken piece of code is.
You hope the programmer who worked on that code before you did not
touch the core.
The programmer who created that feature is now probably on permanent
vacation and/or does not speak a single word of your language!
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO
2 CODING)
#mm17it | Riccardo Tempesta
HOPE IT’S NOT A MESS OF SPAGHETTI
CODE
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO
2 CODING)
#mm17it | Riccardo Tempesta
“I’ve seen PHP code you people wouldn’t believe…”
DEBUGGING FEATURES
Debugging process can be tricky in Magento 2.
Magento 2 has lots of new ways to intercept and change the standard core behaviour...
(I mean without changing the core! Do not try this at home!)
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO
2 CODING)
#mm17it | Riccardo Tempesta
Magento 1 rewriting tools
Rewrites
Routes hijacking
Observers
Layout updates
Magento 2 rewriting tools
Stackable preferences
Routes hijacking
Observers
Layout updates
Stackable plugins (after, before, around)
Extension attributes
Modifiers pool
DEBUGGING FEATURES
FINDING THE PIECE OF CODE YOU
NEED CAN BE OFTEN
CHALLENGING AND TIME
CONSUMING.
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO
2 CODING)
#mm17it | Riccardo Tempesta
DEBUGGING FEATURES
So the hard part is simply
FIND SOME PIECE OF CODE DOING SOMETHING SOMEHOW
SOMEWHERE
and, once found
FIX SOMETHING BROKEN SOMEWHERE WITH
SOME THING YOU WILL DO SOMEHOW
As easy as pie… isn’t it?
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO
2 CODING)
#mm17it | Riccardo Tempesta
DEBUGGING FEATURES
PhpStorm as IDE
MSP DevTools
To find out where the code is
PHP Xdebug
To find out what’s wrong with the code
GIT bisect
To find out when you broke it
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO
2 CODING)
#mm17it | Riccardo Tempesta
DEBUGGING FEATURES: MSP DEVTOOLS
Magento 1 & Magento 2 support
Free github project
Chrome extension
Chrome inspector integration
PHPStorm integration
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO
2 CODING)
#mm17it | Riccardo Tempesta
DEBUGGING FEATURES
MSP DevTools allows to inspect:
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO
2 CODING)
#mm17it | Riccardo Tempesta
Blocks
Observers
Plugins
Preferences
Design
UI Components
SQL queries
Profiler results
...
DEBUGGING FEATURES: PHP X-DEBUG
Suspend code execution
Inspect variables
Log results
Runtime variables value change
PHP Storm integrates it
You can do the same with “var_dump”, “print_r” and “echo”,
but everytime you do that, a programmer dies
somewhere!
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO
2 CODING)
#mm17it | Riccardo Tempesta
DEBUGGING FEATURES: GIT BISECT
A typical customer’s bug report is like:
If you manage to understand what is actually broken you can use GIT bisect.
So you just need to know:
what the broken features is and
when it was working for the last time.
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO
2 CODING)
#mm17it | Riccardo Tempesta
“Yesterday all was working on the website, today nothing
works! Fix it!!11!1!!”
DEBUGGING FEATURES: GIT BISECT
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO
2 CODING)
#mm17it | Riccardo Tempesta
Works like this
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO
2 CODING)
#mm17it | Riccardo Tempesta
THE RIGHT TOOLS FOR THE RIGHT JOB (OR: SURVIVING MAGENTO
2 CODING)
#mm17it | Riccardo Tempesta
THANK YOU!
KEEP CALM AND
I WILL ANSWER YOUR QUESTIONS
top related