From c6f839493463a0909d8a78e3e418b0138aa32efc Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sat, 3 Oct 2020 13:50:37 +0200 Subject: [PATCH] Minor fixes --- composer.json | 3 ++- src/PhotoSizeSource.php | 15 +++++++++++++++ .../PhotoSizeSourceDialogPhoto.php | 2 ++ src/PhotoSizeSource/PhotoSizeSourceLegacy.php | 2 ++ .../PhotoSizeSourceStickersetThumbnail.php | 2 ++ src/PhotoSizeSource/PhotoSizeSourceThumbnail.php | 1 + src/type.php | 4 +++- 7 files changed, 27 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 311c3e2..4a996d4 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,8 @@ }, "require-dev": { "phpunit/phpunit": "^8|^6", - "amphp/php-cs-fixer-config": "dev-master" + "amphp/php-cs-fixer-config": "dev-master", + "vimeo/psalm": "dev-master" }, "autoload": { "psr-4": { diff --git a/src/PhotoSizeSource.php b/src/PhotoSizeSource.php index 2cd9cf3..cef92fc 100644 --- a/src/PhotoSizeSource.php +++ b/src/PhotoSizeSource.php @@ -18,8 +18,12 @@ namespace danog\Decoder; +use danog\Decoder\PhotoSizeSource\PhotoSizeSourceLegacy; + /** * Represents source of photosize. + * + * @template T */ abstract class PhotoSizeSource { @@ -48,6 +52,17 @@ abstract class PhotoSizeSource * * @return integer * + * @psalm-return ( + * T is PhotoSizeSourceLegacy ? + * ? \danog\Decoder\PHOTOSIZE_SOURCE_LEGACY + * : (T is PhotoSizeSourceDialogPhoto + * ? \danog\Decoder\PHOTOSIZE_SOURCE_DIALOGPHOTO_* + * (T is PhotoSizeSourceStickersetThumbnail + * ? \danog\Decoder\PHOTOSIZE_SOURCE_STICKERSET_THUMBNAIL + * : \danog\Decoder\PHOTOSIZE_SOURCE_THUMBNAIL + * ) + * ) + * * @internal Internal use */ public function getType(): int diff --git a/src/PhotoSizeSource/PhotoSizeSourceDialogPhoto.php b/src/PhotoSizeSource/PhotoSizeSourceDialogPhoto.php index d8fccf0..1302e28 100644 --- a/src/PhotoSizeSource/PhotoSizeSourceDialogPhoto.php +++ b/src/PhotoSizeSource/PhotoSizeSourceDialogPhoto.php @@ -25,6 +25,8 @@ use const danog\Decoder\PHOTOSIZE_SOURCE_DIALOGPHOTO_SMALL; /** * Represents source of photosize. + * + * @extends PhotoSizeSource */ class PhotoSizeSourceDialogPhoto extends PhotoSizeSource { diff --git a/src/PhotoSizeSource/PhotoSizeSourceLegacy.php b/src/PhotoSizeSource/PhotoSizeSourceLegacy.php index 652f576..8a1b37a 100644 --- a/src/PhotoSizeSource/PhotoSizeSourceLegacy.php +++ b/src/PhotoSizeSource/PhotoSizeSourceLegacy.php @@ -24,6 +24,8 @@ use const danog\Decoder\PHOTOSIZE_SOURCE_LEGACY; /** * Represents source of photosize. + * + * @extends PhotoSizeSource */ class PhotoSizeSourceLegacy extends PhotoSizeSource { diff --git a/src/PhotoSizeSource/PhotoSizeSourceStickersetThumbnail.php b/src/PhotoSizeSource/PhotoSizeSourceStickersetThumbnail.php index c69289d..30b4964 100644 --- a/src/PhotoSizeSource/PhotoSizeSourceStickersetThumbnail.php +++ b/src/PhotoSizeSource/PhotoSizeSourceStickersetThumbnail.php @@ -24,6 +24,8 @@ use const danog\Decoder\PHOTOSIZE_SOURCE_STICKERSET_THUMBNAIL; /** * Represents source of photosize. + * + * @extends PhotoSizeSource */ class PhotoSizeSourceStickersetThumbnail extends PhotoSizeSource { diff --git a/src/PhotoSizeSource/PhotoSizeSourceThumbnail.php b/src/PhotoSizeSource/PhotoSizeSourceThumbnail.php index 1d1962a..29cc0eb 100644 --- a/src/PhotoSizeSource/PhotoSizeSourceThumbnail.php +++ b/src/PhotoSizeSource/PhotoSizeSourceThumbnail.php @@ -21,6 +21,7 @@ namespace danog\Decoder\PhotoSizeSource; use danog\Decoder\PhotoSizeSource; use const danog\Decoder\PHOTOSIZE_SOURCE_THUMBNAIL; +use const danog\Decoder\TYPES; /** * Represents source of photosize. diff --git a/src/type.php b/src/type.php index 21ac83f..256c0f0 100644 --- a/src/type.php +++ b/src/type.php @@ -206,6 +206,7 @@ $BIG_ENDIAN = \pack('L', 1) === \pack('N', 1); function unpackLong(string $field) { if (PHP_INT_SIZE === 8) { + /** @psalm-suppress InvalidGlobal */ global $BIG_ENDIAN; // Evil return \unpack('q', $BIG_ENDIAN ? \strrev($field) : $field)[1]; } @@ -227,6 +228,7 @@ function unpackLong(string $field) function packLongBig($field): string { if (PHP_INT_SIZE === 8) { + /** @psalm-suppress InvalidGlobal */ global $BIG_ENDIAN; // Evil $res = \pack('q', $field); return $BIG_ENDIAN ? \strrev($res) : $res; @@ -263,7 +265,7 @@ function fixLong(array &$params, string $field) /** * Encode long to string. * - * @param string|array $fields Fields to encode + * @param int|int[] $fields Fields to encode * * @return string */