Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 1 commit into from
Nov 4, 2020

Conversation

dkarlovi
Copy link
Contributor

@dkarlovi dkarlovi commented Nov 2, 2020

This adds fixes which are required to bump static analysis tools to stricter settings, revealing some bugs already.

@codecov
Copy link

codecov bot commented Nov 2, 2020

Codecov Report

Merging #205 into master will increase coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             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              
Impacted Files Coverage Δ Complexity Δ
contrib/Zipkin/Exporter.php 100.00% <ø> (ø) 18.00 <0.00> (ø)
sdk/Trace/SpanProcessor/BatchSpanProcessor.php 97.50% <ø> (ø) 18.00 <0.00> (ø)
contrib/Zipkin/SpanConverter.php 100.00% <100.00%> (ø) 10.00 <0.00> (ø)
sdk/CorrelationContext.php 96.00% <100.00%> (+0.16%) 12.00 <0.00> (+2.00)
sdk/Metrics/Meter.php 100.00% <100.00%> (ø) 6.00 <3.00> (ø)
sdk/Resource/ResourceInfo.php 100.00% <100.00%> (ø) 8.00 <0.00> (ø)
sdk/Trace/Events.php 100.00% <100.00%> (ø) 3.00 <0.00> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f23a50d...84ed646. Read the comment docs.

Copy link
Contributor Author

@dkarlovi dkarlovi left a 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,
Copy link
Contributor Author

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.

Copy link
Contributor Author

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
Copy link
Contributor Author

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

Copy link
Collaborator

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?

Copy link
Contributor Author

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.

Copy link
Collaborator

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?

Copy link
Contributor Author

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sounds good to me.

Copy link
Contributor Author

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) {
Copy link
Contributor Author

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.

Copy link
Contributor Author

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?

Copy link
Collaborator

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
Copy link
Contributor Author

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

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.

Copy link
Contributor Author

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

According to the spec:

https://github.com/open-telemetry/opentelemetry-specification/blob/06d16d7db88c3e266636f84887de61e3363b5429/specification/trace/api.md#add-events

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()

Copy link
Contributor Author

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?

Copy link
Collaborator

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!

@dkarlovi
Copy link
Contributor Author

dkarlovi commented Nov 3, 2020

Rebased on top master to avoid the conflict.

@bobstrecansky bobstrecansky merged commit 2514c45 into open-telemetry:master Nov 4, 2020
@dkarlovi dkarlovi deleted the fix/add-types branch November 4, 2020 13:41
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