最佳实践,包括ZF2中的代码完成 [英] Best Practise including code-completion in ZF2

查看:75
本文介绍了最佳实践,包括ZF2中的代码完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以下代码中,"/** @var BusinessLogic \ User $ user */"未启用代码完成.当在评论中将鼠标悬停在User上时,我得到了:

多个声明:此版本的IDE将对在项目文件中具有多个定义的所有类(包括"在内的所有类)在完成成员解析和继承分析方面存在问题"

 public function indexAction() {
   /**  @var BusinessLogic\User $user */
   $user = $this->getServiceLocator()->get('userBusinessLogic');
   $user->setUsername('testUsername');
 }

我认为Jetbrains已经在研究它: http://youtrack.jetbrains.com/issue /WI-2760 和所有相关任务.

我发现启用此功能的唯一方法是:

 use BusinessLogic\User; 

 public function indexAction() {
   /**  @var User $user */
   $user = $this->getServiceLocator()->get('userBusinessLogic');
   $user->setUsername('testUsername');
 }

但是当我说:

use BusinessLogic\User;

输入我可以实例化用户的代码

$user = new User();

没有serviceLocator;不利于其他开发人员事后处理此文件.

有些想法?代码完成非常重要.

解决方案

尝试在名称空间前添加斜杠.

您的第一次尝试是告诉IDE引用相对于当前名称空间的(即,如果当前名称空间为\Website\Shop,则FQN将为\Website\Shop\BusinessLogic\User).

使用斜杠将其设置为FQN.所以... /** @var \BusinessLogic\User $user */

In the following code the "/** @var BusinessLogic\User $user */" is not enabling code completion. When going by mouse over User in the comment I got:

"Multiple Declarations: this version of IDE will have problems with completion member resolution and inheritance anallysis for all classes that have multiple definitions in project files (regardles of includes)"

 public function indexAction() {
   /**  @var BusinessLogic\User $user */
   $user = $this->getServiceLocator()->get('userBusinessLogic');
   $user->setUsername('testUsername');
 }

I think Jetbrains is already working on it: http://youtrack.jetbrains.com/issue/WI-2760 and all related Tasks.

The only way I found to enable this is:

 use BusinessLogic\User; 

 public function indexAction() {
   /**  @var User $user */
   $user = $this->getServiceLocator()->get('userBusinessLogic');
   $user->setUsername('testUsername');
 }

But when I put:

use BusinessLogic\User;

into the code I can instantiate the user by

$user = new User();

without serviceLocator; not good for other developers to work on this file afterwards.

Some ideas? Code-Completion is quite important.

解决方案

Try adding leading slash before namespace.

Your first attempt tells IDE to reference class relative to current namespace (i.e. if current namespace is \Website\Shop then FQN will be \Website\Shop\BusinessLogic\User).

With leading slash you will make it FQN. So ... /** @var \BusinessLogic\User $user */

这篇关于最佳实践,包括ZF2中的代码完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