Skip to content

Commit

Permalink
reduce redundant doc blocks and fallback to the global namespace
Browse files Browse the repository at this point in the history
also remove the vendor prefix from some @param tags
  • Loading branch information
sj-i committed Sep 8, 2021
1 parent 36c6aa1 commit 174d383
Show file tree
Hide file tree
Showing 119 changed files with 156 additions and 919 deletions.
17 changes: 6 additions & 11 deletions src/Command/CommandEnumerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,26 @@
use FilesystemIterator;
use IteratorAggregate;
use SplFileInfo;
use Symfony\Component\Console\Command\Command;

/**
* Class CommandFinder
* @package App\Command
*/
/** @implements IteratorAggregate<class-string<Command>> */
final class CommandEnumerator implements IteratorAggregate
{
/**
* CommandEnumerator constructor.
*/
public function __construct(
private FilesystemIterator $command_files_iterator
) {
}

/**
* @inheritDoc
*/
/** @return \Generator<class-string<Command>> */
public function getIterator()
{
/** @var SplFileInfo $command_file_info */
foreach ($this->command_files_iterator as $command_file_info) {
$class_name = $command_file_info->getBasename('.php');
$namespace = $command_file_info->getPathInfo()->getFilename();
yield "PhpProfiler\\Command\\{$namespace}\\$class_name";
$result = "PhpProfiler\\Command\\{$namespace}\\$class_name";
assert(is_subclass_of($result, Command::class));
yield $result;
}
}
}
8 changes: 3 additions & 5 deletions src/Command/Inspector/DaemonCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
use Symfony\Component\Console\Output\OutputInterface;

use function Amp\call;
use function fread;

use const STDIN;

final class DaemonCommand extends Command
{
Expand Down Expand Up @@ -62,11 +65,6 @@ public function configure(): void
$this->template_settings_from_console_input->setOptions($this);
}

/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int
*/
public function execute(InputInterface $input, OutputInterface $output): int
{
$get_trace_settings = $this->get_trace_settings_from_console_input->createSettings($input);
Expand Down
3 changes: 0 additions & 3 deletions src/Command/Inspector/GetCurrentFunctionNameCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ public function configure(): void
}

/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int
* @throws MemoryReaderException
* @throws ProcessSymbolReaderException
* @throws ElfParserException
Expand Down
10 changes: 3 additions & 7 deletions src/Command/Inspector/GetEgAddressCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Class GetEgAddressCommand
* @package PhpProfiler\Command\Inspector
*/
use function dechex;
use function sprintf;

final class GetEgAddressCommand extends Command
{
public function __construct(
Expand All @@ -49,9 +48,6 @@ public function configure(): void
}

/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int
* @throws MemoryReaderException
* @throws ProcessSymbolReaderException
* @throws ElfParserException
Expand Down
3 changes: 0 additions & 3 deletions src/Command/Inspector/GetTraceCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ public function configure(): void
}

/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int
* @throws MemoryReaderException
* @throws ProcessSymbolReaderException
* @throws ElfParserException
Expand Down
8 changes: 2 additions & 6 deletions src/Inspector/Daemon/Dispatcher/DispatchTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
namespace PhpProfiler\Inspector\Daemon\Dispatcher;

use PhpProfiler\Inspector\Daemon\Reader\Controller\PhpReaderControllerInterface;
use PhpProfiler\Inspector\Settings\GetTraceSettings\GetTraceSettings;
use PhpProfiler\Inspector\Settings\TargetPhpSettings\TargetPhpSettings;
use PhpProfiler\Inspector\Settings\TraceLoopSettings\TraceLoopSettings;

use function is_null;

