Skip to content

Commit aa51ebc

Browse files
loks0nclaude
andcommitted
Fix static analysis: widen return types to static and add explicit Container/K8sSecret methods
- Change get(), create(), createOrUpdate(), syncWithCluster() return types from K8sResource to static so concrete subclass methods are visible to PHPStan/Psalm after cluster operations - Change updateStatus(), jsonPatchStatus(), jsonMergePatchStatus() from self to static to maintain the covariant chain in subclasses - Add explicit setName/getName, setImagePullPolicy/getImagePullPolicy, setCommand/getCommand, setArgs/getArgs, setWorkingDir/getWorkingDir methods on Container instead of relying on __call magic - Add explicit setType/getType methods on K8sSecret instead of relying on __call magic Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent e584e8a commit aa51ebc

3 files changed

Lines changed: 103 additions & 13 deletions

File tree

src/Instances/Container.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@
44

55
class Container extends Instance
66
{
7+
/**
8+
* Set the container name.
9+
*/
10+
public function setName(string $name): static
11+
{
12+
return $this->setAttribute('name', $name);
13+
}
14+
15+
/**
16+
* Get the container name.
17+
*/
18+
public function getName(): ?string
19+
{
20+
return $this->getAttribute('name');
21+
}
22+
723
/**
824
* Set the image for the container.
925
*
@@ -14,6 +30,70 @@ public function setImage(string $image, string $tag = 'latest')
1430
return $this->setAttribute('image', $image.':'.$tag);
1531
}
1632

33+
/**
34+
* Set the image pull policy.
35+
*/
36+
public function setImagePullPolicy(string $policy): static
37+
{
38+
return $this->setAttribute('imagePullPolicy', $policy);
39+
}
40+
41+
/**
42+
* Get the image pull policy.
43+
*/
44+
public function getImagePullPolicy(): ?string
45+
{
46+
return $this->getAttribute('imagePullPolicy');
47+
}
48+
49+
/**
50+
* Set the command (entrypoint) for the container.
51+
*/
52+
public function setCommand(array $command): static
53+
{
54+
return $this->setAttribute('command', $command);
55+
}
56+
57+
/**
58+
* Get the command (entrypoint) for the container.
59+
*/
60+
public function getCommand(): array
61+
{
62+
return $this->getAttribute('command', []);
63+
}
64+
65+
/**
66+
* Set the args for the container.
67+
*/
68+
public function setArgs(array $args): static
69+
{
70+
return $this->setAttribute('args', $args);
71+
}
72+
73+
/**
74+
* Get the args for the container.
75+
*/
76+
public function getArgs(): array
77+
{
78+
return $this->getAttribute('args', []);
79+
}
80+
81+
/**
82+
* Set the working directory for the container.
83+
*/
84+
public function setWorkingDir(string $dir): static
85+
{
86+
return $this->setAttribute('workingDir', $dir);
87+
}
88+
89+
/**
90+
* Get the working directory for the container.
91+
*/
92+
public function getWorkingDir(): ?string
93+
{
94+
return $this->getAttribute('workingDir');
95+
}
96+
1797
/**
1898
* Add a new port to the container list.
1999
*

src/Kinds/K8sSecret.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@ class K8sSecret extends K8sResource implements InteractsWithK8sCluster, Watchabl
2424
*/
2525
protected static $namespaceable = true;
2626

27+
/**
28+
* Set the secret type.
29+
*/
30+
public function setType(string $type): static
31+
{
32+
return $this->setAttribute('type', $type);
33+
}
34+
35+
/**
36+
* Get the secret type.
37+
*/
38+
public function getType(): ?string
39+
{
40+
return $this->getAttribute('type');
41+
}
42+
2743
/**
2844
* Get the data attribute.
2945
* Supports base64 decoding.

src/Traits/RunsClusterOperations.php

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,8 @@ public function refreshResourceVersion()
111111
/**
112112
* Create or update the resource, wether the resource exists
113113
* or not within the cluster.
114-
*
115-
* @return $this
116114
*/
117-
public function syncWithCluster(array $query = ['pretty' => 1])
115+
public function syncWithCluster(array $query = ['pretty' => 1]): static
118116
{
119117
try {
120118
return $this->get($query);
@@ -125,10 +123,8 @@ public function syncWithCluster(array $query = ['pretty' => 1])
125123

126124
/**
127125
* Create or update the app based on existence.
128-
*
129-
* @return $this
130126
*/
131-
public function createOrUpdate(array $query = ['pretty' => 1])
127+
public function createOrUpdate(array $query = ['pretty' => 1]): static
132128
{
133129
if ($this->exists($query)) {
134130
$this->update($query);
@@ -180,11 +176,10 @@ public function allNamespaces(array $query = ['pretty' => 1])
180176
/**
181177
* Get a fresh instance from the cluster.
182178
*
183-
* @return \RenokiCo\PhpK8s\Kinds\K8sResource
184179
*
185180
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesAPIException
186181
*/
187-
public function get(array $query = ['pretty' => 1])
182+
public function get(array $query = ['pretty' => 1]): static
188183
{
189184
return $this->cluster
190185
->setResourceClass(get_class($this))
@@ -199,11 +194,10 @@ public function get(array $query = ['pretty' => 1])
199194
/**
200195
* Create the resource.
201196
*
202-
* @return \RenokiCo\PhpK8s\Kinds\K8sResource
203197
*
204198
* @throws \RenokiCo\PhpK8s\Exceptions\KubernetesAPIException
205199
*/
206-
public function create(array $query = ['pretty' => 1])
200+
public function create(array $query = ['pretty' => 1]): static
207201
{
208202
return $this->cluster
209203
->setResourceClass(get_class($this))
@@ -622,7 +616,7 @@ public function resourceStatusPath(): string
622616
/**
623617
* Update the status subresource.
624618
*/
625-
public function updateStatus(array $query = ['pretty' => 1]): self
619+
public function updateStatus(array $query = ['pretty' => 1]): static
626620
{
627621
$this->refreshOriginal();
628622
$this->refreshResourceVersion();
@@ -640,7 +634,7 @@ public function updateStatus(array $query = ['pretty' => 1]): self
640634
/**
641635
* JSON Patch (RFC 6902) the status subresource.
642636
*/
643-
public function jsonPatchStatus($patch, array $query = ['pretty' => 1]): self
637+
public function jsonPatchStatus($patch, array $query = ['pretty' => 1]): static
644638
{
645639
if (! $patch instanceof \RenokiCo\PhpK8s\Patches\JsonPatch) {
646640
$patch = new \RenokiCo\PhpK8s\Patches\JsonPatch($patch);
@@ -663,7 +657,7 @@ public function jsonPatchStatus($patch, array $query = ['pretty' => 1]): self
663657
/**
664658
* JSON Merge Patch (RFC 7396) the status subresource.
665659
*/
666-
public function jsonMergePatchStatus($patch, array $query = ['pretty' => 1]): self
660+
public function jsonMergePatchStatus($patch, array $query = ['pretty' => 1]): static
667661
{
668662
if (! $patch instanceof \RenokiCo\PhpK8s\Patches\JsonMergePatch) {
669663
$patch = new \RenokiCo\PhpK8s\Patches\JsonMergePatch($patch);

0 commit comments

Comments
 (0)