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
Related
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.
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 building a Flash, jQuery, and PHP based project which I would like to subversion from the get go. I have experience using Dreamweaver CS5's sub versioning capabilities. So, as far as the PHP and jQuery (the non-flash portion) goes, I'm pretty comfortable.
However, I would like some recommendations on how to subversion the Flash portion. I know Flash Builder has SVN capabilities, however, the flash portion isn't going to function as and RIA, but more, if you will, like a game. As far as my experience with Flash goes, this type of project will work best if done in Flash Professional. Here are the options, as I see them:
find an extension for Flash Professional which will enable SVN. Is there one???
create a "Flash Professional Project" in Flash Builder, built it in Flash Professional, and subversion with Flash Builder.
place my project within a defined site in Dreamweaver, and subversion from Dreamweaver.
I would like to avoid something like Tortoise SVN, as I have had more difficulty with that than I am up for for now. :)
Does anyone have any suggestions, or pointers as to how I can handle this?
Thank you for your time.
Well, any SVN client can handle any kind of file - you don't have to have an extension built into each piece of software you're using. The best way to do this is to put all of your project files into a folder somewhere and then using whatever SVN client you want just add that whole folder to your repo. Does that make sense? The front-end that you're using is more or less irrelevant.
I don't really understand what you are saying about TortoiseSVN, but since you are using different IDE's I would recommend you to use TortoiseSVN as the uniform interface to SVN. And IMO, TortoiseSVN is simple and powerful.
Man up and use the command line ;). Why SVN? Yes, I personally prefer it but there are other great alternatives, have a think about GIT, Mercurial and others too. Mercurial/Git have massive benefits for single developer projects. The flash file will be versioned just like everything else in there. Remember to set your ignore files appropriately to cut out all the os specific poop.
Soon as you get yourself a good versioning repository set up, it doesn't really matter what client you use. I like the one bundled with netbeans / versions or the cli.
I am a cakephp newbie and I would like to know what method you guys use to build your cakephp project. The tutorial I read is using cakephp console to bake application but the book I have use IDE to build the application. It seems console is more convenience because it can generate different projects name...Using IDE would require the developer to manually create all the folders...Thanks for the reply...
What I think you're not hearing enough of, in the answers so far, is that they're really two different tools with two different purposes. Cake's bake command line utility won't really create your application. It will create scaffolding for the parts of an application that you define. This is a great starting point, but that's all it is.
You'll use your IDE to flesh out the bits that make your application, well, an application.
Both tools are very, very useful so it's not really an either/or kind of answer. Although I like using the bake tool to get started, there really aren't that many folders you have to create if you chose the IDE path. Once you drop in the Cake code base, most of that stuff--even the app-centric bits--are waiting for you to fill them out.
I rarely use bake to create views and once I've baked a model or two, I'll often built others from scratch in my text editor. There's no "right" way; just understand what each gives you and use whichever best suits your workflow at a given point in time.
I use both methods, depending on the state of development of the project and/or database.
Often I will copy a controller, model and views and just search & replace the appropriate names.
If I have a lot of database defined, I'll use bake.
As for IDEs, after much pain, frustration and testing I have settled on NetBeans. I did use Komodo for a while when I was forced to work on Windows (Java ate my windows) but now I'm on Ubuntu & Macs Netbeans is powerful, quick and flexible. I still wouldn't touch Eclipse with someone else's, though.
You might be looking for something like ModelBaker. I haven't personally used it, but from what I can see it's a slick GUI on top of CakePHP.
FWIW, I've been using JetBrain's PHPStorm and loving it.
There are so many options when it comes to PHP development environments and you have to piece it all together yourself.
I'm wondering if someone has come up with what they think is the ideal setup that gets out of your way and lets you develop.
Right now I use vim and svn from the command-line. I write scripts to manage builds but I'm thinking about looking into Phing.
I love vim but I'm seriously thinking of trying Eclipse with the PHP plugin because I imagine it makes common SVN options a bit easier (moving files around in a project).
Something to support continuous integration on the database would be a major plus!
UPDATE: Just wanted to stress that previous line up there. I realize some frameworks will help with this, but I don't use a framework. Is there some simple module out there (included in the IDE or not) that will let me easily tie my database schemas/data to a subversion revision, letting me rollback and forward, tag, branch, etc?
Any comments on things beyond the editor? For example: Builds, managing staging/production/development environments, automated testing and building upon SVN commit, etc. Ideally we can make this post a "Go to Whoah" for setting up a professional PHP team development environment.
I recommend to use a complete featured IDE like the PDT (the eclipse PHP project), it gives you:
debugging (using Xdebug or ZendDebugger)
SVN/CVS very convinient integration
DB integration (the DTP plugin)
and much more, based on features of the PDT and eclipse plugins
if you have some money to spent, I think the Zend Studio For eclipse worth it.
It gives you better debugging, PHPUnit integration, ZendFramewrok support, Refactoring and remote system support (ftp, ssh etc.)
I'm giving Netbeans 6.5 PHP bundle a try and liking it very much. I find debugging in it is less clunky than in Eclipse PDT.
I too love vim and used to develop using the same environment as you. These days though I find Eclipse PDT, with Subclipse for SVN integration, to be invaluable. XDebug is great too - no more var_dump();exit; for debugging.
One of the best plugins for a vim fan moving to Eclipse: viPlugin. Well worth the token licence fee to have vi key bindings in Eclipse.
If you are working from the command line, using Git's SVN module eases most of the SVN pain - it handles deletes and moves automagically.
The GUI front ends (kgit or qgit) provide a very intuitive history browser.
I personally like the way that AptanaStudio has pre-packaged all the great Eclipse modules you need to have a very smooth PHP development environment