-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[feature] add static analysis tool #2664
Conversation
@@ -2,8 +2,6 @@ name: CI | |||
|
|||
on: | |||
push: | |||
branches: |
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.
redundant, and not according to the Github Workflow schema
|
||
analysis: | ||
runs-on: "ubuntu-22.04" | ||
continue-on-error: true |
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 will allow the job to continue even if PHPStan finds errors.
For now mostly a convenience to see the output of runs for both PHP 8.1 and 8.2
@@ -53,3 +51,29 @@ jobs: | |||
# The -q option is required until phpcs v4 is released | |||
- name: "Run PHP_CodeSniffer" | |||
run: "vendor/bin/phpcs -q --no-colors --report=checkstyle | cs2pr" | |||
|
|||
analysis: |
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.
@@ -0,0 +1,46 @@ | |||
parameters: |
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 baseline provides PHPStan with a list of errors to ignore, kind of saying
I know these issues exist, will fix it later
editorUrl: 'phpstorm://open?file=%%file%%&line=%%line%%' | ||
|
||
ignoreErrors: | ||
- '#Unsafe usage of new static#' |
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.
These issues were the remaining errors from level 1, I wasn't sure how to fix them. So I chose to ignore them.
@@ -1,13 +1,9 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd" | |||
backupGlobals="false" |
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.
removed options that had the default value.
@@ -82,11 +82,11 @@ protected function setWhere() | |||
} | |||
|
|||
/** @inheritdoc */ | |||
public function save(Model $model, array $joining = [], $touch = true) | |||
public function save(Model $model, array $pivotAttributes = [], $touch = true) |
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 parent method argument name was changed, updated it to match it.
|
||
[*.yml] | ||
indent_size = 2 |
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.
Match the current indenting.
- ./phpstan-baseline.neon | ||
|
||
parameters: | ||
tmpDir: .cache/phpstan |
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.
Will speedup subsequent runs, in a Github Workflow we'd need to use the cache action to store this cache
src/Relations/EmbedsOne.php
Outdated
* @return int | ||
*/ | ||
public function delete() | ||
public function delete($id = null) |
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.
Same here, can we remove this argument, since it's not used.
src/Relations/EmbedsOneOrMany.php
Outdated
* @return int | ||
*/ | ||
public function count() | ||
public function count($columns = '*') |
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 used.
b4989e5
to
848bed3
Compare
src/Eloquent/Builder.php
Outdated
$builder = $this->toBase(); | ||
assert($builder instanceof MongoDBQueryBuilder); | ||
|
||
return $builder->update($this->addUpdatedAtColumn($values), $options); |
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.
So this is an interesting case. Both the IDE and PHPStan think that Illuminate\Database\Query\Builder
is used, while actually it's MongoDB\Laravel\Query\Builder
.
Adding the assertion is quickest/eastiest way to make sure the correct one is used.
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.
You can overload the return type of toBase
with an annotation on this class.
/** @method \MongoDB\Laravel\Query\Builder toBase() */
class Builder extends EloquentBuilder
9f5e849
to
06a405f
Compare
$this->query = $query; | ||
$this->parent = $parent; | ||
parent::__construct($query, $parent); | ||
|
||
$this->related = $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.
This property is also being set in the parent constructor, but when I tried to change it a few mocks broke and I'm not sure how to update those. So I left it alone 😅
Putting in draft while I figure out why the tests are faling |
c48f18e
to
6014fc6
Compare
@@ -3,9 +3,9 @@ | |||
*.sublime-workspace | |||
.DS_Store | |||
.idea/ | |||
.phpunit.cache/ |
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 introduced the .cache
directory for caching phpunit/phpcs/phpstan
@@ -20,10 +18,15 @@ | |||
<env name="MONGODB_DATABASE" value="unittest"/> | |||
<env name="SQLITE_DATABASE" value=":memory:"/> | |||
<env name="QUEUE_CONNECTION" value="database"/> | |||
|
|||
<ini name="memory_limit" value="-1"/> |
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.
While running the tests locally in Docker I ran into the issue that there wasn't enough memory. Disabling the limit here, seems like the most logical place
<include> | ||
<directory suffix=".php">./src</directory> |
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 suffix was redundant so it could be removed
5f48433
to
d26a9cd
Compare
@@ -82,7 +86,7 @@ public function performUpdate(Model $model) | |||
// Get the correct foreign key value. | |||
$foreignKey = $this->getForeignKeyValue($model); | |||
|
|||
$values = $this->getUpdateValues($model->getDirty(), $this->localKey . '.$.'); | |||
$values = self::getUpdateValues($model->getDirty(), $this->localKey . '.$.'); |
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 method is static, so using a static call here
d26a9cd
to
31157c0
Compare
The codecov.io service is no longer used.
42cf4a3
to
48adaeb
Compare
Co-authored-by: Mohammad Mortazavi <39920372+hans-thomas@users.noreply.github.com>
Co-authored-by: Mohammad Mortazavi <39920372+hans-thomas@users.noreply.github.com>
Co-authored-by: Mohammad Mortazavi <39920372+hans-thomas@users.noreply.github.com>
* | ||
* @return array | ||
*/ | ||
protected function formatSyncList(array $records) |
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.
removing in favor of formatRecordList
as mentioned in the comment
Co-authored-by: Mohammad Mortazavi <39920372+hans-thomas@users.noreply.github.com>
Thank you @Treggats |
Introduce PHPStan as static analyser. Continues the work done on #2471
resolves #1930
This PR does the following