Skip to content

Commit 0d64ae2

Browse files
committed
Add codeql workflow
1 parent 992b5f3 commit 0d64ae2

21 files changed

Lines changed: 138 additions & 58 deletions

.github/workflows/codeql.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: "CodeQL"
2+
3+
on: [pull_request]
4+
jobs:
5+
analyse:
6+
name: Static Analysis
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- name: Checkout repository
11+
uses: actions/checkout@v3
12+
with:
13+
fetch-depth: 2
14+
15+
- run: git checkout HEAD^2
16+
17+
- name: Run PHPStan
18+
run: |
19+
docker run --rm -v $PWD:/app composer sh -c \
20+
"composer install --profile --ignore-platform-reqs && composer check"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
vendor
22
composer.lock
33
.phpunit.result.cache
4+
.idea

Dockerfile

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
FROM composer:2.0 AS step0
22

3-
43
ARG TESTING=true
5-
64
ENV TESTING=$TESTING
75

86
WORKDIR /usr/local/src/
@@ -13,17 +11,16 @@ RUN composer update --ignore-platform-reqs --optimize-autoloader \
1311
--no-plugins --no-scripts --prefer-dist \
1412
`if [ "$TESTING" != "true" ]; then echo "--no-dev"; fi`
1513

16-
FROM php:8.0-cli-alpine as final
14+
FROM php:8.4-cli-alpine3.21 AS final
1715
LABEL maintainer="team@appwrite.io"
1816

1917
ENV DEBIAN_FRONTEND=noninteractive \
20-
PHP_VERSION=8
18+
PHP_VERSION=84
2119

2220
RUN \
2321
apk add --no-cache --virtual .deps \
2422
supervisor php$PHP_VERSION php$PHP_VERSION-fpm nginx bash
2523

26-
2724
# Nginx Configuration (with self-signed ssl certificates)
2825
COPY ./tests/docker/nginx.conf /etc/nginx/nginx.conf
2926

docker-compose.yml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
version: '3'
2-
31
services:
4-
web:
5-
build: .
6-
ports:
7-
- "9020:80"
8-
volumes:
9-
- ./tests:/usr/share/nginx/html/tests
10-
- ./src:/usr/share/nginx/html/src
2+
web:
3+
build: .
4+
ports:
5+
- "9020:80"
6+
volumes:
7+
- ./tests:/usr/share/nginx/html/tests
8+
- ./src:/usr/share/nginx/html/src

src/Platform/Action.php

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,34 @@ abstract class Action
4141

4242
protected ?string $desc = null;
4343

44+
/**
45+
* @var array<string>
46+
*/
4447
protected array $groups = [];
4548

49+
/**
50+
* @var callable
51+
*/
4652
protected $callback;
4753

54+
/**
55+
* @var array<string, mixed>
56+
*/
4857
protected array $options = [];
4958

59+
/**
60+
* @var array<string, array<string, mixed>>
61+
*/
5062
protected array $params = [];
5163

64+
/**
65+
* @var array<int, string>
66+
*/
5267
protected array $injections = [];
5368

69+
/**
70+
* @var array<string, mixed>
71+
*/
5472
protected array $labels = [];
5573

5674
protected string $type = self::TYPE_DEFAULT;
@@ -104,7 +122,7 @@ public function desc(string $description): self
104122
/**
105123
* Get the value of groups
106124
*
107-
* @return array
125+
* @return array<string>
108126
*/
109127
public function getGroups(): array
110128
{
@@ -114,7 +132,7 @@ public function getGroups(): array
114132
/**
115133
* Set Groups
116134
*
117-
* @param array $groups
135+
* @param array<string> $groups
118136
* @return self
119137
*/
120138
public function groups(array $groups): self
@@ -150,7 +168,7 @@ public function callback(mixed $callback): self
150168
/**
151169
* Get the value of params
152170
*
153-
* @return array
171+
* @return array<string, array<string, mixed>>
154172
*/
155173
public function getParams(): array
156174
{
@@ -165,7 +183,7 @@ public function getParams(): array
165183
* @param Validator|callable $validator
166184
* @param string $description
167185
* @param bool $optional
168-
* @param array $injections
186+
* @param array<string> $injections
169187
* @param bool $skipValidation
170188
* @param bool $deprecated
171189
* @param string $example
@@ -204,7 +222,7 @@ public function param(
204222
/**
205223
* Get the value of injections
206224
*
207-
* @return array
225+
* @return array<int, string>
208226
*/
209227
public function getInjections(): array
210228
{
@@ -237,7 +255,7 @@ public function inject(string $injection): self
237255
/**
238256
* Get the value of labels
239257
*
240-
* @return array
258+
* @return array<string, mixed>
241259
*/
242260
public function getLabels(): array
243261
{
@@ -261,7 +279,7 @@ public function label(string $key, mixed $value): self
261279
/**
262280
* Get Http Options
263281
*
264-
* @return array
282+
* @return array<string, mixed>
265283
*/
266284
public function getOptions(): array
267285
{

src/Platform/Module.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
abstract class Module
88
{
9+
/**
10+
* @var array<string, array<string, Service>>
11+
*/
912
protected array $services = [
1013
'all' => [],
1114
Service::TYPE_TASK => [],
@@ -19,7 +22,7 @@ abstract class Module
1922
*
2023
* @param string $key
2124
* @param Service $service
22-
* @return Platform
25+
* @return self
2326
*/
2427
public function addService(string $key, Service $service): self
2528
{
@@ -33,7 +36,7 @@ public function addService(string $key, Service $service): self
3336
* Remove Service
3437
*
3538
* @param string $key
36-
* @return Platform
39+
* @return self
3740
*/
3841
public function removeService(string $key): self
3942
{
@@ -68,7 +71,7 @@ public function getService(string $key): ?Service
6871
/**
6972
* Get Services
7073
*
71-
* @return array
74+
* @return array<string, Service>
7275
*/
7376
public function getServices(): array
7477
{
@@ -79,7 +82,7 @@ public function getServices(): array
7982
* Get services by type
8083
*
8184
* @param string $type
82-
* @return array<Service>
85+
* @return array<string, Service>
8386
*/
8487
public function getServicesByType(string $type): array
8588
{

src/Platform/Platform.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public function __construct(Module $module)
3333
/**
3434
* Initialize Application
3535
*
36+
* @param array<string, mixed> $params
3637
* @return void
3738
*/
3839
public function init(string $type, array $params = []): void
@@ -71,7 +72,7 @@ public function init(string $type, array $params = []): void
7172
/**
7273
* Init HTTP service
7374
*
74-
* @param Service $service
75+
* @param array<string, Service> $services
7576
* @return void
7677
*/
7778
protected function initHttp(array $services): void
@@ -94,7 +95,12 @@ protected function initHttp(array $services): void
9495
break;
9596
case Action::TYPE_DEFAULT:
9697
default:
97-
$hook = App::addRoute($action->getHttpMethod(), $action->getHttpPath());
98+
$httpMethod = $action->getHttpMethod();
99+
$httpPath = $action->getHttpPath();
100+
if ($httpMethod === null || $httpPath === null) {
101+
throw new Exception('HTTP method and path must be set for default actions');
102+
}
103+
$hook = App::addRoute($httpMethod, $httpPath);
98104
break;
99105
}
100106

@@ -143,6 +149,7 @@ protected function initHttp(array $services): void
143149
/**
144150
* Init CLI Services
145151
*
152+
* @param array<string, Service> $services
146153
* @return void
147154
*/
148155
protected function initTasks(array $services): void
@@ -193,7 +200,7 @@ protected function initTasks(array $services): void
193200
/**
194201
* Init worker Services
195202
*
196-
* @param array $params
203+
* @param array<string, Service> $services
197204
* @return void
198205
*/
199206
protected function initWorker(array $services, string $workerName): void
@@ -310,7 +317,7 @@ public function getService(string $key): ?Service
310317
/**
311318
* Get Services
312319
*
313-
* @return array
320+
* @return array<string, Service>
314321
*/
315322
public function getServices(): array
316323
{
@@ -362,7 +369,7 @@ public function setWorker(Server $worker): self
362369
* @param string|null $default
363370
* @return mixed
364371
*/
365-
public function getEnv(string $key, string $default = null): mixed
372+
public function getEnv(string $key, ?string $default = null): mixed
366373
{
367374
return $_SERVER[$key] ?? $default;
368375
}

src/Platform/Scope/HTTP.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ trait HTTP
1010

1111
protected ?string $httpAliasPath = null;
1212

13+
/**
14+
* @var array<string, mixed>
15+
*/
1316
protected array $httpAliasParams = [];
1417

1518
/**
@@ -41,9 +44,9 @@ public function setHttpMethod(string $method): self
4144
/**
4245
* Get httpPath
4346
*
44-
* @return string
47+
* @return string|null
4548
*/
46-
public function getHttpPath(): string
49+
public function getHttpPath(): ?string
4750
{
4851
return $this->httpPath;
4952
}
@@ -61,7 +64,7 @@ public function getHttpAliasPath(): ?string
6164
/**
6265
* Get the value of httpAliasParams
6366
*
64-
* @return array
67+
* @return array<string, mixed>
6568
*/
6669
public function getHttpAliasParams(): array
6770
{
@@ -71,9 +74,9 @@ public function getHttpAliasParams(): array
7174
/**
7275
* Get the value of httpMethod
7376
*
74-
* @return string
77+
* @return string|null
7578
*/
76-
public function getHttpMethod(): string
79+
public function getHttpMethod(): ?string
7780
{
7881
return $this->httpMethod;
7982
}
@@ -82,7 +85,7 @@ public function getHttpMethod(): string
8285
* Set httpAlias path and params
8386
*
8487
* @param string $path
85-
* @param array $params
88+
* @param array<string, mixed> $params
8689
* @return self
8790
*/
8891
public function httpAlias(string $path, array $params = []): self

src/Platform/Service.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ abstract class Service
1212

1313
public const TYPE_WORKER = 'Worker';
1414

15+
/**
16+
* @var array<string, Action>
17+
*/
1518
protected array $actions;
1619

1720
protected string $type;
@@ -80,7 +83,7 @@ public function getAction(string $key): ?Action
8083
/**
8184
* Get Actions
8285
*
83-
* @return array
86+
* @return array<string, Action>
8487
*/
8588
public function getActions(): array
8689
{

tests/Platform/TestActionCLI.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ public function __construct()
1818
});
1919
}
2020

21-
public function action($email, $list)
21+
/**
22+
* @param mixed $email
23+
* @param mixed $list
24+
*/
25+
public function action($email, $list): void
2226
{
2327
echo $email.'-'.implode('-', $list);
2428
}

0 commit comments

Comments
 (0)