Skip to content

init psalm on codebase and fix generic issues #167

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

Merged
merged 2 commits into from
Mar 25, 2021
Merged
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
19 changes: 19 additions & 0 deletions .github/workflows/psalm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Psalm

# Controls when the action will run.
on: [push, pull_request]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

- name: Psalm – Static Analysis for PHP
uses: docker://vimeo/psalm-github-actions
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit": "^8.0|^9.0"
"phpunit/phpunit": "^8.0|^9.0",
"vimeo/psalm": "^4.6"
},
"autoload": {
"psr-4": {
Expand Down
15 changes: 15 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<psalm
errorLevel="7"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>
6 changes: 4 additions & 2 deletions src/MessageBird/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,10 @@ public function __construct($accessKey = null, Common\HttpClient $httpClient = n

/**
* @param mixed $accessKey
*
* @return void
*/
public function setAccessKey($accessKey)
public function setAccessKey($accessKey): void
{
$authentication = new Common\Authentication($accessKey);

Expand All @@ -287,7 +289,7 @@ public function setAccessKey($accessKey)
private function getPhpVersion()
{
if (!defined('PHP_VERSION_ID')) {
$version = array_map('int', explode('.', PHP_VERSION));
$version = array_map('intval', explode('.', PHP_VERSION));
define('PHP_VERSION_ID', $version[0] * 10000 + $version[1] * 100 + $version[2]);
}

Expand Down
16 changes: 12 additions & 4 deletions src/MessageBird/Common/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,20 @@ public function __construct($endpoint, $timeout = 10, $connectionTimeout = 2, $h

/**
* @param string $userAgent
*
* @return void
*/
public function addUserAgentString($userAgent)
public function addUserAgentString($userAgent): void
{
$this->userAgent[] = $userAgent;
}

/**
* @param Common\Authentication $authentication
*
* @return void
*/
public function setAuthentication(Common\Authentication $authentication)
public function setAuthentication(Common\Authentication $authentication): void
{
$this->authentication = $authentication;
}
Expand All @@ -126,17 +130,21 @@ public function getRequestUrl($resourceName, $query)

/**
* @param array $headers
*
* @return void
*/
public function setHeaders(array $headers)
public function setHeaders(array $headers): void
{
$this->headers = $headers;
}

/**
* @param mixed $option
* @param mixed $value
*
* @return void
*/
public function addHttpOption($option, $value)
public function addHttpOption($option, $value): void
{
$this->httpOptions[$option] = $value;
}
Expand Down
2 changes: 1 addition & 1 deletion src/MessageBird/Objects/Chat/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Message extends Base
protected $_links = [];


public function getId()
public function getId(): string
{
return $this->id;
}
Expand Down
8 changes: 4 additions & 4 deletions src/MessageBird/Objects/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,17 @@ public function getHref()
}

/**
* @return string
* @return array
*/
public function getGroups()
public function getGroups(): array
{
return $this->groups;
}

/**
* @return string
* @return array
*/
public function getMessages()
public function getMessages(): array
{
return $this->messages;
}
Expand Down
8 changes: 6 additions & 2 deletions src/MessageBird/Objects/Conversation/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ public function loadFromArray($object)

/**
* Sets the location on this object if available.
*
* @return void
*/
private function loadLocationIfNeeded()
private function loadLocationIfNeeded(): void
{
if (!empty($this->location->latitude) && !empty($this->location->longitude)) {
$this->location = [
Expand All @@ -85,8 +87,10 @@ private function loadLocationIfNeeded()

/**
* Sets the media on this object if available.
*
* @return void
*/
private function loadMediaIfNeeded()
private function loadMediaIfNeeded(): void
{
if (!empty($this->audio->url)) {
$this->audio = ['url' => $this->audio->url];
Expand Down
12 changes: 9 additions & 3 deletions src/MessageBird/Objects/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,10 @@ class Message extends Base
* @param mixed $tariff
* @param mixed $mid
* @param mixed $member
*
* @return void
*/
public function setPremiumSms($shortcode, $keyword, $tariff, $mid = null, $member = null)
public function setPremiumSms($shortcode, $keyword, $tariff, $mid = null, $member = null): void
{
$this->typeDetails['shortcode'] = $shortcode;
$this->typeDetails['keyword'] = $keyword;
Expand All @@ -166,8 +168,10 @@ public function setPremiumSms($shortcode, $keyword, $tariff, $mid = null, $membe
/**
* @param mixed $header
* @param mixed $body
*
* @return void
*/
public function setBinarySms($header, $body)
public function setBinarySms($header, $body): void
{
$this->typeDetails['udh'] = $header;
$this->body = $body;
Expand All @@ -176,8 +180,10 @@ public function setBinarySms($header, $body)

/**
* @param mixed $bool
*
* @return void
*/
public function setFlash($bool)
public function setFlash($bool): void
{
if ($bool === true) {
$this->mclass = 0;
Expand Down
3 changes: 3 additions & 0 deletions src/MessageBird/Objects/PartnerAccount/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class Account extends Base

public $signingKey;

/**
* @return false|string
*/
public function loadToJson()
{
return json_encode([
Expand Down
2 changes: 1 addition & 1 deletion src/MessageBird/RequestValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function verify(SignedRequest $request)
return \hash_equals($expectedSignature, $calculatedSignature);
}

private function buildPayloadFromRequest(SignedRequest $request)
private function buildPayloadFromRequest(SignedRequest $request): string
{
$parts = [];

Expand Down
5 changes: 3 additions & 2 deletions src/MessageBird/Resources/AvailablePhoneNumbers.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ public function __construct(Common\HttpClient $httpClient)
* @param string $countryCode
* @param array $parameters
*
* @return Objects\BaseList
* @return Objects\BaseList|Objects\Number
*
* @throws \MessageBird\Exceptions\RequestException
* @throws \MessageBird\Exceptions\ServerException
*/
public function getList($countryCode, $parameters = []): Objects\BaseList
public function getList($countryCode, $parameters = [])
{
list($status, , $body) = $this->httpClient->performHttpRequest(
Common\HttpClient::REQUEST_GET,
Expand Down
35 changes: 25 additions & 10 deletions src/MessageBird/Resources/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Base
protected $resourceName;

/**
* @var Objects\Hlr|Objects\Message|Objects\Balance|Objects\Verify|Objects\Lookup|Objects\VoiceMessage
* @var Objects\Hlr|Objects\Message|Objects\Balance|Objects\Verify|Objects\Lookup|Objects\VoiceMessage|Objects\Conversation\Conversation
*/
protected $object;

Expand All @@ -38,8 +38,10 @@ public function __construct(Common\HttpClient $httpClient)

/**
* @param mixed $resourceName
*
* @return void
*/
public function setResourceName($resourceName)
public function setResourceName($resourceName): void
{
$this->resourceName = $resourceName;
}
Expand All @@ -54,25 +56,30 @@ public function getResourceName()

/**
* @param mixed $object
*
* @return void
*/
public function setObject($object)
public function setObject($object): void
{
$this->object = $object;
}

/**
* @return Objects\Hlr|Objects\Message|Objects\Balance|Objects\Verify|Objects\Lookup|Objects\VoiceMessage
* @return Objects\Balance|Objects\Conversation\Conversation|Objects\Hlr|Objects\Lookup|Objects\Message|Objects\Verify|Objects\VoiceMessage
*/
public function getObject()
{
return $this->object;
}

/**
* @no-named-arguments
*
* @param mixed $object
* @param array|null $query
*
* @return Objects\Hlr|Objects\Message|Objects\Balance|Objects\Verify|Objects\Lookup|Objects\VoiceMessage
* @return Objects\Balance|Objects\Conversation\Conversation|Objects\Hlr|Objects\Lookup|Objects\Message|Objects\Verify|Objects\VoiceMessage|null
*
* @throws Exceptions\HttpException
* @throws Exceptions\RequestException
* @throws Exceptions\ServerException
Expand All @@ -84,7 +91,12 @@ public function create($object, $query = null)
return $this->processRequest($body);
}

public function getList($parameters = [])
/**
* @param array|null $parameters
*
* @return Objects\Balance|Objects\BaseList|Objects\Conversation\Conversation|Objects\Hlr|Objects\Lookup|Objects\Message|Objects\Verify|Objects\VoiceMessage|null
*/
public function getList(?array $parameters = [])
{
list($status, , $body) = $this->httpClient->performHttpRequest(Common\HttpClient::REQUEST_GET, $this->resourceName, $parameters);

Expand All @@ -100,6 +112,7 @@ public function getList($parameters = [])
$objectName = $this->object;

foreach ($items as $item) {
/** @psalm-suppress UndefinedClass */
$object = new $objectName($this->httpClient);

$message = $object->loadFromArray($item);
Expand All @@ -112,9 +125,11 @@ public function getList($parameters = [])
}

/**
* @no-named-arguments
*
* @param mixed $id
*
* @return $this->object
* @return Objects\Balance|Objects\Conversation\Conversation|Objects\Hlr|Objects\Lookup|Objects\Message|Objects\Verify|Objects\VoiceMessage|null
*
* @throws Exceptions\RequestException
* @throws Exceptions\ServerException
Expand All @@ -129,7 +144,7 @@ public function read($id = null)
/**
* @param mixed $id
*
* @return bool
* @return Objects\Balance|Objects\Conversation\Conversation|Objects\Hlr|Objects\Lookup|Objects\Message|Objects\Verify|Objects\VoiceMessage|null|true
*
* @throws Exceptions\RequestException
* @throws Exceptions\ServerException
Expand All @@ -149,7 +164,7 @@ public function delete($id)
/**
* @param string $body
*
* @return $this
* @return Objects\Balance|Objects\Conversation\Conversation|Objects\Hlr|Objects\Lookup|Objects\Message|Objects\Verify|Objects\VoiceMessage|null
*
* @throws \MessageBird\Exceptions\RequestException
* @throws \MessageBird\Exceptions\ServerException
Expand All @@ -174,7 +189,7 @@ public function processRequest($body)
* @param mixed $object
* @param mixed $id
*
* @return $this ->object
* @return Objects\Balance|Objects\Conversation\Conversation|Objects\Hlr|Objects\Lookup|Objects\Message|Objects\Verify|Objects\VoiceMessage|null ->object
*
* @internal param array $parameters
*/
Expand Down
8 changes: 5 additions & 3 deletions src/MessageBird/Resources/Contacts.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(Common\HttpClient $httpClient)
* @param mixed $object
* @param mixed $id
*
* @return $this ->object
* @return Objects\Balance|Objects\Conversation\Conversation|Objects\Hlr|Objects\Lookup|Objects\Message|Objects\Verify|Objects\VoiceMessage|null ->object
*
* @internal param array $parameters
*/
Expand Down Expand Up @@ -58,7 +58,8 @@ public function update($object, $id)
/**
* @param mixed $id
* @param array|null $parameters
* @return $this ->object
*
* @return Objects\Balance|Objects\BaseList|Objects\Conversation\Conversation|Objects\Hlr|Objects\Lookup|Objects\Message|Objects\Verify|Objects\VoiceMessage|null ->object
*/
public function getMessages($id, $parameters = [])
{
Expand All @@ -74,7 +75,8 @@ public function getMessages($id, $parameters = [])
/**
* @param mixed $id
* @param array|null $parameters
* @return $this ->object
*
* @return Objects\Balance|Objects\BaseList|Objects\Conversation\Conversation|Objects\Hlr|Objects\Lookup|Objects\Message|Objects\Verify|Objects\VoiceMessage|null ->object
*/
public function getGroups($id, $parameters = [])
{
Expand Down
Loading