Kahlan\Reporter\Coverage\Metrics::add PHP 메소드

add() 공개 메소드

Adds some metrics to the current metrics.
public add ( string $name, $metrics )
$name string The name reference of the metrics. Possible values are: `'namespace'`, `'class' or 'function'.
    public function add($name, $metrics)
    {
        $parts = $this->_parseName($name);
        $this->_merge($metrics);
        $current = $this;
        $length = count($parts);
        foreach ($parts as $index => $part) {
            list($name, $type) = $part;
            if (!isset($current->_children[$name])) {
                $current->_children[$name] = new static(['name' => $name, 'parent' => $current, 'type' => $type]);
            }
            uksort($current->_children, function ($a, $b) {
                $isFunction1 = substr($a, -2) === '()';
                $isFunction2 = substr($b, -2) === '()';
                if ($isFunction1 === $isFunction2) {
                    return strcmp($a, $b);
                }
                return $isFunction1 ? -1 : 1;
            });
            $current = $current->_children[$name];
            $current->_merge($metrics, $index === $length - 1);
        }
    }