Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Strict-Code and PHP8 Requirement #7

Draft
wants to merge 8 commits into
base: v2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}
],
"require": {
"php": "^7.2|^8.0",
"php": "^8.1",
"ext-json": "*",
"guzzlehttp/guzzle": "^6.5.7|^7.4.4"
},
Expand Down
87 changes: 46 additions & 41 deletions src/Novu.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,7 @@ class Novu
Actions\ManagesNotificationGroups,
Actions\ManagesNotificationTemplates;

/**
* The Novu API Key.
*
* @var string
*/
protected $apiKey;

/**
* The Novu API Base URL.
*
* @var string
*/
protected $baseUri = 'https://api.novu.co/v1/';

/**
* The Guzzle HTTP Client instance.
*
* @var \GuzzleHttp\Client
*/
public $client;

/**
* Number of seconds a request is retried.
*
* @var int
*/
public $timeout = 30;


/**
* Create a new Novu instance.
Expand All @@ -57,23 +31,44 @@ class Novu
* @param \GuzzleHttp\Client|null $guzzle
* @return void
*/
public function __construct($apiKey = null, HttpClient $client = null)
public function __construct(
/**
* The Novu API Key.
*
* @var string
*/
protected string $apiKey,

/**
* The Novu API Base URL.
*
* @var string
*/
protected string $baseUri = 'https://api.novu.co/v1/',

/**
* The Guzzle HTTP Client instance.
*
* @var \GuzzleHttp\Client
*/
public ?\GuzzleHttp\Client $client = null,

/**
* Number of seconds a request is retried.
*
* @var int
*/
public int $timeout = 30,

)
{
if ( is_null($apiKey)) {
throw IsNull::make('API KEY');
}

if( empty($apiKey)) {
throw isEmpty::make('API KEY');
}

if (! is_null($apiKey)) {
$this->setApiKey($apiKey, $client);
}

if (! is_null($client)) {
$this->client = $client;
}
$this->setApiKey($apiKey, $client);
$this->client = $client;
}

/**
Expand All @@ -83,7 +78,7 @@ public function __construct($apiKey = null, HttpClient $client = null)
* @param \GuzzleHttp\Client|null $client
* @return $this
*/
public function setApiKey($apiKey, $client = null)
public function setApiKey($apiKey, $client = null): self
{
$this->apiKey = $apiKey;

Expand All @@ -106,7 +101,7 @@ public function setApiKey($apiKey, $client = null)
* @param int $timeout
* @return $this
*/
public function setTimeout($timeout)
public function setTimeout($timeout): self
{
$this->timeout = $timeout;

Expand All @@ -118,8 +113,18 @@ public function setTimeout($timeout)
*
* @return int
*/
public function getTimeout()
public function getTimeout(): int
{
return $this->timeout;
}

/**
* Get the API Base Uri
*
* @return string
*/
public function getBaseUri(): string
{
return $this->baseUri;
}
}
50 changes: 34 additions & 16 deletions src/Resources/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,52 @@

class Activity extends Resource
{
public function __construct(
/**
* The internal id Novu generated for the activity graph stats.
*
* @var string
*/
private readonly string $id,

/**
* The number of stats.
*
* @var int
*/
private readonly int $count
) {
}

/**
* The internal id Novu generated for the activity graph stats.
* Gets the internal id Novu generated for the activity graph stats.
*
* @var string
* @return string
*/
public $id;
public function getId(): string
{
return $this->id;
}

/**
* The number of stats
* Gets number of stats.
*
* @var int
* @return int
*/
public $count;
public function getCount(): int
{
return $this->count;
}

/**
* Return the array form of Activity object.
*
* @return array
*/
public function toArray(): array
{
$publicProperties = get_object_vars($this);

unset($publicProperties['attributes']);
unset($publicProperties['novu']);

return array_filter($publicProperties, function ($value) {
return null !== $value;
});
return [
'id' => $this->id,
'count' => $this->count,
];
}
}
}
Loading