This commit is contained in:
Daniil Gentili 2021-08-14 16:03:57 +02:00
parent cd57194072
commit 28cdbef38c
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
5 changed files with 27 additions and 40 deletions

View File

@ -1,12 +0,0 @@
<?php
$config = new Amp\CodeStyle\Config();
$config->getFinder()
->in(__DIR__ . '/src')
->in(__DIR__ . '/tests');
$cacheDir = getenv('TRAVIS') ? getenv('HOME') . '/.php-cs-fixer' : __DIR__;
$config->setCacheFile($cacheDir . '/.php_cs.cache');
return $config;

View File

@ -221,7 +221,7 @@ class FileId
case PHOTOSIZE_SOURCE_FULL_LEGACY: case PHOTOSIZE_SOURCE_FULL_LEGACY:
$fileId .= packLong($this->getVolumeId()); $fileId .= packLong($this->getVolumeId());
$fileId .= packLong($photoSize->getSecret()); $fileId .= packLong($photoSize->getSecret());
$fileId .= pack('l',$this->getLocalId()); $fileId .= \pack('l', $this->getLocalId());
break; break;
case PHOTOSIZE_SOURCE_THUMBNAIL: case PHOTOSIZE_SOURCE_THUMBNAIL:
$fileId .= \pack('Va4', $photoSize->getThumbFileType(), $photoSize->getThumbType()); $fileId .= \pack('Va4', $photoSize->getThumbFileType(), $photoSize->getThumbType());
@ -241,7 +241,7 @@ class FileId
case PHOTOSIZE_SOURCE_STICKERSET_THUMBNAIL_VERSION: case PHOTOSIZE_SOURCE_STICKERSET_THUMBNAIL_VERSION:
$fileId .= packLong($photoSize->getStickerSetId()); $fileId .= packLong($photoSize->getStickerSetId());
$fileId .= packLong($photoSize->getStickerSetAccessHash()); $fileId .= packLong($photoSize->getStickerSetAccessHash());
$fileId .= pack('l', $photoSize->getStickerSetVersion()); $fileId .= \pack('l', $photoSize->getStickerSetVersion());
break; break;
} }
if ($photoSize->getType() >= PHOTOSIZE_SOURCE_DIALOGPHOTO_SMALL_LEGACY && $photoSize->getType() <= PHOTOSIZE_SOURCE_STICKERSET_THUMBNAIL_LEGACY) { if ($photoSize->getType() >= PHOTOSIZE_SOURCE_DIALOGPHOTO_SMALL_LEGACY && $photoSize->getType() <= PHOTOSIZE_SOURCE_STICKERSET_THUMBNAIL_LEGACY) {

View File

@ -20,7 +20,6 @@ namespace danog\Decoder\PhotoSizeSource;
use danog\Decoder\PhotoSizeSource; use danog\Decoder\PhotoSizeSource;
use const danog\Decoder\PHOTOSIZE_SOURCE_DIALOGPHOTO_BIG;
use const danog\Decoder\PHOTOSIZE_SOURCE_DIALOGPHOTO_SMALL; use const danog\Decoder\PHOTOSIZE_SOURCE_DIALOGPHOTO_SMALL;
use const danog\Decoder\PHOTOSIZE_SOURCE_DIALOGPHOTO_SMALL_LEGACY; use const danog\Decoder\PHOTOSIZE_SOURCE_DIALOGPHOTO_SMALL_LEGACY;
@ -96,6 +95,6 @@ class PhotoSizeSourceDialogPhoto extends PhotoSizeSource
*/ */
public function isSmallDialogPhoto(): bool public function isSmallDialogPhoto(): bool
{ {
return in_array($this->getType(), [PHOTOSIZE_SOURCE_DIALOGPHOTO_SMALL_LEGACY, PHOTOSIZE_SOURCE_DIALOGPHOTO_SMALL]); return \in_array($this->getType(), [PHOTOSIZE_SOURCE_DIALOGPHOTO_SMALL_LEGACY, PHOTOSIZE_SOURCE_DIALOGPHOTO_SMALL]);
} }
} }

View File

