Test Failed
Push — trunk ( db071f...8d464a )
by SuperNova.WS
06:33
created

Watchdog   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A checkConfigTimeDiff() 0 9 4
1
<?php
2
/**
3
 * Created by Gorlum 15.06.2017 5:07
4
 */
5
6
namespace Core;
7
8
9
use Common\GlobalContainer;
10
11
class Watchdog {
12
  /**
13
   * @var GlobalContainer $gc
14
   */
15
  protected $gc;
16
17
  /**
18
   * @var \classConfig $config
19
   */
20
  protected $config;
21
22
  public function __construct(GlobalContainer $gc) {
23
    $this->gc = $gc;
24
    $this->config = $this->gc->config;
0 ignored issues
show
Documentation introduced by
The property config does not exist on object<Common\GlobalContainer>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
25
  }
26
27
  /**
28
   * @param string   $configName - config record name
29
   * @param int      $timeDiff - interval from SN_TIME_NOW in seconds
30
   * @param callable $callable - function to call when condition is met
31
   * @param int      $configType - type of config record - unixtime or Sql timestamp
32
   * @param bool     $forceLoad - should config value be read from DB
33
   */
34
  public function checkConfigTimeDiff($configName, $timeDiff, $callable, $configType = WATCHDOG_TIME_UNIX, $forceLoad = false) {
35
    $configValue = $forceLoad ? $this->config->db_loadItem($configName) : $this->config[$configName];
36
    $configType == WATCHDOG_TIME_SQL ? $configValue = strtotime($configValue, SN_TIME_NOW) : false;
37
38
    if(SN_TIME_NOW - $configValue > $timeDiff) {
39
      $callable();
40
    }
41
42
  }
43
44
}
45