我试图以某种方式说服phpcs使用Zend编码指南,但是 - 允许我有带下划线的变量(比如$blub->foo_bar).
有人能告诉我如何更改phpcs在PHPStorm中使用的规则集吗?
我使用 PHPStorm 和 Xdebug 来单步调试我的代码。PHPStorm 在 Windows 7 计算机上运行,而我的本地网络服务器在单独的 CentOS 6.4 计算机上运行。我已经phpinfo();验证了 Xdebug 是否正在被 PHP 加载,确实如此。以下是我的 Xdebug 在 PHP.ini 中的设置:
[x调试]
zend_extension =“/usr/lib/php/modules/xdebug.so”
xdebug.remote_enable = 1
xdebug.remote_port = 9000
xdebug.remote_host = "192.168.1.130"
xdebug.remote_log = "/var/log/httpd/xdebug_log"
我同样设置 PHPStorm 以使用我的 CentOS 服务器作为调试服务器,并监听连接。我为这两台机器分配了静态IP。使用 Chrome Xdebug 插件设置适当的 cookie,我尝试设置断点,但没有任何反应。当我查看 /var/log/httpd/xdebug_log (具有 777 权限)时,那里没有写入任何内容。我已经打开了端口 9000,并且我可以从我的 CentOS 计算机通过端口 9000 远程登录回我的 Windows 计算机,没有问题。我也将SELinux设置为permissive,但没有效果。
你知道这里会发生什么吗?
在PHPStorm中,对象数组的代码提示简单而且令人敬畏;
class FooList {
public function __construct(){
$this->_fooList[] = new Foo(1);
$this->_fooList[] = new Foo(2);
$this->_fooList[] = new Foo(3);
$this->_fooList[] = new Foo(4);
}
/**
* @return Foo[]
*/
getFoos() {
return $this->_fooList;
}
}
Run Code Online (Sandbox Code Playgroud)
所以如果我......
$fooList = new FooList();
foreach($fooList as $foo)
{
// Nice hinting.
$foo->FooMethod...
}
Run Code Online (Sandbox Code Playgroud)
PHPStorm理解$ fooList是一个Foos数组,因此知道$ foo的类型是Foo.
问题是我想要一个FooList数组.
$listOfLists[] = new FooList();
$listOfLists[] = new FooList();
$listOfLists[] = new FooList();
$listOfLists[] = new FooList();
foreach ($listOfLists as $fooList)
{
foreach($fooList as $foo)
{
// No …Run Code Online (Sandbox Code Playgroud) 我使用PHPStorm并试图找出如何使它停止唧唧喳喳,当__construct()有@return void在其PHPDocs ...
根据PHPDocs,void是有效的,或者@return可能省略.话虽如此,有没有办法解决这个问题还是一个错误?
我在本地主机上有一个 mysql 数据库。现在我想安装一些需要空数据库的 Web 应用程序(例如“myapplication”)。
如何在 PhpStorm 9 中创建这样的数据库?
我已经下载了PhpStorm并设置了所有必需的配置.当我尝试在端口80上运行项目时,我收到此错误.
无法收听localhost:80(原因:权限被拒绝)
当我尝试使用任何其他端口,如8080时,我收到此错误.
无法收听localhost:8080(原因:地址已在使用中)
我尝试了几个不同的随机端口.但是我一直都在使用这个错误.
我安装了xampp.当我尝试在浏览器中使用端口运行url时,它工作正常.问题是它不能用于PhpStorm.
我被卡住了.
我已经为远程服务器配置了 PhpStorm。但是,要写入文件,我需要 root 访问权限,因此当我在服务器上执行此操作时,sudo suPhpStorm 会抛出权限被拒绝的错误!
知道如何配置 PhpStorm 来处理这种情况吗?
如果我有一个这样的函数:
<?php
function foo($used, $maybe_unused = '') { ... }
Run Code Online (Sandbox Code Playgroud)
Alt-F7将找到对 foo() 的所有调用。但是,我想知道是否有任何调用包含第二个参数。如果所有调用都不包含第二个参数,我就会知道可以安全地删除它。在不查看整个结果列表的情况下,我想知道是否有这样的调用:
foo('first', 'second');
Run Code Online (Sandbox Code Playgroud)
或者,如果它们都是这样的:
foo('first');
Run Code Online (Sandbox Code Playgroud)
因此我可以删除第二个参数。
考虑以下代码:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Car extends Model
{
public static function getTheFirstCar(string $color): ?self
{
/** @var ?self */ // <-- Doesn't apply! Is there any alternative?
return (new self())->newQuery()->firstWhere('color', '=', $color);
}
}
Run Code Online (Sandbox Code Playgroud)
代码工作正常;尽管如此 PhpStorm 抱怨:
返回值应为“
Car|null”,返回
“\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model”
将表达式的结果赋值给一个带注释的变量可以解决警告,但会引入一个“冗余”变量!
/** @var ?self $redundant */
$redundant = (new self())->newQuery()->firstWhere('color', '=', $color);
return $redundant;
Run Code Online (Sandbox Code Playgroud)
那么,在 PhpStorm 中是否有一种方法可以return明确地为语句表达式的值强制执行内联类型注释Car|null,而不引入冗余变量或指定所有预期的返回类型?
我定义一个类如下,使用https://blog.jetbrains.com/phpstorm/2020/10/phpstorm-2020-3-eap-4/#arrayshape的建议将数组形状定义为常量,以便它可以在项目中使用:
<?php
namespace my\namespace\Api;
use JetBrains\PhpStorm\ArrayShape;
class CheckoutSessionLineItemMetadata implements MetadataInterface {
/**
* The ArrayShape of toArray().
*/
public const ARRAY_SHAPE = [
'order_item_id' => "string",
'order_id' => "string",
'product_variation_id' => "string",
];
/**
* Constructs a new object.
*
* @param string $order_item_id
* @param string $order_id
* @param string $product_variation_id
*/
public function __construct(
private string $order_item_id,
private string $order_id,
private string $product_variation_id) {
}
/**
* {@inheritDoc}
*/
#[ArrayShape(self::ARRAY_SHAPE)] public function toArray(): array {
return …Run Code Online (Sandbox Code Playgroud) phpstorm ×10
php ×8
phpdoc ×2
centos6 ×1
code-hinting ×1
codesniffer ×1
constructor ×1
database ×1
laravel ×1
php-8 ×1
port ×1
return ×1
xdebug ×1