final class DispatchTable
{
Expand All @@ -26,9 +25,6 @@ final class DispatchTable

public function __construct(
public WorkerPoolInterface $worker_pool,
private TargetPhpSettings $target_php_settings,
private TraceLoopSettings $trace_loop_settings,
private GetTraceSettings $get_trace_settings
) {
$this->assigned = new TargetProcessList();
}
Expand Down
7 changes: 4 additions & 3 deletions src/Inspector/Daemon/Dispatcher/TargetProcessList.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

namespace PhpProfiler\Inspector\Daemon\Dispatcher;

use function array_diff;
use function array_rand;

final class TargetProcessList implements TargetProcessListInterface
{
/** @var int[] */
Expand Down Expand Up @@ -44,9 +47,7 @@ public function getDiff(TargetProcessListInterface $compare_list): self
return new self(...array_diff($this->pid_list, $compare_list->getArray()));
}

/**
* @return int[]
*/
/** @return int[] */
public function getArray(): array
{
return $this->pid_list;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
interface TargetProcessListInterface
{
public function pickOne(): ?int;

public function putOne(int $pid): void;

public function getDiff(TargetProcessListInterface $compare_list): self;

/** @return int[] */
public function getArray(): array;
}
12 changes: 5 additions & 7 deletions src/Inspector/Daemon/Dispatcher/WorkerPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
use PhpProfiler\Inspector\Settings\TargetPhpSettings\TargetPhpSettings;
use PhpProfiler\Inspector\Settings\TraceLoopSettings\TraceLoopSettings;

use function array_fill;
use function array_keys;
use function count;

final class WorkerPool implements WorkerPoolInterface
{
/** @var array<int, PhpReaderControllerInterface> */
Expand All @@ -28,15 +32,11 @@ final class WorkerPool implements WorkerPoolInterface
/** @var array<int, bool> */
private array $is_free_list;

/** @var array<int, bool> */
private array $on_read_list;

/** @no-named-arguments */
public function __construct(PhpReaderControllerInterface ...$contexts)
{
$this->contexts = $contexts;
$this->is_free_list = array_fill(0, count($contexts), true);
$this->on_read_list = array_fill(0, count($contexts), false);
}

public static function create(
Expand Down Expand Up @@ -78,9 +78,7 @@ public function getFreeWorker(): ?PhpReaderControllerInterface
return null;
}

/**
* @return iterable<int, PhpReaderControllerInterface>
*/
/** @return iterable<int, PhpReaderControllerInterface> */
public function getWorkers(): iterable
{
foreach ($this->contexts as $key => $context) {
Expand Down
4 changes: 1 addition & 3 deletions src/Inspector/Daemon/Dispatcher/WorkerPoolInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ public function getFreeWorker(): ?PhpReaderControllerInterface;

public function returnWorkerToPool(PhpReaderControllerInterface $context_to_return): void;

/**
* @return iterable<int, PhpReaderControllerInterface>
*/
/** @return iterable<int, PhpReaderControllerInterface> */
public function getWorkers(): iterable;

public function debugDump(): array;
Expand Down
20 changes: 3 additions & 17 deletions src/Inspector/Daemon/Reader/Controller/PhpReaderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@

final class PhpReaderController implements PhpReaderControllerInterface
{
/**
* PhpReaderContext constructor.
* @param ContextInterface<PhpReaderControllerProtocolInterface> $context
*/
/** @param ContextInterface<PhpReaderControllerProtocolInterface> $context */
public function __construct(
private ContextInterface $context
) {
Expand All @@ -45,18 +42,12 @@ public function isRunning(): bool
return $this->context->isRunning();
}

/**
* @param TargetPhpSettings $target_php_settings
* @param TraceLoopSettings $loop_settings
* @param GetTraceSettings $get_trace_settings
* @return Promise<int>
*/
/** @return Promise<int> */
public function sendSettings(
TargetPhpSettings $target_php_settings,
TraceLoopSettings $loop_settings,
GetTraceSettings $get_trace_settings
): Promise {
/** @var Promise<int> */
return $this->context->getProtocol()->sendSettings(
new SetSettingsMessage(
$target_php_settings,
Expand All @@ -66,13 +57,9 @@ public function sendSettings(
);
}

/**
* @param int $pid
* @return Promise<int>
*/
/** @return Promise<int> */
public function sendAttach(int $pid): Promise
{
/** @var Promise<int> */
return $this->context->getProtocol()->sendAttach(
new AttachMessage($pid)
);
Expand All @@ -83,7 +70,6 @@ public function sendAttach(int $pid): Promise
*/
public function receiveTraceOrDetachWorker(): Promise
{
/** @var Promise<TraceMessage|DetachWorkerMessage> */
return $this->context->getProtocol()->receiveTraceOrDetachWorker();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,16 @@ public function start(): Promise;

public function isRunning(): bool;

/**
* @param TargetPhpSettings $target_php_settings
* @param TraceLoopSettings $loop_settings
* @param GetTraceSettings $get_trace_settings
* @return Promise<int>
*/
/** @return Promise<int> */
public function sendSettings(
TargetPhpSettings $target_php_settings,
TraceLoopSettings $loop_settings,
GetTraceSettings $get_trace_settings
): Promise;

/**
* @param int $pid
* @return Promise<int>
*/
/** @return Promise<int> */
public function sendAttach(int $pid): Promise;

/**
* @return Promise<TraceMessage|DetachWorkerMessage>
*/
/** @return Promise<TraceMessage|DetachWorkerMessage> */
public function receiveTraceOrDetachWorker(): Promise;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ public function __construct(
) {
}

/** @return static */
public static function createFromChannel(Channel $channel): self
public static function createFromChannel(Channel $channel): static
{
return new self($channel);
}
Expand All @@ -44,9 +43,7 @@ public function sendAttach(AttachMessage $message): Promise
return $this->channel->send($message);
}

/**
* @return Promise<TraceMessage|DetachWorkerMessage>
*/
/** @return Promise<TraceMessage|DetachWorkerMessage> */
public function receiveTraceOrDetachWorker(): Promise
{
/** @var Promise<TraceMessage|DetachWorkerMessage> */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@

interface PhpReaderControllerProtocolInterface extends MessageProtocolInterface
{
/** @return Promise<int> */
public function sendSettings(SetSettingsMessage $message): Promise;

/** @return Promise<int> */
public function sendAttach(AttachMessage $message): Promise;

/**
* @return Promise<TraceMessage|DetachWorkerMessage>
*/
/** @return Promise<TraceMessage|DetachWorkerMessage> */
public function receiveTraceOrDetachWorker(): Promise;
}
7 changes: 2 additions & 5 deletions src/Inspector/Daemon/Reader/Worker/PhpReaderTraceLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use PhpProfiler\Lib\PhpProcessReader\PhpMemoryReader\ExecutorGlobalsReader;
use PhpProfiler\Lib\Process\ProcessStopper\ProcessStopper;

use function is_null;
use function PhpProfiler\Lib\Defer\defer;

final class PhpReaderTraceLoop implements PhpReaderTraceLoopInterface
Expand All @@ -36,10 +37,6 @@ public function __construct(
}

/**
* @param TargetProcessSettings $target_process_settings
* @param TraceLoopSettings $loop_settings
* @param TargetPhpSettings $target_php_settings
* @param GetTraceSettings $get_trace_settings
* @return Generator<TraceMessage>
* @throws \PhpProfiler\Lib\Elf\Parser\ElfParserException
* @throws \PhpProfiler\Lib\Elf\Process\ProcessSymbolReaderException
Expand All @@ -61,7 +58,7 @@ function () use (
$target_php_settings,
$loop_settings,
$eg_address
): \Generator {
): Generator {
if ($loop_settings->stop_process and $this->process_stopper->stop($target_process_settings->pid)) {
defer($_, fn () => $this->process_stopper->resume($target_process_settings->pid));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,16 @@

namespace PhpProfiler\Inspector\Daemon\Reader\Worker;

use Amp\Parallel\Sync\Channel;
use Generator;
use PhpProfiler\Inspector\Daemon\Reader\Protocol\Message\TraceMessage;
use PhpProfiler\Inspector\Daemon\Reader\Protocol\PhpReaderWorkerProtocolInterface;
use PhpProfiler\Inspector\Settings\GetTraceSettings\GetTraceSettings;
use PhpProfiler\Inspector\Settings\TargetPhpSettings\TargetPhpSettings;
use PhpProfiler\Inspector\Settings\TargetProcessSettings\TargetProcessSettings;
use PhpProfiler\Inspector\Settings\TraceLoopSettings\TraceLoopSettings;

interface PhpReaderTraceLoopInterface
{
/**
* @param TargetProcessSettings $target_process_settings
* @param TraceLoopSettings $loop_settings
* @param TargetPhpSettings $target_php_settings
* @param GetTraceSettings $get_trace_settings
* @return Generator<TraceMessage>
*/
/** @return Generator<TraceMessage> */
public function run(
TargetProcessSettings $target_process_settings,
TraceLoopSettings $loop_settings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ public function __construct(
) {
}

/** @return static */
public static function createFromChannel(Channel $channel): self
public static function createFromChannel(Channel $channel): static
{
return new self($channel);
}
Expand Down
Loading

0 comments on commit 174d383

Please sign in to comment.