Magicento
Magicento copied to clipboard
Add @method to PHP Doc is ambiguous doesn't work?
Got this class so far:
<?php
/**
* File
*/
/**
* Class LeMike_DevMode_Model_Php_TraceFile
*
*
*/
class LeMike_DevMode_Model_Php_TraceFile extends Varien_Object
{
public function __construct($fileName)
{
$this->load($fileName);
}
public function ()
{
}
/**
* @param $fh
*/
public function close($fh)
{
fclose($fh);
}
/**
* @param $fh
* @throws Exception
*/
public function open($fh)
{
$version = fgets($fh);
$fileFormat = fgets($fh);
$traceStart = fgets($fh);
if ($fileFormat != XDEBUG_TRACE_COMPUTERIZED)
{
throw new Exception('Could not parse trace file due to wrong format.');
}
}
/**
* @param $fileName
* @param $fh
*/
public function load($fileName)
{
$this->setFileName($fileName);
$this->setFileHandle(fopen($fileName, 'r'));
$this->open($this->getFileHandle());
$this->close($this->getFileHandle());
}
}
- Put my cursor in "getFileHandle()"
- ALT+M -> Add @method to PHP Doc
Expected:
- "@method getFileHandle" appears in doc comment of class
Actually:
- nothing happens
What can I do?
Well that could be really tricky, do you have some idea about how to do this? I mean, with models we can guess the @methods from the Table fields on the DB related with that model, but with a Varien_Object it could be anything.
When you are at a line like this:
$this->get|Foo();
And the cursor is within the method name (I marked it with a "|" line), then on pressing ALT+M for Magicento it could be (php/pseudo code):
$currentMethod = __where_the_cursor_is_in__;
if ( "@method $currentMethod" is in doc-comments )
{
// don't do anything
// maybe show even the option to "remove from doc-comments"
exit;
}
$className = get_class( $this );
$methodSet = get_class_methods( $className );
if ( in_array( $currentMethod, $methodSet ) == false )
{
if ( in_docComment ( $currentMethod, __all_doc_comments_of_current_class__ ) )
{
// find position of "@method" in class comments
// place $currentMethod below (or at the end of the doc-comment) in a new line
}
}
It's more about adding doc comments for the magic of magento as you can see.
OK, so you are thinking in a feature for every "method" not a magic way to discover all the magic methods of the current Varient Object and adding all of them at once (this is how it works for models...).
That could be done, I think an intention with ALT+ENTER could be better in this case (actually this could be an intention native from PhpStorm, could be useful for other frameworks too).
Anyway, now that you have put the pseudocode in PHP, maybe it is worth to note that you can actually implement this feature by yourself, using the Magicento PHP Scripts and a code like that , actually you won't have "$this", but you will receive the full text of the current script and the current cursor position, so you can use that to parse it, even more, if you include Magento in your script (not recommended if you can avoid it, because running Magento is always slow) you could use "$object =new NameOfCurrentFileClass" and then you can use a code similar to your pseudocode (replacing $this by $object). You can also use tokenizers from PHP to parse your code (token_get_all etc) or even more include an external library like: https://github.com/nikic/PHP-Parser. Creativity is your limit here :)
Also I know there are a lot of improvements to do on the Magicento PHP Scripts feature, but because currently that is not used too much I'm not sure if I should spend more time on it.