Autocompete using phpDoc - autocomplete

I heard you can use phpDoc to help IDE with autocomplete. Can someone show how to use it with Doctrine?
For example, I have a JobTable class that extends Doctrine_Table with a bunch of methods and would like to have autocompletion when i type: Doctrine::getTable('Job')-> ... Is it possible? Is there a way to do it without phpDoc?

phpDoc comments assist autocompletion mechanism because the IDE then knows the types of the parameters.
/**
* #param $foo FudgingBreakingImpl
*/
function doStuff($foo) { ... }
This way, the IDE knows that $foo is of type FudgingBreakingImpl, so it can autocomplete anything related to $foo, e.g. $foo->someMet.

In your example need of your code extending a Doctrine class, your IDE will need to know where that Doctrine code is in order to know what that object looks like.
In Eclipse, this is a matter of having the Doctrine code locally on your machine and telling your Eclipse project's "Build Path" / "Include Path" where to find it.
Unless the IDE is capable of inspecting that Doctrine code, there's no way it can know things your own code is inheriting from the Doctrine class.

Related

Use of Extbase Repositories in Symfony Command

Im upgrading an extension to work with TYPO3 v10. Since command controllers can not be used anymore, im migrating them to symfony commands as pointed by the documentation. Everything works smooth as heck except for the usage of extbase repository classes. No matter what i query, i never get a result. Since i can't find any useful information on the web and the documentation i hope this may be just something minor.
After debugging for a while i found out that the pid is not determined correctly while building the query settings. I find that kind of strange since my root template has these lines:
plugin.tx_myext.persistence.storagePid = 15403
module.tx_myext.persistence.storagePid = 15403
The repository instances are correctly injected by injectMyRepository() methods. I've tried using the extbase ObjectManager to fetch the class instances instead but the "error" stays the same.
Am i doing something wrong or is it not possible to use extbase repository classes in symfony commands?
After more research i found out that there is some bootstraping missing which results in extension settings (the storageID in my case) not being loaded. From what i've been reading, that behaviour seems intended to prevent extbase booting, i guess?
There is a reference to something similiar in the official documentation: https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/CommandControllers/Index.html#initialize-backend-user
Knowing that, i tried to find a method to initialize the missing settings which i could not find. So this does indeed seem like a missing feature.
I developed a workaround which i'm not too proud of, but it's better than nothing (or rebuilding everything to doctrine for that matter). If you stumble upon the same issue, here you go. Just insert and call this method before you fire your query:
public static function initializeConfigurationManager(): void
{
/** #var ConfigurationManager $configurationManager */
$configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class);
$tmpConfiguration = $configurationManager->getConfiguration(
ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK,
'myExtensionName'
);
$configurationManager->setConfiguration($tmpConfiguration);
}
That approach exploits the singleton state of the ConfigurationManager. You simply inject the static template of your extension manually and every extbase compound (like repositories) will then use these settings from there on. Lovely.
Be aware however, this is prone to break with future internal changes.

Yii2 autocomplete chain of methods in netbeans

