Skip to content

Commit

Permalink
Merge branch 'qa/13'
Browse files Browse the repository at this point in the history
Close #13
  • Loading branch information
michalbundyra committed Feb 8, 2020
2 parents 4c47a40 + 4773fed commit 0fb0825
Show file tree
Hide file tree
Showing 142 changed files with 4,413 additions and 4,360 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Expand Up @@ -45,6 +45,9 @@ matrix:
- php: 7.3
env:
- DEPS=latest
- php: 7.4
env:
- DEPS=latest

before_install:
- if [[ $TEST_COVERAGE != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -39,7 +39,7 @@
"laminas/laminas-http": "^2.7",
"laminas/laminas-servicemanager": "^2.7.8 || ^3.3",
"laminas/laminas-validator": "^2.10.1",
"phpunit/phpunit": "^5.7.23 || ^6.4.3",
"phpunit/phpunit": "^5.7.27 || ^6.5.14 || ^7.5.20",
"psr/http-message": "^1.0.1"
},
"suggest": {
Expand Down
2 changes: 0 additions & 2 deletions docs/book/http-clients.md
Expand Up @@ -127,8 +127,6 @@ namespace Laminas\Feed\Reader\Http;
class Response implements HeaderAwareResponseInterface
{
/**
* Constructor
*
* @param int $statusCode Response status code
* @param string $body Response body
* @param array $headers Response headers, if available
Expand Down
53 changes: 30 additions & 23 deletions src/PubSubHubbub/AbstractCallback.php
Expand Up @@ -21,7 +21,7 @@ abstract class AbstractCallback implements CallbackInterface
*
* @var Model\SubscriptionPersistenceInterface
*/
protected $storage = null;
protected $storage;

/**
* An instance of a class handling Http Responses. This is implemented in
Expand All @@ -30,15 +30,15 @@ abstract class AbstractCallback implements CallbackInterface
*
* @var HttpResponse|PhpResponse
*/
protected $httpResponse = null;
protected $httpResponse;

/**
* The input stream to use when retrieving the request body. Defaults to
* php://input, but can be set to another value in order to force usage
* of another input method. This should primarily be used for testing
* purposes.
*
* @var string|resource String indicates a filename or stream to open;
* @var resource|string String indicates a filename or stream to open;
* resource indicates an already created stream to use.
*/
protected $inputStream = 'php://input';
Expand All @@ -55,7 +55,7 @@ abstract class AbstractCallback implements CallbackInterface
* options for the Subscriber without calling all supported setter
* methods in turn.
*
* @param array|Traversable $options Options array or Traversable object
* @param null|array|Traversable $options Options array or Traversable object
*/
public function __construct($options = null)
{
Expand All @@ -68,7 +68,7 @@ public function __construct($options = null)
* Process any injected configuration options
*
* @param array|Traversable $options Options array or Traversable object
* @return AbstractCallback
* @return $this
* @throws Exception\InvalidArgumentException
*/
public function setOptions($options)
Expand All @@ -78,8 +78,9 @@ public function setOptions($options)
}

if (! is_array($options)) {
throw new Exception\InvalidArgumentException('Array or Traversable object'
. 'expected, got ' . gettype($options));
throw new Exception\InvalidArgumentException(
'Array or Traversable object expected, got ' . gettype($options)
);
}

if (is_array($options)) {
Expand Down Expand Up @@ -110,8 +111,7 @@ public function sendResponse()
* to background save any verification tokens associated with a subscription
* or other.
*
* @param Model\SubscriptionPersistenceInterface $storage
* @return AbstractCallback
* @return $this
*/
public function setStorage(Model\SubscriptionPersistenceInterface $storage)
{
Expand All @@ -130,8 +130,10 @@ public function setStorage(Model\SubscriptionPersistenceInterface $storage)
public function getStorage()
{
if ($this->storage === null) {
throw new Exception\RuntimeException('No storage object has been'
. ' set that subclasses Laminas\Feed\Pubsubhubbub\Model\SubscriptionPersistence');
throw new Exception\RuntimeException(
'No storage object has been set that subclasses'
. ' Laminas\Feed\Pubsubhubbub\Model\SubscriptionPersistence'
);
}
return $this->storage;
}
Expand All @@ -142,15 +144,17 @@ public function getStorage()
* (i.e. not inherited from) Laminas\Controller\Response\Http.
*
* @param HttpResponse|PhpResponse $httpResponse
* @return AbstractCallback
* @return $this
* @throws Exception\InvalidArgumentException
*/
public function setHttpResponse($httpResponse)
{
if (! $httpResponse instanceof HttpResponse && ! $httpResponse instanceof PhpResponse) {
throw new Exception\InvalidArgumentException('HTTP Response object must'
throw new Exception\InvalidArgumentException(
'HTTP Response object must'
. ' implement one of Laminas\Feed\Pubsubhubbub\HttpResponse or'
. ' Laminas\Http\PhpEnvironment\Response');
. ' Laminas\Http\PhpEnvironment\Response'
);
}
$this->httpResponse = $httpResponse;
return $this;
Expand All @@ -166,7 +170,7 @@ public function setHttpResponse($httpResponse)
public function getHttpResponse()
{
if ($this->httpResponse === null) {
$this->httpResponse = new HttpResponse;
$this->httpResponse = new HttpResponse();
}
return $this->httpResponse;
}
Expand All @@ -176,16 +180,18 @@ public function getHttpResponse()
* In other words, is this class serving one or more subscribers? How many?
* Defaults to 1 if left unchanged.
*
* @param string|int $count
* @return AbstractCallback
* @param int|string $count
* @return $this
* @throws Exception\InvalidArgumentException
*/
public function setSubscriberCount($count)
{
$count = intval($count);
if ($count <= 0) {
throw new Exception\InvalidArgumentException('Subscriber count must be'
. ' greater than zero');
throw new Exception\InvalidArgumentException(
'Subscriber count must be'
. ' greater than zero'
);
}
$this->subscriberCount = $count;
return $this;
Expand All @@ -204,6 +210,7 @@ public function getSubscriberCount()

/**
* Attempt to detect the callback URL (specifically the path forward)
*
* @return string
*/
// @codingStandardsIgnoreStart
Expand Down Expand Up @@ -267,7 +274,7 @@ protected function _getHttpHost()
/**
* Retrieve a Header value from either $_SERVER or Apache
*
* @param string $header
* @param string $header
* @return bool|string
*/
// @codingStandardsIgnoreStart
Expand All @@ -294,7 +301,7 @@ protected function _getHeader($header)
/**
* Return the raw body of the request
*
* @return string|false Raw body, or false if not present
* @return false|string Raw body, or false if not present
*/
// @codingStandardsIgnoreStart
protected function _getRawBody()
Expand All @@ -315,8 +322,8 @@ protected function _getRawBody()
private function buildCallbackUrlFromRequestUri()
{
$callbackUrl = $_SERVER['REQUEST_URI'];
$https = isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : null;
$scheme = $https === 'on' ? 'https' : 'http';
$https = isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : null;
$scheme = $https === 'on' ? 'https' : 'http';
if ($https === 'on') {
$scheme = 'https';
}
Expand Down
2 changes: 1 addition & 1 deletion src/PubSubHubbub/CallbackInterface.php
Expand Up @@ -15,7 +15,7 @@ interface CallbackInterface
* unsubscription request. This should be the Hub Server confirming the
* the request prior to taking action on it.
*
* @param array $httpData GET/POST data if available and not in $_GET/POST
* @param null|array $httpData GET/POST data if available and not in $_GET/POST
* @param bool $sendResponseNow Whether to send response now or when asked
*/
public function handle(array $httpData = null, $sendResponseNow = false);
Expand Down
9 changes: 4 additions & 5 deletions src/PubSubHubbub/HttpResponse.php
Expand Up @@ -80,7 +80,7 @@ public function sendHeaders()
* @param string $name
* @param string $value
* @param bool $replace
* @return \Laminas\Feed\PubSubHubbub\HttpResponse
* @return $this
*/
public function setHeader($name, $value, $replace = false)
{
Expand Down Expand Up @@ -150,14 +150,13 @@ public function canSendHeaders($throw = false)
* Set HTTP response code to use with headers
*
* @param int $code
* @return HttpResponse
* @return $this
* @throws Exception\InvalidArgumentException
*/
public function setStatusCode($code)
{
if (! is_int($code) || (100 > $code) || (599 < $code)) {
throw new Exception\InvalidArgumentException('Invalid HTTP response'
. ' code:' . $code);
throw new Exception\InvalidArgumentException('Invalid HTTP response code: ' . $code);
}
$this->statusCode = $code;
return $this;
Expand All @@ -177,7 +176,7 @@ public function getStatusCode()
* Set body content
*
* @param string $content
* @return \Laminas\Feed\PubSubHubbub\HttpResponse
* @return $this
*/
public function setContent($content)
{
Expand Down
11 changes: 3 additions & 8 deletions src/PubSubHubbub/Model/AbstractModel.php
Expand Up @@ -18,18 +18,13 @@ class AbstractModel
*
* @var TableGatewayInterface
*/
protected $db = null;
protected $db;

/**
* Constructor
*
* @param null|TableGatewayInterface $tableGateway
*/
public function __construct(TableGatewayInterface $tableGateway = null)
{
if ($tableGateway === null) {
$parts = explode('\\', get_class($this));
$table = strtolower(array_pop($parts));
$parts = explode('\\', get_class($this));
$table = strtolower(array_pop($parts));
$this->db = new TableGateway($table, null);
} else {
$this->db = $tableGateway;
Expand Down
18 changes: 9 additions & 9 deletions src/PubSubHubbub/Model/Subscription.php
Expand Up @@ -24,7 +24,6 @@ class Subscription extends AbstractModel implements SubscriptionPersistenceInter
/**
* Save subscription to RDMBS
*
* @param array $data
* @return bool
* @throws PubSubHubbub\Exception\InvalidArgumentException
*/
Expand All @@ -38,7 +37,7 @@ public function setSubscription(array $data)
$result = $this->db->select(['id' => $data['id']]);
if ($result && (0 < count($result))) {
$data['created_time'] = $result->current()->created_time;
$now = $this->getNow();
$now = $this->getNow();
if (array_key_exists('lease_seconds', $data)
&& $data['lease_seconds']
) {
Expand Down Expand Up @@ -66,8 +65,9 @@ public function setSubscription(array $data)
public function getSubscription($key)
{
if (empty($key) || ! is_string($key)) {
throw new PubSubHubbub\Exception\InvalidArgumentException('Invalid parameter "key"'
.' of "' . $key . '" must be a non-empty string');
throw new PubSubHubbub\Exception\InvalidArgumentException(
'Invalid parameter "key" of "' . $key . '" must be a non-empty string'
);
}
$result = $this->db->select(['id' => $key]);
if ($result && count($result)) {
Expand All @@ -86,8 +86,9 @@ public function getSubscription($key)
public function hasSubscription($key)
{
if (empty($key) || ! is_string($key)) {
throw new PubSubHubbub\Exception\InvalidArgumentException('Invalid parameter "key"'
.' of "' . $key . '" must be a non-empty string');
throw new PubSubHubbub\Exception\InvalidArgumentException(
'Invalid parameter "key" of "' . $key . '" must be a non-empty string'
);
}
$result = $this->db->select(['id' => $key]);
if ($result && count($result)) {
Expand All @@ -99,7 +100,7 @@ public function hasSubscription($key)
/**
* Delete a subscription
*
* @param string $key
* @param string $key
* @return bool
*/
public function deleteSubscription($key)
Expand Down Expand Up @@ -130,8 +131,7 @@ public function getNow()
/**
* Set a DateTime instance for assisting with unit testing
*
* @param DateTime $now
* @return Subscription
* @return $this
*/
public function setNow(DateTime $now)
{
Expand Down
4 changes: 2 additions & 2 deletions src/PubSubHubbub/Model/SubscriptionPersistenceInterface.php
Expand Up @@ -13,7 +13,7 @@ interface SubscriptionPersistenceInterface
/**
* Save subscription to RDMBS
*
* @param array $data The key must be stored here as a $data['id'] entry
* @param array $data The key must be stored here as a $data['id'] entry
* @return bool
*/
public function setSubscription(array $data);
Expand All @@ -37,7 +37,7 @@ public function hasSubscription($key);
/**
* Delete a subscription
*
* @param string $key
* @param string $key
* @return bool
*/
public function deleteSubscription($key);
Expand Down

0 comments on commit 0fb0825

Please sign in to comment.