diff --git a/src/Exceptions/PhpK8sException.php b/src/Exceptions/PhpK8sException.php index a9270518dabf1b14ec0f6f889dfc9b69fad19248..f6611b4aac8dd60f130ed063ae1588ac8ef72639 100644 --- a/src/Exceptions/PhpK8sException.php +++ b/src/Exceptions/PhpK8sException.php @@ -20,7 +20,7 @@ class PhpK8sException extends Exception * @param int $code * @param array|null $payload */ - public function __construct($message = null, $code = 0, array $payload = null) + public function __construct($message = null, $code = 0, ?array $payload = null) { parent::__construct($message, $code); diff --git a/src/Instances/Container.php b/src/Instances/Container.php index 4e8c29fa96b7a7518b716e94e4fecc9f7f652350..4c4f34edd8cd1d11bb9df87b1487ee6080be8aff 100644 --- a/src/Instances/Container.php +++ b/src/Instances/Container.php @@ -24,7 +24,7 @@ class Container extends Instance * @param string $name * @return $this */ - public function addPort(int $containerPort, string $protocol = 'TCP', string $name = null) + public function addPort(int $containerPort, string $protocol = 'TCP', ?string $name = null) { return $this->addToAttribute('ports', [ 'name' => $name, diff --git a/src/Instances/MountedVolume.php b/src/Instances/MountedVolume.php index 7d36b5689b9e85802fe7a12127662c32a02070bd..18304fc9e5c319c7a338d768b87bdf7e75b025f8 100644 --- a/src/Instances/MountedVolume.php +++ b/src/Instances/MountedVolume.php @@ -32,7 +32,7 @@ class MountedVolume extends Instance * @param string|null $subPath * @return $this */ - public function mountTo(string $mountPath, string $subPath = null) + public function mountTo(string $mountPath, ?string $subPath = null) { $this->setMountPath($mountPath); diff --git a/src/Instances/Probe.php b/src/Instances/Probe.php index 4cb07bc155c63628cbb06e4c213df79502af6b09..4207813ee207eeb2efadd069d6f2ff4797ac2773 100644 --- a/src/Instances/Probe.php +++ b/src/Instances/Probe.php @@ -72,7 +72,7 @@ class Probe extends Instance * @param string $host * @return $this */ - public function tcp(int $port, string $host = null) + public function tcp(int $port, ?string $host = null) { if ($host) { $this->setAttribute('tcpSocket.host', $host); diff --git a/src/Instances/Volume.php b/src/Instances/Volume.php index 956e9e56cc422e899139e62e9ee2807710343b29..1ef5b44419447e3fc8aacff6f228f6921f9dea8c 100644 --- a/src/Instances/Volume.php +++ b/src/Instances/Volume.php @@ -77,7 +77,7 @@ class Volume extends Instance * @param string|null $subPath * @return \RenokiCo\PhpK8s\Instances\MountedVolume */ - public function mountTo(string $mountPath, string $subPath = null) + public function mountTo(string $mountPath, ?string $subPath = null) { return MountedVolume::from($this)->mountTo($mountPath, $subPath); } diff --git a/src/K8s.php b/src/K8s.php index f410a0749120b67ee0f96df7ebe610ce8fd60c70..8718d649477749ce85e6ecfb96c288d55ca3106b 100644 --- a/src/K8s.php +++ b/src/K8s.php @@ -57,7 +57,7 @@ class K8s * @param Closure|null $callback * @return \RenokiCo\PhpK8s\Kinds\K8sResource|array[\RenokiCo\PhpK8s\Kinds\K8sResource] */ - public static function fromYamlFile($cluster, string $path, Closure $callback = null) + public static function fromYamlFile($cluster, string $path, ?Closure $callback = null) { $content = file_get_contents($path); @@ -79,7 +79,7 @@ class K8s * @param \Closure|null $callback * @return \RenokiCo\PhpK8s\Kinds\K8sResource|array[\RenokiCo\PhpK8s\Kinds\K8sResource] */ - public static function fromTemplatedYamlFile($cluster, string $path, array $replace, Closure $callback = null) + public static function fromTemplatedYamlFile($cluster, string $path, array $replace, ?Closure $callback = null) { return static::fromYamlFile($cluster, $path, function ($content) use ($replace, $callback) { foreach ($replace as $search => $replacement) { @@ -97,7 +97,7 @@ class K8s * @param string|null $name * @return void */ - public static function registerCrd(string $class, string $name = null): void + public static function registerCrd(string $class, ?string $name = null): void { static::macro( Str::camel($name ?: substr($class, strrpos($class, '\\') + 1)), diff --git a/src/Kinds/K8sConfigMap.php b/src/Kinds/K8sConfigMap.php index 563afeb9a7d242d05147a95a3f502a92467dae15..f3735ad395249eec6f787b0484c6660ef2471d73 100644 --- a/src/Kinds/K8sConfigMap.php +++ b/src/Kinds/K8sConfigMap.php @@ -30,7 +30,7 @@ class K8sConfigMap extends K8sResource implements InteractsWithK8sCluster, Watch * @param string|null $name * @return mixed */ - public function getData(string $name = null) + public function getData(?string $name = null) { if ($name) { return $this->getAttribute("data.{$name}", ''); diff --git a/src/Kinds/K8sResource.php b/src/Kinds/K8sResource.php index 9b325342ccb18c4338bf4b65c84085277390490b..5117e6dafed1f23cc1149b70306fbbf209c5717a 100644 --- a/src/Kinds/K8sResource.php +++ b/src/Kinds/K8sResource.php @@ -55,7 +55,7 @@ class K8sResource implements Arrayable, Jsonable * @param string|null $name * @return void */ - public static function register(string $name = null): void + public static function register(?string $name = null): void { K8s::registerCrd(static::class, $name); } @@ -69,7 +69,7 @@ class K8sResource implements Arrayable, Jsonable * @param string|null $defaultVersion * @return string */ - public static function getUniqueCrdMacro(string $kind = null, string $defaultVersion = null): string + public static function getUniqueCrdMacro(?string $kind = null, ?string $defaultVersion = null): string { $kind = $kind ?: static::getKind(); $defaultVersion = $defaultVersion ?: static::getDefaultVersion(); @@ -127,7 +127,7 @@ class K8sResource implements Arrayable, Jsonable * @param string|null $kind * @return array */ - public function toArray(string $kind = null) + public function toArray(?string $kind = null) { $attributes = $this->attributes; @@ -154,7 +154,7 @@ class K8sResource implements Arrayable, Jsonable * @param string|null $kind * @return string */ - public function toJson($options = 0, string $kind = null) + public function toJson($options = 0, ?string $kind = null) { return json_encode($this->toArray($kind), $options); } @@ -167,7 +167,7 @@ class K8sResource implements Arrayable, Jsonable * @param string|null $kind * @return string */ - public function toJsonPayload(string $kind = null) + public function toJsonPayload(?string $kind = null) { $attributes = $this->toJson(JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES, $kind); diff --git a/src/KubernetesCluster.php b/src/KubernetesCluster.php index 1c6a7f4ec0a45100311057f041edb59b192b253c..521273ab28a0b945f4820dd40ad3b0975e94e2fa 100644 --- a/src/KubernetesCluster.php +++ b/src/KubernetesCluster.php @@ -170,7 +170,7 @@ class KubernetesCluster * @param string|null $url * @return void */ - public function __construct(string $url = null) + public function __construct(?string $url = null) { $this->url = $url; } diff --git a/src/Traits/Cluster/AuthenticatesCluster.php b/src/Traits/Cluster/AuthenticatesCluster.php index cbe3f6abb415c652b4514ccadbbb820615a52837..3a48bb5f74316360d1543330b82666e8bd1e280b 100644 --- a/src/Traits/Cluster/AuthenticatesCluster.php +++ b/src/Traits/Cluster/AuthenticatesCluster.php @@ -65,7 +65,7 @@ trait AuthenticatesCluster * @param string|null $token * @return $this */ - public function withToken(string $token = null) + public function withToken(?string $token = null) { $this->token = $this->normalize($token); @@ -80,7 +80,7 @@ trait AuthenticatesCluster * @param string|null $tokenPath * @return $this */ - public function withTokenFromCommandProvider(string $cmdPath, string $cmdArgs = null, string $tokenPath = null) + public function withTokenFromCommandProvider(string $cmdPath, ?string $cmdArgs = null, ?string $tokenPath = null) { $process = Process::fromShellCommandline("{$cmdPath} {$cmdArgs}"); @@ -109,7 +109,7 @@ trait AuthenticatesCluster * @param string|null $path * @return $this */ - public function loadTokenFromFile(string $path = null) + public function loadTokenFromFile(?string $path = null) { return $this->withToken(file_get_contents($path)); } @@ -121,7 +121,7 @@ trait AuthenticatesCluster * @param string|null $password * @return $this */ - public function httpAuthentication(string $username = null, string $password = null) + public function httpAuthentication(?string $username = null, ?string $password = null) { if (! is_null($username) || ! is_null($password)) { $this->auth = [$username, $password]; @@ -136,7 +136,7 @@ trait AuthenticatesCluster * @param string|null $path * @return $this */ - public function withCertificate(string $path = null) + public function withCertificate(?string $path = null) { $this->cert = $path; @@ -149,7 +149,7 @@ trait AuthenticatesCluster * @param string|null $path * @return $this */ - public function withPrivateKey(string $path = null) + public function withPrivateKey(?string $path = null) { $this->sslKey = $path; @@ -162,7 +162,7 @@ trait AuthenticatesCluster * @param string|null $path * @return $this */ - public function withCaCertificate(string $path = null) + public function withCaCertificate(?string $path = null) { $this->verify = $path; diff --git a/src/Traits/Cluster/LoadsFromKubeConfig.php b/src/Traits/Cluster/LoadsFromKubeConfig.php index 091b8ec6c885703b5eaf842eb06206781908af26..068e18b588128cfa474bb4166b23c0748922550f 100644 --- a/src/Traits/Cluster/LoadsFromKubeConfig.php +++ b/src/Traits/Cluster/LoadsFromKubeConfig.php @@ -44,7 +44,7 @@ trait LoadsFromKubeConfig * @throws \RenokiCo\PhpK8s\Exceptions\KubeConfigContextNotFound * @throws \RenokiCo\PhpK8s\Exceptions\KubeConfigUserNotFound */ - public static function fromKubeConfigVariable(string $context = null) + public static function fromKubeConfigVariable(?string $context = null) { /** @var \RenokiCo\PhpK8s\KubernetesCluster $this */ $cluster = new static; @@ -82,7 +82,7 @@ trait LoadsFromKubeConfig * @param string|null $context * @return \RenokiCo\PhpK8s\KubernetesCluster */ - public static function fromKubeConfigYaml(string $yaml, string $context = null) + public static function fromKubeConfigYaml(string $yaml, ?string $context = null) { /** @var \RenokiCo\PhpK8s\KubernetesCluster $this */ $cluster = new static; @@ -97,7 +97,7 @@ trait LoadsFromKubeConfig * @param string|null $context * @return \RenokiCo\PhpK8s\KubernetesCluster */ - public static function fromKubeConfigYamlFile(string $path = '/.kube/config', string $context = null) + public static function fromKubeConfigYamlFile(string $path = '/.kube/config', ?string $context = null) { return (new static)->fromKubeConfigYaml(file_get_contents($path), $context); } @@ -109,7 +109,7 @@ trait LoadsFromKubeConfig * @param string|null $context * @return \RenokiCo\PhpK8s\KubernetesCluster */ - public static function fromKubeConfigArray(array $kubeConfigArray, string $context = null) + public static function fromKubeConfigArray(array $kubeConfigArray, ?string $context = null) { $cluster = new static; @@ -128,7 +128,7 @@ trait LoadsFromKubeConfig * @throws \RenokiCo\PhpK8s\Exceptions\KubeConfigContextNotFound * @throws \RenokiCo\PhpK8s\Exceptions\KubeConfigUserNotFound */ - protected function loadKubeConfigFromArray(array $kubeconfig, string $context = null) + protected function loadKubeConfigFromArray(array $kubeconfig, ?string $context = null) { /** @var \RenokiCo\PhpK8s\KubernetesCluster $this */ diff --git a/src/Traits/Cluster/MakesWebsocketCalls.php b/src/Traits/Cluster/MakesWebsocketCalls.php index 06d85c3cbca2b0579d442b52709de97605464b98..db97e8407ca7950a558a47cb5a50ca0abe4b2204 100644 --- a/src/Traits/Cluster/MakesWebsocketCalls.php +++ b/src/Traits/Cluster/MakesWebsocketCalls.php @@ -143,7 +143,7 @@ trait MakesWebsocketCalls * @param array $query * @return mixed */ - protected function makeWsRequest(string $path, Closure $callback = null, array $query = ['pretty' => 1]) + protected function makeWsRequest(string $path, ?Closure $callback = null, array $query = ['pretty' => 1]) { $url = $this->getCallableUrl($path, $query); diff --git a/src/Traits/RunsClusterOperations.php b/src/Traits/RunsClusterOperations.php index 342a1be8c9028b08be00645a3e12ec7261e826be..6403c6081e38cab1ce1faab5e3b64a09bcd1d9c0 100644 --- a/src/Traits/RunsClusterOperations.php +++ b/src/Traits/RunsClusterOperations.php @@ -455,7 +455,7 @@ trait RunsClusterOperations */ public function exec( $command, - string $container = null, + ?string $container = null, array $query = ['pretty' => 1, 'stdin' => 1, 'stdout' => 1, 'stderr' => 1, 'tty' => 1] ) { if (! $this instanceof Executable) { @@ -486,8 +486,8 @@ trait RunsClusterOperations * @throws \RenokiCo\PhpK8s\Exceptions\KubernetesAPIException */ public function attach( - Closure $callback = null, - string $container = null, + ?Closure $callback = null, + ?string $container = null, array $query = ['pretty' => 1, 'stdin' => 1, 'stdout' => 1, 'stderr' => 1, 'tty' => 1] ) { if (! $this instanceof Attachable) { @@ -594,7 +594,7 @@ trait RunsClusterOperations * @param string|null $preNamespaceAction * @return string */ - protected function getApiPathPrefix(bool $withNamespace = true, string $preNamespaceAction = null): string + protected function getApiPathPrefix(bool $withNamespace = true, ?string $preNamespaceAction = null): string { $version = $this->getApiVersion(); diff --git a/tests/KubeConfigTest.php b/tests/KubeConfigTest.php index 82a657ecaef15ae88c88d2ba78e1c861f3cf19a2..cc4aa87c38bbd9be375d2d332de07683e9d7d250 100644 --- a/tests/KubeConfigTest.php +++ b/tests/KubeConfigTest.php @@ -211,7 +211,7 @@ class KubeConfigTest extends TestCase /** * @dataProvider environmentVariableContextProvider */ - public function test_from_environment_variable(string $context = null, string $expectedDomain) + public function test_from_environment_variable(?string $context = null, string $expectedDomain) { $_SERVER['KUBECONFIG'] = __DIR__.'/cluster/kubeconfig.yaml::'.__DIR__.'/cluster/kubeconfig-2.yaml';