Skip to content

Commit

Permalink
fix psalm errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sj-i committed Jun 10, 2021
1 parent 1d8ec49 commit a1ccec8
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Command/Inspector/DaemonCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
$get_trace_settings
);

$echo_back_canceler = new EchoBackCanceller();
$_echo_back_canceler = new EchoBackCanceller();

Loop::onReadable(
STDIN,
Expand Down
1 change: 1 addition & 0 deletions src/Inspector/Daemon/Dispatcher/WorkerPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ final class WorkerPool implements WorkerPoolInterface
/** @var array<int, bool> */
private array $on_read_list;

/** @no-named-arguments */
public function __construct(PhpReaderControllerInterface ...$contexts)
{
$this->contexts = $contexts;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function __construct(Channel $channel)
$this->channel = $channel;
}

/** @return static */
public static function createFromChannel(Channel $channel): self
{
return new self($channel);
Expand Down
10 changes: 8 additions & 2 deletions src/Inspector/Daemon/Reader/Worker/PhpReaderEntryPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,17 @@ public function __construct(

public function run(): \Generator
{
/** @var SetSettingsMessage $set_settings_message */
/**
* @psalm-ignore-var
* @var SetSettingsMessage $set_settings_message
*/
$set_settings_message = yield $this->protocol->receiveSettings();

while (1) {
/** @var AttachMessage $attach_message */
/**
* @psalm-ignore-var
* @var AttachMessage $attach_message
*/
$attach_message = yield $this->protocol->receiveAttach();

$target_process_settings = new TargetProcessSettings(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function __construct(Channel $channel)
$this->channel = $channel;
}

/** @return static */
public static function createFromChannel(Channel $channel): self
{
return new self($channel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function __construct(Channel $channel)
$this->channel = $channel;
}

/** @return static */
public static function createFromChannel(Channel $channel): self
{
return new self($channel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ public function __construct(

public function run(): \Generator
{
/** @var TargetRegexMessage $target_regex */
/**
* @psalm-ignore-var
* @var TargetRegexMessage $target_regex
*/
$target_regex = yield $this->protocol->receiveTargetRegex();

while (1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function __construct(Channel $channel)
$this->channel = $channel;
}

/** @return static */
public static function createFromChannel(Channel $channel): self
{
return new self($channel);
Expand Down
14 changes: 14 additions & 0 deletions src/Inspector/Settings/InspectorSettingsException.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
namespace PhpProfiler\Inspector\Settings;

use LogicException;
use Throwable;

/**
* @psalm-consistent-constructor
*/
abstract class InspectorSettingsException extends \Exception
{
public const ERROR_NONE = 0;
Expand All @@ -24,6 +28,16 @@ abstract class InspectorSettingsException extends \Exception
self::ERROR_NONE => '',
];

/**
* @param string $message
* @param int $code
* @param Throwable|null $previous
*/
public function __construct($message = "", $code = 0, Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}

/**
* @return array<int, string>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ public function createSettings(InputInterface $input): TargetPhpSettings
TargetPhpSettingsException::TARGET_PHP_VERSION_INVALID
);
}
/** @psalm-var value-of<ZendTypeReader::ALL_SUPPORTED_VERSIONS> $php_version */

$php_path = $input->getOption('php-path');
if (!is_null($php_path) and !is_string($php_path)) {
Expand Down
5 changes: 5 additions & 0 deletions src/Lib/ByteStream/ByteReaderDisableWriteAccessTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@
*/
trait ByteReaderDisableWriteAccessTrait
{
/**
* @param mixed $offset
* @param mixed $value
*/
public function offsetSet($offset, $value): void
{
throw new LogicException('write access is forbidden for ByteReaderInteface');
}

/** @param mixed $offset */
public function offsetUnset($offset): void
{
throw new LogicException('write access is forbidden for ByteReaderInteface');
Expand Down
4 changes: 4 additions & 0 deletions src/Lib/Elf/Parser/Elf64Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ public function parseGnuHashTable(

$chain_offset = $offset + 16 + $bloom_size * 8 + $nbuckets * 4;

if ($buckets === []) {
return null;
}

$max_bucket_index = max($buckets);
$last_chain_offset = $chain_offset + ($max_bucket_index - $symoffset) * 4;
$last_chain_item = $this->integer_reader->read32($data, $last_chain_offset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function __construct(int $sleep_nano_seconds, AsyncLoopMiddlewareInterfac

public function invoke(): \Generator
{
/** @psalm-suppress UnusedFunctionCall */
time_nanosleep(0, $this->sleep_nano_seconds);
yield from $this->chain->invoke();
}
Expand Down
1 change: 1 addition & 0 deletions src/Lib/Loop/LoopMiddleware/NanoSleepMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function __construct(int $sleep_nano_seconds, LoopMiddlewareInterface $ch

public function invoke(): bool
{
/** @psalm-suppress UnusedFunctionCall */
time_nanosleep(0, $this->sleep_nano_seconds);
if (!$this->chain->invoke()) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,10 @@ public function readFunctionName(int $pid, string $php_version, CData $current_f
*/
$current_function_name_pointer = \FFI::cast('long', $current_function->common->function_name);
if ($current_function_name_pointer->cdata !== 0) {
/** @var \FFI\CPointer $current_function_name_pointer */
/**
* @psalm-ignore-var
* @var \FFI\CPointer $current_function_name_pointer
*/
$current_function_name_zstring = $this->memory_reader->read(
$pid,
$current_function_name_pointer->cdata,
Expand Down
2 changes: 1 addition & 1 deletion src/Lib/Process/MemoryMap/ProcessModuleMemoryMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function getMemoryAddressFromOffset(int $offset): int
{
$ranges = $this->getSortedOffsetToMemoryAreaMap();
$file_offset_decided = 0;
foreach ($ranges as $file_offset => $memory_begin) {
foreach ($ranges as $file_offset => $_memory_begin) {
if ($file_offset <= $offset) {
$file_offset_decided = $file_offset;
}
Expand Down
1 change: 0 additions & 1 deletion src/Lib/Process/MemoryReader/MemoryReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public function __construct()
*/
public function read(int $pid, int $remote_address, int $size): CData
{
/** @var CData $buffer */
$buffer = $this->ffi->new("unsigned char[{$size}]");

/**
Expand Down

0 comments on commit a1ccec8

Please sign in to comment.