Skip to content

Commit

Permalink
Code style
Browse files Browse the repository at this point in the history
  • Loading branch information
arokettu committed Dec 7, 2023
1 parent 7343c61 commit dbc258b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/FileSystem/FileDataProgress.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ public function setCurrentData(int $total, int $done, string $fileName)
$this->done = $done;
$this->fileName = $fileName;

call_user_func($this->callback, $this);
\call_user_func($this->callback, $this);
}
}
12 changes: 6 additions & 6 deletions src/FileSystem/MultipleFileData.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected function process(): void
$exploded1 = $path1['explodedPath'];
$exploded2 = $path2['explodedPath'];

$partsCount = min(count($exploded1), count($exploded2));
$partsCount = min(\count($exploded1), \count($exploded2));

for ($i = 0; $i < $partsCount; $i++) {
$result = strcmp($exploded1[$i], $exploded2[$i]);
Expand Down Expand Up @@ -87,19 +87,19 @@ protected function process(): void
$files[] = $fileData;

// create chunk hashes
$chunkReadSize = $chunkSize - strlen($currentChunk);
$chunkReadSize = $chunkSize - \strlen($currentChunk);

while ($partialChunk = $file->fread($chunkReadSize)) {
$currentChunk .= $partialChunk;

if (strlen($currentChunk) < $chunkSize) {
if (\strlen($currentChunk) < $chunkSize) {
break; // add next file to the chunk
}

// we have complete chunk here
$chunkHashes[] = $this->hashChunk($currentChunk);

$doneSize += strlen($currentChunk);
$doneSize += \strlen($currentChunk);
$this->reportProgress($totalSize, $doneSize, $filePath['relativePath']);

$currentChunk = ''; // start new chunk
Expand All @@ -108,10 +108,10 @@ protected function process(): void
}

// hash last chunk
if (strlen($currentChunk) > 0) {
if (\strlen($currentChunk) > 0) {
$chunkHashes[] = $this->hashChunk($currentChunk);

$doneSize += strlen($currentChunk);
$doneSize += \strlen($currentChunk);

$this->reportProgress($totalSize, $doneSize, $data['name']);
}
Expand Down
6 changes: 3 additions & 3 deletions src/TorrentFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,12 @@ public function getAnnounce(): ?string
public function setAnnounceList(array $announceList): self
{
foreach ($announceList as &$group) {
if (is_string($group)) {
if (\is_string($group)) {
$group = [$group];
continue;
}

if (!is_array($group)) {
if (!\is_array($group)) {
throw new InvalidArgumentException(
'announce-list should be an array of strings or an array of arrays of strings'
);
Expand All @@ -152,7 +152,7 @@ public function setAnnounceList(array $announceList): self
$group = array_unique($group);

foreach ($group as $announce) {
if (!is_string($announce)) {
if (!\is_string($announce)) {
throw new InvalidArgumentException(
'announce-list should be an array of strings or an array of arrays of strings'
);
Expand Down
4 changes: 2 additions & 2 deletions tests/all/CreateFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function testSingleFile(): void
$torrent = TorrentFile::fromPath(TEST_ROOT . '/data/files/file1.txt'); // approx 6 mb

$this->assertEquals('6ca8fecb8d4c43183307179652fd31a50f99a912', $torrent->getInfoHash());
$this->assertEquals(260, strlen($torrent->getRawData()['info']['pieces'])); // 13 chunks
$this->assertEquals(260, \strlen($torrent->getRawData()['info']['pieces'])); // 13 chunks
$this->assertEquals('file1.txt', $torrent->getDisplayName());
$this->assertEquals('file1.txt.torrent', $torrent->getFileName());

Expand All @@ -31,7 +31,7 @@ public function testMultipleFiles(): void
$torrent = TorrentFile::fromPath(TEST_ROOT . '/data/files'); // approx 19 mb

$this->assertEquals('2efb80c60b42b261d79b777477276e0b18b47081', $torrent->getInfoHash());
$this->assertEquals(760, strlen($torrent->getRawData()['info']['pieces'])); // 38 chunks
$this->assertEquals(760, \strlen($torrent->getRawData()['info']['pieces'])); // 38 chunks
$this->assertEquals('files', $torrent->getDisplayName());
$this->assertEquals('files.torrent', $torrent->getFileName());

Expand Down
2 changes: 1 addition & 1 deletion tests/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function generate_files(): void

for ($i = 0; $i < 1153; $i++) {
for ($j = 0; $j < 983; $j++) {
$index = ($index + $randomizer) % count($words);
$index = ($index + $randomizer) % \count($words);
fwrite($file, $words[$index]);
fwrite($file, ' ');
}
Expand Down

0 comments on commit dbc258b

Please sign in to comment.