From 3b10336ad86e3cfc9f8fbbf6b9d7fbcd665a0e73 Mon Sep 17 00:00:00 2001 From: Alex Renoki Date: Mon, 25 Oct 2021 09:15:41 +0300 Subject: [PATCH 1/2] static analysis --- .github/workflows/ci.yml | 4 ++++ composer.json | 3 ++- psalm.xml | 18 ++++++++++++++++++ src/K8s.php | 4 ++-- src/Kinds/K8sCronJob.php | 6 +++--- src/Kinds/K8sPod.php | 2 +- src/Kinds/K8sResource.php | 4 ++-- src/Kinds/K8sServiceAccount.php | 2 +- src/Kinds/K8sStatefulSet.php | 2 +- src/KubernetesCluster.php | 2 +- src/Traits/Cluster/ChecksClusterVersion.php | 2 +- src/Traits/Cluster/MakesWebsocketCalls.php | 3 ++- src/Traits/Resource/HasName.php | 4 ++-- src/Traits/Resource/HasNamespace.php | 4 ++-- src/Traits/Resource/HasStorageClass.php | 2 +- src/Traits/Resource/HasTemplate.php | 2 +- src/Traits/RunsClusterOperations.php | 2 +- 17 files changed, 45 insertions(+), 21 deletions(-) create mode 100644 psalm.xml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1bd779ea..2a2d2e41 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -84,6 +84,10 @@ jobs: run: | kubectl apply -f https://raw.githubusercontent.com/bitnami-labs/sealed-secrets/main/helm/sealed-secrets/crds/sealedsecret-crd.yaml + - name: Run static analysis + run: | + vendor/bin/psalm + - name: Run tests run: | vendor/bin/phpunit --coverage-text --coverage-clover=coverage.xml diff --git a/composer.json b/composer.json index bd570873..371b94e5 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,8 @@ }, "require-dev": { "mockery/mockery": "^1.4", - "orchestra/testbench": "^5.0|^6.0" + "orchestra/testbench": "^5.0|^6.0", + "vimeo/psalm": "4.x-dev" }, "config": { "sort-packages": true diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 00000000..b7d600f6 --- /dev/null +++ b/psalm.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + diff --git a/src/K8s.php b/src/K8s.php index 48691157..f410a074 100644 --- a/src/K8s.php +++ b/src/K8s.php @@ -52,7 +52,7 @@ public static function fromYaml($cluster, string $yaml) /** * Load Kind configuration from an YAML file. * - * @param \RenokiCo\PhpK8s\Kinds\KubernetesCluster|null $cluster + * @param \RenokiCo\PhpK8s\KubernetesCluster|null $cluster * @param string $path * @param Closure|null $callback * @return \RenokiCo\PhpK8s\Kinds\K8sResource|array[\RenokiCo\PhpK8s\Kinds\K8sResource] @@ -73,7 +73,7 @@ public static function fromYamlFile($cluster, string $path, Closure $callback = * replace all variables in curly braces with the values from * the given array. * - * @param \RenokiCo\PhpK8s\Kinds\KubernetesCluster|null $cluster + * @param \RenokiCo\PhpK8s\KubernetesCluster|null $cluster * @param string $path * @param array $replace * @param \Closure|null $callback diff --git a/src/Kinds/K8sCronJob.php b/src/Kinds/K8sCronJob.php index 985c4a1d..708effdb 100644 --- a/src/Kinds/K8sCronJob.php +++ b/src/Kinds/K8sCronJob.php @@ -61,7 +61,7 @@ public function getJobTemplate(bool $asInstance = true) $template = $this->getSpec('jobTemplate', []); if ($asInstance) { - $template = new K8sJob($this->cluster ?? null, $template); + $template = new K8sJob($this->cluster, $template); } return $template; @@ -70,7 +70,7 @@ public function getJobTemplate(bool $asInstance = true) /** * Set the schedule for the cronjob. * - * @param string|\Cron\CronExpression $schedule + * @param \Cron\CronExpression|string $schedule * @return $this */ public function setSchedule($schedule) @@ -86,7 +86,7 @@ public function setSchedule($schedule) * Retrieve the schedule. * * @param bool $asInstance - * @return string|\Cron\CronExpression + * @return \Cron\CronExpression|string */ public function getSchedule(bool $asInstance = true) { diff --git a/src/Kinds/K8sPod.php b/src/Kinds/K8sPod.php index 845fbd16..13f1390b 100644 --- a/src/Kinds/K8sPod.php +++ b/src/Kinds/K8sPod.php @@ -349,7 +349,7 @@ public function getPodIps(): array /** * Get the pod host IP. * - * @return string\null + * @return string|null */ public function getHostIp() { diff --git a/src/Kinds/K8sResource.php b/src/Kinds/K8sResource.php index f560bb26..cef93ecd 100644 --- a/src/Kinds/K8sResource.php +++ b/src/Kinds/K8sResource.php @@ -35,7 +35,7 @@ class K8sResource implements Arrayable, Jsonable /** * Create a new resource. * - * @param null|RenokiCo\PhpK8s\KubernetesCluster $cluster + * @param \RenokiCo\PhpK8s\KubernetesCluster|null $cluster * @param array $attributes * @return void */ @@ -80,7 +80,7 @@ public static function getUniqueCrdMacro(string $kind = null, string $defaultVer /** * Get the plural resource name. * - * @return string|null + * @return string */ public static function getPlural() { diff --git a/src/Kinds/K8sServiceAccount.php b/src/Kinds/K8sServiceAccount.php index 02900ef3..8b32e1be 100644 --- a/src/Kinds/K8sServiceAccount.php +++ b/src/Kinds/K8sServiceAccount.php @@ -24,7 +24,7 @@ class K8sServiceAccount extends K8sResource implements InteractsWithK8sCluster, /** * Attach a new secret to the secrets list. * - * @param string|\RenokiCo\PhpK8s\Kings\K8sSecret $secret + * @param \RenokiCo\PhpK8s\Kinds\K8sSecret|string $secret * @return $this */ public function addSecret($secret) diff --git a/src/Kinds/K8sStatefulSet.php b/src/Kinds/K8sStatefulSet.php index 7b1c51cb..5d68df4b 100644 --- a/src/Kinds/K8sStatefulSet.php +++ b/src/Kinds/K8sStatefulSet.php @@ -72,7 +72,7 @@ public function setUpdateStrategy(string $strategy, int $partition = 0) /** * Set the statefulset service. * - * @param string|\RenokiCo\PhpK8s\Kinds\K8sService $service + * @param \RenokiCo\PhpK8s\Kinds\K8sService|string $service * @return $this */ public function setService($service) diff --git a/src/KubernetesCluster.php b/src/KubernetesCluster.php index 9c11a778..c2602a12 100644 --- a/src/KubernetesCluster.php +++ b/src/KubernetesCluster.php @@ -185,7 +185,7 @@ public function setResourceClass(string $resourceClass) * * @param string $operation * @param string $path - * @param string|Closure $payload + * @param string|null|Closure $payload * @param array $query * @return mixed * diff --git a/src/Traits/Cluster/ChecksClusterVersion.php b/src/Traits/Cluster/ChecksClusterVersion.php index 3366d9df..eedea5f2 100644 --- a/src/Traits/Cluster/ChecksClusterVersion.php +++ b/src/Traits/Cluster/ChecksClusterVersion.php @@ -11,7 +11,7 @@ trait ChecksClusterVersion /** * The Kubernetes cluster version. * - * @var \vierbergenlars\SemVer\version + * @var \vierbergenlars\SemVer\version|null */ protected $kubernetesVersion; diff --git a/src/Traits/Cluster/MakesWebsocketCalls.php b/src/Traits/Cluster/MakesWebsocketCalls.php index 0d5f3554..06d85c3c 100644 --- a/src/Traits/Cluster/MakesWebsocketCalls.php +++ b/src/Traits/Cluster/MakesWebsocketCalls.php @@ -3,6 +3,7 @@ namespace RenokiCo\PhpK8s\Traits\Cluster; use Closure; +use Exception; use Illuminate\Support\Str; use Ratchet\Client\Connector as WebSocketConnector; use React\EventLoop\Factory as ReactFactory; @@ -183,7 +184,7 @@ protected function makeWsRequest(string $path, Closure $callback = null, array $ 'output' => $message, ]; }); - }, function ($e) { + }, function (Exception $e) { throw $e; }); } diff --git a/src/Traits/Resource/HasName.php b/src/Traits/Resource/HasName.php index dccd788d..a065090f 100644 --- a/src/Traits/Resource/HasName.php +++ b/src/Traits/Resource/HasName.php @@ -33,10 +33,10 @@ public function whereName(string $name) /** * Get the name. * - * @return string|null + * @return string */ public function getName() { - return $this->getAttribute('metadata.name', null); + return $this->getAttribute('metadata.name'); } } diff --git a/src/Traits/Resource/HasNamespace.php b/src/Traits/Resource/HasNamespace.php index be310a6a..87b176e1 100644 --- a/src/Traits/Resource/HasNamespace.php +++ b/src/Traits/Resource/HasNamespace.php @@ -36,7 +36,7 @@ public static function setDefaultNamespace(string $namespace) /** * Set the namespace of the resource. * - * @param string|\RenokiCo\PhpK8s\Kinds\K8sNamespace $namespace + * @param \RenokiCo\PhpK8s\Kinds\K8sNamespace|string $namespace * @return $this */ public function setNamespace($namespace) @@ -57,7 +57,7 @@ public function setNamespace($namespace) /** * Alias for ->setNamespace(). * - * @param string|\RenokiCo\PhpK8s\Kinds\K8sNamespace $namespace + * @param \RenokiCo\PhpK8s\Kinds\K8sNamespace|string $namespace * @return $this */ public function whereNamespace($namespace) diff --git a/src/Traits/Resource/HasStorageClass.php b/src/Traits/Resource/HasStorageClass.php index d84d0c1d..12f80abb 100644 --- a/src/Traits/Resource/HasStorageClass.php +++ b/src/Traits/Resource/HasStorageClass.php @@ -9,7 +9,7 @@ trait HasStorageClass /** * Set the storageClassName parameter. * - * @param string|\RenokiCo\PhpK8s\Kinds\K8sStorageClass + * @param \RenokiCo\PhpK8s\Kinds\K8sStorageClass|string $storageClass * @return $this */ public function setStorageClass($storageClass) diff --git a/src/Traits/Resource/HasTemplate.php b/src/Traits/Resource/HasTemplate.php index 30274171..c8003c51 100644 --- a/src/Traits/Resource/HasTemplate.php +++ b/src/Traits/Resource/HasTemplate.php @@ -32,7 +32,7 @@ public function getTemplate(bool $asInstance = true) $template = $this->getSpec('template', []); if ($asInstance) { - $template = new K8sPod($this->cluster ?? null, $template); + $template = new K8sPod($this->cluster, $template); } return $template; diff --git a/src/Traits/RunsClusterOperations.php b/src/Traits/RunsClusterOperations.php index c485cf47..342a1be8 100644 --- a/src/Traits/RunsClusterOperations.php +++ b/src/Traits/RunsClusterOperations.php @@ -477,7 +477,7 @@ public function exec( /** * Attach to the current resource. * - * @param + * @param \Closure|null $callback * @param string|null $container * @param array $query * @return string From 0f4b13523bc7991504a5eab83b324038bf0e553b Mon Sep 17 00:00:00 2001 From: Alex Renoki Date: Mon, 25 Oct 2021 09:16:54 +0300 Subject: [PATCH 2/2] ^4.11 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 371b94e5..80a4fd7c 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,7 @@ "require-dev": { "mockery/mockery": "^1.4", "orchestra/testbench": "^5.0|^6.0", - "vimeo/psalm": "4.x-dev" + "vimeo/psalm": "4.11" }, "config": { "sort-packages": true