-
Notifications
You must be signed in to change notification settings - Fork 58
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
Fix almost all PHPStan level 4 errors #42
Conversation
I'm not able to comprehend CI results |
@@ -219,7 +220,7 @@ public function executeTransaction(callable $callable) | |||
$this->commit(); | |||
} | |||
} catch (Exception $exception) { | |||
if ($transaction) { | |||
if (isset($transaction) && $transaction) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe if (!empty($transaction)) {
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
empty
is a highly complex function, although many use it.
@@ -12,7 +12,6 @@ | |||
trait HasRelatedWith | |||
{ | |||
/** | |||
* @param Row|RowCollection|Table | |||
* @param mixed $related |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The right signature is the first one (Row|RowCollection|Table
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then the if ($related instanceof Table) {
line below is in vain as it'll be always true.
@@ -14,6 +14,7 @@ | |||
*/ | |||
class Row implements JsonSerializable | |||
{ | |||
public $id; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class doesn't have public properties. All properties are provided with __get()
magic method. So this should be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see! Then
/**
* @property string $id
*/
@@ -16,6 +16,7 @@ | |||
*/ | |||
class RowCollection implements ArrayAccess, Iterator, Countable, JsonSerializable | |||
{ | |||
public $id; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be removed
@@ -270,7 +271,7 @@ public function offsetGet($offset) | |||
*/ | |||
public function rewind() | |||
{ | |||
return reset($this->rows); | |||
reset($this->rows); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method must return the value of reset
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PHP docs say otherwise. Please see https://www.php.net/manual/en/iterator.rewind.php
@@ -294,7 +295,7 @@ public function key() | |||
*/ | |||
public function next() | |||
{ | |||
return next($this->rows); | |||
next($this->rows); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method must return the value of next
@@ -5,6 +5,9 @@ | |||
|
|||
use SimpleCrud\Table; | |||
|
|||
/** | |||
* @method self where(string $condition, ...$bindInline) | |||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are more methods (the list in the constant ALLOWED_METHODS
). Not sure if it's a good idea because require more maintenance work.
/** | ||
* @method self where(string $condition, ...$bindInline) | ||
* @method self limit(int $limit) | ||
*/ | ||
class Select extends Query |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are more methods (the list in the constant ALLOWED_METHODS
). Not sure if it's a good idea because require more maintenance work.
* @method self orderBy(string $expr, string ...$exprs) | ||
* @method self limit(int $limit) | ||
* @method self offset(int $offset) | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if it's a good idea because require more maintenance work, not only for this Query but all other Queries.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second way to resolve this is writing a PHPStan extension.
@oscarotero This is an inspirational PR. By paying a small price of extra work you can have the huge benefit of PHPStan. I leave all these up to you. |
@oscarotero PHPStan is divisive. So there is #43 |
Ok, thanks for this. I know PHPStan and use it in other projects but not in this. I will. |
@oscarotero There are critical fixes in this PR.
Please consider using @phpstan daily.