summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHannes Kindströmmer <hannes@kindstrommer.se>2017-03-10 15:20:45 +0100
committerHannes Kindströmmer <hannes@kindstrommer.se>2017-03-10 15:20:45 +0100
commit3ea8d6a33e16ddb163c1acae5c53896dab6e763b (patch)
tree9ca0ecd4419137aad59345ed344c6899b9ca1710 /src
parent6b42c2e6f3392aec5c452cd7966879100ee41c67 (diff)
downloadip1-php-sdk-3ea8d6a33e16ddb163c1acae5c53896dab6e763b.zip
ip1-php-sdk-3ea8d6a33e16ddb163c1acae5c53896dab6e763b.tar.gz
ip1-php-sdk-3ea8d6a33e16ddb163c1acae5c53896dab6e763b.tar.bz2
Prepare documentation for merge with master
Signed-off-by: Hannes Kindströmmer <hannes@kindstrommer.se>
Diffstat (limited to 'src')
-rw-r--r--src/Core/ClassValidationArray.php26
-rw-r--r--src/Core/Communicator.php57
-rw-r--r--src/Core/ProcessedComponent.php8
-rw-r--r--src/Core/UpdatableComponent.php12
-rw-r--r--src/Recipient/Contact.php105
-rw-r--r--src/Recipient/Group.php48
-rw-r--r--src/Recipient/Membership.php26
-rw-r--r--src/Recipient/MembershipRelation.php1
-rw-r--r--src/Recipient/ProcessedContact.php111
-rw-r--r--src/Recipient/ProcessedGroup.php94
-rw-r--r--src/Recipient/ProcessedMembership.php33
-rw-r--r--src/Recipient/RecipientFactory.php96
-rw-r--r--src/SMS/LoggedOutGoingSMS.php65
-rw-r--r--src/SMS/OutGoingSMS.php64
-rw-r--r--src/SMS/ProcessedOutGoingSMS.php65
-rw-r--r--src/SMS/SMS.php21
16 files changed, 600 insertions, 232 deletions
diff --git a/src/Core/ClassValidationArray.php b/src/Core/ClassValidationArray.php
index 1b342c0..0d8a1bc 100644
--- a/src/Core/ClassValidationArray.php
+++ b/src/Core/ClassValidationArray.php
@@ -1,11 +1,18 @@
<?php
+/**
+* Contains the ClassValidation class
+* PHP version 7.1.1
+* @author Hannes Kindströmmer <hannes@kindstrommer.se>
+* @copyright 2017 IP1 SMS
+* @package IP1\RESTClient\Core
+*/
namespace IP1\RESTClient\Core;
/**
*
* An extension of ArrayObject that ensures that there's only one type of object in the array.
-* @package IP1\RESTClient\Core
+
*/
class ClassValidationArray extends \ArrayObject implements \JsonSerializable
{
@@ -22,8 +29,8 @@ class ClassValidationArray extends \ArrayObject implements \JsonSerializable
* If the input is an array it will verify that all the objects inside the array are of the same class if not it will
* throw an InvalidArgumentException. If all the indexes are of the same class it will add them to the array.
*
- * @param $input array|object If array it must only contain a single type of class.
- * @throws InvalidArgumentException
+ * @param array|object $input If array it must only contain a single type of class.
+ * @throws \InvalidArgumentException Thrown when getting unexpected arguments.
*/
public function __construct($input = [])
{
@@ -57,7 +64,10 @@ class ClassValidationArray extends \ArrayObject implements \JsonSerializable
/**
* Sets the value at the specified index to value if value's class matches the one set.
* If a class has not been set it will set the given object's class as the only allowed class.
- * @throws InvalidArgumentException
+ * @param mixed $index The index to put the value in.
+ * @param object $value The object that should be added.
+ * @return void
+ * @throws \InvalidArgumentException When $value is not an object or doesn't match the class that has been set.
*/
public function offsetSet($index, $value): void
{
@@ -81,9 +91,11 @@ class ClassValidationArray extends \ArrayObject implements \JsonSerializable
{
return $this->class;
}
- /**
- * {@inheritDoc}
- */
+ /**
+ * Serializes the object to a value that can be serialized natively by json_encode().
+ * @return array Associative.
+ * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
+ */
public function jsonSerialize(): array
{
$returnArray = [];
diff --git a/src/Core/Communicator.php b/src/Core/Communicator.php
index 3164333..e2496da 100644
--- a/src/Core/Communicator.php
+++ b/src/Core/Communicator.php
@@ -4,34 +4,37 @@
* PHP version 7.1.1
* @author Hannes Kindströmmer <hannes@kindstrommer.se>
* @copyright 2017 IP1 SMS
+* @link http://api.ip1sms.com/Help
+* @package \IP1\RESTClient\Core
*/
namespace IP1\RESTClient\Core;
/**
* Handles request to the API and converts the responses into the data classes.
* For the available endpoints check out link.
-* @link http://api.ip1sms.com/Help
-* @package \IP1\RESTClient\Core
*/
class Communicator
{
+ /**
+ * The accountToken and $accessToken combined into the HTTP Basic Auth format.
+ * @var string $accessQuery
+ */
private $accessQuery;
const DOMAIN = "api.ip1sms.com";
/**
* Communicator constructor
- * @param string $accountToken
- * @param string $accessToken
+ * @param string $accountToken Account ID. Provided by IP1.
+ * @param string $apiToken API Key.
*/
- public function __construct(string $accountToken, string $accessToken)
+ public function __construct(string $accountToken, string $apiToken)
{
- $this->accessQuery = base64_encode($accountToken .":" . $accessToken);
- $this->accessToken = $accessToken;
+ $this->accessQuery = base64_encode($accountToken .":" . $apiToken);
}
/**
* Fetches a ProcessedComponent(s) from the given URI.
- * @param string $endPoint API URI
- * @return string JSON API Response
+ * @param string $endPoint API URI.
+ * @return string JSON API Response.
*/
public function get(string $endPoint)
{
@@ -40,9 +43,9 @@ class Communicator
}
/**
* Adds the content object to the endpoint and returns a processed version of given object.
- * @param string $endPoint API URI
- * @param \JsonSerializable
- * @return string JSON repsonse
+ * @param string $endPoint API URI.
+ * @param ?\JsonSerializable $content The JsonSerializable that is to be posted to the API.
+ * @return string JSON repsonse.
*/
public function post(string $endPoint, ?\JsonSerializable $content)
{
@@ -52,8 +55,8 @@ class Communicator
}
/**
* Deletes the object
- * @param string $endPoint API URI
- * @return string JSON string of what got deleted
+ * @param string $endPoint API URI.
+ * @return string JSON string of what got deleted.
*/
public function delete(string $endPoint): \JsonSerializable
{
@@ -61,10 +64,10 @@ class Communicator
return $this->sendRequest($parsedEndPoint, "DELETE");
}
/**
- * Updates/Modifies a ProcessedComponent with the arguments given.
- * @param string $endPoint API URI
- * @param ProcessedComponent $content
- * @return string JSON API Response
+ * Replaces a ProcessedComponent with the arguments given.
+ * @param string $endPoint API URI.
+ * @param ProcessedComponent $content The ProcessedComponent that is to be PUT to the API.
+ * @return string JSON API Response.
*/
public function put(string $endPoint, ProcessedComponent &$content)
{
@@ -72,9 +75,9 @@ class Communicator
return $this->sendRequest($parsedEndPoint, "PUT", json_encode($content));
}
/**
- * Turns the given endPoint string into a usable
- * @param string $endPoint
- * @return string Fixed enpoint string
+ * Turns the given endPoint string into a usable.
+ * @param string $endPoint API URI.
+ * @return string Fixed endpoint string.
*/
private static function parseEndPoint(string $endPoint)
{
@@ -88,13 +91,13 @@ class Communicator
return implode('/', array_filter($endPointArray));
}
/**
- * Sends a HTTP request to the RESTful API and returns the result as a JSON string
+ * Sends a HTTP request to the RESTful API and returns the result as a JSON string.
*
- * @param string $endPoint The URI that the function should use.
- * @param string $method The HTTP method that should be used, valid ones are: POST, GET, DELETE, PUT.
- * @param string $content (optional) A JSON string containing all additional data that doesn't belong in $endPoint.
- * @param bool $https (optional) Whether the the API call should use HTTPS or not(HTTP).
- * @return string The response from the API
+ * @param string $endPoint The URI that the function should use.
+ * @param string $method The HTTP method that should be used, valid ones are: POST, GET, DELETE, PUT.
+ * @param string $content A JSON string containing all additional data that can not be provided by $endPoint.
+ * @param boolean $https Whether the the API call should use HTTPS or not(HTTP).
+ * @return string The response from the API.
*/
private function sendRequest(string $endPoint, string $method, string $content = "", bool $https = false): string
{
diff --git a/src/Core/ProcessedComponent.php b/src/Core/ProcessedComponent.php
index dc2f530..524c9f1 100644
--- a/src/Core/ProcessedComponent.php
+++ b/src/Core/ProcessedComponent.php
@@ -1,9 +1,10 @@
<?php
/**
-* Contains the ProcessedComponent interface
+* Contains the ProcessedComponent class
* PHP version 7.1.1
* @author Hannes Kindströmmer <hannes@kindstrommer.se>
* @copyright 2017 IP1 SMS
+* @package IP1\RESTClient\Core
*/
namespace IP1\RESTClient\Core;
@@ -20,12 +21,13 @@ interface ProcessedComponent extends \JsonSerializable
*/
public function getID(): int;
/**
- * @param DateTimeZone $timezone (optional) The timezone that the user wants to get the DateTime in. Default is UTC
- * @return DateTime When the Component was added
+ * @param \DateTimeZone $timezone The timezone that the user wants to get the DateTime in. Default is UTC.
+ * @return ?\DateTime When the Component was added.
*/
public function getCreated(\DateTimeZone $timezone = null): ?\DateTime;
/**
* Serializes the object to a value that can be serialized natively by json_encode().
+ * @return array Associative.
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
*/
public function jsonSerialize(): array;
diff --git a/src/Core/UpdatableComponent.php b/src/Core/UpdatableComponent.php
index 54fc23f..91d4246 100644
--- a/src/Core/UpdatableComponent.php
+++ b/src/Core/UpdatableComponent.php
@@ -1,9 +1,10 @@
<?php
/**
-* Contains the UpdatableComponent interface
+* Contains the UpdatableComponent interface.
* PHP version 7.1.1
* @author Hannes Kindströmmer <hannes@kindstrommer.se>
* @copyright 2017 IP1 SMS
+* @package IP1\RESTClient\Core
*/
namespace IP1\RESTClient\Core;
@@ -15,17 +16,20 @@ namespace IP1\RESTClient\Core;
interface UpdatableComponent extends ProcessedComponent
{
/**
- * @param DateTimeZone $timezone (optional) The timezone that the user wants to get the DateTime in. Default is UTC
- * @return DateTime When the contact was updated/modified last
+ * Returns when the component was updated last.
+ * @param \DateTimeZone $timezone The timezone that the user wants to get the DateTime in. Default is UTC.
+ * @return \DateTime When the contact was updated/modified last.
*/
public function getUpdated(\DateTimeZone $timezone = null): ?\DateTime;
/**
- * @return bool Whether the object is read only or not
+ * Returns whether the object is read only or not.
+ * @return bool Whether the object is read only or not.
*/
public function isReadOnly(): bool;
/**
* Serializes the object to a value that can be serialized natively by json_encode().
+ * @return array Associative.
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
*/
public function jsonSerialize(): array;
diff --git a/src/Recipient/Contact.php b/src/Recipient/Contact.php
index c45a631..397480d 100644
--- a/src/Recipient/Contact.php
+++ b/src/Recipient/Contact.php
@@ -4,32 +4,62 @@
* PHP version 7.1.1
* @author Hannes Kindströmmer <hannes@kindstrommer.se>
* @copyright 2017 IP1 SMS
+* @link http://api.ip1sms.com/Help/Api/PUT-api-contacts-contact
+* @package \IP1\RESTClient\Recipient;
*/
namespace IP1\RESTClient\Recipient;
/**
* Contact class that represents the JSON that is sent to the API when adding a new Contact
-* @link http://api.ip1sms.com/Help/Api/PUT-api-contacts-contact
-* @package \IP1\RESTClient\Recipient;
*/
class Contact implements \JsonSerializable
{
+ /**
+ * The contacts first name.
+ * @var string $firstName
+ */
private $firstName;
+ /**
+ * The contacts last name.
+ * @var string $lastName
+ */
private $lastName;
+ /**
+ * The contacts title.
+ * @var string $title
+ */
private $title;
+ /**
+ * The contacts company or other organization.
+ * @var string $organization
+ */
private $organization;
+ /**
+ * The contacts phone number.
+ * @var string $phone
+ */
private $phone;
+ /**
+ * The contacts email adress.
+ * @var string $email
+ */
private $email;
+ /**
+ * The contacts notes.
+ * @var string $notes
+ */
private $notes;
/**
* The Contact constructor
*
- * @param string $firstName The first name of the contact in question
- * @param string $phoneNumber Contact phone number: with country code and without spaces and dashes
- * @param string $lastName (optional) Contact last name
- * @param string $organization (optional) Contact company or other organization
- * @param string $email (optional) Contact email address
- * @param string $notes (optional) Contact notes
+ * @param string $firstName The first name of the contact in question.
+ * @param string $phoneNumber Contact phone number: with country code and without spaces and dashes.
+ * @param string $lastName Contact last name.
+ * @param string $title Contacts title Eg. CEO.
+ * @param string $organization Contact company or other organization.
+ * @param string $email Contact email address.
+ * @param string $notes Contact notes.
+ * @throws \InvalidArgumentException Thrown when $firstName or $phoneNumber is empty.
*/
public function __construct(
string $firstName,
@@ -55,8 +85,10 @@ class Contact implements \JsonSerializable
$this->notes = $notes;
}
/**
- * @return array
- */
+ * Serializes the object to a value that can be serialized natively by json_encode().
+ * @return array Associative.
+ * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
+ */
public function jsonSerialize(): array
{
$returnArray = [
@@ -70,88 +102,99 @@ class Contact implements \JsonSerializable
];
return array_filter($returnArray);
}
+ /**
+ * Returns the object as a JSON string.
+ * @return string
+ */
public function __toString(): string
{
return json_encode($this->jsonSerialize());
}
/**
- * @param string $firstName Sets the first name of the contact
+ * @param string $firstName Sets the first name of the contact.
+ * @return void
*/
- public function setFirstName(string $firstName)
+ public function setFirstName(string $firstName) :void
{
$this->firstName = $firstName;
}
/**
- * @param string $lastName|null Sets the last name of the contact
+ * @param ?string $lastName Sets the last name of the contact.
+ * @return void
*/
- public function setLastName(?string $lastName)
+ public function setLastName(?string $lastName): void
{
$this->lastName = $lastName;
}
/**
- * @param string $phoneNumber Sets the phone number of the contact
+ * @param string $phoneNumber Sets the phone number of the contact.
+ * @return void
*/
- public function setPhoneNumber(string $phoneNumber)
+ public function setPhoneNumber(string $phoneNumber): void
{
$this->phone = $phoneNumber;
}
/**
- * @param string $title|null Sets the title of the contact
+ * @param ?string $title Sets the title of the contact.
+ * @return void
*/
- public function setTitle(?string $title)
+ public function setTitle(?string $title): void
{
$this->title = $title;
}
/**
- * @param string $organization|null Sets the contact company or other organization the contact belongs to
+ * @param ?string $organization Sets the contact company or other organization the contact belongs to.
+ * @return void
*/
- public function setOrganization(?string $organization)
+ public function setOrganization(?string $organization): void
{
$this->organization = $organization;
}
/**
- * @param string $email|null Sets the email adress of the contact
+ * @param ?string $email Sets the email adress of the contact.
+ * @return void
*/
- public function setEmail(?string $email)
+ public function setEmail(?string $email): void
{
$this->email = $email;
}
/**
- * @param string $firstName Sets the first name of the contact
+ * @param ?string $notes Sets the notes of the contact.
+ * @return void
*/
- public function setNotes(?string $notes)
+ public function setNotes(?string $notes): void
{
$this->notes = $notes;
}
/**
- * @return string The contacts first name
+ * @return string The contacts first name.
*/
public function getFirstName():string
{
return $this->firstName;
}
/**
- * @return string The contacts last name
+ * @return string The contacts last name.
*/
public function getLastName():string
{
return $this->lastName ?? "";
}
/**
- * @return string The contacts phone number
+ * @return string The contacts phone number.
*/
public function getPhoneNumber():string
{
return $this->phone;
}
/**
- * @return string The contacts email
+ * @return string The contacts email.
*/
public function getEmail():string
{
@@ -159,7 +202,7 @@ class Contact implements \JsonSerializable
}
/**
- * @return string The contacts title
+ * @return string The contacts title.
*/
public function getTitle():string
{
@@ -167,14 +210,14 @@ class Contact implements \JsonSerializable
}
/**
- * @return string The contacts company or other organization
+ * @return string The contacts company or other organization.
*/
public function getOrganization():string
{
return $this->organization ?? "";
}
/**
- * @return string The contact notes
+ * @return string The contact notes.
*/
public function getNotes():string
{
diff --git a/src/Recipient/Group.php b/src/Recipient/Group.php
index ddfe0b0..a1d2d91 100644
--- a/src/Recipient/Group.php
+++ b/src/Recipient/Group.php
@@ -4,34 +4,38 @@
* PHP version 7.1.1
* @author Hannes Kindströmmer <hannes@kindstrommer.se>
* @copyright 2017 IP1 SMS
+* @package IP1\RESTClient\Recipient
*/
-use IP1\RESTClient\Core\UpdatableComponent;
-
namespace IP1\RESTClient\Recipient;
+use IP1\RESTClient\Core\UpdatableComponent;
+
+/**
+* Used to group contacts together with the Membership class.
+*/
class Group implements \JsonSerializable
{
/**
- * Name of Group
+ * Name of Group.
* @var string $name
*/
protected $name;
/**
- * Contact group color, hexadecimal
- * @example #5E5E5E
+ * Contact group color, hexadecimal.
* @var string $color
*/
protected $color;
/**
- * An array of Membership
- * @var array Membership
+ * An array of Membership.
+ * @var array Membership.
*/
protected $memberships = [];
/**
* Group constructor
- * @param string $name Name of Group.
+ * @param string $name Name of Group.
* @param string $color Hexadecimal color code.
+ * @example #5E5E5E
*/
public function __construct(string $name, string $color)
{
@@ -39,7 +43,7 @@ class Group implements \JsonSerializable
$this->setColor($color);
}
/**
- * Returns the name of the group.
+ * Returns the name of the Group.
* @return string Name of Group.
*/
public function getName(): string
@@ -47,37 +51,45 @@ class Group implements \JsonSerializable
return $this->name;
}
/**
- * Returns the groups color in hexadecimal
- * @return string hexadecimal color
+ * Returns the groups color in hexadecimal.
+ * @return string hexadecimal color.
*/
public function getColor(): string
{
return $this->color;
}
/**
- * Sets the Group's name to the given string
- * @param string $name
+ * Sets the Group's name to the given string.
+ * @param string $name Name that the Group should have.
+ * @throws InvalidArgumentException When $name is empty.
+ * @return void
*/
public function setName(string $name):void
{
if (empty($name)) {
- //TODO: Throw EmptyStringException
+ throw new InvalidArgumentException("Group name can not be empty");
}
$this->name = $name;
}
/**
* Sets the groups color.
- * @param $color A hexadecimal color code.
+ * @param string $color A hexadecimal color code.
+ * @example #5E5E5E
+ * @return void
+ * @throws InvalidArgumentException When $color isn't a valid hexadecimal color.
*/
public function setColor(string $color): void
{
if (!preg_match("/^#([A-Fa-f0-9]{6})$/", $color)) {
- //TODO Throw non hexadecimal color exception
- throw new Exception($color. " is not a valid hexadecimal color");
+ throw new InvalidArgumentException($color. " is not a valid hexadecimal color");
}
$this->color = $color;
}
- /** {@inheritDoc} */
+ /**
+ * Serializes the object to a value that can be serialized natively by json_encode().
+ * @return array Associative.
+ * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
+ */
public function jsonSerialize(): array
{
$returnArray = [
diff --git a/src/Recipient/Membership.php b/src/Recipient/Membership.php
index 0ec4077..dee8e29 100644
--- a/src/Recipient/Membership.php
+++ b/src/Recipient/Membership.php
@@ -4,29 +4,30 @@
* PHP version 7.1.1
* @author Hannes Kindströmmer <hannes@kindstrommer.se>
* @copyright 2017 IP1 SMS
+* @package IP1\RESTClient\Recipient
*/
namespace IP1\RESTClient\Recipient;
/**
-*
+* Membership is the bridge between ProcessedGroup and ProcessedContact.
*/
class Membership implements \JsonSerializable
{
/**
- * A Group ID
+ * A Group ID.
* @var int $groupID
*/
protected $groupID;
/**
- * A Contact ID
+ * A Contact ID.
* @var int $contactID
*/
protected $contactID;
/**
- * Membership Constructor
- * @param int $groupID A Group ID
- * @param int $contactID A Contact ID
+ * Membership Constructor.
+ * @param integer $groupID A Group ID.
+ * @param integer $contactID A Contact ID.
*/
public function __construct(int $groupID, int $contactID)
{
@@ -34,21 +35,26 @@ class Membership implements \JsonSerializable
$this->contactID = $contactID;
}
/**
- * Returns Group ID
- * @return int
+ * Returns Group ID.
+ * @return integer
*/
public function getGroupID(): int
{
return $this->groupID;
}
/**
- * Returns Contact ID
- * @return int
+ * Returns Contact ID.
+ * @return integer
*/
public function getContactID(): int
{
return $this->contactID;
}
+ /**
+ * Serializes the object to a value that can be serialized natively by json_encode().
+ * @return array Associative.
+ * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
+ */
public function jsonSerialize(): array
{
$returnArray = [
diff --git a/src/Recipient/MembershipRelation.php b/src/Recipient/MembershipRelation.php
index 02d0f35..0411ec0 100644
--- a/src/Recipient/MembershipRelation.php
+++ b/src/Recipient/MembershipRelation.php
@@ -4,6 +4,7 @@
* PHP version 7.1.1
* @author Hannes Kindströmmer <hannes@kindstrommer.se>
* @copyright 2017 IP1 SMS
+* @package IP1\RESTClient\Recipient
*/
namespace IP1\RESTClient\Recipient;
diff --git a/src/Recipient/ProcessedContact.php b/src/Recipient/ProcessedContact.php
index a152c62..d79b03e 100644
--- a/src/Recipient/ProcessedContact.php
+++ b/src/Recipient/ProcessedContact.php
@@ -4,6 +4,8 @@
* PHP version 7.1.1
* @author Hannes Kindströmmer <hannes@kindstrommer.se>
* @copyright 2017 IP1 SMS
+* @link http://api.ip1sms.com/Help/Api/PUT-api-contacts-contact
+* @package \IP1\RESTClient\Recipient;
*/
namespace IP1\RESTClient\Recipient;
@@ -14,31 +16,66 @@ use IP1\RESTClient\Core\Communicator;
/**
* A Contact that has been added to the API. Has all the options that a normal Contact has.
-* @link http://api.ip1sms.com/Help/Api/PUT-api-contacts-contact
-* @package \IP1\RESTClient\Recipient;
*/
class ProcessedContact extends Contact implements UpdatableComponent, MembershipRelation
{
- private $updated;
+ /**
+ * The ID of the Contact given by the API.
+ * @var int $contactID
+ */
private $contactID;
+ /**
+ * When the Contact was created.
+ * @var \DateTime $created
+ */
private $created;
- const IS_READ_ONLY = false;
+ /**
+ * When the Contact was last updated.
+ * @var \DateTime $updated
+ */
+ private $updated;
+ /**
+ * An array of Memberships that the Group has.
+ *
+ * It is empty by default but is filled when the function getMemberships() is called if a Communicator is given
+ * as an argument.
+ *
+ * @var array $membership
+ */
protected $memberships = [];
- protected $membershipsFetched = false;
+ /**
+ * Tells whether memberships has been fetched from the API.
+ * @var bool $fetchedMemberships Defaults to false.
+ */
+ protected $fetchedMemberships = false;
+ /**
+ * An array of Group that the Contact is a member of.
+ *
+ * It is empty by default but is filled when the function getGroups() is called if a Communicator is given
+ * as an argument.
+ *
+ * @var array $groups Default empty array.
+ */
protected $groups = [];
+ /**
+ * Tells wheter Groups has been fetched from the API.
+ * @var bool $groupsFetched Defaults to false.
+ */
protected $groupsFetched = false;
+ const IS_READ_ONLY = false;
/**
* The ProcessedContact constructor
*
- * @param string $firstName The first name of the contact in question
- * @param string $phoneNumber Contact phone number: with country code and without spaces and dashes
- * @param int $contactID Contact ID
- * @param string $lastName (optional) Contact last name
- * @param string $organization (optional) Contact company or other organization
- * @param string $email (optional) Contact email address
- * @param string $notes (optional) Contact notes
- * @param DateTime $created (optional) Date/time of when the contact was added
- * @param DateTime $updated (optional) Date/time of when the contact was last updated/modified
+ * @param string $firstName The first name of the contact in question.
+ * @param string $phoneNumber Contact phone number: with country code and without spaces and dashes.
+ * @param integer $contactID Contact ID.
+ * @param ?string $lastName Contact last name.
+ * @param ?string $title The contacts title.
+ * @param ?string $organization Contact company or other organization.
+ * @param ?string $email Contact email address.
+ * @param ?string $notes Contact notes.
+ * @param ?\DateTime $created Date/time of when the contact was added.
+ * @param ?\DateTime $updated Date/time of when the contact was last updated/modified.
*/
public function __construct(
string $firstName,
@@ -57,6 +94,13 @@ class ProcessedContact extends Contact implements UpdatableComponent, Membership
$this->created = $created ?? null;
$this->updated = $updated ?? null;
}
+ /**
+ * Returns an array of all the memberships the group is referenced in.
+ * If a communicator is not provided it will not fetch memberships from the API
+ * but return those that has been fetched, if any.
+ * @param Communicator $communicator Used to fetch memberships from the API.
+ * @return array An array of Membership objects.
+ */
public function getMemberships(Communicator $communicator = null): array
{
if ($communicator != null) {
@@ -69,9 +113,15 @@ class ProcessedContact extends Contact implements UpdatableComponent, Membership
$this->memberships = $memberships;
$this->fetchedMemberships = true;
}
- //TODO: Add functionality for fetching from the API
return $this->memberships;
}
+ /**
+ * Returns an array of all the Groups the group is referenced in.
+ * If a communicator is not provided it will not fetch memberships from the API
+ * but return those that has been fetched, if any.
+ * @param Communicator $communicator Used to fetch Groups from the API.
+ * @return array An array of Group objects.
+ */
public function getGroups(Communicator $communicator = null): array
{
if ($communicator != null) {
@@ -83,16 +133,27 @@ class ProcessedContact extends Contact implements UpdatableComponent, Membership
}
return $this->groups;
}
+ /**
+ * Tells whether Groups has been fetched from the API or not.
+ * @return bool Whether the Groups has been fetched from the API or not.
+ */
public function isGroupsFetched(): bool
{
return $this->groupsFetched;
}
+ /**
+ * Tells whether Memberships has been fetched from the API or not.
+ * @return bool Whether the Memberships has been fetched from the API or not.
+ */
public function memberShipsFetched(): bool
{
return $this->fetchedMemberships;
}
/**
- * {@inheritDoc}
+ * Returns when the component was updated last.
+ * @param \DateTimeZone $timezone The timezone that the user wants to get the DateTime in.
+ * Default is UTC.
+ * @return \DateTime When the contact was updated/modified last.
*/
public function getUpdated(\DateTimeZone $timezone = null): ?\DateTime
{
@@ -104,15 +165,15 @@ class ProcessedContact extends Contact implements UpdatableComponent, Membership
return $this->updated ?? null;
}
/**
- * @return bool Whether the object is read only or not
+ * @return bool Whether the object is read only or not.
*/
public function isReadOnly(): bool
{
return self::IS_READ_ONLY;
}
/**
- * @param DateTimeZone $timezone (optional) The timezone that the user wants to get the DateTime in. Default is UTC
- * @return DateTime When the Contact was added
+ * @param \DateTimeZone $timezone The timezone that the user wants to get the DateTime in. Default is UTC.
+ * @return ?\DateTime When the Contact was added.
*/
public function getCreated(\DateTimeZone $timezone = null): ?\DateTime
{
@@ -124,15 +185,17 @@ class ProcessedContact extends Contact implements UpdatableComponent, Membership
return $this->created ?? null;
}
/**
- * @return int Contact ID
+ * @return int Contact ID.
*/
public function getID():int
{
return $this->contactID;
}
/**
- * @return array
- */
+ * Serializes the object to a value that can be serialized natively by json_encode().
+ * @return array Associative.
+ * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
+ */
public function jsonSerialize(): array
{
$contactArray = parent::jsonSerialize();
@@ -148,6 +211,10 @@ class ProcessedContact extends Contact implements UpdatableComponent, Membership
);
return array_filter($returnArray);
}
+ /**
+ * Returns the object as a JSON string.
+ * @return string
+ */
public function __toString(): string
{
return json_encode($this->jsonSerialize());
diff --git a/src/Recipient/ProcessedGroup.php b/src/Recipient/ProcessedGroup.php
index 6376f48..7509841 100644
--- a/src/Recipient/ProcessedGroup.php
+++ b/src/Recipient/ProcessedGroup.php
@@ -4,25 +4,72 @@
* PHP version 7.1.1
* @author Hannes Kindströmmer <hannes@kindstrommer.se>
* @copyright 2017 IP1 SMS
+* @package IP1\RESTClient\Recipient
*/
namespace IP1\RESTClient\Recipient;
use IP1\RESTClient\Core\Communicator;
use IP1\RESTClient\Core\UpdatableComponent;
use IP1\RESTClient\Recipient\RecipientFactory;
+use Prophecy\Argument;
+/**
+*
+*/
class ProcessedGroup extends Group implements UpdatableComponent, MembershipRelation
{
-
+ /**
+ * The ID of the Group given by the API.
+ * @var int $groupID
+ */
private $groupID;
+ /**
+ * When the Group was created.
+ * @var \DateTime $created
+ */
private $created;
+ /**
+ * When the Group was last updated.
+ * @var \DateTime $updated
+ */
private $updated;
+ /**
+ * An array of memberships that the Group has.
+ *
+ * It is empty by default but is filled when the function getMemberships() is called if a Communicator is given
+ * as an argument.
+ *
+ * @var array $membership
+ */
protected $memberships = [];
- protected $fechedMemberships = false;
+ /**
+ * Tells whether memberships has been fetched from the API.
+ * @var bool $fetchedMemberships Defaults to false.
+ */
+ protected $fetchedMemberships = false;
+ /**
+ * An array of Contact that the Group has.
+ *
+ * It is empty by default but is filled when the function getContacts() is called if a Communicator is given
+ * as an argument.
+ *
+ * @var array $contacts Default empty array.
+ */
protected $contacts = [];
+ /**
+ * Tells wheter contacts has been fetched from the API.
+ * @var bool $contactsFetched Defaults to false.
+ */
protected $contactsFetched = false;
const IS_READ_ONLY = false;
-
+ /**
+ * ProcessedGroup Contstructor
+ * @param string $name Name of the Group.
+ * @param string $color A hexadecimal color.
+ * @param integer $groupID An ID generated by the API.
+ * @param \DateTime $created When the Group was initially created.
+ * @param \DateTime $updated When the Group was last updated.
+ */
public function __construct(string $name, string $color, int $groupID, \DateTime $created, \DateTime $updated)
{
parent::__construct($name, $color);
@@ -30,16 +77,28 @@ class ProcessedGroup extends Group implements UpdatableComponent, MembershipRela
$this->created = $created;
$this->updated = $updated;
}
- /** {@inheritDoc} */
+ /**
+ * @return int Group ID
+ */
public function getID(): int
{
return $this->groupID;
}
- /** {@inheritDoc} */
+ /**
+ * Returns whether the object is read only or not.
+ * @return bool Whether the object is read only or not.
+ */
public function isReadOnly(): bool
{
return self::IS_READ_ONLY;
}
+ /**
+ * Returns an array of all the memberships the group is referenced in.
+ * If a communicator is not provided it will not fetch memberships from the API
+ * but return those that has been fetched, if any.
+ * @param Communicator $communicator Used to fetch memberships from the API.
+ * @return array An array of Membership objects
+ */
public function getMemberships(Communicator $communicator = null): array
{
if ($communicator != null) {
@@ -52,14 +111,24 @@ class ProcessedGroup extends Group implements UpdatableComponent, MembershipRela
$this->memberships = $memberships;
$this->fetchedMemberships = true;
}
- //TODO: Add functionality for fetching from the API
return $this->memberships;
}
+ /**
+ * Tells whether memberships has been fetched from the API or not.
+ * @return bool Whether the memberships has been fetched from the API or not.
+ */
public function memberShipsFetched(): bool
{
return $this->fetchedMemberships;
}
- public function getGroups(Communicator $communicator = null): array
+ /**
+ * Returns an array of all the Contacts that belong to the Group.
+ * If a communicator is not provided it will not fetch Contacts from the API
+ * but return those that has been fetched, if any.
+ * @param Communicator $communicator Used to fetch Contacts from the API.
+ * @return array An array of ProcessedContact objects.
+ */
+ public function getContacts(Communicator $communicator = null): array
{
if ($communicator != null) {
$contactStd = $communicator->get('api/groups/'.$this->groupID. '/contacts');
@@ -72,7 +141,10 @@ class ProcessedGroup extends Group implements UpdatableComponent, MembershipRela
}
- /** {@inheritDoc} */
+ /**
+ * @param \DateTimeZone $timezone The timezone that the user wants to get the DateTime in. Default is UTC.
+ * @return \DateTime When the Component was added.
+ */
public function getCreated(\DateTimeZone $timezone = null): ?\DateTime
{
if (!is_null($timezone)) {
@@ -82,7 +154,11 @@ class ProcessedGroup extends Group implements UpdatableComponent, MembershipRela
}
return $this->created ?? null;
}
- /** {@inheritDoc} */
+ /**
+ * Returns when the component was updated last.
+ * @param \DateTimeZone $timezone The timezone that the user wants to get the DateTime in. Default is UTC.
+ * @return \DateTime When the contact was updated/modified last.
+ */
public function getUpdated(\DateTimeZone $timezone = null) : ?\DateTime
{
if (!is_null($timezone)) {
diff --git a/src/Recipient/ProcessedMembership.php b/src/Recipient/ProcessedMembership.php
index cd3f71c..388e6ad 100644
--- a/src/Recipient/ProcessedMembership.php
+++ b/src/Recipient/ProcessedMembership.php
@@ -4,20 +4,25 @@
* PHP version 7.1.1
* @author Hannes Kindströmmer <hannes@kindstrommer.se>
* @copyright 2017 IP1 SMS
+* @package IP1\RESTClient\Recipient
*/
namespace IP1\RESTClient\Recipient;
use IP1\RESTClient\Core\Communicator;
use IP1\RESTClient\Core\ProcessedComponent;
+/**
+* ProcessedMembership class.
+* Is the relation between contacts and groups.
+*/
class ProcessedMembership extends Membership implements ProcessedComponent
{
/**
* The ID of the Membership.
- * @var int $id
+ * @var int $membershipID
*/
- private $id;
+ private $membershipID;
/**
* When the membership was added to the API
* @var DateTime $created
@@ -25,24 +30,30 @@ class ProcessedMembership extends Membership implements ProcessedComponent
private $created;
/**
* ProcessedMembership Constructor
- * @param int $groupID
- * @param int $contactID
- * @param int $id
- * @param \DateTime $created
+ * @param integer $groupID The ID of the group.
+ * @param integer $contactID The ID of the contact.
+ * @param integer $membershipID The ID of the membership.
+ * @param \DateTime $created When the Membership was created.
*/
- public function __construct(int $groupID, int $contactID, int $id, \DateTime $created)
+ public function __construct(int $groupID, int $contactID, int $membershipID, \DateTime $created)
{
parent::__construct($groupID, $contactID);
- $this->id = $id;
+ $this->membershipID = $membershipID;
$this->created = $created;
}
- /** {@inheritDoc} */
+ /**
+ * Returns id of the Membership given by the API.
+ * @return int Membership ID given by the API.
+ */
public function getID(): int
{
- return $this->id;
+ return $this->membershipID;
}
- /** {@inheritDoc} */
+ /**
+ * @param \DateTimeZone $timezone The timezone that the user wants to get the DateTime in. Default is UTC.
+ * @return \DateTime|null When the Component was added.
+ */
public function getCreated(\DateTimeZone $timezone = null): ?\DateTime
{
if (!is_null($timezone)) {
diff --git a/src/Recipient/RecipientFactory.php b/src/Recipient/RecipientFactory.php
index 9e6d411..3aa647f 100644
--- a/src/Recipient/RecipientFactory.php
+++ b/src/Recipient/RecipientFactory.php
@@ -4,23 +4,18 @@
* PHP version 7.1.1
* @author Hannes Kindströmmer <hannes@kindstrommer.se>
* @copyright 2017 IP1 SMS
+* @package \IP1\RESTClient\Recipient
*/
namespace IP1\RESTClient\Recipient;
-use IP1\RESTClient\Recipient\ProcessedGroup;
-use IP1\RESTClient\Recipient\ProcessedContact;
-use IP1\RESTClient\Recipient\ProcessedMembership;
-use IP1\RESTClient\Core\ClassValidationArray;
-
/**
* Handles construction of Recipients.
-* @package \IP1\RESTClient\Recipient
*/
class RecipientFactory
{
/**
* Creates a Contact using the stdClass given.
- * @param string $jsonContact A JSON string matching the format of the IP1 SMS API
+ * @param string $jsonContact A JSON string matching the format of the IP1 SMS API.
* @return Contact
*/
public static function createContactFromJSON(string $jsonContact): Contact
@@ -29,8 +24,9 @@ class RecipientFactory
}
/**
* Creates a Contact using the stdClass given.
- * @param \stdClass $stdContact An stdClass object matching the format of the IP1 SMS API
+ * @param \stdClass $stdContact An stdClass object matching the format of the IP1 SMS API.
* @return Contact
+ * @throws \InvalidArgumentException Thrown when required parameters in the argument is missing.
*/
public static function createContactFromStdClass(\stdClass $stdContact): Contact
{
@@ -54,23 +50,23 @@ class RecipientFactory
}
/**
* Creates a Contact using the parameters given.
- * @param string $firstName The first name of the contact in question
- * @param string $phoneNumber Contact phone number: with country code and without spaces and dashes
- * @param string $lastName (optional) Contact last name
- * @param string $title (optional) Contact title
- * @param string $organization (optional) Contact company or other organization
- * @param string $email (optional) Contact email address
- * @param string $notes (optional) Contact notes
+ * @param string $firstName The first name of the contact in question.
+ * @param string $phoneNumber Contact phone number: with country code and without spaces and dashes.
+ * @param string|null $lastName Contact last name.
+ * @param string|null $title Contact title.
+ * @param string|null $organization Contact company or other organization.
+ * @param string|null $email Contact email address.
+ * @param string|null $notes Contact notes.
* @return Contact
*/
public static function createContactFromAttributes(
string $firstName,
string $phoneNumber,
- string $lastName = null,
- string $title = null,
- string $organization = null,
- string $email = null,
- string $notes = null
+ ?string $lastName = null,
+ ?string $title = null,
+ ?string $organization = null,
+ ?string $email = null,
+ ?string $notes = null
) : Contact {
return new Contact(
$firstName,
@@ -85,13 +81,18 @@ class RecipientFactory
/**
* Creates a ProcessedContact using the JSON given.
- * @param string $jsonContact A JSON string matching the format of the IP1 SMS API
+ * @param string $jsonContact A JSON string matching the format of the IP1 SMS API.
* @return ProcessedContact
*/
public static function createProcessedContactFromJSON(string $jsonContact): ProcessedContact
{
return self::createProcessedContactFromStdClass(json_decode($jsonContact));
}
+ /**
+ * Take an array filled with contact stdClasses and returns a ClassValidationArray filled with ProcessedContact.
+ * @param array $contactArray An array filled with stdClass contacts.
+ * @return ClassValidationArray Filled with ProcessedContact.
+ */
public static function createProcessedContactFromStdClassArray(array $contactArray): ClassValidationArray
{
$contacts = new ClassValidationArray();
@@ -102,8 +103,9 @@ class RecipientFactory
}
/**
* Creates a ProcessedContact using the stdClass given.
- * @param \stdClass $stdContact An stdClass object matching the format of the IP1 SMS API
+ * @param \stdClass $stdContact An stdClass object matching the format of the IP1 SMS API.
* @return ProcessedContact
+ * @throws \InvalidArgumentException Thrown when required parameters in the argument is missing.
*/
public static function createProcessedContactFromStdClass(\stdClass $stdContact): ProcessedContact
{
@@ -127,24 +129,42 @@ class RecipientFactory
);
return $contact;
}
+ /**
+ * Takes a JSON string group and returns a ProcessedGroup.
+ * @param string $jsonGroup A single group JSON string.
+ * @return ProcessedGroup
+ */
public static function createProcessedGroupFromJSON(string $jsonGroup): ProcessedGroup
{
return self::createProcessedGroupFromStdClass(json_decode($jsonGroup));
}
- public static function createProcessedGroupFromStdClass(\stdClass $stdContact): ProcessedGroup
+ /**
+ * Takes a stdClass group and returns a ProcessedGroup.
+ * @param \stdClass $stdGroup A single stdClass group.
+ * @return ProcessedGroup
+ */
+ public static function createProcessedGroupFromStdClass(\stdClass $stdGroup): ProcessedGroup
{
return new ProcessedGroup(
- $stdContact->Name,
- $stdContact->Color,
- $stdContact->ID,
- new \DateTime($stdContact->Created),
- new \DateTime($stdContact->Modified)
+ $stdGroup->Name,
+ $stdGroup->Color,
+ $stdGroup->ID,
+ new \DateTime($stdGroup->Created),
+ new \DateTime($stdGroup->Modified)
);
}
+ /**
+ * @param string $jsonMembership A membership JSON string.
+ * @return ProcessedMembership
+ */
public static function createProcessedMembershipFromJSON(string $jsonMembership): ProcessedMembership
{
return self::createProcessedMembershipFromStdClass(json_decode($jsonMembership));
}
+ /**
+ * @param array $stdGroups An array filled with stdclass Group.
+ * @return ClassValidationArray Filled with ProcessedGroup.
+ */
public static function createProcessedGroupsFromStdClassArray(array $stdGroups): ClassValidationArray
{
$groups = new ClassValidationArray();
@@ -153,6 +173,10 @@ class RecipientFactory
}
return $groups;
}
+ /**
+ * @param \stdClass $stdMembership An stdClass membership.
+ * @return ProcessedMembership
+ */
public static function createProcessedMembershipFromStdClass(\stdClass $stdMembership): ProcessedMembership
{
return new ProcessedMembership(
@@ -162,6 +186,10 @@ class RecipientFactory
new \DateTime($stdMembership->Created)
);
}
+ /**
+ * @param array $stdMemberships An stdClass Membership.
+ * @return ClassValidationArray Filled with ProcessedMembership.
+ */
public static function createProcessedMembershipsFromStdClassArray(array $stdMemberships): ClassValidationArray
{
$memberships = new ClassValidationArray();
@@ -170,16 +198,12 @@ class RecipientFactory
}
return $memberships;
}
+ /**
+ * @param string $membershipJSONArray An stdClass Group array encoded as a JSON string.
+ * @return ClassValidationArray Filled with ProcessedMembership
+ */
public static function createProcessedMembershipsFromStringArray(string $membershipJSONArray): ClassValidationArray
{
return self::createProcessedMembershipsFromStdClassArray(json_decode($membershipJSONArray));
}
- public static function export(array $exportables): ClassValidationArray
- {
- $returnArray = ClassValidationArray();
- foreach ($exportables as $value) {
- $returnArray[] = $value->jsonSerialize();
- }
- return $returnArray;
- }
}
diff --git a/src/SMS/LoggedOutGoingSMS.php b/src/SMS/LoggedOutGoingSMS.php
index f4a748e..d698b42 100644
--- a/src/SMS/LoggedOutGoingSMS.php
+++ b/src/SMS/LoggedOutGoingSMS.php
@@ -4,6 +4,8 @@
* PHP version 7.1.1
* @author Hannes Kindströmmer <hannes@kindstrommer.se>
* @copyright 2017 IP1 SMS
+* @package \IP1\RESTClient\SMS;
+* @link http://api.ip1sms.com/Help/Api/PUT-api-contacts-contact
*/
use IP1\RESTClient\Core\UpdatableComponent;
@@ -11,38 +13,69 @@ namespace IP1\RESTClient\SMS;
/**
* The response you will get when sending an OutGoingSMS. One instance per recipient.
-* @link http://api.ip1sms.com/Help/Api/PUT-api-contacts-contact
-* @package \IP1\RESTClient\SMS;
*/
class LoggedOutGoingSMS extends ProcessedOutGoingSMS implements UpdatableComponent
{
- private $updated;
+ /**
+ * Stores when the sms was created in UTC.
+ * @var DateTime $created
+ */
private $created;
+ /**
+ * Stores when the sms was last updated in UTC.
+ * @var DateTime $created
+ */
+ private $updated;
const IS_READ_ONLY = true;
-
- public function getReadOnly(): bool
+ /**
+ * Returns when the object was updated last. Default timezone is UTC.
+ * @param \DateTimeZone $timezone The timezone that the user wants to get the DateTime in.
+ * Default is UTC.
+ * @return \DateTime When the contact was updated/modified last.
+ */
+ public function getUpdated(\DateTimeZone $timezone = null): ?\DateTime
{
- return IS_READ_ONLY;
+ if (!is_null($timezone)) {
+ $returnDate = clone $this->updated;
+ $returnDate->setTimeZone($timezone);
+ return $returnDate;
+ }
+ return $this->updated ?? null;
}
- public function getUpdated(): \DateTime
+ /**
+ * Returns whether the object is read only or not.
+ * @return bool Whether the object is read only or not
+ */
+ public function isReadOnly(): bool
{
- return $this->updated;
+ return self::IS_READ_ONLY;
}
/**
- * @param DateTimeZone $timezone (optional) The timezone that the user wants to get the DateTime in. Default is UTC
- * @return DateTime When the Component was added
+ * Returns when the object was last updated by the API as a DateTime object. Default timexone is UTC.
+ * @param \DateTimeZone $timezone The timezone that the user wants to get the DateTime in.
+ * Default is UTC.
+ * @return \DateTime|null When the Contact was added.
*/
- public function getCreated(): \DateTime
+ public function getCreated(\DateTimeZone $timezone = null): ?\DateTime
{
- return $this->created;
+ if (!is_null($timezone)) {
+ $returnDate = clone $this->created;
+ $returnDate->setTimeZone($timezone);
+ return $returnDate;
+ }
+ return $this->created ?? null;
}
- /** {@inheritDoc} */
- public function jsonSerialize(): \stdClass
+ /**
+ * Serializes the object to a value that can be serialized natively by json_encode().
+ * @return array Associative .
+ * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
+ */
+ public function jsonSerialize(): array
{
$returnObject = parent::jsonSerialize();
- $returnObject->UpdatedDate = $this->updated;
- $returnObject->CreatedDate = $this->created;
+ $returnObject['UpdatedDate'] = $this->updated;
+ $returnObject['CreatedDate'] = $this->created;
return $returnObject;
}
}
diff --git a/src/SMS/OutGoingSMS.php b/src/SMS/OutGoingSMS.php
index 4cbdb67..5ac763d 100644
--- a/src/SMS/OutGoingSMS.php
+++ b/src/SMS/OutGoingSMS.php
@@ -4,6 +4,8 @@
* PHP version 7.1.1
* @author Hannes Kindströmmer <hannes@kindstrommer.se>
* @copyright 2017 IP1 SMS
+* @package \IP1\RESTClient\SMS
+* @link http://api.ip1sms.com/Help/Api/PUT-api-contacts-contact
*/
namespace IP1\RESTClient\SMS;
@@ -13,14 +15,12 @@ use IP1\RESTClient\Recipient\Group;
/**
* Class that is used when wanting to send SMSes to the API.
-* @link http://api.ip1sms.com/Help/Api/PUT-api-contacts-contact
-* @package \IP1\RESTClient\SMS;
*/
class OutGoingSMS extends SMS implements \JsonSerializable
{
/**
- * Contains all the phone numbers the SMS should be sent to
- * @var array $numbers phone numbers
+ * Contains all the phone numbers the SMS should be sent to.
+ * @var array $numbers Phone numbers
*/
protected $numbers = [];
/**
@@ -41,38 +41,42 @@ class OutGoingSMS extends SMS implements \JsonSerializable
/**
* Adds the number to the recipient list.
- * @param string $number A number that should be added to the recipient list
+ * @param string $number A number that should be added to the recipient list.
+ * @return void
*/
-
public function addNumber(string $number): void
{
$this->numbers[] = $number;
}
/**
* Adds the given array of numbers to the recipient list.
- * @param array $numbers An array of numbers(string)
+ * @param array $numbers An array of numbers(string).
+ * @return void
*/
public function addAllNumbers(array $numbers): void
{
$this->numbers = array_merge($this->numbers, $numbers);
}
/**
- * Removes the given index from the number recipient list
- * @param int $index
+ * Removes the given index from the number recipient list.
+ * @param integer $index The index being requested for deletion.
+ * @return void
*/
- public function removeNumber(int $index)
+ public function removeNumber(int $index): void
{
unset($this->numbers[$index]);
$this->numbers = array_values($this->numbers);
}
/**
* Returns the number in the given index.
- * @param int $index
+ * @param integer $index The index being requested.
+ * @return string Phone number.
+ * @throws \UndefinedOffsetException Thrown when the index requested does not exist.
*/
- public function getNumber(int $index)
+ public function getNumber(int $index): string
{
if ($index >= count($this->numbers)) {
- throw new \IP1\RESTClient\Exception\UndefinedOffsetException();
+ throw new \UndefinedOffsetException();
}
return $this->numbers[$index];
}
@@ -86,15 +90,17 @@ class OutGoingSMS extends SMS implements \JsonSerializable
}
/**
* Adds the ProcessedContact to the recipient list.
- * @param ProcessedContact $contact A ProcessedContact that should be added to the recipient list
+ * @param ProcessedContact $contact A ProcessedContact that should be added to the recipient list.
+ * @return void
*/
public function addContact(ProcessedContact $contact): void
{
$this->contacts[] = $contact;
}
/**
- * Removes the Contact in the given index and reindexes the array
- * @param int $index
+ * Removes the Contact in the given index and reindexes the array.
+ * @param integer $index The index being requested for deletion.
+ * @return void
*/
public function removeContact(int $index): void
{
@@ -103,7 +109,8 @@ class OutGoingSMS extends SMS implements \JsonSerializable
}
/**
* Adds the given array of contacts to the Contact recipient list.
- * @param array An array of Contact
+ * @param array $contacts An array of Contact.
+ * @return void
*/
public function addAllContacts(array $contacts): void
{
@@ -111,7 +118,8 @@ class OutGoingSMS extends SMS implements \JsonSerializable
}
/**
* Adds the given Group to the recipient list.
- * @param Group $group A Group that should be added to the recipient list
+ * @param Group $group A Group that should be added to the recipient list.
+ * @return void
*/
public function addGroup(Group $group): void
{
@@ -119,15 +127,17 @@ class OutGoingSMS extends SMS implements \JsonSerializable
}
/**
* Adds the given array of Groups to the recipient list.
- * @param array $groups An array of Groups
+ * @param array $groups An array of Groups.
+ * @return void
*/
public function addAllGroups(array $groups): void
{
$this->groups = array_merge($this->groups, $groups);
}
/**
- * Removes the Group in the given index and reindexes the array
- * @param int $index
+ * Removes the Group in the given index and reindexes the array.
+ * @param integer $index The index being requested for deletion.
+ * @return void
*/
public function removeGroup(int $index): void
{
@@ -136,11 +146,15 @@ class OutGoingSMS extends SMS implements \JsonSerializable
}
/**
* Returns the group in the given index.
- * @param int $index
+ * @param integer $index The index being requested.
* @return Group
+ * @throws \UndefinedOffsetException Thrown when the index requested does not exist.
*/
public function getGroup(int $index): Group
{
+ if ($index >= count($this->groups)) {
+ throw new \UndefinedOffsetException();
+ }
return $this->groups[$index];
}
/**
@@ -153,7 +167,11 @@ class OutGoingSMS extends SMS implements \JsonSerializable
}
- /** {@inheritDoc} */
+ /**
+ * Serializes the object to a value that can be serialized natively by json_encode().
+ * @return array Associative .
+ * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
+ */
public function jsonSerialize(): array
{
diff --git a/src/SMS/ProcessedOutGoingSMS.php b/src/SMS/ProcessedOutGoingSMS.php
index 74ce339..ab4e3cb 100644
--- a/src/SMS/ProcessedOutGoingSMS.php
+++ b/src/SMS/ProcessedOutGoingSMS.php
@@ -4,6 +4,8 @@
* PHP version 7.1.1
* @author Hannes Kindströmmer <hannes@kindstrommer.se>
* @copyright 2017 IP1 SMS
+* @package \IP1\RESTClient\SMS
+* @link http://api.ip1sms.com/Help/Api/PUT-api-contacts-contact
*/
namespace IP1\RESTClient\SMS;
@@ -12,20 +14,57 @@ use IP1\RESTClient\Core\UpdatableComponent;
/**
* The response from the API when you post an SMS to the API
-* @link http://api.ip1sms.com/Help/Api/PUT-api-contacts-contact
-* @package \IP1\RESTClient\SMS
*/
class ProcessedOutGoingSMS extends SMS implements UpdatableComponent
{
+ /**
+ * The ID of the SMS provided by the API.
+ * @var int $smsID
+ */
private $smsID;
+ /**
+ * An ID that groups SMSes together if they where sent by the same request.
+ * @var int|null $bundleID
+ */
private $bundleID;
+ /**
+ * The status code of the SMS.
+ * @var int $status
+ */
private $status;
+ /**
+ * Describes what $status means.
+ * @var string $statusDescription
+ */
private $statusDescription;
+ /**
+ * The phone number that the SMS was sent to.
+ * @var string $recipient
+ */
private $recipient;
+ /**
+ * Stores when the sms was created in UTC.
+ * @var DateTime $created
+ */
private $created;
+ /**
+ * Stores when the sms was last updated in UTC.
+ * @var DateTime $created
+ */
private $updated;
const IS_READ_ONLY = true;
-
+ /**
+ * ProcessedOutGoingSMS Constructor
+ * @param string $sender Phone number or name of the sender.
+ * @param string $message Message content.
+ * @param string $recipient The phone number that the SMS was sent to.
+ * @param integer $smsID The ID of the SMS provided by the API.
+ * @param \DateTime $created When the SMS was created.
+ * @param \DateTime $updated When the SMS was last updated (With a new status).
+ * @param integer $status What status code the SMS has.
+ * @param string $statusDescription A describing sentence about the status code.
+ * @param integer|null $bundleID An ID that groups SMSes together if they where sent by the same request.
+ */
public function __construct(
string $sender,
string $message,
@@ -78,6 +117,12 @@ class ProcessedOutGoingSMS extends SMS implements UpdatableComponent
{
return $this->recipient;
}
+ /**
+ * Returns when the component was updated last.
+ * @param \DateTimeZone $timezone The timezone that the user wants to get the DateTime in.
+ * Default is UTC.
+ * @return \DateTime When the contact was updated/modified last.
+ */
public function getUpdated(\DateTimeZone $timezone = null): ?\DateTime
{
if (!is_null($timezone)) {
@@ -88,6 +133,7 @@ class ProcessedOutGoingSMS extends SMS implements UpdatableComponent
return $this->updated ?? null;
}
/**
+ * Returns whether the object is read only or not.
* @return bool Whether the object is read only or not
*/
public function isReadOnly(): bool
@@ -95,8 +141,9 @@ class ProcessedOutGoingSMS extends SMS implements UpdatableComponent
return self::IS_READ_ONLY;
}
/**
- * @param DateTimeZone $timezone (optional) The timezone that the user wants to get the DateTime in. Default is UTC
- * @return DateTime When the Contact was added
+ * @param \DateTimeZone $timezone The timezone that the user wants to get the DateTime in.
+ * Default is UTC.
+ * @return \DateTime|null When the Contact was added.
*/
public function getCreated(\DateTimeZone $timezone = null): ?\DateTime
{
@@ -108,14 +155,18 @@ class ProcessedOutGoingSMS extends SMS implements UpdatableComponent
return $this->created ?? null;
}
/**
- * @return int SMS ID
+ * @return int SMS ID.
*/
public function getID():int
{
return $this->smsID;
}
- /** {@inheritDoc} */
+ /**
+ * Serializes the object to a value that can be serialized natively by json_encode().
+ * @return array Associative .
+ * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
+ */
public function jsonSerialize(): array
{
$parentArray = parent::jsonSerialize();
diff --git a/src/SMS/SMS.php b/src/SMS/SMS.php
index 64455df..58485ad 100644
--- a/src/SMS/SMS.php
+++ b/src/SMS/SMS.php
@@ -4,13 +4,13 @@
* PHP version 7.1.1
* @author Hannes Kindströmmer <hannes@kindstrommer.se>
* @copyright 2017 IP1 SMS
+* @package \IP1\RESTClient\SMS
*/
namespace IP1\RESTClient\SMS;
/**
* Abstract class that all other SMS classes extends.
-* @package \IP1\RESTClient\SMS;
*/
abstract class SMS implements \JsonSerializable
{
@@ -33,9 +33,9 @@ abstract class SMS implements \JsonSerializable
/**
- * SMS Constructor
- * @param string $sender Phone number or name of the sender
- * @param string $message Message content
+ * SMS Constructor.
+ * @param string $sender Phone number or name of the sender.
+ * @param string $message Message content.
*/
public function __construct(string $sender, string $message)
{
@@ -45,6 +45,7 @@ abstract class SMS implements \JsonSerializable
/**
* Sets what the content/message of the SMS should be.
* @param string $message The message the SMS should contain.
+ * @return void
*/
public function setMessage(string $message): void
{
@@ -53,7 +54,8 @@ abstract class SMS implements \JsonSerializable
/**
* Setting priority high (1) will cost 0.10SEK more than setting normal (1) for Swedish customers.
* For customers outside sweden the priority will be overritten to normal (1) by the API.
- * @param int $priority Message priority level, normal (1) or high (2)
+ * @param integer $priority Message priority level, normal (1) or high (2).
+ * @return void
*/
public function setPriority(int $priority): void
{
@@ -61,7 +63,8 @@ abstract class SMS implements \JsonSerializable
}
/**
* Sets the sender.
- * @param sting $sender Sending name or phone number
+ * @param string $sender Sending name or phone number.
+ * @return void
*/
public function setSender(string $sender): void
{
@@ -81,8 +84,10 @@ abstract class SMS implements \JsonSerializable
$this->from = $sender;
}
/**
- * {@inheritDoc}
- */
+ * Serializes the object to a value that can be serialized natively by json_encode().
+ * @return array Associative .
+ * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
+ */
public function jsonSerialize(): array
{
$returnArray = [