PHPDoc Comments in Notepad++? - php

I very much enjoy working in Notepad++, but I haven't yet found a plugin to automatically do PHPDoc style comments. Other PHP IDE's (Eclipse, NetBeans, ZendStudio) include this feature, and it's quite handy.
Basically what I want is, if on the line above a function definition or class definition I type in:
/**
It automatically populates the PHPdoc format (something like the following for a function):
/**
*
* #param $first_argument
* #param $second_argument
* #return
*/
Then when I type in additional lines to the comment, it starts each line with an asterisk.
Is there a NP++ plugin that accomplishes this, or a way to tweak NP++ to make it work?

The question is old...but try DoxyIt plugin from plug manager. It works exactly as you need.

While Notepad++'s syntax highlighter recognizes doc comments, it does not actually parse them and generate the corresponding autocomplete code for you, nor does it have any snippet features that allow you to insert doc comments on the fly.

Try DocIt, it works fine, after install move cursor before function and press CTRL + ALT + SHIFT + D to add comments.
Download: https://sourceforge.net/projects/nppdocit/postdownload

I think there aren't a "really tool" por PHPDoc on N++. You can use the WebEdit plugin (plugin manager). Once installed you need to update the edit file adding this line at the end:
pdoc=/**\n * \n * \n * #params \n * #return \n */
Restart N++, write pdoc and press Alt+Enter to get anything like this:
/**
*
*
* #params
* #return
*/
Obviously, it can't get your function params and other tipical info of DocBloks but may be helpfull if we have no choice.

I guess the selected answer is older than the plugin itself but I use DocIt. http://nppdocit.sourceforge.net/

Related

Swagger php two path having same method without repetitive doctrine annotation

From another question:
/**
* #SWG\Post(
* path="/user/login",
* #SWG\Response(response=200, description="OK")
* )
* #SWG\Path(path="/user/", ref="#/user/login");
*/
function login() {
...
}
The above code not working - no definition coming in swagger integrated page. Do I need two definitions for same method for different URLs?
Try changing the reference to
#SWG\Path(path="/user/", ref="#/paths/~1user~1login");
OpenAPI/Swagger path references use the syntax #/paths/path_name, where path_name is the string /user/login with the special character / escaped as ~1. (This answer has more escaping examples.)

Stop TinyMCE stripping empty tags in WordPress - yes I have researched already

Like many other people, I have a problem with TinyMCE stripping HTML tags - specifically the empty ones I'm using with Font Awesome.
I have researched and tried solutions and nothing has worked. I'm not especially strong with PHP, but the problem I'm running into is this: everybody says modifiy the tinyMCE.init function in the tinymce.js file. However being in the newest version of WP, I don't have that. What I have class-wp-editor.php, wherein lives this:
/*
* For people who really REALLY know what they're doing with TinyMCE
* You can modify $mceInit to add, remove, change elements of the config
* before tinyMCE.init. Setting "valid_elements", "invalid_elements"
* and "extended_valid_elements" can be done through this filter. Best
* is to use the default cleanup by not specifying valid_elements,
* as TinyMCE checks against the full set of HTML 5.0 elements and attributes.
*/
if ( $set['teeny'] ) {
/**
* Filter the teenyMCE config before init.
*
* #since 2.7.0
*
* #param array $mceInit An array with teenyMCE config.
* #param string $editor_id Unique editor identifier, e.g. 'content'.
*/
$mceInit = apply_filters( 'teeny_mce_before_init', $mceInit, $editor_id );
} else {
/**
* Filter the TinyMCE config before init.
*
* #since 2.5.0
*
* #param array $mceInit An array with TinyMCE config.
* #param string $editor_id Unique editor identifier, e.g. 'content'.
*/
$mceInit = apply_filters( 'tiny_mce_before_init', $mceInit, $editor_id );
}
Now I know I have to do something with valid_elements, or extended_valid_elements, or verify_html, but I don't know how to do it. I can see from the comments where to put it, but I don't know which to use or the proper syntax.
I found this fiddle: http://fiddle.tinymce.com/j9baab/1 but like I said I don't have that function anywhere in WP.
Please help!
You really don't want to modify the class-wp-editor.php file as each time you update WordPress it will get overwritten.
The easiest way to extend/modify the settings of TinyMCE is to build a simple WordPress Plugin and tie into the hooks WordPress provides to change the editor's settings.
To solve your particular desire to add options to the init you want to look at
the 'tiny_mce_before_init' hook. You might do something like this in the plugin:
add_filter('tiny_mce_before_init', 'add_my_options');
function add_my_options($opt) {
// $opt is the existing array of options for TinyMCE
// We simply add a new array element where the name is the name
// of the TinyMCE configuration setting. The value of the array
// object is the value to be used in the TinyMCE config.
$opt['extended_valid_elements'] = '*[*]';
return $opt;
}
Writing a simple WP plugin is not too hard - there are plenty of examples on the web. For something this simple its really just a single PHP file. Once you have the plugin built you just install and activate it. Once activated, your code is run each time TinyMCE is invoked and your options are injected into the init code.
EDIT: Here is the code from the OPs comment (easier to read than how the comments are formatted):
<?php
/**
* Plugin Name: Disable TinyMCE Filters
* Plugin URI: http://mindspyder.com
* Description: This plugin disables annoying TinyMCE Filters.
* Version: 1.0.0
* Author: Brandon Snow
* Author URI: http://mindspyder.com
* License: GPL2
*/
add_filter('tiny_mce_before_init', 'add_my_options');
function add_my_options($opt) {
// $opt is the existing array of options for TinyMCE
// We simply add a new array element where the name is the name
// of the TinyMCE configuration setting. The value of the array
// object is the value to be used in the TinyMCE config.
$opt['extended_valid_elements'] = '*[*]';
return $opt;
}
?>

