Completed
Push — 2.0 ( 14c778...b5ef61 )
by Marco
11:18
created

Runner::getLaggerTimeout()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 10
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 10
loc 10
rs 9.4285
cc 1
eloc 5
nc 1
nop 1
1
<?php namespace Comodojo\Extender\Jobs;
2
3
use \Comodojo\Extender\Components\Niceness;
4
use \Comodojo\Dispatcher\Components\Configuration;
5
use \Psr\Log\LoggerInterface;
6
7
/**
8
 * Job runner
9
 *
10
 * @package     Comodojo extender
11
 * @author      Marco Giovinazzi <[email protected]>
12
 * @license     GPL-3.0+
13
 *
14
 * LICENSE:
15
 * 
16
 * This program is free software: you can redistribute it and/or modify
17
 * it under the terms of the GNU Affero General Public License as
18
 * published by the Free Software Foundation, either version 3 of the
19
 * License, or (at your option) any later version.
20
 *
21
 * This program is distributed in the hope that it will be useful,
22
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 * GNU Affero General Public License for more details.
25
 *
26
 * You should have received a copy of the GNU Affero General Public License
27
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28
 */
29
30
class Runner {
31
32
    protected $configuration;
33
    
34
    protected $logger;
35
    
36
    protected $niceness;
37
    
38
    protected $lagger_timeout = 5;
39
40
    public function __construct(Configuration $configuration, LoggerInterface $logger) {
41
        
42
        // init components
43
        $this->configuration = $configuration;
44
        
45
        $this->logger = $logger;
46
        
47
        $this->niceness = new Niceness($this->logger);
48
        
49
        // retrieve parameters
50
        
51
        $this->lagger_timeout = self::getLaggerTimeout($this->configuration);
52
        
53
        $this->multithread = $configuration->get('multithread') === true;
0 ignored issues
show
Bug introduced by
The property multithread does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
54
        
55
    }
56
    
57
    
58
    
59
    
60
    
61
    
62
    
63 View Code Duplication
    private static function getLaggerTimeout(Configuration $configuration) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
64
        
65
        return filter_var($configuration->get('child-lagger-timeout'), FILTER_VALIDATE_INT, array(
66
            'options' => array(
67
                'default' => 5,
68
                'min_range' => 0
69
            )
70
        ));
71
        
72
    }
73
    
74
}
75