for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of the PHPProm package.
*
* (c) Philip Lehmann-Böhm <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPProm\Storage;
class Memcached implements StorageInterface {
protected $memcached;
protected $prefix;
public function __construct($host, $port = 11211, $prefix = 'PHPProm:', $weight = 0) {
$this->memcached = new \Memcached();
$this->memcached->addServer($host, $port, $weight);
$this->prefix = $prefix;
}
public function storeMeasurement($prefix, $key, $value) {
$this->memcached->set($this->prefix.$prefix.':'.$key, $value);
public function getMeasurements($prefix, array $keys) {
$measurements = [];
$prefixedKeys = array_map(function($key) use ($prefix) {
return $this->prefix.$prefix.':'.$key;
}, $keys);
foreach ($this->memcached->getMulti($prefixedKeys) as $key => $value) {
$unprefixedKey = substr($key, strlen($this->prefix) + strlen($prefix) + 1);
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
$a = "a"; $ab = "ab"; $abc = "abc";
will produce issues in the first and second line, while this second example
will produce no issues.
$measurements[$unprefixedKey] = $value !== false ? (float)$value : 'Nan';
return $measurements;
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.