Conditions | 5 |
Paths | 13 |
Total Lines | 53 |
Code Lines | 30 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
48 | protected function execute(InputInterface $input, OutputInterface $output) |
||
49 | { |
||
50 | $io = new SymfonyStyle($input, $output); |
||
51 | |||
52 | //Check for valid base current |
||
53 | if (strlen($this->base_current) !== 3) { |
||
54 | $io->error("Choosen Base current is not valid. Check your settings!"); |
||
55 | return; |
||
56 | } |
||
57 | |||
58 | $io->note('Update currency exchange rates with base currency: ' . $this->base_current); |
||
59 | |||
60 | $service = $input->getOption('service'); |
||
61 | $api_key = $input->getOption('api_key'); |
||
62 | |||
63 | //Construct Swap with the given options |
||
64 | $swap = (new Builder()) |
||
65 | ->add($service, ['access_key' => $api_key]) |
||
66 | ->build(); |
||
67 | |||
68 | //Check what currencies we need to update: |
||
69 | $iso_code = $input->getArgument('iso_code'); |
||
70 | $repo = $this->em->getRepository(Currency::class); |
||
71 | $candidates = array(); |
||
72 | |||
73 | if (!empty($iso_code)) { |
||
74 | $candidates = $repo->findBy(['iso_code' => $iso_code]); |
||
75 | } else { |
||
76 | $candidates = $repo->findAll(); |
||
77 | } |
||
78 | |||
79 | $success_counter = 0; |
||
80 | |||
81 | //Iterate over each candidate and update exchange rate |
||
82 | foreach ($candidates as $currency) { |
||
83 | try { |
||
84 | $rate = $swap->latest($currency->getIsoCode() . '/' . $this->base_current); |
||
85 | $currency->setExchangeRate($rate->getValue()); |
||
86 | $io->note(sprintf('Set exchange rate of %s to %f', $currency->getIsoCode(), $currency->getExchangeRate())); |
||
87 | $this->em->persist($currency); |
||
88 | |||
89 | $success_counter++; |
||
90 | } catch (\Exchanger\Exception\Exception $ex) { |
||
91 | $io->warning(sprintf('Error updating %s:', $currency->getIsoCode())); |
||
92 | $io->warning($ex->getMessage()); |
||
93 | } |
||
94 | |||
95 | } |
||
96 | |||
97 | //Save to database |
||
98 | $this->em->flush(); |
||
99 | |||
100 | $io->success(sprintf('%d (of %d) currency exchange rates were updated.', $success_counter, count($candidates))); |
||
101 | } |
||
103 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths