Skip to content

Commit

Permalink
- fixed some phpcs issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mike.pultz committed Apr 23, 2011
1 parent 241ddc8 commit f8f6f25
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 76 deletions.
88 changes: 42 additions & 46 deletions Net/DNS2.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class Net_DNS2
/*
* enable cache; either "shared", "file" or "none"
*/
public $cache_type = "shared";
public $cache_type = 'none';

/*
* file name to use for shared memory segment or file cache
Expand Down Expand Up @@ -162,14 +162,14 @@ class Net_DNS2
protected $cache = null;

/*
* the last erro message returned by the sockets class
* internal setting for enabling cache
*/
private $_last_socket_error = '';
protected $use_cache = false;

/*
* internal setting for enabling cache
* the last erro message returned by the sockets class
*/
public $_use_cache = false;
private $_last_socket_error = '';

/**
* Constructor - base constructor for the Resolver and Updater
Expand Down Expand Up @@ -209,33 +209,32 @@ public function __construct(array $options = null)
// make sure it's been initialized
//
switch($this->cache_type) {
case 'shared':
if (extension_loaded("shmop")) {
case 'shared':
if (extension_loaded("shmop")) {

$this->cache = new Net_DNS2_Cache_Shm;
$this->_use_cache = true;
} else {
$this->cache = new Net_DNS2_Cache_Shm;
$this->use_cache = true;
} else {

throw new Net_DNS2_Exception(
'shmop library is not available for cache'
);
}
break;
case 'file':
throw new Net_DNS2_Exception(
'shmop library is not available for cache'
);
}
break;
case 'file':

$this->cache = new Net_DNS2_Cache_File;
$this->_use_cache = true;
$this->cache = new Net_DNS2_Cache_File;
$this->use_cache = true;

break;
case 'none':
$this->_use_cache = false;
break;
default:
break;
case 'none':
$this->use_cache = false;
break;
default:

throw new Net_DNS2_Exception(
'un-supported cache type: ' . $this->cache_type
);
break;
throw new Net_DNS2_Exception(
'un-supported cache type: ' . $this->cache_type
);
}
}

Expand Down Expand Up @@ -354,6 +353,8 @@ public function setServers($nameservers)
/**
* checks the list of name servers to make sure they're set
*
* @param mixed $default a path to a resolv.conf file or an array of servers.
*
* @return boolean
* @throws Net_DNS2_Exception
* @access protected
Expand Down Expand Up @@ -399,13 +400,13 @@ public function signTSIG($keyname, $signature = "")

$this->auth_signature = $keyname;

//
// otherwise create the TSIG RR, but don't add it just yet; TSIG needs
// to be added as the last additional entry- so we'll add it just
// before we send.
//
} else {

//
// otherwise create the TSIG RR, but don't add it just yet; TSIG needs
// to be added as the last additional entry- so we'll add it just
// before we send.
//
$this->auth_signature = Net_DNS2_RR::fromString(
strtolower(trim($keyname)) .
' TSIG '. $signature
Expand All @@ -418,8 +419,7 @@ public function signTSIG($keyname, $signature = "")
/**
* adds a SIG RR object for authentication
*
* @param string $keyname the key name to use for the TSIG RR
* @param string $signature the key to sign the request.
* @param string $filename the name of a file to load the signature from.
*
* @return boolean
* @throws Net_DNS2_Exception
Expand All @@ -446,13 +446,10 @@ public function signSIG0($filename)

$this->auth_signature = $filename;

//
// otherwise, it's filename which needs to be parsed and processed.
//
} else {

//
// parse the signature file
// otherwise, it's filename which needs to be parsed and processed.
//
$private = new Net_DNS2_PrivateKey($filename);

Expand Down Expand Up @@ -500,14 +497,13 @@ public function signSIG0($filename)
// only RSAMD5 and RSASHA1 are supported for SIG(0)
//
switch($this->auth_signature->algorithm) {
case Net_DNS2_Lookups::DNSSEC_ALGORITHM_RSAMD5:
case Net_DNS2_Lookups::DNSSEC_ALGORITHM_RSASHA1:
//case Net_DNS2_Lookups::DNSSEC_ALGORITHM_DSA:
break;
default:
throw new Net_DNS2_Exception(
'only asymmetric algorithms work with SIG(0)!'
);
case Net_DNS2_Lookups::DNSSEC_ALGORITHM_RSAMD5:
case Net_DNS2_Lookups::DNSSEC_ALGORITHM_RSASHA1:
break;
default:
throw new Net_DNS2_Exception(
'only asymmetric algorithms work with SIG(0)!'
);
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion Net/DNS2/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ protected function resize()
//
if (strlen($cache) > $this->cache_size) {

while(strlen($cache) > $this->cache_size) {
while (strlen($cache) > $this->cache_size) {

//
// go through the data, and remove the entries closed to
Expand Down
6 changes: 4 additions & 2 deletions Net/DNS2/Cache/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ class Net_DNS2_Cache_File extends Net_DNS2_Cache
/**
* open a cache object
*
* @param string $cache_file path to a file to use for cache storage
* @param string $cache_file path to a file to use for cache storage
* @param integer $size the size of the shared memory segment to create
*
* @throws Net_DNS2_Exception
* @access public
* @return void
*
*/
public function open($cache_file, $size)
Expand All @@ -81,7 +82,8 @@ public function open($cache_file, $size)
// check that the file exists first
//
if ( (file_exists($this->cache_file) == true)
&& (filesize($this->cache_file) > 0) ) {
&& (filesize($this->cache_file) > 0)
) {

//
// open the file for reading
Expand Down
5 changes: 3 additions & 2 deletions Net/DNS2/Cache/Shm.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class Net_DNS2_Cache_Shm extends Net_DNS2_Cache
*
* @throws Net_DNS2_Exception
* @access public
* @return void
*
*/
public function open($cache_file, $size)
Expand Down Expand Up @@ -225,8 +226,8 @@ public function __destruct()
$this->_cache_id = @shmop_open(
$this->_cache_file_tok, 'c', 0644, $this->cache_size
);
if ($this->_cache_id === false)
{
if ($this->_cache_id === false) {

//
// not much to do here
//
Expand Down
5 changes: 3 additions & 2 deletions Net/DNS2/Packet/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ public function set($name, $type = 'A', $class = 'IN')
if ( (!isset(Net_DNS2_Lookups::$rr_types_by_name[$type]))
|| (!isset(Net_DNS2_Lookups::$classes_by_name[$class]))
) {
throw new InvalidArgumentException('invalid type (' . $type .
') or class (' . $class . ') specified.');
throw new InvalidArgumentException(
'invalid type (' . $type . ') or class (' . $class . ') specified.'
);
}

//
Expand Down
2 changes: 1 addition & 1 deletion Net/DNS2/PrivateKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public function parseFile($file)
if ($this->algorithm != $value) {
throw new Net_DNS2_Exception(
'Algorithm mis-match! filename is ' . $this->algorithm .
', contents say ' . $value
', contents say ' . $value
);
}
break;
Expand Down
9 changes: 6 additions & 3 deletions Net/DNS2/Question.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ public function set(Net_DNS2_Packet &$packet)
if ($packet->rdlength < ($packet->offset + 4)) {

throw new InvalidArgumentException(
'invalid question question section: to small');
'invalid question question section: to small'
);
}

//
Expand All @@ -177,7 +178,8 @@ public function set(Net_DNS2_Packet &$packet)
if ( (!isset($type_name)) || (!isset($class_name)) ) {
throw new InvalidArgumentException(
'invalid question section: invalid type (' . $type .
') or class (' . $class . ') specified.');
') or class (' . $class . ') specified.'
);
}

//
Expand Down Expand Up @@ -215,7 +217,8 @@ public function get(Net_DNS2_Packet &$packet, $offset)
if ( (!isset($type)) || (!isset($class)) ) {
throw new InvalidArgumentException(
'invalid question section: invalid type (' . $this->qtype .
') or class (' . $this->qclass . ') specified.');
') or class (' . $this->qclass . ') specified.'
);
}

