phpDocumentor document a variable accesable from every part of code Zend2 - php

Hello i have a bootloader where i define some basis services like
/** #var $serviceManager Zend\ServiceManager\ServiceManager */
$serviceManager = new ServiceManagerComposite(new ConfigurationComposite($configuration['service_manager']));
But this type of documentation is not available trough my legacy code for hinting, as i found out this will define the variable only on tht one php file. But because i use it as a legacy acess point for my code i need it for the whole php project...
Any sugestions what type of documentation would work with the IDE hinting from Netbeans?

You'd probably need to duplicate at least the first use of $serviceManager with the same #var docblock in each file. If NetBeans is not already resolving scope for you via requires and includes, then this would be the only way to put a context on that "local" variable in the file you're in.

Sangoku is perfectly right!
/* #var $serviceManager Zend\ServiceManager\ServiceManager */
Should do the trick

Related

Can you create an external PHPdoc for a class?

let's say I have the following
class Something extends ClassWithMagicMethods{}
Normally I would add a docblock for any properties I know exist even if accessed via a magic method
/**
* #property string $someVar
* #method SomeClass getSomeClass()
*/
class Something extends ClassWithMagicMethods{}
Which works great, but what I'm wondering is if we can have that docblock separate from the definition of the class. Two possible usecases:
Third party package that doesn't include the docblock but I want autocompletion from my IDE - I'd like to be able to just add my own docblock somewhere for it.
An extension system - In the file where the extension is defined I'd like to document the new properties this extension adds to the class.
I'm aware I could technically create a dummy ide_helper.php file that never actually gets run - just indexed by the IDE - unfortunately this causes any decent IDE to complain about duplicate declarations which I don't want as it also makes code navigation slower.
So - is it possible to document a PHP class by composing multiple docblocks external from the class definition?
Most of the results I've pulled up on SO are referencing just documenting unknown types where you use them which isn't what I need. I.E:
/** #var Something $something */
$something = FactoryMethodThing::create('Something');
See if this can help you :
phpdoc -d path/to/my/project -f path/to/an/additional/file -t path/to/my/output/folder
Source: http://docs.phpdoc.org/guides/running-phpdocumentor.html

define definition of a variable in phpstorm in (php) yii application

in a Yii Application in PHPStorm i have the following Code:
$datasource = Yii::app()->someComponent;
PHPStorm is now not able to find the definition of method parameters in autocomplete, if i write
$datasource->aMethod(
Is there a way to tell phpstorm the source in order to have a working autocomplete?, e.g.
// #definition components/SomeComponent.php
$datasource = Yii::app()->someComponent;
Thanks,
markus
You could use a PHP Doc comment to tell PHPStorm which type the var has.
/** #var SomeClassName $datasource */
$datasource = Yii::app()->someComponent;
There's better solution. One which makes PhpStorm able to assign Yii::app()->someComponent to class for entire project.
Put in CAplication's php doc (above class):
/**
* #property Someclass $someComponent.
*/
Solved with one line of code. It works with PhpStorm 9.0, haven't tested earlier versions.

PHP: documentation / hinting via #var with multiple classes/interfaces

I am making usage of
/* #var $var Type */
really often for NetBeans can then autocomplete methods and stuff in code.
Still I think its a very useful feature but sometimes I got objects of
classes extending one more class and implementing multiple interfaces.
Or I even got a transitive class hierarchy.
I don't know a way to tell NetBeans that it shall be using autocomplete for
all these interfaces and upper-layer parent classes.
I would like to do so for of course every of these interfaces / classes got
dedicated methods (which are defined somewhere in case of interfaces...)
I tried something like this:
/* #var $var TypeA|\TypeB|\TypeC */
because I saw NetBeans will generate a similar documentation for methods returning
different class objects due a switch/case. But this seems to work only for the
#return notation.
I also tried
/* #var $var TypeA|TypeB */
Also not working...
NetBeans will autocomplete the last told Type in this case but not a combination of both/all told classes.
How can I document so my autocomplete works as desired (a summary of methods of all classes /interfaces I listed)?
regards!
If I understand you correctly, you are asking to chain hint through your PHP code.
The problem is netbeans has no way of knowing what an object actually is; unless you tell it. The solution is to use the #property command in your object decleration to forward type define the objects members , be it a class or interface.
/**
#property classMyClass1 $clsMyClass1
#property classMyClass2 $clsMyClass2
*/
class baseClass{
public $clsMyclass1;
public $clsMyClass2;
public function __construct() {
$this->clsMyClass1 = new classMyClass1();
$this->clsMyClass2 = new classMyClass2();
}
}
$foo = new baseClass();
Now when you type your code in netbeans it will know what hinting to display on your last typed object
$foo->clsMyClass1->
So long as each class has a forward property decleration you can chain as long as you want
$foo->class1->class2->class3->...
The above code would need the autoload() function to load the correct class files....
Hope this helps you!

PHP Docblock Type Hinting for Current Object in Magento Template?

How might I hint at what $this is in the context of a Magento template, with a DocBlock?
As an example, head.phtml within the template/page/html/ directory is an object of Mage_Page_Block_Html_Head. The method I tried was:
<?php
/**
* #var $this Mage_Page_Block_Html_Head
*/
?>
Unfortunately, it doesn't seem my IDE (NetBeans) is picking up on the hint. So my question is if there is a correct way of doing this so that NetBeans recognizes the hint.
Netbeans should accept it, at least my version 6.9 for
/* #var $this Bar */
does this:
and that is an example with the include scenario (no class around).
Take care to use the single-line - single-asterisk - type-of - commment.
Also take care Netbeans updated the index. As in your case:
NetBeans had to scan for changes in this case, which I would have assumed it would do automatically. [...]. In my case it only periodically scans.
Docblock variable hinting related:
How do I make my PHP IDE understand Dependency Injection Containers?

code assistance inside included file for a variable defined outside

Let's say I create an object in index.php and save the reference in the variable $obj.
Later in index.php I include/require a file req.php where I want to use a method of the object.
Is there a way to make Aptana 3.0.4 show me the available methods of the object when I type $obj-> inside req.php?
I.e. Aptana should recognize that the variable $obj is already defined higher in the file hierarchy and that it holds a reference to an object.
May be it helps if you add comment before the first var using
/* #var YOUR_CLASS */
The correct syntax in version 3.0.4 is like that:
/**
* #var Foobar
*/
$obj; // You have to call the variable here (redundant, I know)
$obj-> // will code assist the FooBar functions.
Since this is not that great of a syntax, I'm working on having additional support, like with the PDT special #var syntax:
/* #var $obj Foobar */
$obj-> // will code assist the FooBar functions.
Both should be supported in the Studio's next release.
Hope that helps

Categories