@ -52,19 +52,19 @@ class UniqueFileId
*/ */
private $_localId; private $_localId;
/** /**
* Photo subtype * Photo subtype.
* *
* @var int * @var int
*/ */
private $_subType; private $_subType;
/** /**
* Sticker set ID * Sticker set ID.
* *
* @var int * @var int
*/ */
private $_stickerSetId; private $_stickerSetId;
/** /**
* Sticker set version * Sticker set version.
* *
* @var int * @var int
*/ */
@ -107,12 +107,12 @@ class UniqueFileId
$fileId .= packLong($this->getVolumeId()); $fileId .= packLong($this->getVolumeId());
$fileId .= \pack('l', $this->getLocalId()); $fileId .= \pack('l', $this->getLocalId());
} elseif ($this->hasStickerSetId()) { } elseif ($this->hasStickerSetId()) {
$fileId .= chr($this->getSubType()); $fileId .= \chr($this->getSubType());
$fileId .= packLong($this->getStickerSetId()); $fileId .= packLong($this->getStickerSetId());
$fileId .= pack('l', $this->getStickerSetVersion()); $fileId .= \pack('l', $this->getStickerSetVersion());
} else { } else {
$fileId .= packLong($this->getId()); $fileId .= packLong($this->getId());
$fileId .= chr($this->getSubType()); $fileId .= \chr($this->getSubType());
} }
} elseif ($this->hasId()) { } elseif ($this->hasId()) {
$fileId .= packLong($this->getId()); $fileId .= packLong($this->getId());
@ -139,10 +139,10 @@ class UniqueFileId
if (isset($resultArray['volume_id'])) { if (isset($resultArray['volume_id'])) {
$result->setVolumeId($resultArray['volume_id']); $result->setVolumeId($resultArray['volume_id']);
$result->setLocalId($resultArray['local_id']); $result->setLocalId($resultArray['local_id']);
} else if (isset($resultArray['id'])) { } elseif (isset($resultArray['id'])) {
$result->setId($resultArray['id']); $result->setId($resultArray['id']);
$result->setSubType($resultArray['subType']); $result->setSubType($resultArray['subType']);
} else if (isset($resultArray['sticker_set_id'])) { } elseif (isset($resultArray['sticker_set_id'])) {
$result->setStickerSetId($resultArray['sticker_set_id']); $result->setStickerSetId($resultArray['sticker_set_id']);
$result->setStickerSetVersion($resultArray['sticker_set_version']); $result->setStickerSetVersion($resultArray['sticker_set_version']);
$result->setSubType($resultArray['subType']); $result->setSubType($resultArray['subType']);
@ -186,22 +186,22 @@ class UniqueFileId
if ($fileId->hasVolumeId()) { if ($fileId->hasVolumeId()) {
$result->setVolumeId($fileId->getVolumeId()); $result->setVolumeId($fileId->getVolumeId());
$result->setLocalId($fileId->getLocalId()); $result->setLocalId($fileId->getLocalId());
} else if ($fileId->hasId()) { } elseif ($fileId->hasId()) {
$result->setId($fileId->getId()); $result->setId($fileId->getId());
$photoSize = $fileId->getPhotoSizeSource(); $photoSize = $fileId->getPhotoSizeSource();
if ($photoSize instanceof PhotoSizeSourceThumbnail) { if ($photoSize instanceof PhotoSizeSourceThumbnail) {
$type = $photoSize->getThumbType(); $type = $photoSize->getThumbType();
if ($type === 'a') { if ($type === 'a') {
$type = chr(0); $type = \chr(0);
} else if ($type === 'c') { } elseif ($type === 'c') {
$type = chr(1); $type = \chr(1);
} else { } else {
$type = chr(ord($type)+5); $type = \chr(\ord($type)+5);
} }
$result->setSubType(ord($type)); $result->setSubType(\ord($type));
} else if ($photoSize instanceof PhotoSizeSourceDialogPhoto) { } elseif ($photoSize instanceof PhotoSizeSourceDialogPhoto) {
$result->setSubType($photoSize->isSmallDialogPhoto() ? 0 : 1); $result->setSubType($photoSize->isSmallDialogPhoto() ? 0 : 1);
} else if ($photoSize instanceof PhotoSizeSourceStickersetThumbnailVersion) { } elseif ($photoSize instanceof PhotoSizeSourceStickersetThumbnailVersion) {
$result->setSubType(2); $result->setSubType(2);
$result->setStickerSetId($photoSize->getStickerSetId()); $result->setStickerSetId($photoSize->getStickerSetId());
$result->setStickerSetVersion($photoSize->getStickerSetVersion()); $result->setStickerSetVersion($photoSize->getStickerSetVersion());
@ -386,7 +386,7 @@ class UniqueFileId
} }
/** /**
* Get photo subtype * Get photo subtype.
* *
* @return int * @return int
*/ */
@ -406,7 +406,7 @@ class UniqueFileId
} }
/** /**
* Set photo subtype * Set photo subtype.
* *
* @param int $_subType Photo subtype * @param int $_subType Photo subtype
* *
@ -420,7 +420,7 @@ class UniqueFileId
} }
/** /**
* Get sticker set ID * Get sticker set ID.
* *
* @return int * @return int
*/ */
@ -441,7 +441,7 @@ class UniqueFileId
} }
/** /**
* Set sticker set ID * Set sticker set ID.
* *
* @param int $_stickerSetId Sticker set ID * @param int $_stickerSetId Sticker set ID
* *
@ -455,7 +455,7 @@ class UniqueFileId
} }
/** /**
* Get sticker set version * Get sticker set version.
* *
* @return int * @return int
*/ */
@ -465,7 +465,7 @@ class UniqueFileId
} }
/** /**
* Has sticker set version * Has sticker set version.
* *
* @return bool * @return bool
*/ */
@ -475,7 +475,7 @@ class UniqueFileId
} }
/** /**
* Set sticker set version * Set sticker set version.
* *
* @param int $_stickerSetVersion Sticker set version * @param int $_stickerSetVersion Sticker set version
* *

View File

@ -631,7 +631,7 @@ function internalDecodeUnique(string $fileId): array
$l = 0; $l = 0;
} else { } else {
$l = strlen($fileId); $l = \strlen($fileId);
} }
if ($l > 0) { if ($l > 0) {
\trigger_error("Unique file ID $orig has $l bytes of leftover data"); \trigger_error("Unique file ID $orig has $l bytes of leftover data");