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

Fix almost all PHPStan level 4 errors #42

Closed
wants to merge 1 commit into from

Conversation

szepeviktor
Copy link
Contributor

@szepeviktor szepeviktor commented Apr 24, 2021

@oscarotero There are critical fixes in this PR.

Please consider using @phpstan daily.

@szepeviktor
Copy link
Contributor Author

I'm not able to comprehend CI results
https://travis-ci.com/github/szepeviktor/simple-crud/jobs/500941378
as I do not understand simple-crud internals.
Please help me.

@@ -219,7 +220,7 @@ public function executeTransaction(callable $callable)
$this->commit();
}
} catch (Exception $exception) {
if ($transaction) {
if (isset($transaction) && $transaction) {
Copy link
Owner

Choose a reason for hiding this comment

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

Maybe if (!empty($transaction)) {?

Copy link
Contributor Author

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
Copy link
Owner

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)

Copy link
Contributor Author

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;
Copy link
Owner

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

Copy link
Contributor Author

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;
Copy link
Owner

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);
Copy link
Owner

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

Copy link
Contributor Author

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);
Copy link
Owner

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)
*/
Copy link
Owner

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
Copy link
Owner

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)
*/
Copy link
Owner

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.

Copy link
Contributor Author

@szepeviktor szepeviktor Apr 25, 2021

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.

@szepeviktor
Copy link
Contributor Author

szepeviktor commented Apr 25, 2021

@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.

@szepeviktor
Copy link
Contributor Author

@oscarotero PHPStan is divisive. So there is #43

@oscarotero
Copy link
Owner

Ok, thanks for this. I know PHPStan and use it in other projects but not in this. I will.
Closing this :)

@oscarotero oscarotero closed this Apr 25, 2021
@szepeviktor szepeviktor deleted the phpstan-level-4 branch April 25, 2021 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants