Skip to content

Commit 8ae0072

Browse files
authored
Merge pull request #20 from appwrite-labs/feat-type-safety-v2
Fix static analysis: widen return types to static, add explicit Container/K8sSecret methods
2 parents 554440b + 58a068f commit 8ae0072

6 files changed

Lines changed: 123 additions & 56 deletions

File tree

.github/workflows/ci.yml

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@ name: CI
33
on:
44
push:
55
branches:
6-
- "*"
6+
- main
77
tags:
88
- "*"
99
pull_request:
1010
branches:
1111
- "*"
1212

13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.ref }}
15+
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
16+
1317
jobs:
1418
build:
1519
if: "!contains(github.event.head_commit.message, 'skip ci')"
@@ -22,16 +26,9 @@ jobs:
2226
fail-fast: false
2327
matrix:
2428
php: ['8.3', '8.4', '8.5']
25-
kubernetes: ['1.33.10', '1.34.6', '1.35.3']
26-
laravel: ['12.*', '13.*']
27-
prefer: [prefer-lowest, prefer-stable]
28-
include:
29-
- laravel: "12.*"
30-
testbench: "10.*"
31-
- laravel: "13.*"
32-
testbench: "11.*"
29+
kubernetes: ['1.33.10']
3330

34-
name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - K8s v${{ matrix.kubernetes }} --${{ matrix.prefer }}
31+
name: PHP ${{ matrix.php }} - K8s v${{ matrix.kubernetes }}
3532

3633
steps:
3734
- uses: actions/checkout@v6
@@ -43,27 +40,11 @@ jobs:
4340
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, yaml
4441
coverage: pcov
4542

