Skip to content

Commit 38d3066

Browse files
committed
phpstan compliance
1 parent b250e45 commit 38d3066

17 files changed

Lines changed: 179 additions & 57 deletions

File tree

src/Elements/Element.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace Ezweb\Workflow\Elements;
34

45
abstract class Element
@@ -7,10 +8,19 @@ abstract class Element
78
protected static \Ezweb\Workflow\Providers\Operator $operatorProvider;
89
protected static \Ezweb\Workflow\Providers\InternalFunction $internalFunctionProvider;
910

10-
protected function __construct()
11+
final protected function __construct()
1112
{
1213
self::$typeProviders = \Ezweb\Workflow\Providers\Type::getInstance();
1314
self::$operatorProvider = \Ezweb\Workflow\Providers\Operator::getInstance();
1415
self::$internalFunctionProvider = \Ezweb\Workflow\Providers\InternalFunction::getInstance();
16+
17+
if (method_exists($this, 'setUp')) {
18+
$this->setUp();
19+
}
1520
}
21+
22+
/**
23+
* @return string
24+
*/
25+
abstract public static function getName(): string;
1626
}

src/Elements/InternalFunctions/InternalFunction.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,26 @@
77
abstract class InternalFunction extends \Ezweb\Workflow\Elements\Element
88
{
99
/**
10-
* @var array<\Ezweb\Workflow\Elements\Types\Type>
10+
* @var \Ezweb\Workflow\Elements\Types\Type[]
1111
*/
1212
protected array $args;
1313

14+
/**
15+
* @return string
16+
*/
1417
abstract public static function getName(): string;
1518

19+
/**
20+
* @param mixed[] $vars
21+
* @return mixed
22+
*/
1623
abstract public function getResult(array $vars);
1724

18-
public function addArgs(\Ezweb\Workflow\Elements\Types\Type $arg)
25+
/**
26+
* @param \Ezweb\Workflow\Elements\Types\Type $arg
27+
* @return $this
28+
*/
29+
public function addArgs(\Ezweb\Workflow\Elements\Types\Type $arg): self
1930
{
2031
$this->args[] = $arg;
2132
return $this;

src/Elements/Operators/Equal.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
<?php
22

3-
43
namespace Ezweb\Workflow\Elements\Operators;
54

6-
75
class Equal extends Operator
86
{
97
public static function getName(): string
108
{
119
return 'equal';
1210
}
1311

14-
public function getResult(array $vars)
12+
/**
13+
* @param mixed[] $vars
14+
* @return bool
15+
*/
16+
public function getResult(array $vars): bool
1517
{
16-
if (empty($this->operands)) {
18+
if (count($this->operands) === 0) {
1719
throw new \RuntimeException('No operands');
1820
}
1921
// get first element to initialize value to check
@@ -26,4 +28,4 @@ public function getResult(array $vars)
2628
}
2729
return true;
2830
}
29-
}
31+
}
Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,32 @@
11
<?php
22

3-
43
namespace Ezweb\Workflow\Elements\Operators;
54

6-
75
abstract class Operator extends \Ezweb\Workflow\Elements\Element
86
{
97
/**
108
* @var array<\Ezweb\Workflow\Elements\Types\Type>
119
*/
1210
protected array $operands;
1311

12+
/**
13+
* @return string
14+
*/
1415
abstract public static function getName(): string;
16+
17+
/**
18+
* @param mixed[] $vars
19+
* @return mixed
20+
*/
1521
abstract public function getResult(array $vars);
1622

23+
/**
24+
* @param \Ezweb\Workflow\Elements\Types\Type $value
25+
* @return $this
26+
*/
1727
public function addOperand(\Ezweb\Workflow\Elements\Types\Type $value)
1828
{
1929
$this->operands[] = $value;
2030
return $this;
2131
}
22-
}
32+
}

src/Elements/Types/Condition/Operators/All.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ public static function getName(): string
99
}
1010

1111
/**
12-
* @param array $vars
12+
* @param mixed[] $vars
1313
* @return bool
1414
*/
15-
public function getResult(array $vars)
15+
public function getResult(array $vars): bool
1616
{
1717
foreach ($this->operands as $operand) {
1818
if ($operand->getResult($vars) !== true) {

src/Elements/Types/Condition/Operators/Any.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ public static function getName(): string
1111
return 'any';
1212
}
1313

14-
public function getResult(array $vars)
14+
/**
15+
* @param mixed[] $vars
16+
* @return bool
17+
*/
18+
public function getResult(array $vars): bool
1519
{
1620
foreach ($this->operands as $operand) {
1721
if ($operand->getResult($vars) === true) {

src/Elements/Types/Condition/Operators/Operator.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,17 @@
33
namespace Ezweb\Workflow\Elements\Types\Condition\Operators;
44

55
abstract class Operator extends \Ezweb\Workflow\Elements\Types\Type
6+
67
{
8+
/**
9+
* @var \Ezweb\Workflow\Elements\Types\Type[]
10+
*/
711
protected array $operands;
812

13+
/**
14+
* @param \Ezweb\Workflow\Elements\Types\Type $value
15+
* @return $this
16+
*/
917
public function addOperand(\Ezweb\Workflow\Elements\Types\Type $value)
1018
{
1119
$this->operands[] = $value;

src/Elements/Types/ParentTypes/Condition.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@ class Condition extends ParentType
66
{
77
protected \Ezweb\Workflow\Elements\Types\Condition\Operators\Operator $operator;
88

9+
/**
10+
* @inheritDoc
11+
*/
912
public static function getName(): string
1013
{
1114
return 'condition';
1215
}
1316

1417
public static function loadFromConfig(\stdClass $config): self
1518
{
16-
$instance = new static();
19+
$instance = new self();
1720
$operatorClassName = self::$typeProviders->getClass($config->operator);
1821
$instance->operator = new $operatorClassName();
1922
return $instance;
@@ -26,7 +29,11 @@ public function addValue(\Ezweb\Workflow\Elements\Types\Type $value): ParentType
2629
return $this;
2730
}
2831

29-
public function getResult(array $vars)
32+
/**
33+
* @param mixed[] $vars
34+
* @return bool
35+
*/
36+
public function getResult(array $vars): bool
3037
{
3138
return $this->operator->getResult($vars);
3239
}

src/Elements/Types/ParentTypes/InternalFunction.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ public static function getName(): string
1111
return 'internalFunction';
1212
}
1313

14+
/**
15+
* @param mixed[] $vars
16+
* @return mixed
17+
*/
1418
public function getResult(array $vars)
1519
{
1620
return $this->function->getResult($vars);
@@ -25,7 +29,7 @@ public function addValue(\Ezweb\Workflow\Elements\Types\Type $value): ParentType
2529

2630
public static function loadFromConfig(\stdClass $config): self
2731
{
28-
$instance = new static();
32+
$instance = new self();
2933
$className = self::$internalFunctionProvider->getClass($config->name);
3034
$instance->function = new $className();
3135
return $instance;

src/Elements/Types/ParentTypes/Operator.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public static function getName(): string
1313

1414
public static function loadFromConfig(\stdClass $config): self
1515
{
16-
$instance = new static();
16+
$instance = new self();
1717
$operatorClass = self::$operatorProvider->getClass($config->operator);
1818
$instance->operator = new $operatorClass();
1919
return $instance;
@@ -26,7 +26,9 @@ public function addValue(\Ezweb\Workflow\Elements\Types\Type $value): ParentType
2626
return $this;
2727
}
2828

29-
29+
/**
30+
* @inheritDoc
31+
*/
3032
public function getResult(array $vars)
3133
{
3234
return $this->operator->getResult($vars);

0 commit comments

Comments
 (0)