Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add phpdoc to Exception properties #3511

Open
wants to merge 1 commit into
base: 1.12.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions stubs/Exception.stub
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ interface Throwable

class Exception implements Throwable
{
/** @var string */
protected $message;

/** @var mixed */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only exception type I am aware of which doesnt has a int code is PDOException

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes me too.

But getCode is typed as returning mixed... so I think I have to match this

I'll wait for ondrej decision

protected $code;

/** @var string */
protected $file;

/** @var int */
protected $line;

/**
* @return string
Expand Down Expand Up @@ -99,6 +110,17 @@ class Exception implements Throwable

class Error implements Throwable
{
/** @var string */
protected $message;

/** @var mixed */
protected $code;

/** @var string */
protected $file;

/** @var int */
protected $line;

/**
* @return string
Expand Down
6 changes: 6 additions & 0 deletions tests/PHPStan/Rules/Properties/OverridingPropertyRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,10 @@ public function testBug7692(): void
$this->analyse([__DIR__ . '/data/bug-7692.php'], []);
}

public function testBug11761(): void
{
$this->reportMaybes = true;
$this->analyse([__DIR__ . '/data/bug-11761.php'], []);
}

}
9 changes: 9 additions & 0 deletions tests/PHPStan/Rules/Properties/data/bug-11761.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php declare(strict_types = 1);

namespace Bug11761;

class ApiLimitExceededException extends \Exception
{
/** @var string */
protected $message = 'You have exceeded the 300 API calls per minute.';
}
Loading