46-
- name: Get composer cache directory
47-
id: composer-cache
48-
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
49-
50-
- name: Prepare cache key
51-
id: prep
52-
run: |
53-
PHP_VERSION=${{ matrix.php }}
54-
LARAVEL_VERSION=${{ matrix.laravel }}
55-
PREFER_VERSION=${{ matrix.prefer }}
56-
57-
# Remove any .* from the versions
58-
LARAVEL_VERSION=${LARAVEL_VERSION//.*}
59-
60-
echo "cache-key=composer-php-$PHP_VERSION-$LARAVEL_VERSION-$PREFER_VERSION-${{ hashFiles('composer.json') }}" >> $GITHUB_OUTPUT
61-
6243
- uses: actions/cache@v5
6344
name: Cache dependencies
6445
with:
65-
path: ${{ steps.composer-cache.outputs.dir }}
66-
key: ${{ steps.prep.outputs.cache-key }}
46+
path: ~/.composer/cache/files
47+
key: composer-php-${{ matrix.php }}-${{ hashFiles('composer.json') }}
6748

6849
- uses: medyagh/setup-minikube@latest
6950
name: Setup Minikube
@@ -92,9 +73,7 @@ jobs:
9273
kubectl proxy --port=8080 --reject-paths="^/non-existent-path" &
9374
9475
- name: Install dependencies
95-
run: |
96-
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
97-
composer update --${{ matrix.prefer }} --prefer-dist --no-interaction
76+
run: composer update --prefer-stable --prefer-dist --no-interaction
9877

9978
- name: Setup in-cluster config
10079
run: |

composer.json

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@
3434
"ext-json": "*",
3535
"composer/semver": "^3.4",
3636
"guzzlehttp/guzzle": "^7.10",
37-
"illuminate/macroable": "^12.0|^13.0",
38-
"illuminate/support": "^12.0|^13.0",
39-
"ratchet/pawl": "^0.4.1",
40-
"symfony/process": "^7.3.4|^8.0"
37+
"illuminate/macroable": "^12.0",
38+
"illuminate/support": "^12.0",
39+
"ratchet/pawl": "^0.4.3",
40+
"symfony/process": "^7.4"
4141
},
4242
"suggest": {
4343
"ext-yaml": "YAML extension is used to read or generate YAML from PHP K8s internal classes.",
@@ -57,14 +57,13 @@
5757
"test": "vendor/bin/phpunit"
5858
},
5959
"require-dev": {
60-
"laravel/pint": "dev-main",
60+
"laravel/pint": "^1.29",
6161
"mockery/mockery": "^1.6",
62-
"orchestra/testbench": "^10.9.0|^11.0",
62+
"orchestra/testbench": "^10.9.0",
6363
"phpunit/phpunit": "^11.5",
6464
"vimeo/psalm": "^6.16.1"
6565
},
6666
"config": {
6767
"sort-packages": true
68-
},
69-
"minimum-stability": "dev"
68+
}
7069
}

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'): static
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/K8sScale.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function refreshOriginal(array $query = ['pretty' => 1]): static
8989
* @throws KubernetesAPIException
9090
*/
9191
#[\Override]
92-
public function create(array $query = ['pretty' => 1]): K8sResource
92+
public function create(array $query = ['pretty' => 1]): static
9393
{
9494
return $this->cluster
9595
->setResourceClass(get_class($this))

src/Kinds/K8sSecret.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,22 @@ class K8sSecret extends K8sResource implements InteractsWithK8sCluster, Watchabl
2020
*/
2121
protected static bool $namespaceable = true;
2222

23+
/**
24+
* Set the secret type.
25+
*/
26+
public function setType(string $type): static
27+
{
28+
return $this->setAttribute('type', $type);
29+
}
30+
31+
/**
32+
* Get the secret type.
33+
*/
34+
public function getType(): ?string
35+
{
36+
return $this->getAttribute('type');
37+
}
38+
2339
/**
2440
* Get the data attribute.
2541
* Supports base64 decoding.

src/Traits/RunsClusterOperations.php

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use RenokiCo\PhpK8s\Exceptions\KubernetesLogsException;
1616
use RenokiCo\PhpK8s\Exceptions\KubernetesScalingException;
1717
use RenokiCo\PhpK8s\Exceptions\KubernetesWatchException;
18-
use RenokiCo\PhpK8s\Kinds\K8sResource;
1918
use RenokiCo\PhpK8s\Kinds\K8sScale;
2019
use RenokiCo\PhpK8s\KubernetesCluster;
2120
use RenokiCo\PhpK8s\Patches\JsonMergePatch;
@@ -107,10 +106,8 @@ public function refreshResourceVersion(): static
107106
/**
108107
* Create or update the resource, wether the resource exists
109108
* or not within the cluster.
110-
*
111-
* @return $this
112109
*/
113-
public function syncWithCluster(array $query = ['pretty' => 1]): K8sResource
110+
public function syncWithCluster(array $query = ['pretty' => 1]): static
114111
{
115112
try {
116113
return $this->get($query);
@@ -121,10 +118,8 @@ public function syncWithCluster(array $query = ['pretty' => 1]): K8sResource
121118

122119
/**
123120
* Create or update the app based on existence.
124-
*
125-
* @return $this
126121
*/
127-
public function createOrUpdate(array $query = ['pretty' => 1]): K8sResource
122+
public function createOrUpdate(array $query = ['pretty' => 1]): static
128123
{
129124
if ($this->exists($query)) {
130125
$this->update($query);
@@ -174,10 +169,9 @@ public function allNamespaces(array $query = ['pretty' => 1]): ResourcesList
174169
/**
175170
* Get a fresh instance from the cluster.
176171
*
177-
*
178172
* @throws KubernetesAPIException
179173
*/
180-
public function get(array $query = ['pretty' => 1]): K8sResource
174+
public function get(array $query = ['pretty' => 1]): static
181175
{
182176
return $this->cluster
183177
->setResourceClass(get_class($this))
@@ -192,10 +186,9 @@ public function get(array $query = ['pretty' => 1]): K8sResource
192186
/**
193187
* Create the resource.
194188
*
195-
*
196189
* @throws KubernetesAPIException
197190
*/
198-
public function create(array $query = ['pretty' => 1]): K8sResource
191+
public function create(array $query = ['pretty' => 1]): static
199192
{
200193
return $this->cluster
201194
->setResourceClass(get_class($this))
@@ -604,7 +597,7 @@ public function resourceStatusPath(): string
604597
/**
605598
* Update the status subresource.
606599
*/
607-
public function updateStatus(array $query = ['pretty' => 1]): self
600+
public function updateStatus(array $query = ['pretty' => 1]): static
608601
{
609602
$this->refreshOriginal();
610603
$this->refreshResourceVersion();
@@ -622,9 +615,9 @@ public function updateStatus(array $query = ['pretty' => 1]): self
622615
/**
623616
* JSON Patch (RFC 6902) the status subresource.
624617
*/
625-
public function jsonPatchStatus(JsonPatch|array $patch, array $query = ['pretty' => 1]): self
618+
public function jsonPatchStatus(JsonPatch|array $patch, array $query = ['pretty' => 1]): static
626619
{
627-
if (! $patch instanceof JsonPatch) {
620+
if (is_array($patch)) {
628621
$patch = new JsonPatch($patch);
629622
}
630623

@@ -645,9 +638,9 @@ public function jsonPatchStatus(JsonPatch|array $patch, array $query = ['pretty'
645638
/**
646639
* JSON Merge Patch (RFC 7396) the status subresource.
647640
*/
648-
public function jsonMergePatchStatus(JsonMergePatch|array $patch, array $query = ['pretty' => 1]): self
641+
public function jsonMergePatchStatus(JsonMergePatch|array $patch, array $query = ['pretty' => 1]): static
649642
{
650-
if (! $patch instanceof JsonMergePatch) {
643+
if (is_array($patch)) {
651644
$patch = new JsonMergePatch($patch);
652645
}
653646

0 commit comments

Comments
 (0)