From 500f131d85fd37c6b2dfbd4990d361dc38bf026f Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Mon, 1 Apr 2024 14:28:39 +0200 Subject: [PATCH] Cleanup --- .php-cs-fixer.dist.php | 13 +- composer.json | 2 +- src/FileId.php | 166 +++++++----------- src/PhotoSizeSource.php | 9 +- .../PhotoSizeSourceDialogPhoto.php | 23 +-- src/PhotoSizeSource/PhotoSizeSourceLegacy.php | 14 +- .../PhotoSizeSourceStickersetThumbnail.php | 27 ++- ...toSizeSourceStickersetThumbnailVersion.php | 40 ++--- .../PhotoSizeSourceThumbnail.php | 31 ++-- src/UniqueFileId.php | 131 ++++++-------- src/type.php | 21 +-- tests/IntegrationTest.php | 3 +- 12 files changed, 188 insertions(+), 292 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 859c6f0..0a8a947 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -1,6 +1,17 @@ true, + 'phpdoc_to_param_type' => true, + ] + ); + } +}; $config->getFinder() ->in(__DIR__ . '/src') ->in(__DIR__ . '/tests'); diff --git a/composer.json b/composer.json index 42f1aa1..53f63a9 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ }, "require-dev": { "phpunit/phpunit": "^9", - "amphp/php-cs-fixer-config": "dev-master" + "amphp/php-cs-fixer-config": "^2" }, "autoload": { "psr-4": { diff --git a/src/FileId.php b/src/FileId.php index cdc0af0..9fac9d3 100644 --- a/src/FileId.php +++ b/src/FileId.php @@ -1,4 +1,4 @@ -_version; + return $this->version; } /** * Set bot API file ID version. * - * @param int $_version Bot API file ID version. + * @param int $version Bot API file ID version. * - * @return self */ - public function setVersion(int $_version): self + public function setVersion(int $version): self { - $this->_version = $_version; + $this->version = $version; return $this; } @@ -312,23 +291,21 @@ class FileId /** * Get bot API file ID subversion. * - * @return int */ public function getSubVersion(): int { - return $this->_subVersion; + return $this->subVersion; } /** * Set bot API file ID subversion. * - * @param int $_subVersion Bot API file ID subversion. + * @param int $subVersion Bot API file ID subversion. * - * @return self */ - public function setSubVersion(int $_subVersion): self + public function setSubVersion(int $subVersion): self { - $this->_subVersion = $_subVersion; + $this->subVersion = $subVersion; return $this; } @@ -336,33 +313,30 @@ class FileId /** * Get file type. * - * @return int */ public function getType(): int { - return $this->_type; + return $this->type; } /** * Get file type as string. * - * @return string */ public function getTypeName(): string { - return TYPES[$this->_type]; + return TYPES[$this->type]; } /** * Set file type. * - * @param int $_type File type. + * @param int $type File type. * - * @return self */ - public function setType(int $_type): self + public function setType(int $type): self { - $this->_type = $_type; + $this->type = $type; return $this; } @@ -370,23 +344,21 @@ class FileId /** * Get file reference. * - * @return string */ public function getFileReference(): string { - return $this->_fileReference; + return $this->fileReference; } /** * Set file reference. * - * @param string $_fileReference File reference. + * @param string $fileReference File reference. * - * @return self */ - public function setFileReference(string $_fileReference): self + public function setFileReference(string $fileReference): self { - $this->_fileReference = $_fileReference; + $this->fileReference = $fileReference; return $this; } @@ -398,17 +370,16 @@ class FileId */ public function hasFileReference(): bool { - return !empty($this->_fileReference); + return !empty($this->fileReference); } /** * Get file URL for weblocation. * - * @return string */ public function getUrl(): string { - return $this->_url; + return $this->url; } /** @@ -418,19 +389,18 @@ class FileId */ public function hasUrl(): bool { - return !empty($this->_url); + return !empty($this->url); } /** * Set file URL for weblocation. * - * @param string $_url File URL for weblocation. + * @param string $url File URL for weblocation. * - * @return self */ - public function setUrl(string $_url): self + public function setUrl(string $url): self { - $this->_url = $_url; + $this->url = $url; return $this; } @@ -442,19 +412,18 @@ class FileId */ public function getId() { - return $this->_id; + return $this->id; } /** * Set file id. * - * @param int $_id File id. + * @param int $id File id. * - * @return self */ - public function setId($_id): self + public function setId(int $id): self { - $this->_id = $_id; + $this->id = $id; return $this; } @@ -462,11 +431,10 @@ class FileId /** * Check if has file id. * - * @return bool */ public function hasId(): bool { - return isset($this->_id); + return isset($this->id); } /** @@ -476,19 +444,18 @@ class FileId */ public function getAccessHash() { - return $this->_accessHash; + return $this->accessHash; } /** * Set file access hash. * - * @param int $_accessHash File access hash. + * @param int $accessHash File access hash. * - * @return self */ - public function setAccessHash($_accessHash): self + public function setAccessHash(int $accessHash): self { - $this->_accessHash = $_accessHash; + $this->accessHash = $accessHash; return $this; } @@ -500,19 +467,18 @@ class FileId */ public function getVolumeId() { - return $this->_volumeId; + return $this->volumeId; } /** * Set photo volume ID. * - * @param int $_volumeId Photo volume ID. + * @param int $volumeId Photo volume ID. * - * @return self */ - public function setVolumeId($_volumeId): self + public function setVolumeId(int $volumeId): self { - $this->_volumeId = $_volumeId; + $this->volumeId = $volumeId; return $this; } @@ -523,29 +489,27 @@ class FileId */ public function hasVolumeId(): bool { - return isset($this->_volumeId); + return isset($this->volumeId); } /** * Get photo local ID. * - * @return int */ public function getLocalId(): int { - return $this->_localId; + return $this->localId; } /** * Set photo local ID. * - * @param int $_localId Photo local ID. + * @param int $localId Photo local ID. * - * @return self */ - public function setLocalId(int $_localId): self + public function setLocalId(int $localId): self { - $this->_localId = $_localId; + $this->localId = $localId; return $this; } @@ -557,29 +521,27 @@ class FileId */ public function hasLocalId(): bool { - return isset($this->_localId); + return isset($this->localId); } /** * Get photo size source. * - * @return PhotoSizeSource */ public function getPhotoSizeSource(): PhotoSizeSource { - return $this->_photoSizeSource; + return $this->photoSizeSource; } /** * Set photo size source. * - * @param PhotoSizeSource $_photoSizeSource Photo size source. + * @param PhotoSizeSource $photoSizeSource Photo size source. * - * @return self */ - public function setPhotoSizeSource(PhotoSizeSource $_photoSizeSource): self + public function setPhotoSizeSource(PhotoSizeSource $photoSizeSource): self { - $this->_photoSizeSource = $_photoSizeSource; + $this->photoSizeSource = $photoSizeSource; return $this; } @@ -591,29 +553,27 @@ class FileId */ public function hasPhotoSizeSource(): bool { - return isset($this->_photoSizeSource); + return isset($this->photoSizeSource); } /** * Get dC ID. * - * @return int */ public function getDcId(): int { - return $this->_dcId; + return $this->dcId; } /** * Set dC ID. * - * @param int $_dcId DC ID. + * @param int $dcId DC ID. * - * @return self */ - public function setDcId(int $_dcId): self + public function setDcId(int $dcId): self { - $this->_dcId = $_dcId; + $this->dcId = $dcId; return $this; } diff --git a/src/PhotoSizeSource.php b/src/PhotoSizeSource.php index f819dfd..2a12949 100644 --- a/src/PhotoSizeSource.php +++ b/src/PhotoSizeSource.php @@ -1,4 +1,4 @@ -_type = $type; + $this->type = $type; return $this; } @@ -65,6 +64,6 @@ abstract class PhotoSizeSource */ public function getType(): int { - return $this->_type; + return $this->type; } } diff --git a/src/PhotoSizeSource/PhotoSizeSourceDialogPhoto.php b/src/PhotoSizeSource/PhotoSizeSourceDialogPhoto.php index 8bdfd90..97f78f5 100644 --- a/src/PhotoSizeSource/PhotoSizeSourceDialogPhoto.php +++ b/src/PhotoSizeSource/PhotoSizeSourceDialogPhoto.php @@ -1,4 +1,4 @@ -_dialogId; + return $this->dialogId; } /** * Set dialog ID. * * @param int $id Dialog ID * - * @return self */ - public function setDialogId($id): self + public function setDialogId(int $id): self { - $this->_dialogId = $id; + $this->dialogId = $id; return $this; } /** @@ -71,7 +68,7 @@ class PhotoSizeSourceDialogPhoto extends PhotoSizeSource */ public function getDialogAccessHash() { - return $this->_dialogAccessHash; + return $this->dialogAccessHash; } /** @@ -79,11 +76,10 @@ class PhotoSizeSourceDialogPhoto extends PhotoSizeSource * * @param int $dialogAccessHash Access hash of dialog * - * @return self */ - public function setDialogAccessHash($dialogAccessHash): self + public function setDialogAccessHash(int $dialogAccessHash): self { - $this->_dialogAccessHash = $dialogAccessHash; + $this->dialogAccessHash = $dialogAccessHash; return $this; } @@ -91,7 +87,6 @@ class PhotoSizeSourceDialogPhoto extends PhotoSizeSource /** * Get whether the big or small version of the photo is being used. * - * @return bool */ public function isSmallDialogPhoto(): bool { diff --git a/src/PhotoSizeSource/PhotoSizeSourceLegacy.php b/src/PhotoSizeSource/PhotoSizeSourceLegacy.php index c23dd22..1a16c50 100644 --- a/src/PhotoSizeSource/PhotoSizeSourceLegacy.php +++ b/src/PhotoSizeSource/PhotoSizeSourceLegacy.php @@ -1,4 +1,4 @@ -_secret; + return $this->secret; } /** * Set secret legacy ID. * - * @param int $_secret Secret legacy ID + * @param int $secret Secret legacy ID * - * @return self */ - public function setSecret($_secret): self + public function setSecret(int $secret): self { - $this->_secret = $_secret; + $this->secret = $secret; return $this; } diff --git a/src/PhotoSizeSource/PhotoSizeSourceStickersetThumbnail.php b/src/PhotoSizeSource/PhotoSizeSourceStickersetThumbnail.php index 5069b3d..af48b47 100644 --- a/src/PhotoSizeSource/PhotoSizeSourceStickersetThumbnail.php +++ b/src/PhotoSizeSource/PhotoSizeSourceStickersetThumbnail.php @@ -1,4 +1,4 @@ -_stickerSetId; + return $this->stickerSetId; } /** * Set stickerset ID. * - * @param int $_stickerSetId Stickerset ID + * @param int $stickerSetId Stickerset ID * - * @return self */ - public function setStickerSetId($_stickerSetId): self + public function setStickerSetId(int $stickerSetId): self { - $this->_stickerSetId = $_stickerSetId; + $this->stickerSetId = $stickerSetId; return $this; } @@ -72,19 +68,18 @@ class PhotoSizeSourceStickersetThumbnail extends PhotoSizeSource */ public function getStickerSetAccessHash() { - return $this->_stickerSetAccessHash; + return $this->stickerSetAccessHash; } /** * Set stickerset access hash. * - * @param int $_stickerSetAccessHash Stickerset access hash + * @param int $stickerSetAccessHash Stickerset access hash * - * @return self */ - public function setStickerSetAccessHash($_stickerSetAccessHash): self + public function setStickerSetAccessHash(int $stickerSetAccessHash): self { - $this->_stickerSetAccessHash = $_stickerSetAccessHash; + $this->stickerSetAccessHash = $stickerSetAccessHash; return $this; } diff --git a/src/PhotoSizeSource/PhotoSizeSourceStickersetThumbnailVersion.php b/src/PhotoSizeSource/PhotoSizeSourceStickersetThumbnailVersion.php index f230074..b06f02d 100644 --- a/src/PhotoSizeSource/PhotoSizeSourceStickersetThumbnailVersion.php +++ b/src/PhotoSizeSource/PhotoSizeSourceStickersetThumbnailVersion.php @@ -1,4 +1,4 @@ -_stickerSetId; + return $this->stickerSetId; } /** * Set stickerset ID. * - * @param int $_stickerSetId Stickerset ID + * @param int $stickerSetId Stickerset ID * - * @return self */ - public function setStickerSetId($_stickerSetId): self + public function setStickerSetId(int $stickerSetId): self { - $this->_stickerSetId = $_stickerSetId; + $this->stickerSetId = $stickerSetId; return $this; } @@ -78,19 +73,18 @@ class PhotoSizeSourceStickersetThumbnailVersion extends PhotoSizeSource */ public function getStickerSetAccessHash() { - return $this->_stickerSetAccessHash; + return $this->stickerSetAccessHash; } /** * Set stickerset access hash. * - * @param int $_stickerSetAccessHash Stickerset access hash + * @param int $stickerSetAccessHash Stickerset access hash * - * @return self */ - public function setStickerSetAccessHash($_stickerSetAccessHash): self + public function setStickerSetAccessHash(int $stickerSetAccessHash): self { - $this->_stickerSetAccessHash = $_stickerSetAccessHash; + $this->stickerSetAccessHash = $stickerSetAccessHash; return $this; } @@ -98,23 +92,21 @@ class PhotoSizeSourceStickersetThumbnailVersion extends PhotoSizeSource /** * Get stickerset version. * - * @return int */ public function getStickerSetVersion(): int { - return $this->_stickerSetVersion; + return $this->stickerSetVersion; } /** * Set stickerset version. * - * @param int $_stickerSetVersion Stickerset version. + * @param int $stickerSetVersion Stickerset version. * - * @return self */ - public function setStickerSetVersion(int $_stickerSetVersion): self + public function setStickerSetVersion(int $stickerSetVersion): self { - $this->_stickerSetVersion = $_stickerSetVersion; + $this->stickerSetVersion = $stickerSetVersion; return $this; } diff --git a/src/PhotoSizeSource/PhotoSizeSourceThumbnail.php b/src/PhotoSizeSource/PhotoSizeSourceThumbnail.php index 75453aa..e81b2b0 100644 --- a/src/PhotoSizeSource/PhotoSizeSourceThumbnail.php +++ b/src/PhotoSizeSource/PhotoSizeSourceThumbnail.php @@ -1,4 +1,4 @@ -_thumbFileType; + return $this->thumbFileType; } /** * Get file type of original file as string. * - * @return string */ public function getThumbFileTypeString(): string { - return TYPES[$this->_thumbFileType]; + return TYPES[$this->thumbFileType]; } /** * Set file type of original file. * - * @param int $_thumbFileType File type of original file + * @param int $thumbFileType File type of original file * - * @return self */ - public function setThumbFileType(int $_thumbFileType): self + public function setThumbFileType(int $thumbFileType): self { - $this->_thumbFileType = $_thumbFileType; + $this->thumbFileType = $thumbFileType; return $this; } @@ -76,23 +71,21 @@ class PhotoSizeSourceThumbnail extends PhotoSizeSource /** * Get thumbnail size. * - * @return string */ public function getThumbType(): string { - return $this->_thumbType; + return $this->thumbType; } /** * Set thumbnail size. * - * @param string $_thumbType Thumbnail size + * @param string $thumbType Thumbnail size * - * @return self */ - public function setThumbType(string $_thumbType): self + public function setThumbType(string $thumbType): self { - $this->_thumbType = $_thumbType; + $this->thumbType = $thumbType; return $this; } diff --git a/src/UniqueFileId.php b/src/UniqueFileId.php index 3fdc8ad..979cf77 100644 --- a/src/UniqueFileId.php +++ b/src/UniqueFileId.php @@ -1,4 +1,4 @@ -_type]; + return UNIQUE_TYPES[$this->type]; } /** * Get unique file type. * - * @return int */ public function getType(): int { - return $this->_type; + return $this->type; } /** * Set file type. * - * @param int $_type File type. + * @param int $type File type. * - * @return self */ - public function setType(int $_type): self + public function setType(int $type): self { - $this->_type = $_type; + $this->type = $type; return $this; } @@ -255,19 +239,18 @@ class UniqueFileId */ public function getId() { - return $this->_id; + return $this->id; } /** * Set file ID. * - * @param int $_id File ID. + * @param int $id File ID. * - * @return self */ - public function setId($_id): self + public function setId(int $id): self { - $this->_id = $_id; + $this->id = $id; return $this; } @@ -279,10 +262,9 @@ class UniqueFileId */ public function hasId(): bool { - return isset($this->_id); + return isset($this->id); } - /** * Get photo volume ID. * @@ -290,19 +272,18 @@ class UniqueFileId */ public function getVolumeId() { - return $this->_volumeId; + return $this->volumeId; } /** * Set photo volume ID. * - * @param int $_volumeId Photo volume ID. + * @param int $volumeId Photo volume ID. * - * @return self */ - public function setVolumeId($_volumeId): self + public function setVolumeId(int $volumeId): self { - $this->_volumeId = $_volumeId; + $this->volumeId = $volumeId; return $this; } @@ -313,29 +294,27 @@ class UniqueFileId */ public function hasVolumeId(): bool { - return isset($this->_volumeId); + return isset($this->volumeId); } /** * Get photo local ID. * - * @return int */ public function getLocalId(): int { - return $this->_localId; + return $this->localId; } /** * Set photo local ID. * - * @param int $_localId Photo local ID. + * @param int $localId Photo local ID. * - * @return self */ - public function setLocalId(int $_localId): self + public function setLocalId(int $localId): self { - $this->_localId = $_localId; + $this->localId = $localId; return $this; } @@ -347,30 +326,27 @@ class UniqueFileId */ public function hasLocalId(): bool { - return isset($this->_localId); + return isset($this->localId); } - /** * Get weblocation URL. * - * @return string */ public function getUrl(): string { - return $this->_url; + return $this->url; } /** * Set weblocation URL. * - * @param string $_url Weblocation URL + * @param string $url Weblocation URL * - * @return self */ - public function setUrl(string $_url): self + public function setUrl(string $url): self { - $this->_url = $_url; + $this->url = $url; return $this; } @@ -382,39 +358,36 @@ class UniqueFileId */ public function hasUrl(): bool { - return isset($this->_url); + return isset($this->url); } /** * Get photo subtype. * - * @return int */ public function getSubType(): int { - return $this->_subType; + return $this->subType; } /** * Has photo subtype? * - * @return bool */ public function hasSubType(): bool { - return isset($this->_subType); + return isset($this->subType); } /** * Set photo subtype. * - * @param int $_subType Photo subtype + * @param int $subType Photo subtype * - * @return self */ - public function setSubType(int $_subType): self + public function setSubType(int $subType): self { - $this->_subType = $_subType; + $this->subType = $subType; return $this; } @@ -426,30 +399,27 @@ class UniqueFileId */ public function getStickerSetId() { - return $this->_stickerSetId; + return $this->stickerSetId; } - /** * Has sticker set ID? * - * @return bool */ public function hasStickerSetId(): bool { - return isset($this->_stickerSetId); + return isset($this->stickerSetId); } /** * Set sticker set ID. * - * @param int $_stickerSetId Sticker set ID + * @param int $stickerSetId Sticker set ID * - * @return self */ - public function setStickerSetId($_stickerSetId): self + public function setStickerSetId(int $stickerSetId): self { - $this->_stickerSetId = $_stickerSetId; + $this->stickerSetId = $stickerSetId; return $this; } @@ -457,33 +427,30 @@ class UniqueFileId /** * Get sticker set version. * - * @return int */ public function getStickerSetVersion(): int { - return $this->_stickerSetVersion; + return $this->stickerSetVersion; } /** * Has sticker set version. * - * @return bool */ public function hasStickerSetVersion(): bool { - return isset($this->_stickerSetVersion); + return isset($this->stickerSetVersion); } /** * Set sticker set version. * - * @param int $_stickerSetVersion Sticker set version + * @param int $stickerSetVersion Sticker set version * - * @return self */ - public function setStickerSetVersion(int $_stickerSetVersion): self + public function setStickerSetVersion(int $stickerSetVersion): self { - $this->_stickerSetVersion = $_stickerSetVersion; + $this->stickerSetVersion = $stickerSetVersion; return $this; } diff --git a/src/type.php b/src/type.php index f318292..9d48d15 100644 --- a/src/type.php +++ b/src/type.php @@ -1,4 +1,4 @@ - 254) { @@ -430,7 +421,6 @@ function readTLString($stream): string * * @param string $string String * - * @return string */ function packTLString(string $string): string { @@ -458,7 +448,6 @@ function packTLString(string $string): string * * @internal * - * @return array */ function internalDecode(string $fileId): array { @@ -583,14 +572,12 @@ function internalDecode(string $fileId): array * * @internal * - * @return array */ function internalDecodeUnique(string $fileId): array { $orig = $fileId; $fileId = rleDecode(base64urlDecode($fileId)); - $result = \unpack('VtypeId', $fileId); if (!isset(UNIQUE_TYPES[$result['typeId']])) { throw new \InvalidArgumentException("Invalid file type provided: {$result['typeId']}"); diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index 2f8a587..3fa31cd 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -1,4 +1,4 @@ -