Conditions | 20 |
Paths | 530 |
Total Lines | 105 |
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 |
||
43 | protected function execute(InputInterface $input, OutputInterface $output) |
||
44 | { |
||
45 | $this->setThreshold($input->getOption('days')); |
||
46 | |||
47 | $suffix = $input->getOption('suffix'); |
||
48 | $ignoreSuffixes = $input->getOption('ignore-suffix'); |
||
49 | |||
50 | $suffixRegex = sprintf('/%s$/', $suffix); |
||
51 | $ignoreSuffixesRegex = sprintf('/(%s)$/', join('|', $ignoreSuffixes)); |
||
52 | |||
53 | if ($input->getOption('dry-run')) { |
||
54 | $output->writeln('<info>This is a dry-run run, no pad will deleted.</info>'); |
||
55 | } |
||
56 | |||
57 | if ($output->isVerbose()) { |
||
58 | $output->writeln( |
||
59 | sprintf('<info>INFO:</info> Pads before %s will be deleted', $this->threshold->format($this->dateFormat)) |
||
60 | ); |
||
61 | if (null !== $suffix) { |
||
62 | $output->writeln( |
||
63 | sprintf('<info>INFO:</info> Only pads ending with suffix \'%s\' will be deleted', $suffix) |
||
64 | ); |
||
65 | } |
||
66 | if (!empty($ignoreSuffixes)) { |
||
67 | $output->writeln( |
||
68 | sprintf('<info>INFO:</info> Pads ending with suffixes \'%s\' will be ignored', join('\', \'', $ignoreSuffixes)) |
||
69 | ); |
||
70 | } |
||
71 | } |
||
72 | |||
73 | $padIds = $this->getAllPads($input->getOption('apikey'), $input->getOption('host')); |
||
74 | |||
75 | if ($padIds === false) { |
||
76 | $output->writeln('<error>Could not receive all pads.</error>'); |
||
77 | |||
78 | return 0; |
||
79 | } |
||
80 | |||
81 | if ($output->isVerbose()) { |
||
82 | $output->writeln( |
||
83 | sprintf('<info>INFO:</info> %s pad(s) stored', $this->countPads) |
||
84 | ); |
||
85 | } |
||
86 | |||
87 | foreach ($padIds as $padId) { |
||
88 | if (null !== $suffix && !preg_match($suffixRegex, $padId)) { |
||
89 | if ($output->isDebug()) { |
||
90 | $output->writeln( |
||
91 | sprintf('<info>DEBUG:</info> "%s" will be ignored as it doesn\'t match suffix', $padId) |
||
92 | ); |
||
93 | } |
||
94 | continue; |
||
95 | } |
||
96 | if (!empty($ignoreSuffixes) && preg_match($ignoreSuffixesRegex, $padId)) { |
||
97 | if ($output->isDebug()) { |
||
98 | $output->writeln( |
||
99 | sprintf('<info>DEBUG:</info> "%s" will be ignored as it matches an ignore-suffix', $padId) |
||
100 | ); |
||
101 | } |
||
102 | continue; |
||
103 | } |
||
104 | |||
105 | $lastEdited = Pad::getLastEdited( |
||
106 | $padId, |
||
107 | $input->getOption('apikey'), |
||
108 | $input->getOption('host') |
||
109 | ); |
||
110 | |||
111 | if ($lastEdited === false) { |
||
112 | $this->countPadsFailed++; |
||
113 | continue; |
||
114 | } |
||
115 | |||
116 | if ($lastEdited < $this->threshold->getTimestamp()) { |
||
117 | if ($output->isDebug()) { |
||
118 | $output->writeln( |
||
119 | sprintf( |
||
120 | '<info>DEBUG:</info> "%s" was last edited on %s and will purged', |
||
121 | $padId, |
||
122 | date($this->dateFormat, $lastEdited) |
||
123 | ) |
||
124 | ); |
||
125 | } |
||
126 | |||
127 | if (!$input->getOption('dry-run')) { |
||
128 | if (!Pad::deletePad( |
||
129 | $padId, |
||
130 | $input->getOption('apikey'), |
||
131 | $input->getOption('host') |
||
132 | )) { |
||
133 | $this->countPadsFailed++; |
||
134 | } |
||
135 | } |
||
136 | |||
137 | $this->countPadsDeleted++; |
||
138 | } |
||
139 | } |
||
140 | |||
141 | if ($output->isVerbose()) { |
||
142 | $output->writeln(sprintf('<info>INFO:</info> %s pad(s) deleted', $this->countPadsDeleted)); |
||
143 | $output->writeln(sprintf('<info>INFO:</info> %s pad(s) failed', $this->countPadsFailed)); |
||
144 | } |
||
145 | |||
146 | return 0; |
||
147 | } |
||
148 | |||
178 |