Skip to content

Commit

Permalink
Static analysis fixes for latest Psalm release
Browse files Browse the repository at this point in the history
  • Loading branch information
asgrim committed Dec 15, 2020
1 parent 992febd commit cb6ff1b
Show file tree
Hide file tree
Showing 23 changed files with 262 additions and 120 deletions.
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,29 @@

All notable changes to this project will be documented in this file, in reverse chronological order by release.

## 5.2.0 - 2020-12-15

### Added

- Nothing.

### Changed

- [#198](https://github.com/scoutapp/scout-apm-php/pull/198) Adjust log level for `Response length returned (%d)
exceeded our limit for reading (%d)` message

### Deprecated

- Nothing.

### Removed

- Nothing.

### Fixed

- Nothing.

## 5.1.0 - 2020-11-02

### Added
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
"doctrine/coding-standard": "^6.0",
"monolog/monolog": "^1.25",
"phpunit/phpunit": "^7.5.20",
"psalm/plugin-phpunit": "^0.15.0",
"psr/log": "^1.1",
"roave/doctrine-simplecache": "^2.2",
"vimeo/psalm": "^3.12.2"
"vimeo/psalm": "^4.3.1"
},
"suggest": {
"ext-scoutapm": "Recommended for additional recording capability of IO-bound PHP internal functions"
Expand Down
140 changes: 75 additions & 65 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 17 additions & 1 deletion psalm.xml.dist
Original file line number Diff line number Diff line change
@@ -1,21 +1,37 @@
<?xml version="1.0"?>
<psalm
totallyTyped="false"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<directory name="tests" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
<issueHandlers>
<DeprecatedClass>
<errorLevel type="info">
<!-- Handles usage of composer/package-versions-deprecated -->
<referencedClass name="PackageVersions\Versions" />
</errorLevel>
</DeprecatedClass>
<MissingConstructor>
<errorLevel type="info">
<!-- Mostly caused by PHPUnit -->
<directory name="tests"/>
</errorLevel>
</MissingConstructor>
<InvalidThrow>
<errorLevel type="info">
<!-- Does not extend any \Throwable for some reason -->
<referencedClass name="Psr\SimpleCache\InvalidArgumentException" />
</errorLevel>
</InvalidThrow>
</issueHandlers>
<plugins>
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
</plugins>
</psalm>
1 change: 1 addition & 0 deletions src/Connector/SocketConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ public function sendCommand(Command $message) : string
throw Exception\FailedToSendCommand::fromEmptyResponseSize($message, $this->connectionAddress);
}

/** @var mixed[]|false $responseLengthUnpacked */
$responseLengthUnpacked = unpack('Nlen', $responseLengthPacked);

if (! is_array($responseLengthUnpacked) || ! array_key_exists('len', $responseLengthUnpacked)) {
Expand Down
21 changes: 21 additions & 0 deletions src/Events/Request/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,26 @@ public function tag(string $tagName, $value) : void
* turn this object into a list of commands to send to the CoreAgent
*
* @return array<string, array<string, array<int, array<string, (string|array|bool|null)>>>>
*
* @todo document more of the command structures better:
* @psalm-suppress InvalidReturnType
* @psalm-return array{
* BatchCommand: array{
* commands: list<
* array{
* StartRequest: array{
* request_id: string,
* timestamp: string|null,
* }
* }|array{
* FinishRequest: array{
* request_id: string,
* timestamp: string|null,
* }
* }
* >
* }
* }
*/
public function jsonSerialize() : array
{
Expand All @@ -260,6 +280,7 @@ public function jsonSerialize() : array
],
];

/** @psalm-suppress InvalidReturnStatement */
return [
'BatchCommand' => ['commands' => $commands],
];
Expand Down
15 changes: 14 additions & 1 deletion src/Events/Tag/TagRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,20 @@
*/
class TagRequest extends Tag
{
/** @return array<int, array<string, (string|array|bool|null)>> */
/**
* @return string[][][]|array[][][]|bool[][][]|null[][][]
*
* @psalm-return list<
* array{
* TagRequest: array{
* request_id: string,
* tag: string,
* value: mixed,
* timestamp: string
* }
* }
* >
*/
public function jsonSerialize() : array
{
// Format the timestamp
Expand Down
14 changes: 13 additions & 1 deletion src/Events/Tag/TagSpan.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,19 @@ public function __construct(string $tag, $value, RequestId $requestId, SpanId $s
}

/**
* @return array<int, array<string, (string|array|bool|null)>>
* @return string[][][]|array[][][]|bool[][][]|null[][][]
*
* @psalm-return list<
* array{
* TagSpan: array{
* request_id: string,
* span_id: string,
* tag: string,
* value: mixed,
* timestamp: string
* }
* }
* >
*/
public function jsonSerialize() : array
{
Expand Down
6 changes: 5 additions & 1 deletion src/Extension/PotentiallyAvailableExtensionCapabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@

final class PotentiallyAvailableExtensionCapabilities implements ExtentionCapabilities
{
/** @return RecordedCall[]|array<int, RecordedCall> */
/**
* @return RecordedCall[]
*
* @psalm-return list<RecordedCall>
*/
public function getCalls() : array
{
if (! $this->extensionIsAvailable()) {
Expand Down
8 changes: 4 additions & 4 deletions src/Extension/RecordedCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ public static function fromExtensionLoggedCallArray(array $extensionCall) : self
Assert::keyExists($extensionCall, 'argv');

return new self(
(string) $extensionCall['function'],
(float) $extensionCall['time_taken'],
(float) $extensionCall['entered'],
(float) $extensionCall['exited'],
$extensionCall['function'],
$extensionCall['time_taken'],
$extensionCall['entered'],
$extensionCall['exited'],
$extensionCall['argv']
);
}
Expand Down
Loading

0 comments on commit cb6ff1b

Please sign in to comment.