PHPDOC Examples Without Line Numbers

According to PHPDocumentor's documentation, to show an example it would be like this:
#example [location] [<start-line> [<number-of-lines>] ] [<description>]
This seems like a valid solution if code never changes but whenever you go and add new code to wherever the location is, your start-line potentially changes meaning you have to constantly be updating these various references.
Is there a better way to show an example of how to use a class method, within the DocBlock, without referencing an external current use example?
Here is what I am aiming for:
/**
* #example This is how you use this method:
*
* $baz = Foo::bar( array('bing' => $bing) );
*/
And then it shows up in the documentation as an example. Any ideas?
You can show a code example in the docblock itself by means of the "code" delimiter. So, for your original example:
/**
* This is how you use this method:
* <code>
* $baz = Foo::bar( array('bing' => $bing) );
* </code>
*/
The manual page [1] for the #example tag shows both a "code" section in the docblock as well as #example pointers to lines in separate files.
[1] -- http://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_tags.example.pkg.html

Can you automatically put a method's code into its DockBlock in phpDocumentor 2?

I've installed phpDocumentor 2 and want to include the source for each method in the generated documentation. However, I notice that the inline #source tag does not appear to be picked up, and there only seems to be reference to it in phpDocumentor 1's documentation.
Here's what I've been trying:
/**
* Test Comment
*
* {#source}
*/
public function test_method() {
echo('Hi!');
}
I was hoping {#source} would be replaced with the following HTML:
<code>
echo('Hi!');
</code>
Is this now deprecated? And if so, is there any way to achieve this using phpDocumentor 2?
I've had a proper look into this today and spoken with Mike van Riel on the phpDocumentor mailing list.
Simply put - you can't do exactly what I'm after.
PHPDocumentor 2's default template, 'responsive', has no support for dynamically showing code. What you can do is switch to an alternate template, 'new-black', and that will show you the source code for the corresponding file. This works with the #filesource tag and there's a --sourcecode switch when building the documentation which will automatically enable this for all files.
However, what you can't do is include code at method level, which is what the #source tag is for. That simply isn't supported, and the raw structure.xml file doesn't even store this information.
Having said that, Mike has said "I definitely want the functionality" - so here's to hoping it gets included in the future! I haven't got time this second, but I'll submit it as an issue on GitHub. If you're keen on having this functionality too, please make it known.

How do I customize NetBeans PHP auto DocBlock for methods and attributes?

After I create a method I use /**<enter> to generate the DocBlock. It auto fills the #param and #return for that function.
Example:
/**
*
* #param type $str
* #return type
*/
public function strlen($str){
return strlen($str);
}
How can I customize the block being generated so that it also fills in the #author and end up with this after /**<enter>
/**
*
* #param type $str
* #return type
* #author John Doe <john#doe.com>
*/
public function strlen($str){
return strlen($str);
}
Thanks
There may be a better way to do this, but here's what I've used: under Tools > Options > Editor > Code Templates, there are some predefined combos for generating code quickly. One of the default templates in 7.0 is:
vdoc<tab>
This generates a pseudo-docblock and the variable definition. You can replace this and add new ones that expand into whatever text you want, much like vim abbreviations. You can find more on this on the Netbeans documentation site:
http://netbeans.org/kb/docs/php/code-templates.html#using-templates
I believe the answer you're looking for will be found here: phpDocumentor Tutorial
I think you'll want to look at the --customtags Command-line switch.
So most likely, when you go to Tools -> Options -> "PHP" -> "PHPDoc", you can add that --customtags command-line switch into the PHPDoc script line.
I haven't attempted this personally, but I have been playing around with the idea of using NetBeans in combination with DocBlocks and PHPDocumentor to "automagically" create a good amount of usable documentation without being too strenuous on the rest of the coders. ;-)
There's a nice video tutorial about setting up NetBeans to work with PHPDocumentor available here: Generating PHP Documentation With NetBeans IDE 7.0
To enable proper #author tag autocompletion, just go to: Tools->Templates->PHP->PHP Class, press the "Settings" button and uncomment the line starting with #user=.
Now you're able to edit the name and email, which are passed to your Class comment.
Short Answer from various sources: No you can't edit a template that could add it for you.
If you are still looking for a feature alike, you can create a Macro do to it and then bind it to a shortcut ("Alt + W" for instance).
To create a Macro : Tools -> Options -> Editor -> Macros
Example :
Alt+W => insert-break "/**" insert-break
This Macro helps add PHPDoc with the left hand which makes it faster. You can generate whatever you wish to generate like using this Macro, and then placing the cursor at the right place and then adding the #author YOUR_NAME at the end of the comment.
You can also set the general Author of your project by going to : Tools -> Templates; Click "Settings"
Add the line :
user=YOUR NAME <email.prefix at domain.extension>
This will add the #author to all your new class/interface definitions.
I hope this will help you!

Categories