return $packet->compress($this->qname, $offset) . chr($type << 8) .
Expand Down
23 changes: 15 additions & 8 deletions Net/DNS2/RR.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,12 +390,14 @@ public static function parse(Net_DNS2_Packet &$packet)
if (is_null($object['name'])) {

throw new Net_DNS2_Exception(
'failed to parse resource record: failed to expand name.');
'failed to parse resource record: failed to expand name.'
);
}
if ($packet->rdlength < ($packet->offset + 10)) {

throw new Net_DNS2_Exception(
'failed to parse resource record: packet too small.');
'failed to parse resource record: packet too small.'
);
}

//
Expand Down Expand Up @@ -433,8 +435,9 @@ public static function parse(Net_DNS2_Packet &$packet)
}
} else {

throw new Net_DNS2_Exception('un-implemented resource record type: ' .
$object['type']);
throw new Net_DNS2_Exception(
'un-implemented resource record type: ' . $object['type']
);
}

return $o;
Expand Down Expand Up @@ -516,7 +519,8 @@ public static function fromString($line)
break;
default:
throw new InvalidArgumentException(
'invalid config line provided: unknown file: ' . $value);
'invalid config line provided: unknown file: ' . $value
);
}
}

Expand Down Expand Up @@ -546,19 +550,22 @@ public static function fromString($line)
if ($o->rrFromString($values) === false) {

throw new Net_DNS2_Exception(
'failed to parse rdata for config: ' . $line);
'failed to parse rdata for config: ' . $line
);
}

} else {

throw new Net_DNS2_Exception(
'failed to create new RR record for type: ' . $type);
'failed to create new RR record for type: ' . $type
);
}

} else {

throw new Net_DNS2_Exception(
'un-implemented resource record type: '. $type);
'un-implemented resource record type: '. $type
);
}

