Issue 1 patch: users:profile PHP notice
This commit is contained in:
parent
36c4cc837c
commit
6711f1ae0c
|
@ -55,7 +55,7 @@ Usage: <comment>torrents:details</comment> <info>TORRENT_ID</info>");
|
||||||
|
|
||||||
$output->writeln(sprintf('<info>%s</info>', $data['name']));
|
$output->writeln(sprintf('<info>%s</info>', $data['name']));
|
||||||
$output->writeln('');
|
$output->writeln('');
|
||||||
$output->writeln(sprintf('Category : <comment>%s</comment>', $data['categoryname']));
|
$output->writeln(sprintf('Category : <comment>%s</comment>', $data['categoryname']));
|
||||||
|
|
||||||
foreach ($data['terms'] as $title => $value) {
|
foreach ($data['terms'] as $title => $value) {
|
||||||
$output->writeln(sprintf('%-16s: <comment>%s</comment>', $title, $value));
|
$output->writeln(sprintf('%-16s: <comment>%s</comment>', $title, $value));
|
||||||
|
|
|
@ -11,6 +11,7 @@ use Api\Client;
|
||||||
use Api\ConfigLoader;
|
use Api\ConfigLoader;
|
||||||
use Api\ClientResponse;
|
use Api\ClientResponse;
|
||||||
use Api\ClientException;
|
use Api\ClientException;
|
||||||
|
use Helper\Formater;
|
||||||
|
|
||||||
class TorrentsSearchCommand extends Command
|
class TorrentsSearchCommand extends Command
|
||||||
{
|
{
|
||||||
|
@ -160,18 +161,10 @@ Usage: <comment>torrents:search</comment> <info>QUERY</info> [OPTIONS]
|
||||||
'[<info>%4d</info><comment>%6d</comment>] [%8s] %7d %s',
|
'[<info>%4d</info><comment>%6d</comment>] [%8s] %7d %s',
|
||||||
$torrent['seeders'],
|
$torrent['seeders'],
|
||||||
$torrent['leechers'],
|
$torrent['leechers'],
|
||||||
$this->formatBytes((int) $torrent['size']),
|
Formater::humanSize((int) $torrent['size']),
|
||||||
$torrent['id'],
|
$torrent['id'],
|
||||||
$torrent['name']
|
$torrent['name']
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function formatBytes($size, $precision = 2)
|
|
||||||
{
|
|
||||||
$base = log($size, 1024);
|
|
||||||
$suffixes = array('', 'kB', 'MB', 'GB', 'TB');
|
|
||||||
|
|
||||||
return round(pow(1024, $base - floor($base)), $precision) . $suffixes[floor($base)];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ use Api\Client;
|
||||||
use Api\ConfigLoader;
|
use Api\ConfigLoader;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
use Api\ClientException;
|
use Api\ClientException;
|
||||||
|
use Helper\Formater;
|
||||||
|
|
||||||
class UsersProfileCommand extends Command
|
class UsersProfileCommand extends Command
|
||||||
{
|
{
|
||||||
|
@ -74,8 +75,8 @@ Usage: <comment>users:profile</comment> [OPTIONS]");
|
||||||
|
|
||||||
$output->writeln(sprintf(
|
$output->writeln(sprintf(
|
||||||
'DOWN <comment>%sB</comment> UP <comment>%sB</comment> RATIO %s',
|
'DOWN <comment>%sB</comment> UP <comment>%sB</comment> RATIO %s',
|
||||||
$this->getHumainSize($data['downloaded']),
|
Formater::humanSize((int) $data['downloaded']),
|
||||||
$this->getHumainSize($data['uploaded']),
|
Formater::humanSize((int) $data['uploaded']),
|
||||||
sprintf(
|
sprintf(
|
||||||
$ratio > 1 ? '<info>%.2f</info>' : '<error>%.2f</error>',
|
$ratio > 1 ? '<info>%.2f</info>' : '<error>%.2f</error>',
|
||||||
$ratio
|
$ratio
|
||||||
|
@ -86,12 +87,4 @@ Usage: <comment>users:profile</comment> [OPTIONS]");
|
||||||
$output->writeln(sprintf('An error occured. <error>%s</error>', $e->getMessage()));
|
$output->writeln(sprintf('An error occured. <error>%s</error>', $e->getMessage()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getHumainSize($bytes, $decimals = 2)
|
|
||||||
{
|
|
||||||
$sizes = 'BKMGTP';
|
|
||||||
$factor = floor((strlen($bytes) - 1) / 3);
|
|
||||||
|
|
||||||
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)).$sizes[$factor];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
18
src/Helper/Formater.php
Normal file
18
src/Helper/Formater.php
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Helper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Formater
|
||||||
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
|
*/
|
||||||
|
class Formater
|
||||||
|
{
|
||||||
|
public static function humanSize($size, $precision = 2)
|
||||||
|
{
|
||||||
|
$base = log($size, 1024);
|
||||||
|
$suffixes = array('', 'kB', 'MB', 'GB', 'TB');
|
||||||
|
|
||||||
|
return round(pow(1024, $base - floor($base)), $precision) . $suffixes[floor($base)];
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue