Passed
Push — master ( 202822...ce601f )
by Nils
02:41
created

DaemonCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 30
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 22 3
1
<?php
2
3
namespace Startwind\Inventorio\Command;
4
5
use Startwind\Inventorio\Remote\RemoteConnect;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
8
9
class DaemonCommand extends InventorioCommand
10
{
11
    protected static $defaultName = 'daemon';
12
    protected static $defaultDescription = 'Start long running daemon';
13
14
    /**
15
     * @inheritDoc
16
     */
17
    protected function execute(InputInterface $input, OutputInterface $output): int
18
    {
19
        $this->initConfiguration($input->getOption('configFile'));
20
21
        $lastRun = time() - 7200;
22
23
        $remoteConnect = new RemoteConnect(
24
            $this->config->getInventorioServer(),
25
            $this->getServerId(),
26
            $this->config->getCommands()
27
        );
28
29
        while (true) {
30
            if ($lastRun < time() - 3600) {
31
                $command = $this->getApplication()->find('collect');
32
                $command->run($input, $output);
33
                $lastRun = time();
34
            }
35
36
            $remoteConnect->run();
37
38
            sleep(10);
39
        }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return integer. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
40
    }
41
}
42