Skip to content

Commit

Permalink
Use strict type comparisons
Browse files Browse the repository at this point in the history
Misc clean up and formatting
  • Loading branch information
davidwdan committed Oct 4, 2017
1 parent 5588328 commit a4f7963
Show file tree
Hide file tree
Showing 40 changed files with 57 additions and 149 deletions.
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@
},
"replace": {
"voryx/thruway-message": "1.*"
},
"require-dev": {
"phpunit/phpunit": "^5.5.4"
}
}
15 changes: 7 additions & 8 deletions src/Common/Utils.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace Thruway\Common;

/**
Expand All @@ -17,7 +16,7 @@ public static function getUniqueId()
{
$filter = 0x1fffffffffffff; // 53 bits
$randomBytes = openssl_random_pseudo_bytes(8);
list($high, $low) = array_values(unpack("N2", $randomBytes));
list($high, $low) = array_values(unpack('N2', $randomBytes));
return abs(($high << 32 | $low) & $filter);
}

Expand All @@ -29,7 +28,7 @@ public static function getUniqueId()
*/
public static function uriIsValid($uri)
{
return !!preg_match('/^([0-9a-z_]+\.)*([0-9a-z_]+)$/', $uri);
return (bool)preg_match('/^([0-9a-z_]+\.)*([0-9a-z_]+)$/', $uri);
}

