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::passesCondition()   C
last analyzed

Complexity

Conditions 7
Paths 88

Size

Total Lines 39
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 7.9936

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 39
ccs 16
cts 22
cp 0.7272
rs 6.7272
cc 7
eloc 24
nc 88
nop 3
crap 7.9936
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