Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code refactoring #75

Merged
merged 2 commits into from
Dec 21, 2023
Merged

Code refactoring #75

merged 2 commits into from
Dec 21, 2023

Conversation

butschster
Copy link
Member

We've made a strategic decision to improve the developer experience (DX) within the temporal/sdk PHP package rather than in the integration bridge package itself. This approach simplifies the structure and focuses on making the SDK more user-friendly for developers.

The spiral/temporal-bridge package will now primarily serve to facilitate the integration with the Spiral framework, avoiding additional complexities. This streamlines the overall setup and usage.

In addition, we've revised the way Workflow and Activity classes are created. Instead of generating both a class and an interface for these, we're now only creating the class. This simplification makes the process more straightforward and efficient.

Here are the updated examples for Activity and Workflow classes in PHP:

For an Activity class:

Command:

php app.php create:activity Payment --method=pay --method=refund:void --method=getPaymentStatus:bool

Result:

<?php

declare(strict_types=1);

namespace Spiral\Testing\Endpoint\Temporal\Activity;

use React\Promise\PromiseInterface;
use Temporal\Activity\ActivityInterface;
use Temporal\Activity\ActivityMethod;

#[ActivityInterface]
class PaymentActivity
{
    /**
     * @return PromiseInterface<mixed>
     */
    #[ActivityMethod(name: 'pay')]
    public function pay(): mixed
    {
        // TODO: Implement activity method
    }

    /**
     * @return PromiseInterface<void>
     */
    #[ActivityMethod(name: 'refund')]
    public function refund(): void
    {
        // TODO: Implement activity method
    }

    /**
     * @return PromiseInterface<bool>
     */
    #[ActivityMethod(name: 'getPaymentStatus')]
    public function getPaymentStatus(): bool
    {
        // TODO: Implement activity method
    }
}

For a Workflow class:

Command:

php app.php create:workflow Payment --query-method=getPayment:string' --query-method=getTotal:int --signal-method=pay

Result:

<?php

declare(strict_types=1);

namespace Spiral\Testing\Endpoint\Temporal\Workflow;

use Temporal\Workflow\SignalMethod;
use Temporal\Workflow\QueryMethod;
use Temporal\Workflow\WorkflowInterface;
use Temporal\Workflow\WorkflowMethod;

#[WorkflowInterface]
class PaymentWorkflow
{
    /**
     * Handle workflow
     */
    #[WorkflowMethod]
    public function handle()
    {
        // TODO: Implement handle method
    }

    #[QueryMethod]
    public function getPayment(): string
    {
        // TODO: Implement query method
    }

    #[QueryMethod]
    public function getTotal(): int
    {
        // TODO: Implement query method
    }

    #[SignalMethod]
    public function pay(): void
    {
        // TODO: Implement signal method
    }
}

Additionally, we've removed presets from the package. This decision was made because presets are often specific to particular applications and trying to accommodate all potential scenarios was becoming overly complex.

1. Removes code generation with interfaces, handlers, etc. Now there is only an ability to generate Workflow class and Activity class with methods.

2. Removes generator based on presets.

3. Removes WorkflowManager class.
@butschster butschster added the enhancement New feature or request label Dec 19, 2023
@butschster butschster self-assigned this Dec 19, 2023
# Conflicts:
#	composer.json
#	psalm.xml
#	src/Attribute/AssignWorker.php
#	src/Generator/Utils.php
#	tests/src/Commands/MakePresetCommandTest.php
#	tests/src/Generator/PhpCodePrinterTest.php
#	tests/src/Preset/PresetRegistryTest.php
Copy link

codecov bot commented Dec 19, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (05c7410) 77.45% compared to head (11ef03e) 97.76%.

Additional details and impacted files
@@              Coverage Diff              @@
##                3.x      #75       +/-   ##
=============================================
+ Coverage     77.45%   97.76%   +20.31%     
+ Complexity      198       70      -128     
=============================================
  Files            28       12       -16     
  Lines           683      224      -459     
=============================================
- Hits            529      219      -310     
+ Misses          154        5      -149     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@butschster butschster merged commit 66f8754 into 3.x Dec 21, 2023
6 checks passed
@butschster butschster deleted the feature/refactoring branch December 21, 2023 06:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants