Skip to content

Commit b3f34f8

Browse files
authored
improve exceptions (#9)
* improve exceptions * fix ci, up php version * update readme * up stan level * fix conf * update doc * fix ci * fix ci
1 parent 970e674 commit b3f34f8

33 files changed

+307
-186
lines changed

README.md

+14-12
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,18 @@
22

33
# Kafka Schema Registry API Client
44

5-
## What is it?
5+
## Description
66
An API Client written in PHP to communicate with Kafka Schema Registry.
77

8-
## What it can do?
8+
## Installation
9+
```bash
10+
composer require jobcloud/php-kafka-schema-registry-client
11+
```
12+
13+
## Requirements
14+
- php: >= 7.4
15+
16+
## Supported API calls
917
Currently it supports:
1018

1119
* Get list of subjects
@@ -24,13 +32,7 @@ Currently it supports:
2432
* Get Subject's latest schema version
2533
* Setting the registry mode
2634

27-
## How to use it?
28-
### Installation
29-
```bash
30-
composer require jobcloud/php-kafka-schema-registry-client
31-
```
32-
33-
### Code example
35+
## Code example
3436

3537
```php
3638
<?php
@@ -85,7 +87,7 @@ $api = $container['kafka.schema.registry.client.api']);
8587
$data = $api->getSubjects();
8688
```
8789

88-
## External links?
89-
If you want to be so kind to extend this library, make a pull request,
90-
and whatever functionality you want to implement, this is a API reference to follow:
90+
## Contributing
91+
This is an open source project that welcomes pull requests and issues from anyone.
92+
This is the API reference to follow for any new functionality:
9193
https://docs.confluent.io/current/schema-registry/develop/api.html

composer.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"sort-packages": true
2020
},
2121
"require": {
22-
"php": ">7.3",
22+
"php": ">=7.4",
2323
"ext-json": "*",
2424
"pimple/pimple": "^3.2",
2525
"symfony/cache": "^5.0",
@@ -29,9 +29,9 @@
2929
},
3030
"require-dev": {
3131
"squizlabs/php_codesniffer": "^3.4.2",
32-
"phpunit/phpunit": "^8.3.4",
33-
"phpstan/phpstan": "^0.11.8",
32+
"phpunit/phpunit": "^9.5",
33+
"phpstan/phpstan": "^0.12",
3434
"rregeer/phpunit-coverage-check": "^0.3.1",
35-
"infection/infection": "^0.14.2"
35+
"infection/infection": "^0.21"
3636
}
3737
}

docker/.env

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
COMPOSE_PROJECT_NAME=php-kafka-schema-registry-client

docker/dev/php/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM php:7.3-cli-alpine3.10
1+
FROM php:7.4-cli-alpine3.10
22

33
ARG HOST_USER_ID
44

phpstan.neon

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
parameters:
22
paths:
33
- src
4-
level: 7
4+
level: 8

phpunit.xml

+28-44
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,30 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit
3-
backupGlobals = "false"
4-
backupStaticAttributes = "false"
5-
colors = "true"
6-
convertErrorsToExceptions = "true"
7-
convertNoticesToExceptions = "true"
8-
convertWarningsToExceptions = "true"
9-
processIsolation = "false"
10-
stopOnFailure = "false"
11-
bootstrap = "vendor/autoload.php" >
12-
<php>
13-
<ini name="max_execution_time" value="-1"/>
14-
<ini name="html_errors" value="false"/>
15-
<ini name="memory_limit" value="2G"/>
16-
17-
<ini name="xdebug.default_enable" value="1" />
18-
<ini name="xdebug.enable_coverage" value="1" />
19-
<ini name="xdebug.remote_autostart" value="0" />
20-
<ini name="xdebug.remote_enable" value="0" />
21-
<ini name="xdebug.overload_var_dump" value="0" />
22-
<ini name="xdebug.show_mem_delta" value="0" />
23-
24-
<env name="ENVIRONMENT" value="test" />
25-
</php>
26-
27-
<testsuites>
28-
<testsuite name="Unit">
29-
<directory>./tests</directory>
30-
</testsuite>
31-
</testsuites>
32-
33-
<filter>
34-
<whitelist>
35-
<directory>src</directory>
36-
</whitelist>
37-
</filter>
38-
39-
<logging>
40-
<log type="coverage-text" target="php://stdout" showOnlySummary="true"/>
41-
<log type="coverage-clover" target="build/logs/phpunit/coverage/coverage.xml"/>
42-
<log type="coverage-html" target="build/logs/phpunit/coverage"/>
43-
<log type="coverage-xml" target="build/logs/phpunit/coverage/coverage-xml"/>
44-
<log type="junit" target="build/logs/phpunit/junit.xml"/>
45-
</logging>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" bootstrap="vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
3+
<coverage>
4+
<include>
5+
<directory>src</directory>
6+
</include>
7+
<report>
8+
<clover outputFile="build/logs/phpunit/coverage/coverage.xml"/>
9+
<html outputDirectory="build/logs/phpunit/coverage"/>
10+
<text outputFile="php://stdout" showOnlySummary="true"/>
11+
<xml outputDirectory="build/logs/phpunit/coverage/coverage-xml"/>
12+
</report>
13+
</coverage>
14+
<php>
15+
<ini name="max_execution_time" value="-1"/>
16+
<ini name="html_errors" value="false"/>
17+
<ini name="memory_limit" value="2G"/>
18+
<env name="error_reporting" value="E_ALL"/>
19+
<env name="display_errors" value="1"/>
20+
<env name="ENVIRONMENT" value="test"/>
21+
</php>
22+
<testsuites>
23+
<testsuite name="Unit">
24+
<directory>./tests</directory>
25+
</testsuite>
26+
</testsuites>
27+
<logging>
28+
<junit outputFile="build/logs/phpunit/junit.xml"/>
29+
</logging>
4630
</phpunit>

