I guess, it's an off-topic question, but let me try to ask it. I've just started learing about Continuous Integration and now I know that for Java language there are tools like Checkstyle and PMD that enable to enforce coding standards and to report any lines of code that are not meeting these standards.
And now I wonder if there are similar tools for PHP language, that I could incorporate to my Continuous Integration system. What If want all my codes to follow PSR-1 and PSR-2 specification. Are there any tools for PHP that can automate this process - check the whole code base and find files which do not meet the requirements etc.?
Try CodeSniffer.
For example, to verify code for PSR-2 compliance use phpcs --standard=PSR2 src.
Also, I recommend to check out this PHP package boilerplate. It has some basic CI setup with Travis CI and Codeclimate that might be helpful to you.
Related
In some PHP frameworks there exist ways to check quality of code. Laravel uses the PSR-1 and PSR-2 code. Is there way for checking PSR-1 and PSR-2, that checks code via terminal or before commit to git?
PHP CodeSniffer is a useful tool for this. You can also opt in on Scrutinizer or StyleCI, though they may cost money for private projects.
You could run CodeSniffer like this in a pre-commit hook:
"vendor/bin/phpcs --extensions=php --warning-severity=0 --report=full --standard=phpcs.xml app/" which will check for all code in the App folder.
If you are using PHPStorm there is an option to reformat your code with PSR-2. Otherwise you can always use tools like StyleCI.
In 2017 you have 3 options:
already mentioned PHP_CodeSniffer with PSR2, stable, but slowly evolving
PHP-CS-Fixer with PSR2 and Symfony standards (much extra checks, closer to Laravel than PSR2)
vendor/bin/php-cs-fixer fix src --rules=#Symfony
or combine the best of both above in EasyCodingStandard - super easy to use and setup
I'm coming back to programming with Laravel by reading the documentation in the official website. Now I realized there is a 5.0 version and I'm trying it, but by I've noticed something called "scaffolding for user registration and authentication" and I don't understand it at all.
Maybe it's because my main language is Spanish and that word doesn't make sense for me in this context, but I'm really confused.
In the website, the paragraph says this:
Laravel ships with scaffolding for user registration and authentication. If you would like to remove this scaffolding, use the fresh Artisan command:
php artisan fresh
So I would like to know what does it exactly mean and what does it stand for.
The term Scaffolding roughly aims to a quickly set up skeleton for an app or your project.
The main purpose of Scaffolding is to speed your workflow rather than creating it new.
Here is the JeffreyWay/Laravel-4-Generators for your reference.
If you don't want you shall use php artisan fresh as you said in your question.
To get the generator back from your composer
composer require laracasts/generators --dev
Referring to my own answer in another question, I believe that Wikipedia provides a narrow and restricted view. Scaffolding is not just for CRUD operations on top of a database. Scaffolding has a broader objective to give you a skeleton app for any kind of technology.
Yeoman is a modern and useful tool for scaffolding. Using their own words:
The web's scaffolding tool for modern webapps
What's Yeoman?
Yeoman helps you to kickstart new projects, prescribing best practices
and tools to help you stay productive.
To do so, we provide a generator ecosystem. A generator is basically a
plugin that can be run with the yo command to scaffold complete
projects or useful parts.
Through our official Generators, we promote the "Yeoman workflow".
This workflow is a robust and opinionated client-side stack,
comprising tools and frameworks that can help developers quickly build
beautiful web applications. We take care of providing everything
needed to get started without any of the normal headaches associated
with a manual setup.
With a modular architecture that can scale out of the box, we leverage
the success and lessons learned from several open-source communities
to ensure the stack developers use is as intelligent as possible.
As firm believers in good documentation and well thought out build
processes, Yeoman includes support for linting, testing, minification
and much more, so developers can focus on solutions rather than
worrying about the little things.
That's it. Use scaffolding to create a quick-start application to work as an example or the foundation of your solution. It makes you productive faster them building things from scratch.
I am developing TYPO3 projects since 2006 now, and projects are getting bigger and more complex. Setting up a simple CMS site with a contact form and news listing is all routine.
Right now, we finished a bigger project: A platform for an international company with countless extensions:
Login & registration, news, listing database records, dynamic contact forms, surveys & statistics, intranet functions: document upload & download, several backend "tweaks" per TCA modifications, etc. .
The project managers got upset at us developers, because sometimes, after we finished on function X and later committed function Y to the dev server, function X was broken. This was related to typoscript settings, extension interdependencies, versioning errors or sometimes simple programming mistakes and typos.
I know how to take care of the latter, but in general:
From your experience:
How can we develop an error-proof system in TYPO3, where everything works in hand and extensions don't get in their way? In other words:
How can we secure and isolate functionalities (extensions) - and avoid those interdepency issues?
We are working in a DEV team with two developers, and we already use:
Subversion Repository
Local DEV server for development & testing
External typoscript configuration files, split into single files for each extension
Edit for Bountyhunters:
What I am looking for is a best-practice-summary that might include these topics:
General workflow habits
General coding habits
Reliability of our subversion commits (or Git)
Unit testing (PHPUnit, Selenium?)
Deployment (I haven't yet figured out how automated deployment can
help us)
Typoscript best practices
Problems we could find in large TYPO3 projects are not to much different from any development project.
General practices :
configure continuous integration platform with continuous deployment tools;
Test Driven Development with automated testing;
robust architecture (dB, URL routing, ...);
performance tests during development;
use versionning with formatted comments;
use powerful IDE as PHPStorm, Eclipse, Netbeans;
Common TYPO3 practices :
use official API;
follow TYPO3 API code guideline;
use TYPO3 hooks where You can if You need to modify the logic of Core or 3rd party extensions;
use TypoScript constants to separate data from logic in Your configuration;
Additional references :
TYPO3 Best Practice Workshop
TYPO3 Best Practices (de)
TDD & Best Practices mit TYPO3 (de)
Extensions could help to manage complex TYPO3 installation :
caretaker
additional reports
Use modern project management methodologies & tools
Scrum, Kanban, lean developement principles
Bugtrackers as Redmine, Trac
Books :
php|architect's Guide to Enterprise PHP Development
I absolutely recommmend start using PHPUnit for unit testing, but remember unit testing is really about how you create the code in the first place, not usually something you add later. But of course, better late than never.
You should consider setting up a build server like jenkins/hudson or atlassian bamboo. The latter is quite nice and integrates with zend studio which in my opinion is the better choice when developing in PHP. In general the atlassian products are widely used for software projects. (Jira + confluence + greenhopper in particular)
I would also recommend setting up phpunit on jenkins - see http://jenkins-php.org/ as a template, although I've read good feedback about Teamcity. Then, depending on the code you write you setup unit tests (for raw php code, maybe a bit with of mocks), integration tests (API and module connectivity) and system tests (selenium).
Once you have it running after each build you can be sure that at least covered functionality is working. The problem however is that you will spend more time on writing tests and their support as well as thinking about testable code. Also keep in mind that you cannot cover everything - thats not the point. You must have critical paths covered.
I am not sure if this is a stupid question or not.
I have been working with Mongodb and found myself writing the same logic in different applications for simple stuff like selecting collections and drop them etc.
If I made some classes based on the datamapper pattern using all the Mongodb functions would this be a basic SDK ?
If I am totally wrong could someone help me out in defining a SDK ?
I think you're creating a reusable library or if you are getting a bit more ambitious an application framework.
My understanding of an SDK is that it would have the tools (eg. compilers, WSDL pre-processors) necessary to develop applications, whereas the Runtime Environment would just have what you need to run the developed application. Contrast a Java JRE (VM, standard libraries) and JDK (compiler etc.) When we develop for specialised platforms (eg. smart phones) we often have in the SDK an emulation of the target platform to allow us to test our code on our workstation.
I don't think you should be concerned as to whether or not you are building a framework or an SDK, rather be concerned about if it will be useful to other developers. If you say to them: "download your standard Java JDK, + standard mongodb + my excellent framework) you may well help them a lot. I would view something such as Spring as having started like that, and look what happened to that.
Once you start packaging other stuff with your framework, with the objective of making the developers initial download simpler you buy into a world of maintenance issues, when will you release a new version of your package? What happens when fixes are needed for packages you include.
Software Development Kit
A software development kit (SDK or "devkit") is typically a set of development tools that allows for the creation of applications for a certain software package, software framework, hardware platform, computer system, video game console, operating system, or similar platform
We're about to look at implementing some PHP Coding Standards in our workplace to add some consistency between all of our developers.
I've read around and seen Zend and PEAR standards etc, but what's the best way to enforce these?
I've found a PHP Codesniffer plugin for netbeans, but are there any other ways I could enforce a standard, possibly CI (Continuous Integration) / Hudson or even when committing to SVN?
I was just wondering If anyone had experience or any other tools/methods I could look into?
Thanks
CodeSniffer is indeed the best tool for this.
There is a number of ways to use it:
integrating into Eclipse
integrate as pre-commit hook in you VCS
integrating into your CI Server
Disclaimer: the linked pages are just random picks from Google on that topic. They are not to suggest to use Eclipse, SVN or Hudson. Use what you think is appropriate for your development environment.
Also see http://www.qatools.org for additional tools.
I always wanted to perform code beautification on each SVN commit via SVN hooks.
Still belive it's the best & most efficient way.
Currently all team members just know that XXX is approved code beautifier and everyone supposed to use it.
At 2017 you have basically 3 options:
From oldest to newest (by features and codebase):
PHP_CodeSniffer
PHP CS Fixer
EasyCodingStandard - connects them both in super easy to understand way