-
Notifications
You must be signed in to change notification settings - Fork 205
fix: bump PHPStan to level 5, Psalm to level 3 #205
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #205 +/- ##
============================================
+ Coverage 91.78% 91.82% +0.03%
- Complexity 319 321 +2
============================================
Files 36 36
Lines 755 758 +3
============================================
+ Hits 693 696 +3
Misses 62 62
Continue to review full report at Codecov.
|
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.
@bobstrecansky mentioned in Gitter
$row = [ | ||
'id' => $span->getContext()->getSpanId(), | ||
'traceId' => $span->getContext()->getTraceId(), | ||
'parentId' => $span->getParent() ? $span->getParent()->getSpanId() : null, | ||
'parentId' => $spanParent ? $spanParent->getSpanId() : 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.
You can fix this with what Psalm calls "memoizing simple method calls" setting, but in general you want this form.
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.
Alternatively, making classes immutable, which Psalm also supports.
phpstan.neon
Outdated
- sdk |
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.
Newline, meaning the project is missing .editorconfig
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.
Should we add a .editorconfig
?
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.
Don't see why not, it can only help with the consistency of the changes.
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.
@dkarlovi - do you have a particular preference on what should be included in our .editorconfig
?
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.
We can start with something very simple and tweak when needed.
Example
https://github.com/flexolabs/reddit-client/blob/master/.editorconfig
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.
Sounds good to me.
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.
@bobstrecansky added in #207
@@ -59,7 +59,9 @@ private function removeCorrelationHelper(ContextKey $key, ?CorrelationContext $c | |||
return; | |||
} | |||
|
|||
$child->setParent($this->parent); | |||
if ($child !== null && $this->parent !== 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.
NPE on both the child and the parent.
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 complexity increase is because of this additional check, AFAIK?
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 find that to be an acceptable tradeoff.
@@ -40,23 +40,23 @@ public function getVersion(): string | |||
/** | |||
* {@inheritdoc} | |||
*/ | |||
public function newCounter(string $name, string $description = null): API\Counter | |||
public function newCounter(string $name, string $description = ''): API\Counter |
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 are not nullable.
@@ -15,7 +15,7 @@ public function addEvent( | |||
?API\Attributes $attributes = null, | |||
int $timestamp = null | |||
): API\Events { | |||
$this->events[] = new Event($name, $timestamp, $attributes); | |||
$this->events[] = new Event($name, $timestamp ?? time(), $attributes); |
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.
Notice this one, it's probably incorrect, but the type is now correct, it's int
, but int|null
passed.
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.
Note: even though this was changed, no tests failed, meaning this wasn't tested at all. This should have been caught by Infection. /cc @prondubuisi
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.
According to the spec:
An Event is structurally defined by the following properties:
- Name of the event.
- A timestamp for the event. Either the time at which the event was added or a custom timestamp provided by the user.
- Zero or more Attributes further describing the event.
Maybe we shouldn't default int $timestamp = null
on line 16 and check for the value of $timestamp
before passing time()
to new Event()
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 API takes the name of the event, optional Attributes and an optional Timestamp which can be used to specify the time at which the event occurred
If no custom timestamp is provided by the user, the implementation automatically sets the time at which this API is called on the event.
(emphasis mine)
Since the timestamp is supposed to be optional, it must be nullable so I think that part is correct. Event itself requires the exact timestamp which is also OK, so I guess my solution seems to be close to OK?
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.
Agreed that your solution is okay!
0685375
to
84ed646
Compare
Rebased on top master to avoid the conflict. |
This adds fixes which are required to bump static analysis tools to stricter settings, revealing some bugs already.