/**
Expand All @@ -43,7 +42,7 @@ public static function uriIsValid($uri)
*/
public static function getDerivedKey($key, $salt, $iterations = 1000, $keyLen = 32)
{
if (function_exists("hash_pbkdf2")) {
if (function_exists('hash_pbkdf2')) {
$key = hash_pbkdf2('sha256', $key, $salt, $iterations, $keyLen, true);
} else {
// PHP v5.4 compatibility
Expand Down Expand Up @@ -72,7 +71,7 @@ public static function getDerivedKey($key, $salt, $iterations = 1000, $keyLen =
public static function compat_pbkdf2($algo, $password, $salt, $iterations, $length = 0, $rawOutput = false)
{
// check for hashing algorithm
if (!in_array(strtolower($algo), hash_algos())) {
if (!in_array(strtolower($algo), hash_algos(), true)) {
trigger_error(sprintf(
'%s(): Unknown hashing algorithm: %s',
__FUNCTION__, $algo
Expand Down Expand Up @@ -133,7 +132,7 @@ public static function compat_pbkdf2($algo, $password, $salt, $iterations, $leng
$block = $digest;
for ($j = 1; $j < $iterations; $j++) {
$digest = hash_hmac($algo, $digest, $password, true);
$block ^= $digest;
$block ^= $digest;
}
$derivedKey .= $block;
}
Expand All @@ -152,10 +151,10 @@ public static function compat_pbkdf2($algo, $password, $salt, $iterations, $leng
/**
* Changes the Precision for PHP configs that default to less than 16
*/
static public function checkPrecision()
public static function checkPrecision()
{
if (ini_get('precision') < 16) {
ini_set('precision', 16);
}
}
}
}
15 changes: 1 addition & 14 deletions src/Message/AbortMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*/
class AbortMessage extends Message
{

use DetailsTrait;

/**
Expand All @@ -33,18 +32,7 @@ public function __construct($details, $responseURI)
{
parent::__construct();

$this->setDetails($details);
$this->setResponseURI($responseURI);
}


/**
* Set response URI
*
* @param mixed $responseURI
*/
public function setResponseURI($responseURI)
{
$this->details = (object)$details;
$this->responseURI = $responseURI;
}

Expand Down Expand Up @@ -78,5 +66,4 @@ public function getAdditionalMsgFields()
{
return [(object)$this->getDetails(), $this->getResponseURI()];
}

}
7 changes: 3 additions & 4 deletions src/Message/ActionMessageInterface.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php


namespace Thruway\Message;


/**
* Interface ActionMessageInterface
*
Expand All @@ -12,7 +10,8 @@
*
* @package Thruway\Message
*/
interface ActionMessageInterface {
interface ActionMessageInterface
{
/**
* This returns the Uri so that the authorization manager doesn't have to know
* exactly the type of object to get the Uri
Expand All @@ -27,4 +26,4 @@ public function getUri();
* @return mixed
*/
public function getActionName();
}
}
5 changes: 2 additions & 3 deletions src/Message/AuthenticateMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
*/
class AuthenticateMessage extends Message
{

/**
* @var mixed
*/
Expand All @@ -28,8 +27,8 @@ class AuthenticateMessage extends Message
*/
public function __construct($signature, $extra = null)
{
$this->setSignature($signature);
$this->setExtra($extra);
$this->signature = $signature;
$this->extra = (object)$extra;
}

/**
Expand Down
7 changes: 1 addition & 6 deletions src/Message/CallMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Thruway\Message\Traits\OptionsTrait;
use Thruway\Message\Traits\RequestTrait;


/**
* Class CallMessage
* Call as originally issued by the Caller to the Dealer.
Expand All @@ -18,7 +17,6 @@
*/
class CallMessage extends Message implements ActionMessageInterface
{

use RequestTrait;
use OptionsTrait;
use ArgumentsTrait;
Expand Down Expand Up @@ -67,7 +65,6 @@ public function getAdditionalMsgFields()
$a = [$this->getRequestId(), $this->getOptions(), $this->getProcedureName()];

return array_merge($a, $this->getArgumentsForSerialization());

}

/**
Expand Down Expand Up @@ -104,8 +101,6 @@ public function getUri()
*/
public function getActionName()
{
return "call";
return 'call';
}


}
2 changes: 0 additions & 2 deletions src/Message/CancelMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
*/
class CancelMessage extends Message
{

use RequestTrait;
use OptionsTrait;

Expand Down Expand Up @@ -50,5 +49,4 @@ public function getAdditionalMsgFields()
{
return [$this->getRequestId(), (object)$this->getOptions()];
}

}
2 changes: 0 additions & 2 deletions src/Message/ChallengeMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,11 @@ public function getAuthMethod()
return $this->authMethod;
}


/**
* @param mixed $authMethod
*/
public function setAuthMethod($authMethod)
{
$this->authMethod = $authMethod;
}

}
6 changes: 2 additions & 4 deletions src/Message/ErrorMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class ErrorMessage extends Message
*/
public function __construct($errorMsgCode, $errorRequestId, $details, $errorURI, $arguments = null, $argumentsKw = null)
{

$this->setErrorRequestId($errorRequestId);
$this->setErrorMsgCode($errorMsgCode);
$this->setDetails($details);
Expand Down Expand Up @@ -94,10 +93,10 @@ public function getErrorURI()
public static function createErrorMessageFromMessage(Message $msg, $errorUri = null)
{
if ($errorUri === null) {
$errorUri = "wamp.error.unknown";
$errorUri = 'wamp.error.unknown';
}

if (method_exists($msg, "getRequestId")) {
if (method_exists($msg, 'getRequestId')) {
return new ErrorMessage($msg->getMsgCode(), $msg->getRequestId(), new \stdClass, $errorUri);
}

Expand Down Expand Up @@ -207,5 +206,4 @@ public function __toString()
{
return $this->getErrorURI();
}

}
3 changes: 1 addition & 2 deletions src/Message/EventMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
class EventMessage extends Message
{

use DetailsTrait;
use ArgumentsTrait;

Expand Down Expand Up @@ -178,4 +177,4 @@ public function setRestoringState($restoringState)
$details->_thruway_restoring_state = true;
}
}
}
}
11 changes: 4 additions & 7 deletions src/Message/GoodbyeMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Thruway\Message\Traits\DetailsTrait;


/**
* Class GoodbyeMessage
* Sent by a Peer to close a previously opened WAMP session. Must be echo'ed by the receiving Peer.
Expand All @@ -14,7 +13,6 @@
*/
class GoodbyeMessage extends Message
{

use DetailsTrait;

/**
Expand All @@ -34,7 +32,7 @@ public function __construct($details, $reason)

/**
* Set reason
*
*
* @param string $reason
*/
public function setReason($reason)
Expand All @@ -44,8 +42,8 @@ public function setReason($reason)

/**
* Get reason
*
* @return string
*
* @return string
*/
public function getReason()
{
Expand All @@ -72,5 +70,4 @@ public function getAdditionalMsgFields()
{
return [(object)$this->getDetails(), $this->getReason()];
}

}
}
13 changes: 5 additions & 8 deletions src/Message/HeartbeatMessage.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?php


namespace Thruway\Message;


class HeartbeatMessage extends Message {
class HeartbeatMessage extends Message
{
/**
* @var int
*/
Expand All @@ -23,7 +22,7 @@ class HeartbeatMessage extends Message {
* @param $incomingSeq
* @param $outgoingSeq
*/
function __construct($incomingSeq, $outgoingSeq, $discard = null)
public function __construct($incomingSeq, $outgoingSeq, $discard = null)
{
$this->setDiscard($discard);
$this->setIncomingSeq($incomingSeq);
Expand Down Expand Up @@ -51,7 +50,7 @@ public function getAdditionalMsgFields()
$a = [$this->getIncomingSeq(), $this->getOutgoingSeq()];

if (is_string($this->getDiscard())) {
array_push($a, $this->getDiscard());
$a[] = $this->getDiscard();
}

return $a;
Expand Down Expand Up @@ -104,6 +103,4 @@ public function setOutgoingSeq($outgoingSeq)
{
$this->outgoingSeq = $outgoingSeq;
}


}
}
2 changes: 0 additions & 2 deletions src/Message/HelloMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public function __construct($realm, $details)
$this->setAuthMethods($authMethods);
}


/**
* Get message code
*
Expand Down Expand Up @@ -108,5 +107,4 @@ public function setAuthMethods($authMethods)
{
$this->authMethods = $authMethods;
}

}
8 changes: 2 additions & 6 deletions src/Message/InterruptMessage.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
<?php


namespace Thruway\Message;


use Thruway\Message\Traits\OptionsTrait;
use Thruway\Message\Traits\RequestTrait;

class InterruptMessage extends Message
{

use RequestTrait;
use OptionsTrait;

/**
* @param int $requestId
* @param \stdClass $options
*/
function __construct($requestId, $options)
public function __construct($requestId, $options)
{
$this->setRequestId($requestId);
$this->setOptions($options);
Expand All @@ -43,5 +40,4 @@ public function getAdditionalMsgFields()
{
return [$this->getRequestId(), (object)$this->getOptions()];
}

}
}
Loading

0 comments on commit a4f7963

Please sign in to comment.