Skip to content

Commit

Permalink
Update flix-tech/avro-php dependency (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-zh authored Aug 27, 2020
1 parent c488c06 commit a98ad31
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 45 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ composer-update:
PHP_VERSION=$(PHP_VERSION) $(PHP) $(COMPOSER) update --no-interaction --no-progress --no-suggest --no-scripts

phpstan:
PHP_VERSION=$(PHP_VERSION) $(PHP) vendor/bin/phpstan.phar analyse -l 7 src
PHP_VERSION=$(PHP_VERSION) $(PHP) vendor/bin/phpstan.phar analyse

cs-fixer:
PHP_VERSION=$(PHP_VERSION) $(PHP) bin/php-cs-fixer.phar fix --config=.php_cs.dist -v --dry-run \
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
"require": {
"php": "^7.2",
"beberlei/assert": "^2.9.9|~3.0",
"flix-tech/confluent-schema-registry-api": "~7.0",
"flix-tech/avro-php": "^3.0.0",
"flix-tech/confluent-schema-registry-api": "~7.1",
"flix-tech/avro-php": "^4.0.0",
"widmogrod/php-functional": "^4.2|^5.0"
},
"require-dev": {
"phpunit/phpunit": "~7.0,<8.0",
"phpstan/phpstan-shim": "^0.11",
"phpstan/phpstan": "^0.12",
"phpbench/phpbench": "~0.9",
"vlucas/phpdotenv": "~2.4",
"symfony/serializer": "^3.4|^4.3"
Expand Down
3 changes: 3 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
parameters:
level: 8
paths: [ src ]
13 changes: 13 additions & 0 deletions src/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

const get = '\FlixTech\AvroSerializer\Common\get';

/**
* @param mixed $key
* @param array<mixed,mixed> $array
*/
function get($key, array $array): Maybe
{
return isset($array[$key])
Expand All @@ -25,6 +29,9 @@ function getter(): callable

const inflectRecord = '\FlixTech\AvroSerializer\Common\inflectRecord';

/**
* @param mixed $record
*/
function inflectRecord($record): Maybe
{
return \is_object($record)
Expand All @@ -34,6 +41,12 @@ function inflectRecord($record): Maybe

const memoize = '\FlixTech\AvroSerializer\Common\memoize';

/**
* @param array<mixed,mixed> $arguments
* @param string|null $key
*
* @return mixed|null
*/
function memoize(callable $callback = null, array $arguments = [], $key = null)
{
static $storage = [];
Expand Down
3 changes: 3 additions & 0 deletions src/Objects/DefaultRecordSerializerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

final class DefaultRecordSerializerFactory
{
/**
* @param array<string,mixed> $guzzleClientOptions
*/
public static function get(
string $schemaRegistryURL,
array $guzzleClientOptions = [],
Expand Down
3 changes: 3 additions & 0 deletions src/Objects/Exceptions/Exceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ final class Exceptions
public const ERROR_ENCODING = 501;
public const ERROR_DECODING = 502;

/**
* @param mixed $record
*/
public static function forEncode($record, \AvroSchema $schema, \Exception $previous = null): AvroEncodingException
{
$exportedRecord = \var_export($record, true);
Expand Down
23 changes: 8 additions & 15 deletions src/Objects/RecordSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ class RecordSerializer
*/
protected $protocolValidatorFunc;

/**
* RecordSerializer constructor.
*
* @param array<string,mixed> $options
*
* @throws \AvroIOException
*/
public function __construct(Registry $registry, array $options = [])
{
$this->registry = $registry;
Expand All @@ -100,11 +107,7 @@ public function __construct(Registry $registry, array $options = [])
}

/**
* @param string $subject
* @param \AvroSchema $schema
* @param mixed $record
*
* @return string
* @param mixed $record
*
* @throws \Exception
* @throws \FlixTech\SchemaRegistryApi\Exception\SchemaRegistryException
Expand All @@ -120,9 +123,6 @@ public function encodeRecord(string $subject, AvroSchema $schema, $record): stri
}

/**
* @param string $binaryMessage
* @param \AvroSchema|null $readersSchema
*
* @return mixed
*
* @throws \InvalidArgumentException
Expand Down Expand Up @@ -150,11 +150,6 @@ public function decodeMessage(string $binaryMessage, AvroSchema $readersSchema =
}

/**
* @param string $subject
* @param \AvroSchema $schema
*
* @return int
*
* @throws \Exception
* @throws \FlixTech\SchemaRegistryApi\Exception\SchemaRegistryException
*/
Expand Down Expand Up @@ -192,8 +187,6 @@ private function extractValueFromRegistryResponse($response)
}

/**
* @param \FlixTech\SchemaRegistryApi\Exception\SchemaRegistryException $e
*
* @throws \FlixTech\SchemaRegistryApi\Exception\SchemaRegistryException
*/
private function handleSubjectOrSchemaNotFound(SchemaRegistryException $e): void
Expand Down
5 changes: 3 additions & 2 deletions src/Objects/SchemaResolverInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
*/
interface SchemaResolverInterface
{
/**
* @param mixed $record
*/
public function valueSchemaFor($record): AvroSchema;

/**
Expand All @@ -20,8 +23,6 @@ public function valueSchemaFor($record): AvroSchema;
* If the key schema cannot be resolved otherwise, this method should throw an `CannotResolveSchemaException`.
*
* @param mixed $record
*
* @return AvroSchema|null
*/
public function keySchemaFor($record): ?AvroSchema;
}
4 changes: 1 addition & 3 deletions src/Objects/SchemaResolvers/ChainResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ public function valueSchemaFor($record): AvroSchema
}
}

throw new \InvalidArgumentException(
'No schema resolver in the chain is able to resolve the schema for the record'
);
throw new \InvalidArgumentException('No schema resolver in the chain is able to resolve the schema for the record');
}

public function keySchemaFor($record): ?AvroSchema
Expand Down
7 changes: 3 additions & 4 deletions src/Objects/SchemaResolvers/DefinitionInterfaceResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ class DefinitionInterfaceResolver implements SchemaResolverInterface
/**
* @param mixed $record
*
* @return \AvroSchema
*
* @throws \AvroSchemaParseException
*/
public function valueSchemaFor($record): AvroSchema
Expand All @@ -29,8 +27,6 @@ public function valueSchemaFor($record): AvroSchema
/**
* @param mixed $record
*
* @return \AvroSchema|null
*
* @throws \AvroSchemaParseException
*/
public function keySchemaFor($record): ?AvroSchema
Expand All @@ -46,6 +42,9 @@ public function keySchemaFor($record): ?AvroSchema
return AvroSchema::parse($keySchemaJson);
}

/**
* @param mixed $record
*/
private function guardRecordHasDefinition($record): void
{
Assert::that($record)
Expand Down
8 changes: 7 additions & 1 deletion src/Protocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function decode(string $binaryString): Either
PROTOCOL_ACCESSOR_AVRO
);

/** @var array|bool $unpacked */
/** @var array<mixed,mixed>|bool $unpacked */
$unpacked = @\unpack(
$packedFormat,
$binaryString
Expand All @@ -84,6 +84,9 @@ function decode(string $binaryString): Either

const validate = '\FlixTech\AvroSerializer\Protocol\validate';

/**
* @param array<mixed,mixed> $decoded
*/
function validate(int $protocolVersion, array $decoded): Maybe
{
$valid = isset($decoded[PROTOCOL_ACCESSOR_VERSION], $decoded[PROTOCOL_ACCESSOR_SCHEMA_ID], $decoded[PROTOCOL_ACCESSOR_AVRO])
Expand All @@ -98,6 +101,9 @@ function validate(int $protocolVersion, array $decoded): Maybe

const validator = '\FlixTech\AvroSerializer\Protocol\validator';

/**
* @return \Closure
*/
function validator(int $protocolVersion)
{
return curryN(2, validate)($protocolVersion);
Expand Down
14 changes: 6 additions & 8 deletions src/Serialize.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
const avroStringIo = '\FlixTech\AvroSerializer\Serialize\avroStringIo';

/**
* @param string $contents
*
* @return \AvroStringIO
*
* @throws \AvroIOException
*/
function avroStringIo(string $contents): AvroStringIO
Expand All @@ -46,8 +42,6 @@ function avroBinaryDecoder(AvroStringIO $io): AvroIOBinaryDecoder
const avroDatumWriter = '\FlixTech\AvroSerializer\Serialize\avroDatumWriter';

/**
* @return callable
*
* @throws \AvroIOException
*/
function avroDatumWriter(): callable
Expand All @@ -60,6 +54,9 @@ function avroDatumWriter(): callable

const writeDatum = '\FlixTech\AvroSerializer\Serialize\writeDatum';

/**
* @param mixed $record
*/
function writeDatum(AvroIODatumWriter $writer, AvroStringIO $io, AvroSchema $schema, $record): Either
{
return tryCatch(
Expand All @@ -81,8 +78,6 @@ static function (\AvroException $e) use ($record, $schema) {
const avroDatumReader = '\FlixTech\AvroSerializer\Serialize\avroDatumReader';

/**
* @return callable
*
* @throws \AvroIOException
*/
function avroDatumReader(): callable
Expand All @@ -95,6 +90,9 @@ function avroDatumReader(): callable

const readDatum = '\FlixTech\AvroSerializer\Serialize\readDatum';

/**
* @param mixed $data
*/
function readDatum(
AvroIODatumReader $reader,
AvroStringIO $io,
Expand Down
2 changes: 0 additions & 2 deletions test/Integrations/Symfony/Serializer/AvroSerDeEncoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ public function it_should_decode_with_valid_decode_context(): void
* @test
* @expectedException \InvalidArgumentException
* @dataProvider encodeContextValidationDataProvider
*
* @param array $context
*/
public function it_should_validate_encode_context(array $context): void
{
Expand Down
6 changes: 0 additions & 6 deletions test/Objects/RecordSerializerIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ public function it_encodes_valid_records(): RecordSerializer
*
* @expectedException \FlixTech\SchemaRegistryApi\Exception\IncompatibleAvroSchemaException
*
* @param \FlixTech\AvroSerializer\Objects\RecordSerializer $serializer
*
* @throws \FlixTech\SchemaRegistryApi\Exception\SchemaRegistryException
*/
public function it_cannot_evolve_incompatible_schema(RecordSerializer $serializer): void
Expand All @@ -50,10 +48,6 @@ public function it_cannot_evolve_incompatible_schema(RecordSerializer $serialize
*
* @depends it_encodes_valid_records
*
* @param \FlixTech\AvroSerializer\Objects\RecordSerializer $serializer
*
* @return \FlixTech\AvroSerializer\Objects\RecordSerializer
*
* @throws \FlixTech\SchemaRegistryApi\Exception\SchemaRegistryException
*/
public function it_decodes_with_readers_schema(RecordSerializer $serializer): RecordSerializer
Expand Down

0 comments on commit a98ad31

Please sign in to comment.