Skip to content

Commit

Permalink
[HttpKernel] fixed CS
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Mar 3, 2012
1 parent 8f72183 commit c4ded6a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 36 deletions.
64 changes: 29 additions & 35 deletions src/Symfony/Component/HttpKernel/Profiler/RedisProfilerStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Redis;

/**
* RedisProfilerStorage stores profiling information in a Redis.
* RedisProfilerStorage stores profiling information in Redis.
*
* @author Andrej Hudec <pulzarraider@gmail.com>
*/
Expand All @@ -33,10 +33,10 @@ class RedisProfilerStorage implements ProfilerStorageInterface
/**
* Constructor.
*
* @param string $dsn A data source name
* @param string $username
* @param string $password
* @param int $lifetime The lifetime to use for the purge
* @param string $dsn A data source name
* @param string $username Not used
* @param string $password Not used
* @param int $lifetime The lifetime to use for the purge
*/
public function __construct($dsn, $username = '', $password = '', $lifetime = 86400)
{
Expand All @@ -51,17 +51,14 @@ public function find($ip, $url, $limit, $method)
{
$indexName = $this->getIndexName();

$indexContent = $this->getValue($indexName, Redis::SERIALIZER_NONE);

if (!$indexContent) {
if (!$indexContent = $this->getValue($indexName, Redis::SERIALIZER_NONE)) {
return array();
}

$profileList = explode("\n", $indexContent);
$result = array();

foreach ($profileList as $item) {

if ($limit === 0) {
break;
}
Expand Down Expand Up @@ -91,6 +88,7 @@ public function find($ip, $url, $limit, $method)
if ($a['time'] === $b['time']) {
return 0;
}

return $a['time'] > $b['time'] ? -1 : 1;
});

Expand All @@ -102,10 +100,7 @@ public function find($ip, $url, $limit, $method)
*/
public function purge()
{
//dangerous:
//$this->getRedis()->flushDB();

//delete only items from index
// delete only items from index
$indexName = $this->getIndexName();

$indexContent = $this->getValue($indexName, Redis::SERIALIZER_NONE);
Expand All @@ -119,13 +114,11 @@ public function purge()
$result = array();

foreach ($profileList as $item) {

if ($item == '') {
continue;
}

$pos = strpos($item, "\t");
if (false !== $pos) {
if (false !== $pos = strpos($item, "\t")) {
$result[] = $this->getItemName(substr($item, 0, $pos));
}
}
Expand Down Expand Up @@ -180,7 +173,7 @@ public function write(Profile $profile)
$profile->getUrl(),
$profile->getTime(),
$profile->getParentToken(),
)) . "\n";
))."\n";

return $this->appendValue($indexName, $indexRow, $this->lifetime);
}
Expand All @@ -189,22 +182,22 @@ public function write(Profile $profile)
}

/**
* Internal convenience method that returns the instance of Redis
* Internal convenience method that returns the instance of Redis.
*
* @return Redis
*/
protected function getRedis()
{
if (null === $this->redis) {
if (!preg_match('#^redis://(?(?=\[.*\])\[(.*)\]|(.*)):(.*)$#', $this->dsn, $matches)) {
throw new \RuntimeException('Please check your configuration. You are trying to use Redis with an invalid dsn. "' . $this->dsn . '". The expected format is redis://host:port, redis://127.0.0.1:port, redis://[::1]:port');
throw new \RuntimeException(sprintf('Please check your configuration. You are trying to use Redis with an invalid dsn. "%s". The expected format is redis://host:port, redis://127.0.0.1:port, redis://[::1]:port', $this->dsn));
}

$host = $matches[1]?: $matches[2];
$host = $matches[1] ?: $matches[2];
$port = $matches[3];

if (!extension_loaded('redis')) {
throw new \RuntimeException('RedisProfilerStorage requires redis extension to be loaded.');
throw new \RuntimeException('RedisProfilerStorage requires that the redis extension is loaded.');
}

$redis = new Redis;
Expand Down Expand Up @@ -251,7 +244,7 @@ private function createProfileFromData($token, $data, $parent = null)
}

/**
* Get item name
* Gets the item name.
*
* @param string $token
*
Expand All @@ -269,7 +262,7 @@ private function getItemName($token)
}

/**
* Get name of index
* Gets the name of the index.
*
* @return string
*/
Expand All @@ -296,10 +289,10 @@ private function isItemNameValid($name)
}

/**
* Retrieve item from the Redis server
* Retrieves an item from the Redis server.
*
* @param string $key
* @param int $serializer
* @param int $serializer
*
* @return mixed
*/
Expand All @@ -312,14 +305,14 @@ private function getValue($key, $serializer = Redis::SERIALIZER_NONE)
}

/**
* Store an item on the Redis server under the specified key
* Stores an item on the Redis server under the specified key.
*
* @param string $key
* @param mixed $value
* @param int $expiration
* @param int $serializer
* @param mixed $value
* @param int $expiration
* @param int $serializer
*
* @return boolean
* @return Boolean
*/
private function setValue($key, $value, $expiration = 0, $serializer = Redis::SERIALIZER_NONE)
{
Expand All @@ -330,13 +323,13 @@ private function setValue($key, $value, $expiration = 0, $serializer = Redis::SE
}

/**
* Append data to an existing item on the Redis server
* Appends data to an existing item on the Redis server.
*
* @param string $key
* @param string $value
* @param int $expiration
* @param int $expiration
*
* @return boolean
* @return Boolean
*/
private function appendValue($key, $value, $expiration = 0)
{
Expand All @@ -345,18 +338,19 @@ private function appendValue($key, $value, $expiration = 0)

if ($redis->exists($key)) {
$redis->append($key, $value);

return $redis->setTimeout($key, $expiration);
}

return $redis->setex($key, $expiration, $value);
}

/**
* Remove specified keys
* Removes the specified keys.
*
* @param array $key
*
* @return boolean
* @return Boolean
*/
private function delete(array $keys)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected function setUp()

self::$storage->purge();

} catch(\Exception $e) {
} catch (\Exception $e) {
self::$storage = false;
$this->markTestSkipped('RedisProfilerStorageTest requires that there is a Redis server present on localhost');
}
Expand Down

0 comments on commit c4ded6a

Please sign in to comment.