return $o;
Expand Down
7 changes: 5 additions & 2 deletions Net/DNS2/RR/SIG.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,8 @@ protected function rrGet(Net_DNS2_Packet &$packet)
//
case Net_DNS2_Lookups::DNSSEC_ALGORITHM_DSA:
//
// DSA won't work in PHP until the OpenSSL extension has better DSA support
// DSA won't work in PHP until the OpenSSL extension has
// better DSA support
//
case Net_DNS2_Lookups::DSNSEC_ALGORITHM_RSASHA1NSEC3SHA1:
case Net_DNS2_Lookups::DNSSEC_ALGORITHM_RSASHA256:
Expand All @@ -378,7 +379,9 @@ protected function rrGet(Net_DNS2_Packet &$packet)
//
// sign the data
//
if (openssl_sign($sigdata, $this->signature, $this->private_key->instance, $algorithm) == false) {
if (openssl_sign(
$sigdata, $this->signature, $this->private_key->instance, $algorithm
) == false) {

throw new Net_DNS2_Exception(openssl_error_string());
}
Expand Down
14 changes: 9 additions & 5 deletions Net/DNS2/Resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ public function query($name, $type = 'A', $class = 'IN')
// if caching is turned on, then check then hash the question, and
// do a cache lookup.
//
$packet_hash = "";
$packet_hash = '';

if ($this->_use_cache == true) {
if ($this->use_cache == true) {

//
// open the cache
Expand All @@ -143,7 +143,9 @@ public function query($name, $type = 'A', $class = 'IN')
//
// build the key and check for it in the cache.
//
$packet_hash = md5($packet->question[0]->qname . '|' . $packet->question[0]->qtype);
$packet_hash = md5(
$packet->question[0]->qname . '|' . $packet->question[0]->qtype
);

if ($this->cache->has($packet_hash)) {

Expand All @@ -154,8 +156,10 @@ public function query($name, $type = 'A', $class = 'IN')
//
// send the packet and get back the response
//
$response = $this->sendPacket($packet, ($type == 'AXFR') ? true : $this->use_tcp);
if ($this->_use_cache == true) {
$response = $this->sendPacket(
$packet, ($type == 'AXFR') ? true : $this->use_tcp
);
if ($this->use_cache == true) {

$this->cache->put($packet_hash, $response);
}
Expand Down
Loading

0 comments on commit f8f6f25

Please sign in to comment.