fix: bump PHPStan to level 5, Psalm to level 3#205
fix: bump PHPStan to level 5, Psalm to level 3#205bobstrecansky merged 1 commit intoopen-telemetry:masterfrom
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.
|
dkarlovi
left a comment
There was a problem hiding this comment.
@bobstrecansky mentioned in Gitter
| '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.
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.
Alternatively, making classes immutable, which Psalm also supports.
phpstan.neon
Outdated
| - api | ||
| - contrib | ||
| - sdk No newline at end of file | ||
| - sdk |
There was a problem hiding this comment.
Newline, meaning the project is missing .editorconfig
There was a problem hiding this comment.
Should we add a .editorconfig?
There was a problem hiding this comment.
Don't see why not, it can only help with the consistency of the changes.
There was a problem hiding this comment.
@dkarlovi - do you have a particular preference on what should be included in our .editorconfig?
There was a problem hiding this comment.
We can start with something very simple and tweak when needed.
Example
https://github.com/flexolabs/reddit-client/blob/master/.editorconfig
| } | ||
|
|
||
| $child->setParent($this->parent); | ||
| if ($child !== null && $this->parent !== null) { |
There was a problem hiding this comment.
NPE on both the child and the parent.
There was a problem hiding this comment.
The complexity increase is because of this additional check, AFAIK?
There was a problem hiding this comment.
I find that to be an acceptable tradeoff.
| * {@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.
These are not nullable.
| 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.
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.
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.
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.
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.
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.