src/ErrorHandler.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace Jobcloud\Kafka\SchemaRegistryClient;
44

5+
use Buzz\Exception\ClientException;
56
use Jobcloud\Kafka\SchemaRegistryClient\Exception\BackendDatastoreException;
67
use Jobcloud\Kafka\SchemaRegistryClient\Exception\ImportException;
7-
use Jobcloud\Kafka\SchemaRegistryClient\Exception\ClientException;
88
use Jobcloud\Kafka\SchemaRegistryClient\Exception\CompatibilityException;
99
use Jobcloud\Kafka\SchemaRegistryClient\Exception\IncompatibileAvroSchemaException;
1010
use Jobcloud\Kafka\SchemaRegistryClient\Exception\InvalidAvroSchemaException;
@@ -13,12 +13,15 @@
1313
use Jobcloud\Kafka\SchemaRegistryClient\Exception\PathNotFoundException;
1414
use Jobcloud\Kafka\SchemaRegistryClient\Exception\RequestForwardException;
1515
use Jobcloud\Kafka\SchemaRegistryClient\Exception\SchemaNotFoundException;
16+
use Jobcloud\Kafka\SchemaRegistryClient\Exception\SchemaRegistryExceptionInterface;
1617
use Jobcloud\Kafka\SchemaRegistryClient\Exception\SubjectNotFoundException;
1718
use Jobcloud\Kafka\SchemaRegistryClient\Exception\UnauthorizedException;
1819
use Jobcloud\Kafka\SchemaRegistryClient\Exception\UnprocessableEntityException;
1920
use Jobcloud\Kafka\SchemaRegistryClient\Exception\VersionNotFoundException;
21+
use Psr\Http\Client\ClientExceptionInterface;
2022
use Psr\Http\Message\RequestInterface;
2123
use Psr\Http\Message\ResponseInterface;
24+
use JsonException;
2225

