Skip to content

Commit

Permalink
#98 Raise PHP version (#99)
Browse files Browse the repository at this point in the history
* #98 Raise php version

* #98 Add native types

* #98 Drop redundand type information from doc blocks

* #98 Drop PHP 7.1, 7.2, 7.3 from travis configuration

* #98 Add `ReturnTypeWillChange` attribute

Add `ReturnTypeWillChange` attribute for methods with mixed return type to support PHP 8.1 type inheritance check.
  • Loading branch information
MaSpeng authored Dec 22, 2021
1 parent a29c6c2 commit b20b5b6
Show file tree
Hide file tree
Showing 102 changed files with 343 additions and 727 deletions.
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ language: php
dist: bionic

php:
- 7.1
- 7.2
- 7.3
- 7.4
# - 8.0 # PHP 8.0 requires PHPUnit to be upgraded, which then would break earlier versions

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
],
"license" : "MIT",
"require": {
"php" : "^7.1|^8.0",
"php" : "^7.4|^8.0",
"php-http/client-common": "^2.0",
"php-http/socket-client": "^2.0",
"php-http/discovery" : "^1.0",
Expand Down
120 changes: 34 additions & 86 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use Http\Client\HttpClient;
use Http\Client\Common\HttpMethodsClient;
use Http\Client\Common\HttpMethodsClientInterface;
use Http\Client\Exception\TransferException as HttpTransferException;
use Http\Message\RequestFactory as HttpRequestFactory;
use Http\Discovery\HttpClientDiscovery;
Expand Down Expand Up @@ -68,59 +69,43 @@ class Client
{
/**
* The api version.
*
* @var string
*/
protected $apiVersion = 'v1';
protected string $apiVersion = 'v1';

/**
* The address of the master server.
*
* @var string|null
*/
protected $master;
protected ?string $master = null;

/**
* The servide account token.
*
* @var string
*/
protected $token;
protected ?string $token = null;

/**
* The username for basic auth.
*
* @var string
*/
protected $username;
protected ?string $username = null;

/**
* The password for basic auth.
*
* @var string
*/
protected $password;
protected ?string $password = null;

/**
* The namespace.
*
* @var string
*/
protected $namespace = 'default';
protected string $namespace = 'default';

/**
* The http client.
*
* @var \Http\Client\Common\HttpMethodsClientInterface
*/
protected $httpClient;
protected HttpMethodsClientInterface $httpClient;

/**
* The exec channels for result messages.
*
* @var array
*/
protected $execChannels = [
protected array $execChannels = [
'stdin',
'stdout',
'stderr',
Expand All @@ -130,32 +115,29 @@ class Client

/**
* The repository class registry.
*
* @var RepositoryRegistry
*/
protected $classRegistry;
protected RepositoryRegistry $classRegistry;

/**
* The class instances.
*
* @var array
*/
protected $classInstances = [];
protected array $classInstances = [];

/**
* header for patch.
*
* @var array
*/
protected $patchHeaders = ['Content-Type' => 'application/strategic-merge-patch+json'];
protected array $patchHeaders = ['Content-Type' => 'application/strategic-merge-patch+json'];

protected ?bool $verify = null;

protected ?string $caCert = null;

protected ?string $clientCert = null;

protected ?string $clientKey = null;

/**
* The constructor.
*
* @param array $options
* @param \Maclof\Kubernetes\RepositoryRegistry|null $repositoryRegistry
* @param ClientInterface|null $httpClient Some client implementing PSR HTTP ClientInterface
* @param \Http\Message\RequestFactory $httpRequestFactory
*/
public function __construct(array $options = [], RepositoryRegistry $repositoryRegistry = null, ClientInterface $httpClient = null, HttpRequestFactory $httpRequestFactory = null)
{
Expand All @@ -169,11 +151,8 @@ public function __construct(array $options = [], RepositoryRegistry $repositoryR

/**
* Set the options.
*
* @param array $options
* @param bool $reset
*/
public function setOptions(array $options, $reset = false)
public function setOptions(array $options, bool $reset = false): void
{
if ($reset) {
$this->master = null;
Expand Down Expand Up @@ -205,11 +184,9 @@ public function setOptions(array $options, $reset = false)
* Parse a kubeconfig.
*
* @param string|array $content Mixed type, based on the second input argument
* @param string $contentType
* @return array
* @throws \InvalidArgumentException
*/
public static function parseKubeconfig($content, $contentType = 'yaml')
public static function parseKubeconfig($content, string $contentType = 'yaml'): array
{
if ($contentType === 'array') {
if (!is_array($content)) {
Expand Down Expand Up @@ -328,11 +305,9 @@ public static function parseKubeconfig($content, $contentType = 'yaml')
/**
* Parse a kubeconfig file.
*
* @param string $filePath
* @return array
* @throws \InvalidArgumentException
*/
public static function parseKubeconfigFile($filePath)
public static function parseKubeconfigFile(string $filePath): array
{
if (!file_exists($filePath)) {
throw new InvalidArgumentException('Kubeconfig file does not exist at path: ' . $filePath);
Expand All @@ -343,12 +318,8 @@ public static function parseKubeconfigFile($filePath)

/**
* Get a temp file path for some content.
*
* @param string $fileName
* @param string $fileContent
* @return string
*/
protected static function getTempFilePath($fileName, $fileContent)
protected static function getTempFilePath(string $fileName, string $fileContent): string
{
$fileName = 'kubernetes-client-' . $fileName;

Expand All @@ -363,20 +334,16 @@ protected static function getTempFilePath($fileName, $fileContent)

/**
* Set namespace.
*
* @param string $namespace
*/
public function setNamespace($namespace)
public function setNamespace(string $namespace): void
{
$this->namespace = $namespace;
}

/**
* Set patch header
*
* @param string patch type
*/
public function setPatchType($patchType = "strategic")
public function setPatchType(string $patchType = "strategic"): void
{
if ($patchType === "merge") {
$this->patchHeaders = ['Content-Type' => 'application/merge-patch+json'];
Expand All @@ -390,17 +357,12 @@ public function setPatchType($patchType = "strategic")
/**
* Send a request.
*
* @param string $method
* @param string $uri
* @param array $query
* @param mixed $body
* @param boolean $namespace
* @param string $apiVersion
* @param array $requestOptions
* @param mixed $body
* @return mixed
* @throws \Maclof\Kubernetes\Exceptions\BadRequestException
*/
public function sendRequest($method, $uri, $query = [], $body = null, $namespace = true, $apiVersion = null, array $requestOptions = [])
#[\ReturnTypeWillChange]
public function sendRequest(string $method, string $uri, array $query = [], $body = null, bool $namespace = true, string $apiVersion = null, array $requestOptions = [])
{
$baseUri = $apiVersion ? ('apis/' . $apiVersion) : ('api/' . $this->apiVersion);
if ($namespace) {
Expand Down Expand Up @@ -472,23 +434,16 @@ public function sendRequest($method, $uri, $query = [], $body = null, $namespace

/**
* Check if an upgrade request is required.
*
* @param array $response
* @return boolean
*/
protected function isUpgradeRequestRequired(array $response)
protected function isUpgradeRequestRequired(array $response): bool
{
return $response['code'] == 400 && $response['status'] === 'Failure' && $response['message'] === 'Upgrade request required';
}

/**
* Send an upgrade request and return any response messages.
*
* @param string $requestUri
* @param array $query
* @return array
*/
protected function sendUpgradeRequest($requestUri, array $query)
protected function sendUpgradeRequest(string $requestUri, array $query): array
{
$fullUrl = $this->master .'/' . $requestUri . '?' . implode('&', $this->parseQueryParams($query));
if (parse_url($fullUrl, PHP_URL_SCHEME) === 'https') {
Expand Down Expand Up @@ -568,11 +523,8 @@ protected function sendUpgradeRequest($requestUri, array $query)

/**
* Parse an array of query params.
*
* @param array $query
* @return array
*/
protected function parseQueryParams(array $query)
protected function parseQueryParams(array $query): array
{
$parts = [];

Expand Down Expand Up @@ -603,23 +555,19 @@ public function health()

/**
* Check the version.
*
* @return array
*/
public function version()
public function version(): array
{
return $this->sendRequest('GET', '/version');
}

/**
* Magic call method to grab a class instance.
*
* @param string $name
* @param array $args
* @return \stdClass
* @throws \BadMethodCallException
*/
public function __call($name, array $args)
public function __call(string $name, array $args)
{
if (isset($this->classRegistry[$name])) {
$class = $this->classRegistry[$name];
Expand Down
7 changes: 1 addition & 6 deletions src/Collections/CertificateCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ class CertificateCollection extends Collection
{
/**
* The constructor.
*
* @param array $items
*/
public function __construct(array $items)
{
Expand All @@ -16,11 +14,8 @@ public function __construct(array $items)

/**
* Get an array of certificates.
*
* @param array $items
* @return array
*/
protected function getCertificates(array $items)
protected function getCertificates(array $items): array
{
foreach ($items as &$item) {
if ($item instanceof Certificate) {
Expand Down
7 changes: 1 addition & 6 deletions src/Collections/ConfigMapCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ class ConfigMapCollection extends Collection
{
/**
* The constructor.
*
* @param array $items
*/
public function __construct(array $items)
{
Expand All @@ -16,11 +14,8 @@ public function __construct(array $items)

/**
* Get an array of config maps.
*
* @param array $items
* @return array
*/
protected function getConfigMaps(array $items)
protected function getConfigMaps(array $items): array
{
foreach ($items as &$item) {
if ($item instanceof ConfigMap) {
Expand Down
7 changes: 1 addition & 6 deletions src/Collections/CronJobCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ class CronJobCollection extends Collection
{
/**
* The constructor.
*
* @param array $items
*/
public function __construct(array $items)
{
Expand All @@ -16,11 +14,8 @@ public function __construct(array $items)

/**
* Get an array of cron jobs.
*
* @param array $items
* @return array
*/
protected function getCronJobs(array $items)
protected function getCronJobs(array $items): array
{
foreach ($items as &$item) {
if ($item instanceof CronJob) {
Expand Down
7 changes: 1 addition & 6 deletions src/Collections/DaemonSetCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ class DaemonSetCollection extends Collection
{
/**
* The constructor.
*
* @param array $items
*/
public function __construct(array $items)
{
Expand All @@ -16,11 +14,8 @@ public function __construct(array $items)

/**
* Get an array of daemon sets.
*
* @param array $items
* @return array
*/
protected function getDaemonSets(array $items)
protected function getDaemonSets(array $items): array
{
foreach ($items as &$item) {
if ($item instanceof DaemonSet) {
Expand Down
Loading

0 comments on commit b20b5b6

Please sign in to comment.