Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
level: 5
level: 6
paths:
- src
- tests
Expand All @@ -9,6 +9,7 @@ parameters:
- '#is_callable.*recruiter_#'
- '#recruiter_became_master#'
- '#recruiter_stept_back#'
- '#afterSuccess.*0 required#'
- '#Unsafe usage of new static\(\).#'
- '#Call to an undefined method.*FactoryMethodCommand::#'
inferPrivatePropertyTypeFromConstructor: true
treatPhpDocTypesAsCertain: false
6 changes: 3 additions & 3 deletions src/Recruiter/Cleaner.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ public function __construct(private readonly Repository $repository)
{
}

public function cleanArchived(Interval $gracePeriod)
public function cleanArchived(Interval $gracePeriod): int
{
$upperLimit = T\now()->before($gracePeriod);

return $this->repository->cleanArchived($upperLimit);
}

public function cleanScheduled(?Interval $gracePeriod = null)
public function cleanScheduled(?Interval $gracePeriod = null): int
{
$upperLimit = T\now();
if (!is_null($gracePeriod)) {
Expand All @@ -31,7 +31,7 @@ public function cleanScheduled(?Interval $gracePeriod = null)
return $this->repository->cleanScheduled($upperLimit);
}

public function bye()
public function bye(): void
{
}
}
3 changes: 3 additions & 0 deletions src/Recruiter/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

class Factory
{
/**
* @param array<string, mixed> $options
*/
public function getMongoDb(URI $uri, array $options = []): Database
{
try {
Expand Down
11 changes: 10 additions & 1 deletion src/Recruiter/Infrastructure/Command/Bko/AnalyticsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ protected function configure(): void

protected function execute(InputInterface $input, OutputInterface $output): int
{
/** @var string */
/** @var string $target */
$target = $input->getOption('target');
$db = $this->factory->getMongoDb(MongoURI::from($target));
$recruiter = new Recruiter($db);

/** @var ?string $group */
$group = $input->getOption('group');
$analytics = $recruiter->analytics($group);

Expand Down Expand Up @@ -77,6 +78,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return self::SUCCESS;
}

/**
* @param array{
* jobs: array{queued: int, postponed: int, zombies: int},
* throughput: array{value: float, value_per_second: float},
* latency: array{average: float},
* execution_time: array{average: float}
* } $analytics
*/
private function calculateColumnsWidth(array $analytics): int
{
$maxColumns = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,14 @@

class RemoveSchedulerCommand extends Command
{
/**
* @var SchedulerRepository
*/
private $schedulerRepository;
private SchedulerRepository $schedulerRepository;

public function __construct(private readonly Factory $factory, private readonly LoggerInterface $logger)
{
parent::__construct();
}

protected function configure()
protected function configure(): void
{
$this
->setName('scheduler:remove')
Expand All @@ -45,9 +42,9 @@ protected function configure()
;
}

protected function initialize(InputInterface $input, OutputInterface $output)
protected function initialize(InputInterface $input, OutputInterface $output): void
{
/** @var string */
/** @var string $target */
$target = $input->getOption('target');
$db = $this->factory->getMongoDb(MongoURI::from($target));
$this->schedulerRepository = new SchedulerRepository($db);
Expand Down Expand Up @@ -75,7 +72,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return self::SUCCESS;
}

private function selectUrnToDelete(array $urns, InputInterface $input, OutputInterface $output)
/**
* @param string[] $urns
*/
private function selectUrnToDelete(array $urns, InputInterface $input, OutputInterface $output): string|false
{
/** @var QuestionHelper $helper */
$helper = $this->getHelper('question');
Expand All @@ -96,6 +96,9 @@ private function selectUrnToDelete(array $urns, InputInterface $input, OutputInt
return $selectedUrn;
}

/**
* @param array<array<string, string>> $data
*/
private function printTable(array $data, OutputInterface $output): void
{
$rows = [];
Expand All @@ -114,6 +117,9 @@ private function printTable(array $data, OutputInterface $output): void
echo PHP_EOL;
}

/**
* @return ?array<array<string, string>>
*/
protected function buildOutputData(): ?array
{
$outputData = [];
Expand Down
11 changes: 10 additions & 1 deletion src/Recruiter/Infrastructure/Command/RecruiterCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Recruiter\Geezer\Timing\WaitStrategy;
use Recruiter\Infrastructure\Filesystem\BootstrapFile;
use Recruiter\Infrastructure\Memory\MemoryLimit;
use Recruiter\Infrastructure\Memory\MemoryLimitExceededException;
use Recruiter\Infrastructure\Persistence\Mongodb\URI as MongoURI;
use Recruiter\Recruiter;
use Symfony\Component\Console\Input\InputDefinition;
Expand All @@ -42,6 +43,9 @@ public static function toRobustCommand(Factory $factory, LoggerInterface $logger
return new RobustCommandRunner(new static($factory, $logger), $logger);
}

/**
* @throws MemoryLimitExceededException
*/
public function execute(): bool
{
$this->rollbackLockedJobs();
Expand All @@ -62,6 +66,11 @@ private function rollbackLockedJobs(): void
$this->log(sprintf('rolled back %d jobs in %fms', $rolledBack, ($rollbackEndAt - $rollbackStartAt) * 1000), $logLevel);
}

/**
* @return array<string, string>
*
* @throws MemoryLimitExceededException
*/
private function assignJobsToWorkers(): array
{
$pickStartAt = microtime(true);
Expand Down Expand Up @@ -182,7 +191,7 @@ public function init(InputInterface $input): void
$this->recruiter->createCollectionsAndIndexes();

if ($input->getOption('bootstrap')) {
/** @var string */
/** @var string $bootstrap */
$bootstrap = $input->getOption('bootstrap');
BootstrapFile::fromFilePath($bootstrap)->load($this->recruiter);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Recruiter/Infrastructure/Filesystem/BootstrapFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public static function fromFilePath(string $filePath): self
return new static($filePath);
}

public function load(Recruiter $recruiter)
public function load(Recruiter $recruiter): void
{
return require $this->filePath;
require $this->filePath;
}

private function validate(string $filePath): void
Expand Down
2 changes: 1 addition & 1 deletion src/Recruiter/Infrastructure/Memory/MemoryLimit.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct(int|string|System $limit)
try {
$this->limit = box($limit);
} catch (ParseException $e) {
throw new \UnexpectedValueException(sprintf("Memory limit '%s' is an invalid value: %s", $limit, $e->getMessage()));
throw new \UnexpectedValueException(sprintf("Memory limit '%s' is an invalid value: %s", (string) $limit, $e->getMessage()));
}
}

Expand Down
Loading