Skip to content

Commit

Permalink
declare strict_types and tighten return and parameter types
Browse files Browse the repository at this point in the history
  • Loading branch information
pavarnos committed Aug 14, 2018
1 parent dac4028 commit 6bf1a2f
Show file tree
Hide file tree
Showing 43 changed files with 172 additions and 129 deletions.
13 changes: 3 additions & 10 deletions samples/testFetchPublicKey.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
<?php

use Threema\MsgApi\Connection;
declare(strict_types=1);

require_once '../vendor/autoload.php';

//define your connection settings
$driver = new \Threema\MsgApi\HttpDriver\CurlHttpDriver(
'*YOUR_GATEWAY_THREEMA_ID',
'YOUR_GATEWAY_THREEMA_ID_SECRET'
);

//create a connection
$connector = new Connection($driver);
$factory = new \Threema\MsgApi\ConnectionFactory();
$connection = $factory->getConnection('*YOUR_GATEWAY_THREEMA_ID', 'YOUR_GATEWAY_THREEMA_ID_SECRET');

$result = $connector->fetchPublicKey('ECHOECHO');
if ($result->isSuccess()) {
Expand Down
13 changes: 4 additions & 9 deletions samples/testKeyLookup.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
<?php
declare(strict_types=1);

use Threema\MsgApi\Connection;

require_once '../vendor/autoload.php';

//define your connection settings
$driver = new \Threema\MsgApi\HttpDriver\CurlHttpDriver(
'*YOUR_GATEWAY_THREEMA_ID',
'YOUR_GATEWAY_THREEMA_ID_SECRET'
);
$factory = new \Threema\MsgApi\ConnectionFactory();
$connection = $factory->getConnection('*YOUR_GATEWAY_THREEMA_ID', 'YOUR_GATEWAY_THREEMA_ID_SECRET');

//create a connection
$connector = new Connection($driver);

$result = $connector->keyLookupByPhoneNumber('123456789');
$result = $connection->keyLookupByPhoneNumber('123456789');
if ($result->isSuccess()) {
echo 'Threema ID found: ' . $result->getId() . "\n";
} else {
Expand Down
19 changes: 5 additions & 14 deletions samples/testSendE2EFile.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
<?php

use Threema\MsgApi\Connection;
declare(strict_types=1);

require_once '../vendor/autoload.php';

//define your connection settings
$driver = new \Threema\MsgApi\HttpDriver\CurlHttpDriver(
'*YOUR_GATEWAY_THREEMA_ID',
'YOUR_GATEWAY_THREEMA_ID_SECRET'
);

//create a connection
$connector = new Connection($driver);
$factory = new \Threema\MsgApi\ConnectionFactory();
$connection = $factory->getConnection('*YOUR_GATEWAY_THREEMA_ID', 'YOUR_GATEWAY_THREEMA_ID_SECRET');

$senderPrivateKey = "MY_PUBLIC_KEY_IN_BIN";
$senderPrivateKey = "MY_PRIVATE_KEY_AS_HEX";
$filePath = "/path/to/my/file.pdf";

$e2eHelper = new \Threema\MsgApi\Helpers\E2EHelper($senderPrivateKey, $connector);
$result = $e2eHelper->sendFileMessage("TEST1234", "thePublicKeyAsHex", $filePath);
$result = $connection->sendFileMessage($senderPrivateKey, "TEST1234", "thePublicKeyAsHex", $filePath);

if (true === $result->isSuccess()) {
echo 'File Message ID: ' . $result->getMessageId() . "\n";
Expand Down
19 changes: 5 additions & 14 deletions samples/testSendE2EText.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
<?php

use Threema\MsgApi\Connection;
declare(strict_types=1);

require_once '../vendor/autoload.php';

//define your connection settings
$driver = new \Threema\MsgApi\HttpDriver\CurlHttpDriver(
'*YOUR_GATEWAY_THREEMA_ID',
'YOUR_GATEWAY_THREEMA_ID_SECRET'
);

//create a connection
$connector = new Connection($driver);

$senderPrivateKey = "MY_PUBLIC_KEY_IN_BIN";
$factory = new \Threema\MsgApi\ConnectionFactory();
$connection = $factory->getConnection('*YOUR_GATEWAY_THREEMA_ID', 'YOUR_GATEWAY_THREEMA_ID_SECRET');

$e2eHelper = new \Threema\MsgApi\Helpers\E2EHelper($senderPrivateKey, $connector);
$result = $e2eHelper->sendTextMessage("TEST1234", "thePublicKeyAsHex", "This is an end-to-end encrypted message");
$result = $connection->sendTextMessage("MY_PRIVATE_KEY_AS_HEX", "TEST1234", "thePublicKeyAsHex",
"This is an end-to-end encrypted message");

if (true === $result->isSuccess()) {
echo 'Message ID: ' . $result->getMessageId() . "\n";
Expand Down
14 changes: 4 additions & 10 deletions samples/testSendSimple.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
<?php
declare(strict_types=1);

use Threema\MsgApi\Connection;
use Threema\MsgApi\Receiver;

require_once '../vendor/autoload.php';

//define your connection settings
$driver = new \Threema\MsgApi\HttpDriver\CurlHttpDriver(
'*YOUR_GATEWAY_THREEMA_ID',
'YOUR_GATEWAY_THREEMA_ID_SECRET'
);

//create a connection
$connector = new Connection($driver);
$factory = new \Threema\MsgApi\ConnectionFactory();
$connection = $factory->getConnection('*YOUR_GATEWAY_THREEMA_ID', 'YOUR_GATEWAY_THREEMA_ID_SECRET');

//create a receiver
$receiver = new Receiver('ECHOECHO', Receiver::TYPE_ID);

$result = $connector->sendSimple($receiver, "This is a Test Message");
$result = $connection->sendSimple($receiver, "This is a Test Message");
if ($result->isSuccess()) {
echo 'Message ID: ' . $result->getMessageId() . "\n";
} else {
Expand Down
4 changes: 3 additions & 1 deletion src/Threema/MsgApi/Commands/Capability.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* @copyright Copyright (c) 2015-2016 Threema GmbH
*/

declare(strict_types=1);

namespace Threema\MsgApi\Commands;

use Threema\MsgApi\Commands\Results\CapabilityResult;
Expand All @@ -19,7 +21,7 @@ class Capability implements CommandInterface
/**
* @param string $threemaId
*/
public function __construct($threemaId)
public function __construct(string $threemaId)
{
$this->threemaId = $threemaId;
}
Expand Down
5 changes: 4 additions & 1 deletion src/Threema/MsgApi/Commands/Credits.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
* @copyright Copyright (c) 2015-2016 Threema GmbH
*/

declare(strict_types=1);

namespace Threema\MsgApi\Commands;

use Threema\MsgApi\Commands\Results\CreditsResult;
use Threema\MsgApi\Commands\Results\Result;

class Credits implements CommandInterface
{
Expand All @@ -28,7 +31,7 @@ public function getPath(): string
* @param string $response
* @return CreditsResult
*/
public function parseResult(int $httpCode, string $response): \Threema\MsgApi\Commands\Results\Result
public function parseResult(int $httpCode, string $response): Result
{
return new CreditsResult($httpCode, $response);
}
Expand Down
7 changes: 5 additions & 2 deletions src/Threema/MsgApi/Commands/DownloadFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
* @copyright Copyright (c) 2015-2016 Threema GmbH
*/

declare(strict_types=1);

namespace Threema\MsgApi\Commands;

use Threema\MsgApi\Commands\Results\DownloadFileResult;
use Threema\MsgApi\Commands\Results\Result;

class DownloadFile implements CommandInterface
{
Expand All @@ -18,7 +21,7 @@ class DownloadFile implements CommandInterface
/**
* @param string $blobId
*/
public function __construct($blobId)
public function __construct(string $blobId)
{
$this->blobId = $blobId;
}
Expand All @@ -44,7 +47,7 @@ public function getPath(): string
* @param string $response
* @return DownloadFileResult
*/
public function parseResult(int $httpCode, string $response): \Threema\MsgApi\Commands\Results\Result
public function parseResult(int $httpCode, string $response): Result
{
return new DownloadFileResult($httpCode, $response);
}
Expand Down
4 changes: 3 additions & 1 deletion src/Threema/MsgApi/Commands/FetchPublicKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* @copyright Copyright (c) 2015-2016 Threema GmbH
*/

declare(strict_types=1);

namespace Threema\MsgApi\Commands;

use Threema\MsgApi\Commands\Results\FetchPublicKeyResult;
Expand All @@ -18,7 +20,7 @@ class FetchPublicKey implements CommandInterface
/**
* @param string $threemaId
*/
public function __construct($threemaId)
public function __construct(string $threemaId)
{
$this->threemaId = $threemaId;
}
Expand Down
16 changes: 9 additions & 7 deletions src/Threema/MsgApi/Commands/Results/CapabilityResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* @copyright Copyright (c) 2015-2016 Threema GmbH
*/

declare(strict_types=1);

namespace Threema\MsgApi\Commands\Results;

class CapabilityResult extends Result
Expand All @@ -22,7 +24,7 @@ class CapabilityResult extends Result
/**
* @return string[]
*/
public function getCapabilities()
public function getCapabilities(): array
{
return $this->capabilities;
}
Expand All @@ -31,7 +33,7 @@ public function getCapabilities()
* the threema id can receive text
* @return bool
*/
public function canText()
public function canText(): bool
{
return $this->can(self::TEXT);
}
Expand All @@ -40,7 +42,7 @@ public function canText()
* the threema id can receive images
* @return bool
*/
public function canImage()
public function canImage(): bool
{
return $this->can(self::IMAGE);
}
Expand All @@ -49,7 +51,7 @@ public function canImage()
* the threema id can receive videos
* @return bool
*/
public function canVideo()
public function canVideo(): bool
{
return $this->can(self::VIDEO);
}
Expand All @@ -58,7 +60,7 @@ public function canVideo()
* the threema id can receive files
* @return bool
*/
public function canAudio()
public function canAudio(): bool
{
return $this->can(self::AUDIO);
}
Expand All @@ -67,12 +69,12 @@ public function canAudio()
* the threema id can receive files
* @return bool
*/
public function canFile()
public function canFile(): bool
{
return $this->can(self::FILE);
}

public function can($key)
public function can(string $key): bool
{
return in_array($key, $this->capabilities);
}
Expand Down
4 changes: 3 additions & 1 deletion src/Threema/MsgApi/Commands/Results/CreditsResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* @copyright Copyright (c) 2015-2016 Threema GmbH
*/

declare(strict_types=1);

namespace Threema\MsgApi\Commands\Results;

class CreditsResult extends Result
Expand All @@ -16,7 +18,7 @@ class CreditsResult extends Result
/**
* @return int
*/
public function getCredits()
public function getCredits(): int
{
return $this->credits;
}
Expand Down
4 changes: 3 additions & 1 deletion src/Threema/MsgApi/Commands/Results/DownloadFileResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* @copyright Copyright (c) 2015-2016 Threema GmbH
*/

declare(strict_types=1);

namespace Threema\MsgApi\Commands\Results;

class DownloadFileResult extends Result
Expand All @@ -18,7 +20,7 @@ class DownloadFileResult extends Result
*
* @return string
*/
public function getData()
public function getData(): string
{
return $this->data;
}
Expand Down
6 changes: 4 additions & 2 deletions src/Threema/MsgApi/Commands/Results/FetchPublicKeyResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@
* @copyright Copyright (c) 2015-2016 Threema GmbH
*/

declare(strict_types=1);

namespace Threema\MsgApi\Commands\Results;

class FetchPublicKeyResult extends Result
{
/**
* @var string
* @var string as hex
*/
private $publicKey;

/**
* @return string
*/
public function getPublicKey()
public function getPublicKey(): string
{
return $this->publicKey;
}
Expand Down
2 changes: 2 additions & 0 deletions src/Threema/MsgApi/Commands/Results/LookupBulkResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* @copyright Copyright (c) 2015-2016 Threema GmbH
*/

declare(strict_types=1);

namespace Threema\MsgApi\Commands\Results;

use Threema\MsgApi\Commands\LookupBulk;
Expand Down
4 changes: 3 additions & 1 deletion src/Threema/MsgApi/Commands/Results/LookupIdResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* @copyright Copyright (c) 2015-2016 Threema GmbH
*/

declare(strict_types=1);

namespace Threema\MsgApi\Commands\Results;

class LookupIdResult extends Result
Expand All @@ -16,7 +18,7 @@ class LookupIdResult extends Result
/**
* @return string
*/
public function getId()
public function getId(): string
{
return $this->id;
}
Expand Down
2 changes: 2 additions & 0 deletions src/Threema/MsgApi/Commands/Results/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* @copyright Copyright (c) 2015-2016 Threema GmbH
*/

declare(strict_types=1);

namespace Threema\MsgApi\Commands\Results;

abstract class Result
Expand Down
Loading

0 comments on commit 6bf1a2f

Please sign in to comment.