In netbeans I already installed yii2 plugin, my query was how to make autocomplete for method chaining too. Because here in the below code
$query = Message::find()->orderBy('name')->
After the second object operator (->) autocomplete not working.
So How we can achieve autocomplete for chain of methods in netbeans with yii2.
I don't think you can without changing the Yii framework code (not recommended).
Autocomplete does not work properly on the orderBy() method, most likely because it's using phpdoc #return $this.
Seems NetBeans prefers the use of the keyword this instead of $this (Also see: NetBeans bug#239987) but changing it in the framework code didn't work for me either. It worked when I changed it to static though.
This might also be related to NetBeans bug#196565
Alternatively you could use inline type hinting:
$query = Message::find()->orderBy('name');
/* #var $query \yii\db\ActiveQuery */
but I usually just grab the docs to prevent cluttering up the code. (Having 2 monitors helps)

PhpStorm 8.0 - How enable code completion in another file?

I implement MyClass containing the method method() and I store the instance in $_ENV['key'] in test.php. Also in test.php the code completion works when I type $_ENV['key']->.
In test2.php I include test.php and the code completion does not work any more for $_ENV['key']->.
Does anyone know how to enable this in PhpStorm?
AFAIK type tracking for arrays works within the same file only.
You can bypass it via intermediate variable (yes, it's not a nicest solution) and small PHPDoc comment, like this:
/** #var MyClass $myVar */
$myVar = $_ENV['key'];
$myVar->
P.S.
In general, I'd suggest not using global arrays this way (or even not using global vars at all -- only very basic stuff during bootstrap, if possible). Instead (based on your code) I may suggest using some static class (as one of the alternatives) with dedicated field where you can easily give type hint (via PHPDoc) to a class field -- this way IDE will always know hat type it is. Current PHP versions (5.5 and especially 5.6) work with objects nearly as fast as with arrays, even leading in (smaller) memory consumption.
Obviously, such suggestion does not really apply if this code is not yours.

Generate all setXXX calls of a POJO in Eclipse?

Im currently doing a lot of testing with JPA entities, where i have to keep calling the setter methods on the entity that looks something like this :
myEntity.setXXX(value);
myEntity.setYYY(value);
myEntity.setZZZ(value);
Is there any magic shortcut or menu in eclipse IDE to generate all the setter-method-calls that starts with "set", like those displayed in the ctrl-space (auto completion) popup (i think the inherited methods from Object are not being shown at popup) ?
So im imagining something like :
i type myEntity.set
and myEntity.set* are generated right away
Im a lazy programmer and currently using Eclipse Helios IDE.
Thank you !
Edit
Im not looking for source -> generate getter and setter, because that would helps me in generating the methods itself. Generating the method calls is what i want to achieve.
I have found the answer (I was always searching for this thing)...
The easiest way is to expand the class members in the "Package Explorer", sort them by name, multi-select all the setters, and then you have in the clipboard all the method names...
;-)
I like #Oscar's answer. It does lead to some cleanup though.
When I paste from the clipboard, I get something that looks like this:
setOne(int)
setTwo(String)
In order to clean this up, I first add semicolons with this search/replace regexp:
search = (.)$
replace = \1;
Then I add the getter calls (assuming incoming data object is named "data"):
search = s(et.*)\(.*
replace = s\1(data.g\1());
This doesn't handle multiple arguments in a method call...
you can use the outline at right side. There you can sort alphabetically or by declaration order using the toolbar button of the view.
and then you can filter out non required this.
From here also you can copy..all setter functions or getters functions names...
There is eclipse plugin to do that. The name of the plugin is **
FastCode
**. There are so many templates. Among those there is template to generate code for create object of the class and all setters method.
Source --> Generate Getters and Setters...
You can also get at it via the Quick Fix command (Ctrl+1) when the cursor is on a property.
EDIT
If you are simply looking for a faster way to copy properties from one object to another I suggest that you look at using reflection. I think this path would be much easier long term then generating the same-looking code over-and-over.
Commons BeanUtils can take away some of the pain in writing pure reflection code. For example, copyProperties takes a destination bean and either another bean or a Map as the source.

Zend Studio for Eclipse: Useful Features

There are several 'best Eclipse features' topics, with some great information, but there's much that isn't applicable to Zend Studio.
So, Zend Studio users, what are your best timesavers?
Here are a few I use:
ctrl-shift-r: open any file in your workspace
ctrl-F8: tab between perspectives
ctrl-click on variable, class or method: of course, jump to applicable definition
Describing a variable so intellisense knows what it is:
$variable = someFunction(); /* #var $variable Zend_Form_Element */
ctrl-3 gives you a searchable list of all the commands and such available.
ctrl-f6 cycles between open editors
ctrl-shift-t allows you to search for objects
alt-shift-r allows you to rename all the variables with the same name in a given scope