Day One - Workshop Day
Quality Assurance for PHP
- Introduction to Quality Assurance
Introduction to Quality Assurance
- Safeguarding code
- Detect bugs early
- Observe behaviour
- Tracking progress
- Delivers ready to deploy packages
Document for new members in the team / remote workers, force 'think before doing' and code hinting.
Document with DocBlocks in your code. A tool like PHPDoc2 enables you to generate a complete set of documentation.
Testing improves the maintainability of your software:
- During development, tests will fail indicating bugs
- Fixing issues won't break code base
- Long term projects, refacorting made easy
Combine unit tests with integration tests.
Measure the stableness / flexibility / complexity / possibilities to refactor the code.
There are different tools that help to measure your code:
- PHPDepend - Dependency calculations
- Generates multiple metrics based on your code
- Average Number of Derived Classes
- Average Hierarchy Height
- Size and complexity
- Cyclomatic complexity
- Lines of Code
- Number of Methods
- Number of Classes
- Number of Packages
- Number of Methods
- Number of Called Classes (Fanout)
- Number of Operation Calls
- Stability graph
- A mix between abstract and concrete classes
- PHPMD - Mess detection
- Detects 'mess' / suboptimal code
- Detects over complicated expressions
- Detects unused parameters etc.
- PHPCPD - Copy / Paste detection
- Detects similiar code snippets. This indicates problems and stimulates improvement.
- PHPCS - PHP_CodeSniffer
- Validates coding standards
- Apache Benchmarks testing - Server stress testing
It's possible to automate all this test when building. A great build tool is Phing.
Things to include in a build are the tools noted above or a deployment.
Introduction to Docker
Docker containers are separated by kernel namespaces and cgroups It tries to create an enviroment as close as possible as a standard Linux installation but without the need for a seperate kernel.
- Fast disposable development environments
- Easy deployment of applications
- Testing and integration tasks
- Microservice architectures
- Scaling applications
- DIY PaaS
- There is no init process, your process is PID 1 instead.
- No reaping, no cron, no services
- Security implications, isolation is not complete
Go You can automate the setup of a docker container by using a Dockerfile.
Use a tool like Fugu to wrap docker run commands in a config file.
How PHP Changed the World of Programming
Is the PHP community stable?
What happens when the community isn't happy with an OS project? Right, they Fork. The community 'decides'.
When PHP5 was introduced. The adaption of PHP5 was slow. The community then decided to ship multiple projects only with PHP 5, to force the migration. They succeeded.
Composer caused the component revolution. Components are great but needs a lot of trust (security, continuity etc.)
Still when someone new to PHP asks what to learn, everybody suggests a full blown framework. Why does everyone wants an one stop solution, this can over complicate things.
WordPress host 30% of the websites worldwide, but there were not that much WordPress developers at the conference (only 5%). Don't let this get an us/them discussion. But embrace eachother. WordPress still supports PHP 5.2.
Drupal rewrote every version basically from scratch. Now they use Composer besides there own code.
Conclusion: Be part of the community to keep PHP alive / a success
Magento 2 > 1: modernising an e-commerce powerhouse
Magento 1 was developed to be an "one solution to rule them all". They wanted to 'own' OSCommerce and jumped on the ZF1 bandwagon. Sadly enough, ZF1 appeared to be too young.
There were lots of problems in Magento 1, Magento 2 addresses a lot of these problems, but after the release there is still a long way to go.
Composer for corporate use
A project often exists out of multiple sub-projects / dependencies. Managing this with Subversion links caused a lot of problems. So; Composer ftw.
Sensio offers a security check for Composer (also available via api), named: SensioLabs Security Advisories Checker. They check if there are known security issues with one of the used components.
You can list all the used licenses in your project with: composer.phar licenses
Small problem domains
Don't install phing globally but keep track locally with phpunit
Build your own packages, booktip:
- Simplify your project setup. Standardize package layout
- Split app, maintain core lib
- Custom package events 3.1 for example managing assets 3.2 vagrant cachier 3.3 private packages (host with satis, light-weight packagist) 3.3.1 also possible to mirror packages
Jenkins, let the build fail ad soon as possible, composer validate
Debugging: Past, Present and Future by Derick Rethans
A talk about the past, present and future of debugging. Addressed XDebug, PHPDBG.
- Function tracing in XDebug is powerful. It supports multiple output formats.
Derick recommends Komodo for debugging.
PHPStorm supports conditional breakpoints
Derick is working on debug functionality that enables the possibility to do a step back while debugging. It takes an execution, to trace it forward / backward.
Create isolation, small independent classes and methods.
Don't change your unit tests while refactoring, cause you change the behaviour
Refactor continuously, your code gets better, one step at a time.
Functional testing (http://codeception.com)
Implementing Server Side Data Synchronization for Mobile Apps
Sync logic @ server, dumb clients
Best practice: Server suggests next updatetimestamp, because you can't rely on device clocks
Client sends local id to server?
Howto resolve conflicts? -> Last write wins or use domain knowledge.
- Vector clocks
- Products like: Couchbase mobile
Design how your objects talk through mocking
Test the communication between your classes instead of the results.
"Should It?" - A New BDD Tool, Pain Not Included!
The Action-Domain-Responder Design Pattern
Is the widely used MVC pattern still the way to go?
The key points of Action-Domain-Responder:
- A Class (or closure) per Action instead of a controller class with multiple actions.
- The action interacts with the Domain (model) and feeds data to the responder (view).
- The responder is entirely responsible for building the response, including the headers/body of the response.