WorkflowDefinition   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 29
c 1
b 0
f 0
dl 0
loc 62
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __set_state() 0 13 1
A __construct() 0 14 3
1
<?php
2
3
namespace Kaliop\eZWorkflowEngineBundle\API\Value;
4
5
use Kaliop\eZMigrationBundle\API\Value\MigrationDefinition;
6
7
/**
8
 * @property-read string $signalName
9
 * @property-read string $runAs use false for 'current user'
10
 * @property-read bool $useTransaction
11
 * @property-read bool $avoidRecursion
12
 */
13
class WorkflowDefinition extends MigrationDefinition
14
{
15
    const MANIFEST_STEP_TYPE= 'workflow';
16
    const MANIFEST_SIGNAL_ELEMENT= 'signal';
17
    const MANIFEST_RUNAS_ELEMENT= 'run_as';
18
    const MANIFEST_USETRANSACTION_ELEMENT= 'transaction';
19
    const MANIFEST_AVOIDRECURSION_ELEMENT= 'avoid_recursion';
20
21
    protected $signalName;
22
    // unlike migrations, workflows default to run as current user
23
    protected $runAs = false;
24
    protected $useTransaction = false;
25
    protected $avoidRecursion;
26
27
    /**
28
     * WorkflowDefinition constructor.
29
     * @param string $name
30
     * @param string $path
31
     * @param string $rawDefinition
32
     * @param int $status
33
     * @param \Kaliop\eZMigrationBundle\API\Value\MigrationStep[]|\Kaliop\eZMigrationBundle\API\Collection\MigrationStepsCollection $steps
34
     * @param string $parsingError
35
     * @param string $signalName
36
     * @param string|int|false|null $runAs if false will use the current user; if null will use hardcoded 14; string for login or user id
37
     * @param bool $useTransaction
38
     * @throws \Exception
39
     */
40
    public function __construct($name, $path, $rawDefinition, $status = 0, $steps = array(), $parsingError = null,
41
        $signalName = null, $runAs = false, $useTransaction = false, $avoidRecursion = false)
42
    {
43
        if ($status == MigrationDefinition::STATUS_PARSED && $signalName == null) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $signalName of type null|string against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
44
            throw new \Exception("Can not create a parsed Workflow definition without a corresponding signal");
45
        }
46
47
        $this->signalName = $signalName;
0 ignored issues
show
Bug introduced by
The property signalName is declared read-only in Kaliop\eZWorkflowEngineB...alue\WorkflowDefinition.
Loading history...
48
        $this->runAs = $runAs;
0 ignored issues
show
Documentation Bug introduced by
It seems like $runAs can also be of type false. However, the property $runAs is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
Bug introduced by
The property runAs is declared read-only in Kaliop\eZWorkflowEngineB...alue\WorkflowDefinition.
Loading history...
49
        $this->useTransaction = $useTransaction;
0 ignored issues
show
Bug introduced by
The property useTransaction is declared read-only in Kaliop\eZWorkflowEngineB...alue\WorkflowDefinition.
Loading history...
50
        $this->avoidRecursion = $avoidRecursion;
0 ignored issues
show
Bug introduced by
The property avoidRecursion is declared read-only in Kaliop\eZWorkflowEngineB...alue\WorkflowDefinition.
Loading history...
51
52
        parent::__construct(
53
            $name, $path, $rawDefinition, $status, $steps, $parsingError
54
        );
55
    }
56
57
    /**
58
     * Allow the class to be serialized to php using var_export
59
     * @param array $data
60
     * @return static
61
     */
62
    public static function __set_state(array $data)
63
    {
64
        return new static(
65
            $data['name'],
66
            $data['path'],
67
            $data['rawDefinition'],
68
            $data['status'],
69
            $data['steps'],
70
            $data['parsingError'],
71
            $data['signalName'],
72
            $data['runAs'],
73
            $data['useTransaction'],
74
            $data['avoidRecursion']
75
        );
76
    }
77
}
78