• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tochka-developers / queue-promises / 9935584685

15 Jul 2024 07:44AM UTC coverage: 47.259% (-18.3%) from 65.524%
9935584685

push

github

darkdarin
fix: tests

4 of 4 new or added lines in 2 files covered. (100.0%)

431 existing lines in 40 files now uncovered.

612 of 1295 relevant lines covered (47.26%)

2.53 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.77
/src/Core/Support/ConditionTransition.php
1
<?php
2

3
namespace Tochka\Promises\Core\Support;
4

5
use Tochka\Promises\Contracts\ConditionContract;
6
use Tochka\Promises\Enums\StateEnum;
7
use Tochka\Promises\Exceptions\IncorrectResolvingClass;
8

9
class ConditionTransition
10
{
11
    private ConditionContract $condition;
12
    private StateEnum $from_state;
13
    private StateEnum $to_state;
14

15
    public function __construct(ConditionContract $condition, StateEnum $from_state, StateEnum $to_state)
16
    {
17
        $this->condition = $condition;
9✔
18
        $this->from_state = $from_state;
9✔
19
        $this->to_state = $to_state;
9✔
20
    }
21

22
    public function getCondition(): ConditionContract
23
    {
24
        return $this->condition;
6✔
25
    }
26

27
    public function getFromState(): StateEnum
28
    {
29
        return $this->from_state;
6✔
30
    }
31

32
    public function getToState(): StateEnum
33
    {
34
        return $this->to_state;
6✔
35
    }
36

37
    public function toArray(): array
38
    {
39
        return [
3✔
40
            'condition'  => serialize($this->condition),
3✔
41
            'from_state' => $this->from_state->value,
3✔
42
            'to_state'   => $this->to_state->value,
3✔
43
        ];
3✔
44
    }
45

46
    /**
47
     * @throws IncorrectResolvingClass
48
     */
49
    public static function fromArray(array $value): self
50
    {
51
        if (
52
            !array_key_exists('condition', $value)
9✔
53
            || !array_key_exists('from_state', $value)
9✔
54
            || !array_key_exists('to_state', $value)
9✔
55
        ) {
56
            throw new IncorrectResolvingClass(
3✔
57
                'ConditionTransition array must contains required elements [condition,from_state,to_state]',
3✔
58
            );
3✔
59
        }
60

61
        $condition = unserialize($value['condition'], ['allowed_classes' => true]);
6✔
62
        if (!$condition instanceof ConditionContract) {
6✔
63
            throw new IncorrectResolvingClass(
3✔
64
                sprintf(
3✔
65
                    'Condition must implements contract [%s], but class [%s] is incorrect',
3✔
66
                    ConditionContract::class,
3✔
67
                    get_class($condition),
3✔
68
                ),
3✔
69
            );
3✔
70
        }
71

72
        $fromState = StateEnum::coerce($value['from_state']);
3✔
73
        $toState = StateEnum::coerce($value['to_state']);
3✔
74

75
        if ($fromState === null || $toState === null) {
3✔
UNCOV
76
            throw new IncorrectResolvingClass('ConditionTransition array must contains required elements [from_state,to_state]');
×
77
        }
78

79
        return new self($condition, $fromState, $toState);
3✔
80
    }
81
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc