GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

PhpShellConditionProvider   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 72.72%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
c 2
b 0
f 0
lcom 0
cbo 4
dl 0
loc 53
ccs 16
cts 22
cp 0.7272
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
C passesCondition() 0 39 7
1
<?php
2
/**
3
 * @link    https://github.com/old-town/old-town-workflow
4
 * @author  Malofeykin Andrey  <[email protected]>
5
 */
6
namespace OldTown\Workflow\Util\PhpShell;
7
8
use OldTown\PropertySet\PropertySetInterface;
9
use OldTown\Workflow\ConditionInterface;
10
use OldTown\Workflow\Exception\WorkflowException;
11
use OldTown\Workflow\Spi\WorkflowEntryInterface;
12
use OldTown\Workflow\TransientVars\TransientVarsInterface;
13
use OldTown\Workflow\Util\TextUtils;
14
use OldTown\Workflow\WorkflowContextInterface;
15
16
17
/**
18
 * Class PhpShellConditionProvider
19
 *
20
 * @package OldTown\Workflow\Util\PhpShell
21
 */
22
class  PhpShellConditionProvider implements ConditionInterface, PhpShellProviderInterface
23
{
24
    /**
25
     *
26
     * @param TransientVarsInterface $transientVars
27
     * @param array $args
28
     * @param PropertySetInterface $ps
29
     * @return bool
30
     *
31
     * @throws \OldTown\Workflow\Exception\WorkflowException
32
     * @throws \OldTown\Workflow\Exception\RuntimeException
33
     * @throws \OldTown\Workflow\Exception\InvalidArgumentException
34
     */
35 11
    public function passesCondition(TransientVarsInterface $transientVars, array $args = [], PropertySetInterface $ps)
36
    {
37 11
        $script = array_key_exists(static::PHP_SCRIPT, $args) ? $args[static::PHP_SCRIPT] : '';
38
39
        /**@var WorkflowContextInterface $context */
40 11
        $context = $transientVars->offsetExists('context')  ? $transientVars['context'] : null;
41
42
        /**@var WorkflowEntryInterface $entry */
43 11
        $entry = $transientVars->offsetExists('entry')  ? $transientVars['entry'] : null;
44
45
46 11
        $i = new Interpreter($script);
47
48
        try {
49 11
            $i->setContextParam('entry', $entry);
50 11
            $i->setContextParam('context', $context);
51 11
            $i->setContextParam('transientVars', $transientVars);
52 11
            $i->setContextParam('propertySet', $ps);
53 11
            $i->setContextParam('args', $args);
54
55
56 11
            $o = $i->evalScript();
57
58 11
            if (null === $o) {
59
                return false;
60
            } else {
61 11
                $oStr = $o;
62 11
                if (!settype($o, 'string')) {
63
                    $errMsg = 'Результат скрипта должен быть строкой либо пребразовываться в строковое значение';
64
                    throw new WorkflowException($errMsg);
65
                }
66 11
                $result = TextUtils::parseBoolean($oStr);
0 ignored issues
show
Bug Compatibility introduced by
The expression \OldTown\Workflow\Util\T...s::parseBoolean($oStr); of type boolean|string adds the type string to the return on line 67 which is incompatible with the return type declared by the interface OldTown\Workflow\Conditi...erface::passesCondition of type boolean.
Loading history...
67 11
                return $result;
68
            }
69
        } catch (\Exception $e) {
70
            $errMsg = 'Ошибка выполнения скрипта-условия';
71
            throw new WorkflowException($errMsg, $e->getCode(), $e);
72
        }
73
    }
74
}
75