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.

BasicWorkflowFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 0
cbo 5
dl 0
loc 32
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B createService() 0 18 5
1
<?php
2
/**
3
 * @link https://github.com/old-town/workflow-zf2
4
 * @author  Malofeykin Andrey  <[email protected]>
5
 */
6
namespace  OldTown\Workflow\ZF2\Factory;
7
8
use Zend\Mvc\Application;
9
use Zend\ServiceManager\FactoryInterface;
10
use Zend\ServiceManager\MutableCreationOptionsInterface;
11
use Zend\ServiceManager\MutableCreationOptionsTrait;
12
use Zend\ServiceManager\ServiceLocatorInterface;
13
use OldTown\Workflow\Basic\BasicWorkflow;
14
use OldTown\Workflow\ZF2\Event\CallerEvent;
15
16
/**
17
 * Class PluginMessageAbstractFactory
18
 *
19
 * @package OldTown\EventBus\Message
20
 */
21
class BasicWorkflowFactory implements FactoryInterface, MutableCreationOptionsInterface
22
{
23
    use MutableCreationOptionsTrait;
24
25
    /**
26
     * @param ServiceLocatorInterface $serviceLocator
27
     *
28
     * @return BasicWorkflow
29
     *
30
     * @throws Exception\RuntimeException
31
     * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
32
     * @throws \OldTown\Workflow\Exception\InternalWorkflowException
33
     */
34
    public function createService(ServiceLocatorInterface $serviceLocator)
35
    {
36
        $caller = false;
37
        $appSm = method_exists($serviceLocator, 'getServiceLocator') ? call_user_func([$serviceLocator, 'getServiceLocator']) : null;
38
        if ($appSm && $appSm->has('Application')) {
39
            /** @var Application $app */
40
            $app = $appSm->get('Application');
41
            $callerEvent = new CallerEvent();
42
            $app->getEventManager()->trigger(CallerEvent::EVENT_RESOLVE_CALLER, $callerEvent);
43
            if ($callerEvent->getCaller()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $callerEvent->getCaller() of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
44
                $caller = $callerEvent->getCaller();
45
            }
46
        }
47
48
        $w = new BasicWorkflow($caller);
0 ignored issues
show
Security Bug introduced by
It seems like $caller defined by false on line 36 can also be of type false; however, OldTown\Workflow\Basic\B...Workflow::__construct() does only seem to accept string, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
49
50
        return $w;
51
    }
52
}
53