Skip to content

Commit

Permalink
Use type hints instead of doc blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
sibprogrammer committed Oct 1, 2021
1 parent 0fdd640 commit 8ad7345
Show file tree
Hide file tree
Showing 67 changed files with 579 additions and 815 deletions.
5 changes: 5 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@
<directory name="vendor" />
</ignoreFiles>
</projectFiles>

<issueHandlers>
<PropertyNotSetInConstructor errorLevel="suppress" />
<UndefinedPropertyFetch errorLevel="suppress" />
</issueHandlers>
</psalm>
42 changes: 21 additions & 21 deletions src/Api/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ class Client
const RESPONSE_SHORT = 1;
const RESPONSE_FULL = 2;

protected $_host;
protected $_port;
protected $_protocol;
protected $_login;
protected $_password;
protected $_proxy = '';
protected $_secretKey;
protected $_version = '';
protected string $_host;
protected int $_port;
protected string $_protocol;
protected string $_login = '';
protected string $_password = '';
protected string $_proxy = '';
protected string $_secretKey = '';
protected string $_version = '';

protected $_operatorsCache = [];
protected array $_operatorsCache = [];

/**
* @var callable
Expand All @@ -36,7 +36,7 @@ class Client
* @param int $port
* @param string $protocol
*/
public function __construct($host, $port = 8443, $protocol = 'https')
public function __construct(string $host, int $port = 8443, string $protocol = 'https')
{
$this->_host = $host;
$this->_port = $port;
Expand All @@ -49,7 +49,7 @@ public function __construct($host, $port = 8443, $protocol = 'https')
* @param string $login
* @param string $password
*/
public function setCredentials($login, $password)
public function setCredentials(string $login, string $password): void
{
$this->_login = $login;
$this->_password = $password;
Expand All @@ -60,7 +60,7 @@ public function setCredentials($login, $password)
*
* @param string $secretKey
*/
public function setSecretKey($secretKey)
public function setSecretKey(string $secretKey): void
{
$this->_secretKey = $secretKey;
}
Expand All @@ -70,7 +70,7 @@ public function setSecretKey($secretKey)
*
* @param string $proxy
*/
public function setProxy($proxy)
public function setProxy(string $proxy): void
{
$this->_proxy = $proxy;
}
Expand All @@ -80,7 +80,7 @@ public function setProxy($proxy)
*
* @param string $version
*/
public function setVersion($version)
public function setVersion(string $version): void
{
$this->_version = $version;
}
Expand All @@ -90,7 +90,7 @@ public function setVersion($version)
*
* @param callable|null $function
*/
public function setVerifyResponse(callable $function = null)
public function setVerifyResponse(callable $function = null): void
{
$this->_verifyResponseCallback = $function;
}
Expand All @@ -100,7 +100,7 @@ public function setVerifyResponse(callable $function = null)
*
* @return string
*/
public function getHost()
public function getHost(): string
{
return $this->_host;
}
Expand All @@ -110,7 +110,7 @@ public function getHost()
*
* @return int
*/
public function getPort()
public function getPort(): int
{
return $this->_port;
}
Expand All @@ -120,7 +120,7 @@ public function getPort()
*
* @return string
*/
public function getProtocol()
public function getProtocol(): string
{
return $this->_protocol;
}
Expand All @@ -132,7 +132,7 @@ public function getProtocol()
*
* @return SimpleXMLElement
*/
public function getPacket($version = null)
public function getPacket($version = null): SimpleXMLElement
{
$protocolVersion = !is_null($version) ? $version : $this->_version;
$content = "<?xml version='1.0' encoding='UTF-8' ?>";
Expand Down Expand Up @@ -295,7 +295,7 @@ protected function _getHeaders()
*
* @throws Exception
*/
protected function _verifyResponse($xml)
protected function _verifyResponse($xml): void
{
if ($xml->system && $xml->system->status && 'error' == (string) $xml->system->status) {
throw new Exception((string) $xml->system->errtext, (int) $xml->system->errcode);
Expand All @@ -315,7 +315,7 @@ protected function _verifyResponse($xml)
* @param string $request
* @param SimpleXMLElement $xml
*
* @return string
* @return false|string
*/
protected function _expandRequestShortSyntax($request, SimpleXMLElement $xml)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Api/InternalClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public function __construct()
/**
* Setup login to execute requests under certain user.
*
* @param $login
* @param string $login
*/
public function setLogin($login)
public function setLogin(string $login): void
{
$this->_login = $login;
}
Expand Down
9 changes: 3 additions & 6 deletions src/Api/Operator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@

class Operator
{
/** @var string|null */
protected $_wrapperTag = null;

/** @var \PleskX\Api\Client */
protected $_client;
protected string $_wrapperTag = '';
protected Client $_client;

public function __construct($client)
{
$this->_client = $client;

if (is_null($this->_wrapperTag)) {
if ('' === $this->_wrapperTag) {
$classNameParts = explode('\\', get_class($this));
$this->_wrapperTag = end($classNameParts);
$this->_wrapperTag = strtolower(preg_replace('/([a-z])([A-Z])/', '\1-\2', $this->_wrapperTag));
Expand Down
2 changes: 1 addition & 1 deletion src/Api/Operator/DatabaseServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class DatabaseServer extends \PleskX\Api\Operator
{
protected $_wrapperTag = 'db_server';
protected string $_wrapperTag = 'db_server';

/**
* @return array
Expand Down
2 changes: 1 addition & 1 deletion src/Api/Operator/DnsTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class DnsTemplate extends \PleskX\Api\Operator
{
protected $_wrapperTag = 'dns';
protected string $_wrapperTag = 'dns';

/**
* @param array $properties
Expand Down
2 changes: 1 addition & 1 deletion src/Api/Operator/EventLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class EventLog extends \PleskX\Api\Operator
{
protected $_wrapperTag = 'event_log';
protected string $_wrapperTag = 'event_log';

/**
* @return Struct\Event[]
Expand Down
2 changes: 1 addition & 1 deletion src/Api/Operator/ProtectedDirectory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class ProtectedDirectory extends \PleskX\Api\Operator
{
protected $_wrapperTag = 'protected-dir';
protected string $_wrapperTag = 'protected-dir';

/**
* @param string $name
Expand Down
2 changes: 1 addition & 1 deletion src/Api/Operator/SecretKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class SecretKey extends \PleskX\Api\Operator
{
protected $_wrapperTag = 'secret_key';
protected string $_wrapperTag = 'secret_key';

/**
* @param string $ipAddress
Expand Down
57 changes: 16 additions & 41 deletions src/Api/Operator/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
namespace PleskX\Api\Operator;

use PleskX\Api\Struct\Server as Struct;
use PleskX\Api\XmlResponse;

class Server extends \PleskX\Api\Operator
{
/**
* @return array
*/
public function getProtos()
public function getProtos(): array
{
$packet = $this->_client->getPacket();
$packet->addChild($this->_wrapperTag)->addChild('get_protos');
Expand All @@ -19,25 +17,22 @@ public function getProtos()
return (array) $response->protos->proto;
}

public function getGeneralInfo()
public function getGeneralInfo(): Struct\GeneralInfo
{
return new Struct\GeneralInfo($this->_getInfo('gen_info'));
}

public function getPreferences()
public function getPreferences(): Struct\Preferences
{
return new Struct\Preferences($this->_getInfo('prefs'));
}

public function getAdmin()
public function getAdmin(): Struct\Admin
{
return new Struct\Admin($this->_getInfo('admin'));
}

/**
* @return array
*/
public function getKeyInfo()
public function getKeyInfo(): array
{
$keyInfo = [];
$keyInfoXml = $this->_getInfo('key');
Expand All @@ -49,10 +44,7 @@ public function getKeyInfo()
return $keyInfo;
}

/**
* @return array
*/
public function getComponents()
public function getComponents(): array
{
$components = [];
$componentsXml = $this->_getInfo('components');
Expand All @@ -64,10 +56,7 @@ public function getComponents()
return $components;
}

/**
* @return array
*/
public function getServiceStates()
public function getServiceStates(): array
{
$states = [];
$statesXml = $this->_getInfo('services_state');
Expand All @@ -83,15 +72,12 @@ public function getServiceStates()
return $states;
}

public function getSessionPreferences()
public function getSessionPreferences(): Struct\SessionPreferences
{
return new Struct\SessionPreferences($this->_getInfo('session_setup'));
}

/**
* @return array
*/
public function getShells()
public function getShells(): array
{
$shells = [];
$shellsXml = $this->_getInfo('shells');
Expand All @@ -103,25 +89,19 @@ public function getShells()
return $shells;
}

/**
* @return array
*/
public function getNetworkInterfaces()
public function getNetworkInterfaces(): array
{
$interfacesXml = $this->_getInfo('interfaces');

return (array) $interfacesXml->interface;
}

public function getStatistics()
public function getStatistics(): Struct\Statistics
{
return new Struct\Statistics($this->_getInfo('stat'));
}

/**
* @return array
*/
public function getSiteIsolationConfig()
public function getSiteIsolationConfig(): array
{
$config = [];
$configXml = $this->_getInfo('site-isolation-config');
Expand All @@ -133,7 +113,7 @@ public function getSiteIsolationConfig()
return $config;
}

public function getUpdatesInfo()
public function getUpdatesInfo(): Struct\UpdatesInfo
{
return new Struct\UpdatesInfo($this->_getInfo('updates'));
}
Expand All @@ -144,7 +124,7 @@ public function getUpdatesInfo()
*
* @return string
*/
public function createSession($login, $clientIp)
public function createSession(string $login, string $clientIp): string
{
$packet = $this->_client->getPacket();
$sessionNode = $packet->addChild($this->_wrapperTag)->addChild('create_session');
Expand All @@ -157,12 +137,7 @@ public function createSession($login, $clientIp)
return (string) $response->id;
}

/**
* @param string $operation
*
* @return \SimpleXMLElement
*/
private function _getInfo($operation)
private function _getInfo(string $operation): XmlResponse
{
$packet = $this->_client->getPacket();
$packet->addChild($this->_wrapperTag)->addChild('get')->addChild($operation);
Expand Down
2 changes: 1 addition & 1 deletion src/Api/Operator/VirtualDirectory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@

class VirtualDirectory extends \PleskX\Api\Operator
{
protected $_wrapperTag = 'virtdir';
protected string $_wrapperTag = 'virtdir';
}
Loading

0 comments on commit 8ad7345

Please sign in to comment.