Conditions | 11 |
Paths | 99 |
Total Lines | 70 |
Code Lines | 29 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
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:
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
1 | <?php |
||
58 | protected function newSpan( |
||
59 | Context $context, |
||
60 | string $name, |
||
61 | array $tags = [], |
||
62 | array $log = [], |
||
63 | string $exaFormat = null, |
||
64 | $exaCarrier = null, |
||
65 | SpanContext $exaContext = null, |
||
66 | Platform $platform = null, |
||
67 | int $timestamp = null |
||
68 | ) : void { |
||
69 | if (is_null($platform)) { |
||
70 | if (DI::has(Platform::class)) { |
||
71 | $platform = DI::get(Platform::class); |
||
72 | } else { |
||
73 | // missing platform support |
||
74 | return; |
||
75 | } |
||
76 | } |
||
77 | |||
78 | // check platform is ready |
||
79 | if (!$platform->joined()) { |
||
80 | return; |
||
81 | } |
||
82 | |||
83 | // get/set tracer |
||
84 | if ($context->has(CTX::G_TRACER)) { |
||
85 | $tracer = $context->get(CTX::G_TRACER); |
||
86 | } else { |
||
87 | $context->set(CTX::G_TRACER, $tracer = new Tracer($platform)); |
||
88 | } |
||
89 | |||
90 | // options |
||
91 | $options = [ |
||
92 | 'start_time' => $timestamp ?? $this->microseconds(), |
||
93 | 'tags' => array_merge($platform->env()->tags(), $tags), |
||
94 | ]; |
||
95 | |||
96 | // inherit from root |
||
97 | if (is_null($exaFormat) && $context->has(CTX::G_ROOT)) { |
||
98 | $exaFormat = FMT::PREV_CTX; |
||
99 | $exaCarrier = $context->get(CTX::G_ROOT); |
||
100 | } |
||
101 | |||
102 | // extracting |
||
103 | if ($exaFormat) { |
||
104 | try { |
||
105 | // check reference |
||
106 | if ($exaContext) { |
||
107 | $tracer->inject($exaContext, $exaFormat, $exaCarrier); |
||
108 | $options['child_of'] = $exaContext; |
||
109 | } else { |
||
110 | $options['child_of'] = $tracer->extract($exaFormat, $exaCarrier); |
||
111 | } |
||
112 | } catch (SpanContextNotFound $e) { |
||
113 | // root span |
||
114 | } |
||
115 | } |
||
116 | |||
117 | // is root |
||
118 | $root = ! $context->has(CTX::G_SPAN); |
||
119 | |||
120 | // new span |
||
121 | $context->set(CTX::G_SPAN, $span = $tracer->startSpan($name, SpanOptions::create($options))); |
||
122 | |||
123 | // root ctx |
||
124 | $root && $context->set(CTX::G_ROOT, $span->getContext()); |
||
125 | |||
126 | // some log |
||
127 | $span->log($log); |
||
128 | } |
||
203 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.