Skip to content

Commit

Permalink
Update code style; add psalm baseline
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Dec 11, 2024
1 parent 531808d commit fbfefa7
Show file tree
Hide file tree
Showing 34 changed files with 263 additions and 238 deletions.
100 changes: 100 additions & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.26.1@d747f6500b38ac4f7dfc5edbcae6e4b637d7add0">
<file src="src/Bootloader/TemporalBridgeBootloader.php">
<MixedArgument>
<code><![CDATA[$env->get('TEMPORAL_ADDRESS', '127.0.0.1:7233')]]></code>
</MixedArgument>
</file>
<file src="src/Commands/InfoCommand.php">
<MixedArgumentTypeCoercion>
<code><![CDATA[$taskQueue]]></code>
<code><![CDATA[$taskQueue]]></code>
</MixedArgumentTypeCoercion>
<UnusedVariable>
<code><![CDATA[$class]]></code>
</UnusedVariable>
</file>
<file src="src/Commands/Scaffolder/ActivityCommand.php">
<MixedArgument>
<code><![CDATA[$method]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$method]]></code>
</MixedAssignment>
</file>
<file src="src/Commands/Scaffolder/WorkflowCommand.php">
<MixedArgument>
<code><![CDATA[$method]]></code>
<code><![CDATA[$name]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$method]]></code>
<code><![CDATA[$name]]></code>
</MixedAssignment>
</file>
<file src="src/Config/TemporalConfig.php">
<MixedArgument>
<code><![CDATA[$address]]></code>
<code><![CDATA[$clientOptions]]></code>
<code><![CDATA[$namespace]]></code>
</MixedArgument>
<MixedArrayAssignment>
<code><![CDATA[$config['clients']['default']]]></code>
</MixedArrayAssignment>
<MixedAssignment>
<code><![CDATA[$address]]></code>
<code><![CDATA[$clientOptions]]></code>
<code><![CDATA[$namespace]]></code>
</MixedAssignment>
<MixedMethodCall>
<code><![CDATA[withNamespace]]></code>
</MixedMethodCall>
</file>
<file src="src/Dispatcher.php">
<MixedArgument>
<code><![CDATA[$taskQueue]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$taskQueue]]></code>
</MixedAssignment>
<MixedInferredReturnType>
<code><![CDATA[object]]></code>
</MixedInferredReturnType>
<MixedMethodCall>
<code><![CDATA[getDeclarationList]]></code>
</MixedMethodCall>
<MixedReturnStatement>
<code><![CDATA[$this->scope->runScope(
new Scope('temporal-activity'),
static fn(FactoryInterface $factory): object => $factory->make($class->getName()),
)]]></code>
</MixedReturnStatement>
</file>
<file src="src/Scaffolder/Declaration/ActivityDeclaration.php">
<InvalidClassConstantType>
<code><![CDATA[TYPE]]></code>
</InvalidClassConstantType>
</file>
<file src="src/Scaffolder/Declaration/WorkflowDeclaration.php">
<InvalidClassConstantType>
<code><![CDATA[TYPE]]></code>
</InvalidClassConstantType>
</file>
<file src="src/WorkerFactory.php">
<MixedInferredReturnType>
<code><![CDATA[object]]></code>
</MixedInferredReturnType>
<MixedReturnStatement>
<code><![CDATA[match (true) {
\is_string($alias) => $this->factory->make($alias),
$alias instanceof Autowire => $alias->resolve($this->factory),
default => $alias,
}]]></code>
<code><![CDATA[match (true) {
\is_string($alias) => $this->factory->make($alias),
$alias instanceof Autowire => $alias->resolve($this->factory),
default => $alias,
}]]></code>
</MixedReturnStatement>
</file>
</files>
3 changes: 1 addition & 2 deletions src/Attribute/AssignWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ final class AssignWorker
*/
public function __construct(
public readonly string $taskQueue,
) {
}
) {}
}
17 changes: 8 additions & 9 deletions src/Bootloader/TemporalBridgeBootloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
*/
class TemporalBridgeBootloader extends Bootloader
{
public function __construct(
private readonly ConfiguratorInterface $config,
private readonly FactoryInterface $factory,
) {}

public function defineDependencies(): array
{
return [
Expand All @@ -66,7 +71,7 @@ public function defineSingletons(): array
rpc: Goridge::create(),
),
WorkerFactoryInterface::class => WorkerFactory::class,
DeclarationLocator::class => static fn (): DeclarationLocator => new DeclarationLocator(
DeclarationLocator::class => static fn(): DeclarationLocator => new DeclarationLocator(
reader: new AttributeReader(),
),
DeclarationLocatorInterface::class => DeclarationLocator::class,
Expand Down Expand Up @@ -101,12 +106,6 @@ public function defineSingletons(): array
];
}

public function __construct(
private readonly ConfiguratorInterface $config,
private readonly FactoryInterface $factory,
) {
}

public function init(
AbstractKernel $kernel,
EnvironmentInterface $env,
Expand Down Expand Up @@ -164,7 +163,7 @@ protected function initConfig(EnvironmentInterface $env): void
),
),
],
'defaultWorker' => (string)$env->get(
'defaultWorker' => (string) $env->get(
'TEMPORAL_TASK_QUEUE',
TemporalWorkerFactoryInterface::DEFAULT_TASK_QUEUE,
),
Expand Down Expand Up @@ -198,7 +197,7 @@ protected function initPipelineProvider(TemporalConfig $config, FactoryInterface
static fn(mixed $interceptor) => match (true) {
\is_string($interceptor) => $factory->make($interceptor),
$interceptor instanceof Autowire => $interceptor->resolve($factory),
default => $interceptor
default => $interceptor,
},
$config->getInterceptors(),
);
Expand Down
12 changes: 6 additions & 6 deletions src/Config/ConnectionConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
*
* How to connect to local Temporal server:
*
* new ConnectionConfig('localhost:7233'),
* new ConnectionConfig('localhost:7233'),
*
* How to connect to Temporal Cloud:
*
* (new ConnectionConfig('foo-bar-default.baz.tmprl.cloud:7233'))
* ->withTls(
* privateKey: '/my-project.key',
* certChain: '/my-project.pem',
* ),
* (new ConnectionConfig('foo-bar-default.baz.tmprl.cloud:7233'))
* ->withTls(
* privateKey: '/my-project.key',
* certChain: '/my-project.pem',
* ),
*/
final class ConnectionConfig
{
Expand Down
4 changes: 2 additions & 2 deletions src/Config/TemporalConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function __construct(array $config = [])
public function getTemporalNamespace(): string
{
$client = $this->getDefaultClient();
return match(true) {
return match (true) {
isset($this->config['clients'][$client]) => $this->config['clients'][$client]->options->namespace,
isset($this->config['temporalNamespace']) => $this->config['temporalNamespace'],
default => 'default',
Expand Down Expand Up @@ -141,7 +141,7 @@ public function getInterceptors(): array
public function getClientOptions(): ClientOptions
{
$client = $this->getDefaultClient();
return match(true) {
return match (true) {
isset($this->config['clients'][$client]) => $this->config['clients'][$client]->options,
isset($this->config['clientOptions']) => $this->config['clientOptions'],
default => (new ClientOptions())->withNamespace($this->getTemporalNamespace()),
Expand Down
3 changes: 2 additions & 1 deletion src/Config/TlsConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
/**
* gRPC TLS configuration.
*/
final class TlsConfig {
final class TlsConfig
{
/**
* @param non-empty-string|null $rootCerts Root certificates string or file in PEM format.
* If null provided, default gRPC root certificates are used.
Expand Down
3 changes: 1 addition & 2 deletions src/Declaration/DeclarationDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ public function __construct(
public readonly DeclarationType $type,
public readonly \ReflectionClass $class,
public readonly ?string $taskQueue = null,
) {
}
) {}
}
5 changes: 2 additions & 3 deletions src/DeclarationLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ final class DeclarationLocator implements

public function __construct(
private readonly ReaderInterface $reader,
) {
}
) {}

public function addDeclaration(DeclarationDto|\ReflectionClass|string $class): void
{
Expand All @@ -47,7 +46,7 @@ public function getDeclarationList(): iterable
public function getDeclarations(): iterable
{
foreach ($this->declarations as $declaration) {
yield match($declaration->type) {
yield match ($declaration->type) {
DeclarationType::Workflow => WorkflowInterface::class,
DeclarationType::Activity => ActivityInterface::class,
} => $declaration->class;
Expand Down
3 changes: 1 addition & 2 deletions src/DeclarationWorkerResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ final class DeclarationWorkerResolver
public function __construct(
private readonly ReaderInterface $reader,
private readonly TemporalConfig $config,
) {
}
) {}

/**
* Find the worker name for the given workflow or class declaration. If no worker is assigned, the default task
Expand Down
8 changes: 3 additions & 5 deletions src/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Spiral\TemporalBridge;

use Psr\Container\ContainerInterface;
use ReflectionClass;
use Spiral\Attribute\DispatcherScope;
use Spiral\Boot\DispatcherInterface;
use Spiral\Core\FactoryInterface;
Expand All @@ -23,8 +22,7 @@ public function __construct(
private readonly ContainerInterface $container,
private readonly DeclarationWorkerResolver $workerResolver,
private readonly ScopeInterface $scope,
) {
}
) {}

public static function canServe(RoadRunnerMode $mode): bool
{
Expand Down Expand Up @@ -75,12 +73,12 @@ public function serve(): void
$factory->run();
}

private function makeActivity(ReflectionClass $class): object
private function makeActivity(\ReflectionClass $class): object
{
/** @psalm-suppress InvalidArgument */
return $this->scope->runScope(
new Scope('temporal-activity'),
static fn (FactoryInterface $factory): object => $factory->make($class->getName()),
static fn(FactoryInterface $factory): object => $factory->make($class->getName()),
);
}
}
5 changes: 1 addition & 4 deletions src/Exception/TemporalBridgeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,4 @@

namespace Spiral\TemporalBridge\Exception;

class TemporalBridgeException extends \Exception
{

}
class TemporalBridgeException extends \Exception {}
5 changes: 1 addition & 4 deletions src/Exception/WorkersRegistryException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,4 @@

namespace Spiral\TemporalBridge\Exception;

class WorkersRegistryException extends TemporalBridgeException
{

}
class WorkersRegistryException extends TemporalBridgeException {}
6 changes: 3 additions & 3 deletions src/WorkerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function create(string $name): WorkerInterface
$this->getExceptionInterceptor($name),
$this->pipelineProvider,
);
$worker->registerActivityFinalizer(fn () => $this->finalizer->finalize());
$worker->registerActivityFinalizer(fn() => $this->finalizer->finalize());

return $worker;
}
Expand All @@ -59,7 +59,7 @@ private function getWorkerOptions(string $name): ?WorkerOptions
return match (true) {
$worker instanceof WorkerOptions => $worker,
isset($worker['options']) && $worker['options'] instanceof WorkerOptions => $worker['options'],
default => null
default => null,
};
}

Expand All @@ -84,7 +84,7 @@ private function wire(mixed $alias): object
return match (true) {
\is_string($alias) => $this->factory->make($alias),
$alias instanceof Autowire => $alias->resolve($this->factory),
default => $alias
default => $alias,
};
}
}
9 changes: 5 additions & 4 deletions src/WorkersRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,22 @@ final class WorkersRegistry implements WorkersRegistryInterface
/** @psalm-var array<non-empty-string, WorkerInterface> */
private array $workers = [];

/** @psalm-param array<non-empty-string, WorkerOptions> $options */
/**
* @psalm-param array<non-empty-string, WorkerOptions> $options
*/
public function __construct(
private readonly WorkerFactoryInterface|TemporalWorkerFactory $workerFactory,
private readonly FinalizerInterface $finalizer,
private readonly TemporalConfig $config,
) {
}
) {}

public function register(string $name, ?WorkerOptions $options): void
{
\assert($name !== '');

if ($this->has($name)) {
throw new WorkersRegistryException(
\sprintf('Temporal worker with given name `%s` has already been registered.', $name)
\sprintf('Temporal worker with given name `%s` has already been registered.', $name),
);
}

Expand Down
5 changes: 1 addition & 4 deletions tests/app/src/SimpleWorkflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,5 @@

class SimpleWorkflow
{
public function handle()
{

}
public function handle(): void {}
}
4 changes: 1 addition & 3 deletions tests/app/src/SomeActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@
use Spiral\TemporalBridge\Attribute\AssignWorker;

#[AssignWorker(taskQueue: 'worker1')]
class SomeActivity
{
}
class SomeActivity {}
4 changes: 1 addition & 3 deletions tests/app/src/SomeActivityWithDefaultWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

namespace Spiral\TemporalBridge\Tests\App;

class SomeActivityWithDefaultWorker
{
}
class SomeActivityWithDefaultWorker {}
3 changes: 1 addition & 2 deletions tests/app/src/SomeActivityWithScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@ class SomeActivityWithScope
// Binding ArrayAccess $tasks available only in `temporal-activity` scope
public function __construct(
private readonly \ArrayAccess $tasks,
) {
}
) {}
}
4 changes: 1 addition & 3 deletions tests/app/src/SomeInterceptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,5 @@

final class SomeInterceptor implements ActivityInboundInterceptor
{
public function handleActivityInbound(ActivityInput $input, callable $next): mixed
{
}
public function handleActivityInbound(ActivityInput $input, callable $next): mixed {}
}
Loading

0 comments on commit fbfefa7

Please sign in to comment.