Skip to content

Commit 1401cbf

Browse files
committed
Use contracts package auth header
1 parent f8051eb commit 1401cbf

File tree

7 files changed

+128
-46
lines changed

7 files changed

+128
-46
lines changed

Makefile

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# set all to phony
2+
SHELL=bash
3+
4+
.PHONY: *
5+
6+
DOCKER_CGROUP:=$(shell cat /proc/1/cgroup | grep docker | wc -l)
7+
COMPOSER_CACHE_DIR=$(shell composer config --global cache-dir -q || echo ${HOME}/.composer/cache)
8+
9+
ifneq ("$(wildcard /.dockerenv)","")
10+
IN_DOCKER=TRUE
11+
else ifneq ("$(DOCKER_CGROUP)","0")
12+
IN_DOCKER=TRUE
13+
else
14+
IN_DOCKER=FALSe
15+
endif
16+
17+
ifeq ("$(IN_DOCKER)","TRUE")
18+
DOCKER_RUN=
19+
else
20+
DOCKER_RUN=docker run --rm -it \
21+
-v "`pwd`:`pwd`" \
22+
-v "${COMPOSER_CACHE_DIR}:/home/app/.composer/cache" \
23+
-w "`pwd`" \
24+
"wyrihaximusnet/php:8.2-nts-alpine-slim-dev"
25+
endif
26+
27+
all: ## Runs everything ###
28+
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | grep -v "###" | awk 'BEGIN {FS = ":.*?## "}; {printf "%s\n", $$1}' | xargs --open-tty $(MAKE)
29+
30+
syntax-php: ## Lint PHP syntax
31+
$(DOCKER_RUN) vendor/bin/parallel-lint --exclude vendor .
32+
33+
cs-fix: ## Fix any automatically fixable code style issues
34+
$(DOCKER_RUN) vendor/bin/phpcbf --parallel=$(shell nproc)
35+
36+
cs: ## Check the code for code style issues
37+
$(DOCKER_RUN) vendor/bin/phpcs --parallel=$(shell nproc)
38+
39+
stan: ## Run static analysis (PHPStan)
40+
$(DOCKER_RUN) vendor/bin/phpstan analyse src tests --level max --ansi -c phpstan.neon
41+
42+
psalm: ## Run static analysis (Psalm)
43+
$(DOCKER_RUN) vendor/bin/psalm --threads=$(shell nproc) --shepherd --stats
44+
45+
unit: ## Run tests
46+
$(DOCKER_RUN) vendor/bin/phpunit --colors=always -c phpunit.xml.dist --coverage-text --coverage-html covHtml --coverage-clover ./build/logs/clover.xml
47+
48+
unit-ci: unit
49+
if [ -f ./build/logs/clover.xml ]; then wget https://scrutinizer-ci.com/ocular.phar && sleep 3 && php ocular.phar code-coverage:upload --format=php-clover ./build/logs/clover.xml; fi
50+
51+
infection: ## Run mutation testing
52+
$(DOCKER_RUN) vendor/bin/infection --ansi --min-msi=100 --min-covered-msi=100 --threads=$(shell nproc)
53+
54+
composer-require-checker: ## Ensure we require every package used in this package directly
55+
$(DOCKER_RUN) vendor/bin/composer-require-checker --ignore-parse-errors --ansi -vvv --config-file=composer-require-checker.json
56+
57+
composer-unused: ## Ensure we don't require any package we don't use in this package directly
58+
$(DOCKER_RUN) composer unused --ansi
59+
60+
backward-compatibility-check: ## Check code for backwards incompatible changes
61+
$(DOCKER_RUN) vendor/bin/roave-backward-compatibility-check || true
62+
63+
shell: ## Provides Shell access in the expected environment ###
64+
$(DOCKER_RUN) ash
65+
66+
task-list-ci: ## CI: Generate a JSON array of jobs to run, matches the commands run when running `make (|all)` ###
67+
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | grep -v "###" | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "%s\n", $$1}' | jq --raw-input --slurp -c 'split("\n")| .[0:-1]'
68+
69+
help: ## Show this help ###
70+
@printf "\033[33mUsage:\033[0m\n make [target]\n\n\033[33mTargets:\033[0m\n"
71+
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[32m%-32s\033[0m %s\n", $$1, $$2}' | tr -d '#'
72+
73+
generate-clients:
74+
ls ./etc/clients | xargs -I % ./vendor/bin/openapi-client-generator ./etc/clients/%

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
}
2020
},
2121
"require": {
22-
"php": "^8.1",
22+
"php": "^8.2",
2323
"cebe/php-openapi": "dev-openapi-31 as 1.6.0",
2424
"jawira/case-converter": "^3.4",
2525
"twig/twig": "^3.0",
@@ -31,7 +31,8 @@
3131
"wyrihaximus/hydrator": "dev-master",
3232
"league/openapi-psr7-validator": "^0.16",
3333
"react/http": "^1.8",
34-
"reactivex/rxphp": "^2.0"
34+
"reactivex/rxphp": "^2.0",
35+
"api-clients/contracts": "dev-main"
3536
},
3637
"autoload": {
3738
"psr-4": {
@@ -46,7 +47,7 @@
4647
},
4748
"config": {
4849
"platform": {
49-
"php": "8.1.99"
50+
"php": "8.2.13"
5051
},
5152
"allow-plugins": {
5253
"wyrihaximus/composer-update-bin-autoload-path": true

composer.lock

Lines changed: 46 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Generator.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,6 @@ private function all(string $namespace): iterable
177177
);
178178
}
179179

180-
yield from Authentication::generate(
181-
$namespace,
182-
);
183-
184180
while ($schemaRegistry->hasUnknownSchemas()) {
185181
foreach ($schemaRegistry->unknownSchemas() as $schema) {
186182
yield from Schema::generate(

src/Generator/Authentication.php

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/Generator/Client.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace ApiClients\Tools\OpenApiClientGenerator\Generator;
44

5+
use ApiClients\Contracts\HTTP\Headers\AuthenticationInterface;
56
use ApiClients\Tools\OpenApiClientGenerator\File;
67
use ApiClients\Tools\OpenApiClientGenerator\SchemaRegistry;
78
use cebe\openapi\spec\Operation as OpenAPiOperation;
@@ -34,7 +35,7 @@ public static function generate(string $namespace, array $clients, SchemaRegistr
3435
$stmt = $factory->namespace(rtrim($namespace, '\\'));
3536

3637
$class = $factory->class('Client')->makeFinal()->addStmt(
37-
$factory->property('authentication')->setType('\\' . $namespace . Authentication::INTERFACE_NAME)->makeReadonly()->makePrivate()
38+
$factory->property('authentication')->setType('\\' . AuthenticationInterface::class)->makeReadonly()->makePrivate()
3839
)->addStmt(
3940
$factory->property('browser')->setType('\\' . Browser::class)->makeReadonly()->makePrivate()
4041
)->addStmt(
@@ -43,7 +44,7 @@ public static function generate(string $namespace, array $clients, SchemaRegistr
4344
$factory->property('responseSchemaValidator')->setType('\League\OpenAPIValidation\Schema\SchemaValidator')->makeReadonly()->makePrivate()
4445
)->addStmt(
4546
$factory->method('__construct')->makePublic()->addParam(
46-
(new Param('authentication'))->setType('\\' . $namespace . Authentication::INTERFACE_NAME)
47+
(new Param('authentication'))->setType('\\' . AuthenticationInterface::class)
4748
)->addStmt(
4849
new Node\Expr\Assign(
4950
new Node\Expr\PropertyFetch(

src/Generator/Schema.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private static function fillUpSchema(string $name, string $namespace, string $cl
9898
$propertyStmt = $factory->property($propertyName)->makePrivate();
9999
$propertyDocBlock = [];
100100
$methodDocBlock = [];
101-
if (strlen($property->description) > 0) {
101+
if (is_string($property->description) && strlen($property->description) > 0) {
102102
$propertyDocBlock[] = $property->description;
103103
$methodDocBlock[] = $property->description;
104104
}

0 commit comments

Comments
 (0)