赶知识网

PhpStorm 使用经验

2023-11-27 / 245次点击 php/mysql/apache PhpStorm

主题配置

自己主要使用下面两个插件,安装并启用:


Material Theme UI

Atom Material Icons

还有个 One Dark theme 但是 Material Theme UI 已经包含这个主题。


配置:


Preferences > Appearance & Behavior > Appearance 下,右侧配置:Theme: Darcula,勾选 User custom font: .AppleSystemUIFont Size: 18。


Preferences > Editor > Font 下,右侧配置:Font: Menlo Size: 18 Line spacing: 1.2。



Preferences > Editor > Color Scheme 下,右侧配置:Seheme: Atom One Dark(Material) 点击右侧的三个点 Duplicate 复制一份。


Preferences > Editor > Color Scheme > General 下,右侧配置:


Editor > Gutter background,右侧 Background: 292929(设置行号背景色)

Editor > Vertical Scrollar > Thumb 与 Thumb while scrolling,右侧 Background: 305599C0(设置垂直滑块色)

Editor > Text > Default text,右侧 Background: 292929(设置面板背景色)

优秀插件推荐

PHP Annotation

Php Inspections (EA Ultimate)

String Manipulation

框架支持:


Laravel

Swoole IDE Helper

Symfony Support

Yii2 Support

技巧

围绕选择输入

设置选择了一个词后,再按单引号或双引号,将选中的单词用引号括起来。


Preferences 中搜索 Surround Selection on typing quote or brace 将其勾选(Editor > General > Smart Keys 下)。


关闭文档提示

鼠标放在方法上会出现文档提示,想关闭。


Preferences 中搜索 Show quick documentation on mouse move 取消勾选(Editor > Code Editing 下)。


使用 PHP-CS-Fixer

The PHP Coding Standards Fixer (PHP CS Fixer) tool fixes your code to follow standards.


工作环境:MacBook。


打开 PhpStorm Preferences > Tools > External Tools 添加:


180416-use-php-cs-fixer-in-phpstorm-001


Program: /usr/local/bin/php-cs-fixer

Arguments: --verbose fix "$FileDir$/$FileName$" --dry-run --rules=@PSR1,@PSR2,@Symfony(Note that previous verions of PHP-CS-Fixer used –levels instead of –rules. 未找到)

Working directory: $ProjectFileDir$

我取消勾选了 Open console for tool output,可以不输出日志信息

为了方便使用,保存文件时就可以格式化,设置快捷键 Preferences > Keymap > Macros:


180416-use-php-cs-fixer-in-phpstorm-002


设置 php-cs-fix 单独的快捷键 Preferences > Keymap > External Tools:


180416-use-php-cs-fixer-in-phpstorm-003


关闭不常用的插件

Preferences > Plugins > Installed 向下滚动,Bundled 中有不少预装但不常用的可以禁掉。


遇到过的一些问题

文件类型错误

一个文件被新建后,明明扩展名没有错,但是却没有语法高亮,删除文件后也不解决问题。


解决办法:Editor > File Types 找 Text 将里面涉及的文件删除掉。


phpstorm 文件类型错误

Undefined function XXX

出现 PHP 的原生方法未定义的警告。


解决方法:File > Invalidate Caches / Restart


Typo: In word XXX

提示单词拼写错误,但是其中没有问题,比如全拼的名字。


解决方法:option + enter -> Save to dictionary


Spellchecking | jetbrains

warning: Multiple definitions exists for class

I resolved this by going to Preferences-> Languages & Frameworks-> PHP; and then under Include path, remove the conflicting path. (In my case a package reference in the vendor directory to a package I was developing inside my Laravel project)


有用 没用

Top10

沪ICP备09053415号 © 赶知识网