PhpInfoCollector::trimVersion()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
namespace LeKoala\DebugBar\Collector;
4
5
/**
6
 * Extends the default PhpInfoCollector to trim long PHP version numbers
7
 */
8
class PhpInfoCollector extends \DebugBar\DataCollector\PhpInfoCollector
9
{
10
    public function collect()
11
    {
12
        $metrics = parent::collect();
13
        $metrics['version'] = $this->trimVersion($metrics['version']);
14
        return $metrics;
15
    }
16
17
    /**
18
     * Given a PHP_VERSION constant value, trim any "extra" meta information from the end, returning the major, minor
19
     * and patch release of the version. Will fall back to returning the input if the matching fails.
20
     *
21
     * @param string $version
22
     * @return string
23
     */
24
    protected function trimVersion($version)
25
    {
26
        preg_match('/^\d+\.\d+\.\d+/', $version, $matches);
27
        return !empty($matches[0]) ? $matches[0] : $version;
28
    }
29
}
30