From a98ad31f851350931962ed93bb6875b8b9add519 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 27 Aug 2020 03:53:43 +0200 Subject: [PATCH] Update `flix-tech/avro-php` dependency (#34) --- Makefile | 2 +- composer.json | 6 ++--- phpstan.neon | 3 +++ src/Common.php | 13 +++++++++++ .../DefaultRecordSerializerFactory.php | 3 +++ src/Objects/Exceptions/Exceptions.php | 3 +++ src/Objects/RecordSerializer.php | 23 +++++++------------ src/Objects/SchemaResolverInterface.php | 5 ++-- src/Objects/SchemaResolvers/ChainResolver.php | 4 +--- .../DefinitionInterfaceResolver.php | 7 +++--- src/Protocol.php | 8 ++++++- src/Serialize.php | 14 +++++------ .../Serializer/AvroSerDeEncoderTest.php | 2 -- .../RecordSerializerIntegrationTest.php | 6 ----- 14 files changed, 54 insertions(+), 45 deletions(-) create mode 100644 phpstan.neon diff --git a/Makefile b/Makefile index d460429..43c14c1 100644 --- a/Makefile +++ b/Makefile @@ -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 \ diff --git a/composer.json b/composer.json index 19dd90e..fe53623 100644 --- a/composer.json +++ b/composer.json @@ -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" diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..c7b1758 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,3 @@ +parameters: + level: 8 + paths: [ src ] diff --git a/src/Common.php b/src/Common.php index bbc03bf..9ac5b8f 100644 --- a/src/Common.php +++ b/src/Common.php @@ -9,6 +9,10 @@ const get = '\FlixTech\AvroSerializer\Common\get'; +/** + * @param mixed $key + * @param array $array + */ function get($key, array $array): Maybe { return isset($array[$key]) @@ -25,6 +29,9 @@ function getter(): callable const inflectRecord = '\FlixTech\AvroSerializer\Common\inflectRecord'; +/** + * @param mixed $record + */ function inflectRecord($record): Maybe { return \is_object($record) @@ -34,6 +41,12 @@ function inflectRecord($record): Maybe const memoize = '\FlixTech\AvroSerializer\Common\memoize'; +/** + * @param array $arguments + * @param string|null $key + * + * @return mixed|null + */ function memoize(callable $callback = null, array $arguments = [], $key = null) { static $storage = []; diff --git a/src/Objects/DefaultRecordSerializerFactory.php b/src/Objects/DefaultRecordSerializerFactory.php index 3f6e5f6..c369ec7 100644 --- a/src/Objects/DefaultRecordSerializerFactory.php +++ b/src/Objects/DefaultRecordSerializerFactory.php @@ -13,6 +13,9 @@ final class DefaultRecordSerializerFactory { + /** + * @param array $guzzleClientOptions + */ public static function get( string $schemaRegistryURL, array $guzzleClientOptions = [], diff --git a/src/Objects/Exceptions/Exceptions.php b/src/Objects/Exceptions/Exceptions.php index dbc1655..0b2a96b 100644 --- a/src/Objects/Exceptions/Exceptions.php +++ b/src/Objects/Exceptions/Exceptions.php @@ -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); diff --git a/src/Objects/RecordSerializer.php b/src/Objects/RecordSerializer.php index 6854e06..e358e75 100644 --- a/src/Objects/RecordSerializer.php +++ b/src/Objects/RecordSerializer.php @@ -75,6 +75,13 @@ class RecordSerializer */ protected $protocolValidatorFunc; + /** + * RecordSerializer constructor. + * + * @param array $options + * + * @throws \AvroIOException + */ public function __construct(Registry $registry, array $options = []) { $this->registry = $registry; @@ -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 @@ -120,9 +123,6 @@ public function encodeRecord(string $subject, AvroSchema $schema, $record): stri } /** - * @param string $binaryMessage - * @param \AvroSchema|null $readersSchema - * * @return mixed * * @throws \InvalidArgumentException @@ -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 */ @@ -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 diff --git a/src/Objects/SchemaResolverInterface.php b/src/Objects/SchemaResolverInterface.php index a285c01..b44bf4b 100644 --- a/src/Objects/SchemaResolverInterface.php +++ b/src/Objects/SchemaResolverInterface.php @@ -11,6 +11,9 @@ */ interface SchemaResolverInterface { + /** + * @param mixed $record + */ public function valueSchemaFor($record): AvroSchema; /** @@ -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; } diff --git a/src/Objects/SchemaResolvers/ChainResolver.php b/src/Objects/SchemaResolvers/ChainResolver.php index ab5d65a..a3351e8 100644 --- a/src/Objects/SchemaResolvers/ChainResolver.php +++ b/src/Objects/SchemaResolvers/ChainResolver.php @@ -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 diff --git a/src/Objects/SchemaResolvers/DefinitionInterfaceResolver.php b/src/Objects/SchemaResolvers/DefinitionInterfaceResolver.php index d497b61..d569147 100644 --- a/src/Objects/SchemaResolvers/DefinitionInterfaceResolver.php +++ b/src/Objects/SchemaResolvers/DefinitionInterfaceResolver.php @@ -14,8 +14,6 @@ class DefinitionInterfaceResolver implements SchemaResolverInterface /** * @param mixed $record * - * @return \AvroSchema - * * @throws \AvroSchemaParseException */ public function valueSchemaFor($record): AvroSchema @@ -29,8 +27,6 @@ public function valueSchemaFor($record): AvroSchema /** * @param mixed $record * - * @return \AvroSchema|null - * * @throws \AvroSchemaParseException */ public function keySchemaFor($record): ?AvroSchema @@ -46,6 +42,9 @@ public function keySchemaFor($record): ?AvroSchema return AvroSchema::parse($keySchemaJson); } + /** + * @param mixed $record + */ private function guardRecordHasDefinition($record): void { Assert::that($record) diff --git a/src/Protocol.php b/src/Protocol.php index 18924bf..17ce63e 100644 --- a/src/Protocol.php +++ b/src/Protocol.php @@ -64,7 +64,7 @@ function decode(string $binaryString): Either PROTOCOL_ACCESSOR_AVRO ); - /** @var array|bool $unpacked */ + /** @var array|bool $unpacked */ $unpacked = @\unpack( $packedFormat, $binaryString @@ -84,6 +84,9 @@ function decode(string $binaryString): Either const validate = '\FlixTech\AvroSerializer\Protocol\validate'; +/** + * @param array $decoded + */ function validate(int $protocolVersion, array $decoded): Maybe { $valid = isset($decoded[PROTOCOL_ACCESSOR_VERSION], $decoded[PROTOCOL_ACCESSOR_SCHEMA_ID], $decoded[PROTOCOL_ACCESSOR_AVRO]) @@ -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); diff --git a/src/Serialize.php b/src/Serialize.php index 2276832..1733751 100644 --- a/src/Serialize.php +++ b/src/Serialize.php @@ -18,10 +18,6 @@ const avroStringIo = '\FlixTech\AvroSerializer\Serialize\avroStringIo'; /** - * @param string $contents - * - * @return \AvroStringIO - * * @throws \AvroIOException */ function avroStringIo(string $contents): AvroStringIO @@ -46,8 +42,6 @@ function avroBinaryDecoder(AvroStringIO $io): AvroIOBinaryDecoder const avroDatumWriter = '\FlixTech\AvroSerializer\Serialize\avroDatumWriter'; /** - * @return callable - * * @throws \AvroIOException */ function avroDatumWriter(): callable @@ -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( @@ -81,8 +78,6 @@ static function (\AvroException $e) use ($record, $schema) { const avroDatumReader = '\FlixTech\AvroSerializer\Serialize\avroDatumReader'; /** - * @return callable - * * @throws \AvroIOException */ function avroDatumReader(): callable @@ -95,6 +90,9 @@ function avroDatumReader(): callable const readDatum = '\FlixTech\AvroSerializer\Serialize\readDatum'; +/** + * @param mixed $data + */ function readDatum( AvroIODatumReader $reader, AvroStringIO $io, diff --git a/test/Integrations/Symfony/Serializer/AvroSerDeEncoderTest.php b/test/Integrations/Symfony/Serializer/AvroSerDeEncoderTest.php index 831a3b5..3c822a2 100644 --- a/test/Integrations/Symfony/Serializer/AvroSerDeEncoderTest.php +++ b/test/Integrations/Symfony/Serializer/AvroSerDeEncoderTest.php @@ -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 { diff --git a/test/Objects/RecordSerializerIntegrationTest.php b/test/Objects/RecordSerializerIntegrationTest.php index 58984b0..3df2a00 100644 --- a/test/Objects/RecordSerializerIntegrationTest.php +++ b/test/Objects/RecordSerializerIntegrationTest.php @@ -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 @@ -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