Completed
Push — 2.0 ( ee0168...76e968 )
by Marco
11:26
created

ExtenderDaemon::__construct()   B

Complexity

Conditions 3
Paths 1

Size

Total Lines 25
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 12
nc 1
nop 4
1
<?php namespace Comodojo\Extender;
2
3
use \Comodojo\Extender\Workers\ScheduleWorker;
4
use \Comodojo\Extender\Workers\QueueWorker;
5
use \Comodojo\Daemon\Daemon as AbstractDaemon;
6
use \Comodojo\Dispatcher\Traits\EventsTrait;
7
use \Comodojo\Dispatcher\Traits\LoggerTrait;
8
use \Comodojo\Dispatcher\Traits\CacheTrait;
9
use \Comodojo\Dispatcher\Traits\ConfigurationTrait;
10
use \Comodojo\Foundation\Events\Manager as EventsManager;
11
use \Comodojo\Foundation\Base\Configuration;
12
use \Comodojo\SimpleCache\Manager as SimpleCacheManager;
13
use \Comodojo\Foundation\Logging\Manager as LogManager;
14
use \Psr\Log\LoggerInterface;
15
16
class ExtenderDaemon extends AbstractDaemon {
17
18
    use ConfigurationTrait;
19
    use EventsTrait;
20
    use LoggerTrait;
21
    use CacheTrait;
22
23
    protected static $default_properties = array(
24
        'pidfile' => 'extender.pid',
25
        'socketfile' => 'unix://extender.sock',
26
        'socketbuffer' => 8192,
27
        'sockettimeout' => 15,
28
        'niceness' => 0,
29
        'arguments' => '\\Comodojo\\Daemon\\Console\\DaemonArguments',
30
        'description' => 'Extender Daemon'
31
    );
32
33
    public function __construct(
34
        array $configuration = [],
35
        EventsManager $events = null,
36
        SimpleCacheManager $cache = null,
37
        LoggerInterface $logger = null
38
    ) {
39
40
        $this->configuration = new Configuration(self::$default_properties);
41
        $this->configuration->merge($configuration);
42
43
        // $this->logger = is_null($logger) ? LogManager::createFromConfiguration($this->configuration)->getLogger() : $logger;
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
44
45
        try {
0 ignored issues
show
Unused Code introduced by
This try statement is empty and can be removed.

This check looks for try blocks that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

If there is nothing in the try then the catch block can never be executed either. Thus, these try statements can be removed completely.

Loading history...
46
            // init other components
47
            //$this->setEvents(is_null($events) ? EventsManager::create($this->logger) : $events);
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
48
49
        } catch (Exception $e) {
0 ignored issues
show
Unused Code introduced by
catch (\Comodojo\Extende...n $e) { throw $e; } does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
Bug introduced by
The class Comodojo\Extender\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
50
            throw $e;
51
        }
52
53
        parent::__construct($this->configuration->get(), $logger, $events);
54
55
        $this->setCache(is_null($cache) ? SimpleCacheManager::createFromConfiguration($this->configuration, $this->logger) : $cache);
56
57
    }
58
59
    public function setup() {
60
61
        // add workers
62
        $manager = $this->getWorkers();
63
        $schedule_worker = new ScheduleWorker("schedule");
64
        $queue_worker = new QueueWorker("queue");
65
        $manager->install($schedule_worker, 1, true)
66
            ->install($queue_worker, 1, true);
67
68
    }
69
70
}
71