Conditions | 10 |
Paths | 36 |
Total Lines | 57 |
Code Lines | 29 |
Lines | 0 |
Ratio | 0 % |
Changes | 6 | ||
Bugs | 1 | 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 |
||
65 | public function log($level, $message, array $context = []) |
||
66 | { |
||
67 | $output = $this->output; |
||
68 | $outputStyle = new OutputFormatterStyle('white'); |
||
69 | $output->getFormatter()->setStyle('text', $outputStyle); |
||
70 | |||
71 | // updates the levels mapping if output supports the Progress Bar |
||
72 | if ($output->isDecorated()) { |
||
73 | array_replace_recursive($this->verbosityLevelMap, [ |
||
74 | LogLevel::NOTICE => OutputInterface::VERBOSITY_NORMAL, |
||
75 | LogLevel::INFO => OutputInterface::VERBOSITY_VERBOSE, |
||
76 | ]); |
||
77 | } |
||
78 | |||
79 | if (!isset($this->verbosityLevelMap[$level])) { |
||
80 | throw new InvalidArgumentException(sprintf('The log level "%s" does not exist.', $level)); |
||
81 | } |
||
82 | |||
83 | // steps Progress Bar |
||
84 | if ($output->isDecorated()) { |
||
85 | if ($output->getVerbosity() == OutputInterface::VERBOSITY_NORMAL && array_key_exists('step', $context)) { |
||
86 | $this->printProgressBar($context['step'][0], $context['step'][1]); |
||
87 | |||
88 | return; |
||
89 | } |
||
90 | } |
||
91 | |||
92 | // default pattern: <level>message</level> |
||
93 | $pattern = '<%1$s>%2$s%3$s</%1$s>'; |
||
94 | $prefix = ''; |
||
95 | |||
96 | // steps prefix |
||
97 | if (array_key_exists('step', $context)) { |
||
98 | $prefix = sprintf('%s. ', $this->padPrefix($context['step'][0], $context['step'][1])); |
||
99 | } |
||
100 | |||
101 | // sub steps progress |
||
102 | if (array_key_exists('progress', $context)) { |
||
103 | // the verbose Progress Bar |
||
104 | if ($output->isDecorated()) { |
||
105 | if ($output->getVerbosity() == OutputInterface::VERBOSITY_VERBOSE) { |
||
106 | $this->printProgressBar($context['progress'][0], $context['progress'][1]); |
||
107 | |||
108 | return; |
||
109 | } |
||
110 | } |
||
111 | // prefix |
||
112 | $prefix = sprintf( |
||
113 | '[%s/%s] ', |
||
114 | $this->padPrefix($context['progress'][0], $context['progress'][1]), |
||
115 | $context['progress'][1] |
||
116 | ); |
||
117 | } |
||
118 | |||
119 | $output->writeln( |
||
120 | sprintf($pattern, $this->formatLevelMap[$level], $prefix, $this->interpolate($message, $context)), |
||
121 | $this->verbosityLevelMap[$level] |
||
122 | ); |
||
180 |