2326
class ErrorHandler implements ErrorHandlerInterface
2427
{
@@ -42,6 +45,9 @@ class ErrorHandler implements ErrorHandlerInterface
4245
* @throws UnprocessableEntityException
4346
* @throws VersionNotFoundException
4447
* @throws ImportException
48+
* @throws JsonException
49+
* @throws ClientExceptionInterface
50+
* @throws SchemaRegistryExceptionInterface
4551
*/
4652
public function handleError(ResponseInterface $response, string $uri = null, RequestInterface $request = null): void
4753
{

src/ErrorHandlerInterface.php

+6
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@
22

33
namespace Jobcloud\Kafka\SchemaRegistryClient;
44

5+
use Jobcloud\Kafka\SchemaRegistryClient\Exception\SchemaRegistryExceptionInterface;
6+
use Psr\Http\Client\ClientExceptionInterface;
57
use Psr\Http\Message\RequestInterface;
68
use Psr\Http\Message\ResponseInterface;
9+
use JsonException;
710

811
interface ErrorHandlerInterface
912
{
1013
/**
1114
* @param ResponseInterface $response
1215
* @param string|null $uri
16+
* @throws ClientExceptionInterface
17+
* @throws SchemaRegistryExceptionInterface
18+
* @throws JsonException
1319
*/
1420
public function handleError(
1521
ResponseInterface $response,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Jobcloud\Kafka\SchemaRegistryClient\Exception;
4+
5+
use Exception;
6+
7+
abstract class AbstractKafkaSchemaRegistryException extends Exception implements SchemaRegistryExceptionInterface
8+
{
9+
10+
}

src/Exception/BackendDatastoreException.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace Jobcloud\Kafka\SchemaRegistryClient\Exception;
44

5-
use Exception;
6-
7-
class BackendDatastoreException extends Exception
5+
class BackendDatastoreException extends AbstractKafkaSchemaRegistryException
86
{
97

108
}

src/Exception/ClientException.php

-10
This file was deleted.

src/Exception/CompatibilityException.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace Jobcloud\Kafka\SchemaRegistryClient\Exception;
44

5-
use Exception;
6-
7-
class CompatibilityException extends Exception
5+
class CompatibilityException extends AbstractKafkaSchemaRegistryException
86
{
97

108
}

src/Exception/ImportException.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace Jobcloud\Kafka\SchemaRegistryClient\Exception;
44

5-
use Exception;
6-
7-
class ImportException extends Exception
5+
class ImportException extends AbstractKafkaSchemaRegistryException
86
{
97

108
}

src/Exception/IncompatibileAvroSchemaException.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace Jobcloud\Kafka\SchemaRegistryClient\Exception;
44

5-
use Exception;
6-
7-
class IncompatibileAvroSchemaException extends Exception
5+
class IncompatibileAvroSchemaException extends AbstractKafkaSchemaRegistryException
86
{
97

108
}

src/Exception/InvalidAvroSchemaException.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace Jobcloud\Kafka\SchemaRegistryClient\Exception;
44

5-
use Exception;
6-
7-
class InvalidAvroSchemaException extends Exception
5+
class InvalidAvroSchemaException extends AbstractKafkaSchemaRegistryException
86
{
97

108
}

src/Exception/InvalidVersionException.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace Jobcloud\Kafka\SchemaRegistryClient\Exception;
44

5-
use Exception;
6-
7-
class InvalidVersionException extends Exception
5+
class InvalidVersionException extends AbstractKafkaSchemaRegistryException
86
{
97

108
}

src/Exception/OperationTimeoutException.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace Jobcloud\Kafka\SchemaRegistryClient\Exception;
44

5-
use Exception;
6-
7-
class OperationTimeoutException extends Exception
5+
class OperationTimeoutException extends AbstractKafkaSchemaRegistryException
86
{
97

108
}

src/Exception/PathNotFoundException.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace Jobcloud\Kafka\SchemaRegistryClient\Exception;
44

5-
use Exception;
6-
7-
class PathNotFoundException extends Exception
5+
class PathNotFoundException extends AbstractKafkaSchemaRegistryException
86
{
97

108
}

src/Exception/RequestForwardException.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace Jobcloud\Kafka\SchemaRegistryClient\Exception;
44

5-
use Exception;
6-
7-
class RequestForwardException extends Exception
5+
class RequestForwardException extends AbstractKafkaSchemaRegistryException
86
{
97

108
}

src/Exception/SchemaNotFoundException.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace Jobcloud\Kafka\SchemaRegistryClient\Exception;
44

5-
use Exception;
6-
7-
class SchemaNotFoundException extends Exception
5+
class SchemaNotFoundException extends AbstractKafkaSchemaRegistryException
86
{
97

108
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Jobcloud\Kafka\SchemaRegistryClient\Exception;
4+
5+
use Psr\Http\Client\ClientExceptionInterface;
6+
7+
interface SchemaRegistryExceptionInterface extends ClientExceptionInterface
8+
{
9+
10+
}

src/Exception/SubjectNotFoundException.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace Jobcloud\Kafka\SchemaRegistryClient\Exception;
44

5-
use Exception;
6-
7-
class SubjectNotFoundException extends Exception
5+
class SubjectNotFoundException extends AbstractKafkaSchemaRegistryException
86
{
97

108
}

src/Exception/UnauthorizedException.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace Jobcloud\Kafka\SchemaRegistryClient\Exception;
44

5-
use Exception;
6-
7-
class UnauthorizedException extends Exception
5+
class UnauthorizedException extends AbstractKafkaSchemaRegistryException
86
{
97

108
}

src/Exception/UnprocessableEntityException.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace Jobcloud\Kafka\SchemaRegistryClient\Exception;
44

5-
use Exception;
6-
7-
class UnprocessableEntityException extends Exception
5+
class UnprocessableEntityException extends AbstractKafkaSchemaRegistryException
86
{
97

108
}

0 commit comments

Comments
 (0)