for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Kraken\Redis;
use InvalidArgumentException;
class Config
{
public function __construct($target)
if ($target === null) {
$target = 'tcp://127.0.0.1';
}
if (strpos($target, '://') === false) {
$target = 'tcp://' . $target;
$parts = parse_url($target);
if ($parts === false || !isset($parts['host']) || $parts['scheme'] !== 'tcp') {
throw new InvalidArgumentException('Given URL can not be parsed');
if (!isset($parts['port'])) {
$parts['port'] = 6379;
$this->port = 6379;
port
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
if ($parts['host'] === 'localhost') {
$parts['host'] = '127.0.0.1';
$this->host = '127.0.0.1';
host
$auth = null;
if (isset($parts['user'])) {
$auth = $parts['user'];
$this->auth = $auth;
auth
if (isset($parts['pass'])) {
$auth .= ':' . $parts['pass'];
if ($auth !== null) {
$parts['auth'] = $auth;
if (isset($parts['path']) && $parts['path'] !== '') {
$parts['db'] = substr($parts['path'], 1);
unset($parts['scheme'], $parts['user'], $parts['pass'], $parts['path']);
$this->host = $parts['host'];
$this->port = $parts['port'];
$this->db = $parts['db'];
db
public function getHost()
public function getPort()
public function getDb()
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: