Could you please recommend some software that will do PHP code polishing according to pre-defined formatting rules?
Thanks!
I use Polystyle. It's quite nice and has very customizable rules. Costs $15, trial version is available. Is worth the money.
There are free ones around as well. I think there is a good formatter in some Eclipse PHP package (I forgot the name) and there is the on-line PHP Beautifier service (that one doesn't have any formatting rules, though).
I use codesniffer (http://pear.php.net/package/PHP_CodeSniffer) to check my code and keep it nice and tidy. It doesn't do any re-formatting tho, just displays a list of errors based on whichever standard you choose to check against then you go fix them by hand. Personally I prefer that tho. Its also very flexible and you can add your own standards or amend the existing ones using php
Related
When JSON came out, it came with a nice dedicated web-page. They summarized the ggrammar on a single page. They explained how easy it is to use JSON (natively) in JS. Then they provided a miriad of libraries for other languages.
Now NEON is available in PHP. I am new to PHP, but I lack to see it's usefulness (except it tries to be pretty, for the price of ambiguity and white-space problems).
Is there any reason I shouldn't cut out all NEON stuff and replace it with simple JSON?
I think you misunderstand some things.
NEON is default configuration file for Nette framework, it's nothing like that will be replacing JSON in PHP for ever.
NEON is 100% capable of replacing JSON object, but it's mainly targeted for configuration files, which will be modified by people. At same time it's a powerful alternative for YAML which is also great configuration file format for humans used for example in Symfony FW.
There are no problem with spaces/tabs in real at all, you just must use one of them - that's only strict not bad. Because good code starts with consistency. There are plenty ways of doing things, but in one project, you should have things unified.
JSON is cross-platform compatible format which is surely has place in projects. Mostly in generated files. But it's really clumsy and ugly for files which are directly changed by developer. NEON/YAML do this thing 1000x better, and if you does not get it that value added to configuration files, then you probably doesn't work enough with configuration files.
In Nette, you can use configuration in many other file types - even in json. But if you new in PHP as you said, don't do it. Nette and Symfony FWs weren't use this formats for nothing. It is has added value.
Neon is maybe more readable than json, but as you said there are some problems with white-space / tab. But many IDEs (NetBeans, PhpStorm...) support it, so you can use auto-format.
Background
I'm looking to create a wiki-style website.
First I took a look at http://en.wikipedia.org/wiki/List_of_wiki_software
Wanting to use PHP and being sceptic about using plain file storage the choice was lijited down to three alternatives:
Tiki Wiki CMS Groupware
PhpWiki
MediaWiki
Correct me if I'm wrong but all of these felt very heavyweight and pretty much overkill for a rather small project.
The question
My idea was then to use some kind of existing libraries and/or tools for the history, diff and markup parts but implementing the rest myself.
Do you know of any (good) libraries and/or tools like these?
Use an existing library like Markdown for marking up wiki text. Extend it if you have to. A diff algorithm for a wiki can be as trivial as you want it to be. First result on google for php diff showed an extremely simple algorithm that will probably get you started in the right direction.
PHP Diff Algorithm
PHP Markdown
Also don't forget about Github! There are all kinds of wiki projects written in PHP on there. Like this one!
Is there a addon where let say I want to see the origin/stack/trace of a variable I can do so?
I primarily want to see where variables are coming from, what classes and files they go through.
If there is another editor that does this well Ill take suggestions as well!
Thanks.
I don't think TextMate is able to do that, with or without a plugin.
-- START EDIT --
When I was still using it and I wanted to see (and possibly jump to) where a method or property came from I just used Search in Project.
-- END EDIT --
Vim in conjunction with ctags and cscope can help you jump from instance to prototype and vice-versa — wether it's in the current file or not — with <C-]> (or <C-$> on my french Mac keyboard); with TagList or TagBar you can see the structure of your code… but none of this can give you the clean overview you are looking for. But there is probably a plugin for that.
But if that kind of features is important for you it is typically a good reason to use an IDE instead of a text editor. In Eclipse, for example, you have a Type Hierarchy view that does most of what you want and possibly other tools to do the rest. I haven't tried every single IDE under the sun but I think a similar or more powerful feature exists in all of them.
Maybe in Emacs…
Plugins to make PHP coding easier and efficient in (g)Vim?
e.g. Error detection/highlight, debugging, etc?
For error detection, there is no miracle, but Syntastic is a good start.
If you have installed xdebug, then you can use :
DBGp-client
vim-add-xdebug (I never used it, but seems more recent)
DBGPavim (the most recent, nice plugin with good documentation)
Also, there is a package with some PHP config/plugins all-in-one, PIV, but I prefer installing plugins one by one.
Finally, the best advice would be to first install Vundle, so that you can then do this :
:BundleSearch php
Then yank the plugins results you're interested in, into your .vimrc, then
:BundleInstall
And you can test these plugins in no time. And launch :BundleClean after removing lines in your .vimrc if you don't like the plugin.
I found the free book 'A Byte of Vim' very helpful. It contains descriptions of a useful set of plugins.
http://www.swaroopch.com/notes/Vim
See also Dr Chip's Vim page.
http://www.drchip.org/
I'm working with websites written in PHP, along with many other programmers, and sometimes I have to deal with really awful code.
Indentation totally messed up, curly braces in the wrong places, terrible whitespace use, it really hurts my eyes and actually makes my work harder and take longer.
Is there a tool where you can specify your coding style and then it applies it to files?
I'm sure there must be such functions in different IDEs, but I need an independent tool as I code with simple notepads like Notepad++ or the like. ( if it's such a function in Notepad++, I didn't see it )
Try PHP Code Sniffer.
That should be exactly what you are looking for(at least that's what I thought afert reading the heading, see the update).
UPDATE:
Actually what Code Sniffer does is go through your code and detect coding style violations, it does not however fix the problems.
But by telling you what's wrong it enforces you to adhere to a certain coding style. So that might be an option for you in the future.
While I have never used any, as I (luckly?) don't use anyone else code much, google found this, PHP Beautifier.
EDIT
See this question which recommends PHP Code Beautifier which is free (but requires an account creation)
Eclipse PDT also can format your code. Not sure how configurable it is. Just hit CTRL-Shift-F.
Well for a quick solution Aptana IDE does support a code format option
See the SD PHP Formatter for a tool that prettyprints source files, one at a time, or in large batches, according to your preferred style.
From what I can find Notepad++ doesn't even do basic linting (syntax checking) so it won't be able to do code sniffing: http://sourceforge.net/p/notepad-plus/discussion/482781/thread/b802c218:
Can anyone write a PHP syntax checker plugin?
...
What's wrong with PHP itself? If you run PHP as a command line utility with -l (letter L), it will run as PHP lint and check for syntax errors. e.g.
php -l broken.php
Hook it up as an external tool, perhaps through a batch file.
But you can get Code Sniffers for other text editors e.g. Sublime Text, Atom.io.