| Conditions | 1 |
| Paths | 1 |
| Total Lines | 55 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 17 | protected function configure() |
||
| 18 | { |
||
| 19 | parent::configure(); |
||
| 20 | $this |
||
| 21 | ->setName('stats-get') |
||
| 22 | ->setAliases(['sg']) |
||
| 23 | ->setDescription('Get metrics from InfluxDB') |
||
| 24 | ->addOption('name', null, InputOption::VALUE_OPTIONAL, 'Sort by torrent name (regexp)') |
||
| 25 | ->addOption('age', null, InputOption::VALUE_OPTIONAL, 'Sort by torrent age, ex. \'>1 <5\'') |
||
| 26 | ->addOption('profit', null, InputOption::VALUE_OPTIONAL, 'Filter by profit') |
||
| 27 | ->addOption('days', null, InputOption::VALUE_OPTIONAL, 'Show stats for last days', 7) |
||
| 28 | ->addOption('sort', null, InputOption::VALUE_OPTIONAL, 'Sort by column number', 4) |
||
| 29 | ->addOption('limit', null, InputOption::VALUE_OPTIONAL, 'Limit torrent list') |
||
| 30 | ->addOption('rm', null, InputOption::VALUE_NONE, 'Remove filtered torrents') |
||
| 31 | ->addOption('soft', null, InputOption::VALUE_NONE, 'Remove only from Transmission, not delete data') |
||
| 32 | ->addOption('yes', 'y', InputOption::VALUE_NONE, 'Don\'t ask confirmation') |
||
| 33 | ->addOption('transmission-host', null, InputOption::VALUE_OPTIONAL, 'Transmission host') |
||
| 34 | ->setHelp(<<<EOT |
||
| 35 | ## Get torrents stats from InfluxDB |
||
| 36 | |||
| 37 | Command `stats-get` almost same as `torrent-list`, but it use InfluxDB: |
||
| 38 | ``` |
||
| 39 | transmission-cli stats-get [--name='name'] [--age='age'] [profit='>0'] [--days=7] [--sort=1] [--limit=10] [--rm] |
||
| 40 | ``` |
||
| 41 | |||
| 42 | You can also use `--name`, `--age`, `--sort`, `--limit`, plus `--profit` and `--days` options. |
||
| 43 | |||
| 44 | Profit = uploaded for period / torrent size. Profit metric more precise than uploaded ever value. |
||
| 45 | |||
| 46 | Show 10 worst torrents for last week: |
||
| 47 | ``` |
||
| 48 | transmission-cli stats-get --days 7 --profit '=0' --limit 10 |
||
| 49 | ``` |
||
| 50 | |||
| 51 | Show stats of last added torrents sorted by profit: |
||
| 52 | ``` |
||
| 53 | transmission-cli stats-get --days 1 --age '<2' --sort='-7' |
||
| 54 | ``` |
||
| 55 | |||
| 56 | |||
| 57 | ## Remove torrents |
||
| 58 | |||
| 59 | You can use command `stats-get` with `--rm` option to remove filtered unpopular torrents: |
||
| 60 | ``` |
||
| 61 | transmission-cli stats-get --days 7 --profit '=0' --rm |
||
| 62 | ``` |
||
| 63 | |||
| 64 | With `--rm` option you can use all options of `torrent-remove` command: `--soft`, `--dry-run`, `-y`. |
||
| 65 | |||
| 66 | Without `-y` option command ask your confirmation for remove torrents. |
||
| 67 | |||
| 68 | If you don't want to remove all filtered torrents, you can save ids of torrents and call `torrent-remove` manually. |
||
| 69 | EOT |
||
| 70 | ); |
||
| 71 | } |
||
| 72 | |||
| 195 |