Complex classes like Ebi often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Ebi, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 11 | class Ebi { |
||
| 12 | /** |
||
| 13 | * @var string |
||
| 14 | */ |
||
| 15 | protected $cachePath; |
||
| 16 | /** |
||
| 17 | * @var callable[] |
||
| 18 | */ |
||
| 19 | protected $functions; |
||
| 20 | /** |
||
| 21 | * @var TemplateLoaderInterface |
||
| 22 | */ |
||
| 23 | private $templateLoader; |
||
| 24 | /** |
||
| 25 | * @var CompilerInterface |
||
| 26 | */ |
||
| 27 | private $compiler; |
||
| 28 | /** |
||
| 29 | * @var callable[] |
||
| 30 | */ |
||
| 31 | private $components = []; |
||
| 32 | /** |
||
| 33 | * @var array |
||
| 34 | */ |
||
| 35 | private $meta; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Ebi constructor. |
||
| 39 | * |
||
| 40 | * @param TemplateLoaderInterface $templateLoader Used to load template sources from component names. |
||
| 41 | * @param string $cachePath The path to cache compiled templates. |
||
| 42 | * @param CompilerInterface $compiler The compiler used to compile templates. |
||
|
|
|||
| 43 | */ |
||
| 44 | 62 | public function __construct(TemplateLoaderInterface $templateLoader, $cachePath, CompilerInterface $compiler = null) { |
|
| 45 | 62 | $this->templateLoader = $templateLoader; |
|
| 46 | 62 | $this->cachePath = $cachePath; |
|
| 47 | 62 | $this->compiler = $compiler ?: new Compiler(); |
|
| 48 | |||
| 49 | 62 | $this->defineFunction('abs'); |
|
| 50 | 62 | $this->defineFunction('arrayColumn', 'array_column'); |
|
| 51 | 62 | $this->defineFunction('arrayKeyExists', 'array_key_exists'); |
|
| 52 | 62 | $this->defineFunction('arrayKeys', 'array_keys'); |
|
| 53 | 62 | $this->defineFunction('arrayMerge', 'array_merge'); |
|
| 54 | 62 | $this->defineFunction('arrayMergeRecursive', 'array_merge_recursive'); |
|
| 55 | 62 | $this->defineFunction('arrayReplace', 'array_replace'); |
|
| 56 | 62 | $this->defineFunction('arrayReplaceRecursive', 'array_replace_recursive'); |
|
| 57 | 62 | $this->defineFunction('arrayReverse', 'array_reverse'); |
|
| 58 | 62 | $this->defineFunction('arrayValues', 'array_values'); |
|
| 59 | 62 | $this->defineFunction('base64Encode', 'base64_encode'); |
|
| 60 | 62 | $this->defineFunction('ceil'); |
|
| 61 | 62 | $this->defineFunction('componentExists', [$this, 'componentExists']); |
|
| 62 | 62 | $this->defineFunction('count'); |
|
| 63 | 62 | $this->defineFunction('empty'); |
|
| 64 | 62 | $this->defineFunction('floor'); |
|
| 65 | 62 | $this->defineFunction('formatDate', [$this, 'formatDate']); |
|
| 66 | 62 | $this->defineFunction('formatNumber', 'number_format'); |
|
| 67 | 62 | $this->defineFunction('htmlEncode', 'htmlspecialchars'); |
|
| 68 | 62 | $this->defineFunction('join'); |
|
| 69 | 62 | $this->defineFunction('lcase', $this->mb('strtolower')); |
|
| 70 | 62 | $this->defineFunction('lcfirst'); |
|
| 71 | 62 | $this->defineFunction('ltrim'); |
|
| 72 | 62 | $this->defineFunction('max'); |
|
| 73 | 62 | $this->defineFunction('min'); |
|
| 74 | 62 | $this->defineFunction('queryEncode', 'http_build_query'); |
|
| 75 | 62 | $this->defineFunction('round'); |
|
| 76 | 62 | $this->defineFunction('rtrim'); |
|
| 77 | 62 | $this->defineFunction('sprintf'); |
|
| 78 | 62 | $this->defineFunction('strlen', $this->mb('strlen')); |
|
| 79 | 62 | $this->defineFunction('substr', $this->mb('substr')); |
|
| 80 | 62 | $this->defineFunction('trim'); |
|
| 81 | 62 | $this->defineFunction('ucase', $this->mb('strtoupper')); |
|
| 82 | 62 | $this->defineFunction('ucfirst'); |
|
| 83 | 62 | $this->defineFunction('ucwords'); |
|
| 84 | 62 | $this->defineFunction('urlencode', 'rawurlencode'); |
|
| 85 | |||
| 86 | 62 | $this->defineFunction('@class', [$this, 'attributeClass']); |
|
| 87 | |||
| 88 | // Define a simple component not found component to help troubleshoot. |
||
| 89 | 62 | $this->defineComponent('@component-not-found', function ($props) { |
|
| 90 | 1 | echo '<!-- Ebi component "'.htmlspecialchars($props['component']).'" not found. -->'; |
|
| 91 | 62 | }); |
|
| 92 | |||
| 93 | // Define a simple component exception. |
||
| 94 | 62 | $this->defineComponent('@exception', function ($props) { |
|
| 95 | 1 | echo "\n<!--\nEbi exception in component \"".htmlspecialchars($props['component'])."\".\n". |
|
| 96 | 1 | htmlspecialchars($props['message'])."\n-->\n"; |
|
| 97 | |||
| 98 | 62 | }); |
|
| 99 | |||
| 100 | 62 | $this->defineComponent('@compile-exception', [$this, 'writeCompileException']); |
|
| 101 | 62 | } |
|
| 102 | |||
| 103 | /** |
||
| 104 | * Register a runtime function. |
||
| 105 | * |
||
| 106 | * @param string $name The name of the function. |
||
| 107 | * @param callable $function The function callback. |
||
| 108 | */ |
||
| 109 | 62 | public function defineFunction($name, $function = null) { |
|
| 110 | 62 | if ($function === null) { |
|
| 111 | 62 | $function = $name; |
|
| 112 | } |
||
| 113 | |||
| 114 | 62 | $this->functions[strtolower($name)] = $function; |
|
| 115 | 62 | $this->compiler->defineFunction($name, $function); |
|
| 116 | 62 | } |
|
| 117 | |||
| 118 | 62 | private function mb($func) { |
|
| 121 | |||
| 122 | /** |
||
| 123 | * Write a component to the output buffer. |
||
| 124 | * |
||
| 125 | * @param string $component The name of the component. |
||
| 126 | * @param array ...$args |
||
| 127 | */ |
||
| 128 | 16 | public function write($component, ...$args) { |
|
| 129 | 16 | $component = strtolower($component); |
|
| 130 | |||
| 131 | try { |
||
| 132 | 16 | $callback = $this->lookup($component); |
|
| 133 | |||
| 134 | 16 | if (is_callable($callback)) { |
|
| 135 | 16 | call_user_func($callback, ...$args); |
|
| 136 | } else { |
||
| 137 | 16 | $this->write('@component-not-found', ['component' => $component]); |
|
| 138 | } |
||
| 139 | 1 | } catch (\Throwable $ex) { |
|
| 140 | 1 | $this->write('@exception', ['message' => $ex->getMessage(), 'code', $ex->getCode(), 'component' => $component]); |
|
| 141 | 1 | return; |
|
| 142 | } catch (\Exception $ex) { |
||
| 143 | $this->write('@exception', ['message' => $ex->getMessage(), 'code', $ex->getCode(), 'component' => $component]); |
||
| 144 | return; |
||
| 145 | } |
||
| 146 | 16 | } |
|
| 147 | |||
| 148 | /** |
||
| 149 | * Lookup a component with a given name. |
||
| 150 | * |
||
| 151 | * @param string $component The component to lookup. |
||
| 152 | * @return callable|null Returns the component function or **null** if the component is not found. |
||
| 153 | */ |
||
| 154 | 57 | public function lookup($component) { |
|
| 155 | 57 | $component = strtolower($component); |
|
| 156 | 57 | $key = $this->componentKey($component); |
|
| 157 | |||
| 158 | 57 | if (!array_key_exists($key, $this->components)) { |
|
| 159 | 52 | $this->loadComponent($component); |
|
| 160 | } |
||
| 161 | |||
| 162 | 57 | if (isset($this->components[$key])) { |
|
| 163 | 56 | return $this->components[$key]; |
|
| 164 | } else { |
||
| 165 | // Mark a tombstone to the component array so it doesn't keep getting loaded. |
||
| 166 | 2 | $this->components[$key] = null; |
|
| 167 | 2 | return null; |
|
| 168 | } |
||
| 169 | } |
||
| 170 | |||
| 171 | /** |
||
| 172 | * Check to see if a component exists. |
||
| 173 | * |
||
| 174 | * @param string $component The name of the component. |
||
| 175 | * @param bool $loader Whether or not to use the component loader or just look in the component cache. |
||
| 176 | * @return bool Returns **true** if the component exists or **false** otherwise. |
||
| 177 | */ |
||
| 178 | 2 | public function componentExists($component, $loader = true) { |
|
| 187 | |||
| 188 | /** |
||
| 189 | * Strip the namespace off a component name to get the component key. |
||
| 190 | * |
||
| 191 | * @param string $component The full name of the component with a possible namespace. |
||
| 192 | * @return string Returns the component key. |
||
| 193 | */ |
||
| 194 | 59 | protected function componentKey($component) { |
|
| 195 | 59 | if (false !== $pos = strpos($component, ':')) { |
|
| 196 | 1 | $component = substr($component, $pos + 1); |
|
| 197 | } |
||
| 198 | 59 | return strtolower($component); |
|
| 199 | } |
||
| 200 | |||
| 201 | /** |
||
| 202 | * Load a component. |
||
| 203 | * |
||
| 204 | * @param string $component The name of the component to load. |
||
| 205 | * @return callable|null Returns the component or **null** if the component isn't found. |
||
| 206 | */ |
||
| 207 | 52 | protected function loadComponent($component) { |
|
| 208 | 52 | $cacheKey = $this->templateLoader->cacheKey($component); |
|
| 209 | // The template loader can tell us a template doesn't exist when giving the cache key. |
||
| 210 | 52 | if (empty($cacheKey)) { |
|
| 211 | 2 | return null; |
|
| 212 | } |
||
| 213 | |||
| 214 | 50 | $cachePath = "{$this->cachePath}/$cacheKey.php"; |
|
| 215 | 50 | $componentKey = $this->componentKey($component); |
|
| 216 | |||
| 217 | 50 | if (!file_exists($cachePath)) { |
|
| 218 | 50 | $src = $this->templateLoader->load($component); |
|
| 219 | try { |
||
| 220 | 50 | return $this->compile($componentKey, $src, $cacheKey); |
|
| 221 | 3 | } catch (CompileException $ex) { |
|
| 222 | 3 | $props = ['message' => $ex->getMessage()] + $ex->getContext(); |
|
| 223 | 3 | return $this->components[$componentKey] = function() use ($props) { |
|
| 224 | 3 | $this->write('@compile-exception', $props); |
|
| 225 | 3 | }; |
|
| 226 | } |
||
| 227 | } else { |
||
| 228 | return $this->includeComponent($componentKey, $cachePath); |
||
| 229 | } |
||
| 230 | } |
||
| 231 | |||
| 232 | 3 | protected function writeCompileException($props) { |
|
| 233 | 3 | echo "\n<section class=\"ebi-ex\">\n", |
|
| 234 | 3 | '<h2>Error compiling '.htmlspecialchars($props['path'])." near line {$props['line']}.</h2>\n"; |
|
| 235 | |||
| 236 | 3 | echo '<p class="ebi-ex-message">'.htmlspecialchars($props['message'])."</p>\n"; |
|
| 237 | |||
| 238 | 3 | if (!empty($props['source'])) { |
|
| 239 | 3 | $source = $props['source']; |
|
| 240 | 3 | if (isset($props['sourcePosition'])) { |
|
| 241 | 3 | $pos = $props['sourcePosition']; |
|
| 242 | 3 | $source = htmlspecialchars(substr($source, 0, $pos)). |
|
| 243 | 3 | '<mark class="ebi-ex-highlight">'.htmlspecialchars(substr($source, $pos, 1)).'</mark>'. |
|
| 244 | 3 | htmlspecialchars(substr($source, $pos + 1)); |
|
| 245 | } else { |
||
| 246 | $source = htmlspecialchars($source); |
||
| 247 | } |
||
| 248 | |||
| 249 | 3 | echo '<pre class="ebi-ex-source ebi-ex-context"><code>', |
|
| 250 | 3 | $source, |
|
| 251 | 3 | "</code></pre>\n"; |
|
| 252 | } |
||
| 253 | |||
| 254 | 3 | if (!empty($props['lines'])) { |
|
| 255 | 3 | echo '<pre class="ebi-ex-source ebi-ex-lines">'; |
|
| 256 | |||
| 257 | 3 | foreach ($props['lines'] as $i => $line) { |
|
| 258 | 3 | echo '<code class="ebi-ex-line">'; |
|
| 259 | |||
| 260 | 3 | $str = sprintf("%3d. %s", $i, htmlspecialchars($line)); |
|
| 261 | 3 | if ($i === $props['line']) { |
|
| 262 | 3 | echo "<mark class=\"ebi-ex-highlight\">$str</mark>"; |
|
| 263 | } else { |
||
| 264 | 3 | echo $str; |
|
| 265 | } |
||
| 266 | |||
| 267 | 3 | echo "</code>\n"; |
|
| 268 | } |
||
| 269 | |||
| 270 | 3 | echo "</pre>\n"; |
|
| 271 | } |
||
| 272 | |||
| 273 | 3 | echo "</section>\n"; |
|
| 274 | 3 | } |
|
| 275 | |||
| 276 | /** |
||
| 277 | * Check to see if a specific cache key exists in the cache. |
||
| 278 | * |
||
| 279 | * @param string $cacheKey The cache key to check. |
||
| 280 | * @return bool Returns **true** if there is a cache key at the file or **false** otherwise. |
||
| 281 | */ |
||
| 282 | 1 | public function cacheKeyExists($cacheKey) { |
|
| 286 | |||
| 287 | /** |
||
| 288 | * Compile a component from source, cache it and include it. |
||
| 289 | * |
||
| 290 | * @param string $component The name of the component. |
||
| 291 | * @param string $src The component source. |
||
| 292 | * @param string $cacheKey The cache key of the component. |
||
| 293 | * @return callable|null Returns the compiled component closure. |
||
| 294 | */ |
||
| 295 | 54 | public function compile($component, $src, $cacheKey) { |
|
| 306 | |||
| 307 | /** |
||
| 308 | * Include a cached component. |
||
| 309 | * |
||
| 310 | * @param string $component The component key. |
||
| 311 | * @param string $cachePath The path to the component. |
||
| 312 | * @return callable|null Returns the component function or **null** if the component wasn't properly defined. |
||
| 313 | */ |
||
| 314 | 51 | private function includeComponent($component, $cachePath) { |
|
| 328 | |||
| 329 | /** |
||
| 330 | * A safe version of {@link file_put_contents()} that also clears op caches. |
||
| 331 | * |
||
| 332 | * @param string $path The path to save to. |
||
| 333 | * @param string $contents The contents of the file. |
||
| 334 | * @return bool Returns **true** on success or **false** on failure. |
||
| 335 | */ |
||
| 336 | 51 | private function filePutContents($path, $contents) { |
|
| 337 | 51 | if (!file_exists(dirname($path))) { |
|
| 338 | 4 | mkdir(dirname($path), 0777, true); |
|
| 339 | } |
||
| 340 | 51 | $tmpPath = tempnam(dirname($path), 'ebi-'); |
|
| 341 | 51 | $r = false; |
|
| 342 | 51 | if (file_put_contents($tmpPath, $contents) !== false) { |
|
| 343 | 51 | chmod($tmpPath, 0664); |
|
| 344 | 51 | $r = rename($tmpPath, $path); |
|
| 345 | } |
||
| 346 | |||
| 347 | 51 | if (function_exists('apc_delete_file')) { |
|
| 348 | // This fixes a bug with some configurations of apc. |
||
| 349 | @apc_delete_file($path); |
||
| 350 | 51 | } elseif (function_exists('opcache_invalidate')) { |
|
| 351 | 51 | @opcache_invalidate($path); |
|
| 352 | } |
||
| 353 | |||
| 354 | 51 | return $r; |
|
| 355 | } |
||
| 356 | |||
| 357 | /** |
||
| 358 | * Include a file. |
||
| 359 | * |
||
| 360 | * This is method is useful for including a file bound to this object instance. |
||
| 361 | * |
||
| 362 | * @param string $path The path to the file to include. |
||
| 363 | * @return mixed Returns the result of the include. |
||
| 364 | */ |
||
| 365 | 51 | public function requireFile($path) { |
|
| 368 | |||
| 369 | /** |
||
| 370 | * Register a component. |
||
| 371 | * |
||
| 372 | * @param string $name The name of the component to register. |
||
| 373 | * @param callable $component The component function. |
||
| 374 | */ |
||
| 375 | 62 | public function defineComponent($name, callable $component) { |
|
| 378 | |||
| 379 | /** |
||
| 380 | * Render a component to a string. |
||
| 381 | * |
||
| 382 | * @param string $component The name of the component to render. |
||
| 383 | * @param array ...$args Arguments to pass to the component. |
||
| 384 | * @return string|null Returns the rendered component or **null** if the component was not found. |
||
| 385 | */ |
||
| 386 | 53 | public function render($component, ...$args) { |
|
| 387 | 53 | if ($callback = $this->lookup($component)) { |
|
| 388 | 53 | ob_start(); |
|
| 389 | 53 | $errs = error_reporting(error_reporting() & ~E_NOTICE & ~E_WARNING); |
|
| 390 | 53 | call_user_func($callback, ...$args); |
|
| 391 | 53 | error_reporting($errs); |
|
| 392 | 53 | $str = ob_get_clean(); |
|
| 393 | 53 | return $str; |
|
| 394 | } else { |
||
| 395 | trigger_error("Could not find component $component.", E_USER_NOTICE); |
||
| 396 | return null; |
||
| 397 | } |
||
| 398 | } |
||
| 399 | |||
| 400 | /** |
||
| 401 | * Set the error reporting appropriate for template rendering. |
||
| 402 | * |
||
| 403 | * @return int Returns the previous error level. |
||
| 404 | */ |
||
| 405 | public function setErrorReporting() { |
||
| 409 | |||
| 410 | /** |
||
| 411 | * Call a function registered with **defineFunction()**. |
||
| 412 | * |
||
| 413 | * If a static or global function is registered then it's simply rendered in the compiled template. |
||
| 414 | * This method is for closures or callbacks. |
||
| 415 | * |
||
| 416 | * @param string $name The name of the registered function. |
||
| 417 | * @param array ...$args The function's argument. |
||
| 418 | * @return mixed Returns the result of the function |
||
| 419 | * @throws RuntimeException Throws an exception when the function isn't found. |
||
| 420 | */ |
||
| 421 | 3 | public function call($name, ...$args) { |
|
| 428 | |||
| 429 | /** |
||
| 430 | * Render a variable appropriately for CSS. |
||
| 431 | * |
||
| 432 | * This is a convenience runtime function. |
||
| 433 | * |
||
| 434 | * @param string|array $expr A CSS class, an array of CSS classes, or an associative array where the keys are class |
||
| 435 | * names and the values are truthy conditions to include the class (or not). |
||
| 436 | * @return string Returns a space-delimited CSS class string. |
||
| 437 | */ |
||
| 438 | 6 | public function attributeClass($expr) { |
|
| 439 | 6 | if (is_array($expr)) { |
|
| 440 | 3 | $classes = []; |
|
| 441 | 3 | foreach ($expr as $i => $val) { |
|
| 442 | 3 | if (is_array($val)) { |
|
| 443 | 1 | $classes[] = $this->attributeClass($val); |
|
| 444 | 3 | } elseif (is_int($i)) { |
|
| 445 | 1 | $classes[] = $val; |
|
| 446 | 2 | } elseif (!empty($val)) { |
|
| 447 | 3 | $classes[] = $i; |
|
| 448 | } |
||
| 449 | } |
||
| 450 | 3 | return implode(' ', $classes); |
|
| 451 | } else { |
||
| 452 | 3 | return (string)$expr; |
|
| 453 | } |
||
| 454 | } |
||
| 455 | |||
| 456 | /** |
||
| 457 | * Format a data. |
||
| 458 | * |
||
| 459 | * @param mixed $date The date to format. This can be a string data, a timestamp or an instance of **DateTimeInterface**. |
||
| 460 | * @param string $format The format of the date. |
||
| 461 | * @return string Returns the formatted data. |
||
| 462 | * @see date_format() |
||
| 463 | */ |
||
| 464 | 1 | public function formatDate($date, $format = 'c') { |
|
| 465 | 1 | if (is_string($date)) { |
|
| 466 | try { |
||
| 467 | 1 | $date = new \DateTimeImmutable($date); |
|
| 468 | } catch (\Exception $ex) { |
||
| 469 | 1 | return '#error#'; |
|
| 470 | } |
||
| 471 | } elseif (empty($date)) { |
||
| 472 | return ''; |
||
| 473 | } elseif (is_int($date)) { |
||
| 474 | try { |
||
| 475 | $date = new \DateTimeImmutable('@'.$date); |
||
| 476 | } catch (\Exception $ex) { |
||
| 477 | return '#error#'; |
||
| 478 | } |
||
| 479 | } elseif (!$date instanceof \DateTimeInterface) { |
||
| 480 | return '#error#'; |
||
| 481 | } |
||
| 482 | |||
| 483 | 1 | return $date->format($format); |
|
| 484 | } |
||
| 485 | |||
| 486 | /** |
||
| 487 | * Get a single item from the meta array. |
||
| 488 | * |
||
| 489 | * @param string $name The key to get from. |
||
| 490 | * @param mixed $default The default value if no item at the key exists. |
||
| 491 | * @return mixed Returns the meta value. |
||
| 492 | */ |
||
| 493 | public function getMeta($name, $default = null) { |
||
| 496 | |||
| 497 | /** |
||
| 498 | * Set a single item to the meta array. |
||
| 499 | * |
||
| 500 | * @param string $name The key to set. |
||
| 501 | * @param mixed $value The new value. |
||
| 502 | * @return $this |
||
| 503 | */ |
||
| 504 | 1 | public function setMeta($name, $value) { |
|
| 508 | |||
| 509 | /** |
||
| 510 | * Get the template loader. |
||
| 511 | * |
||
| 512 | * The template loader translates component names into template contents. |
||
| 513 | * |
||
| 514 | * @return TemplateLoaderInterface Returns the template loader. |
||
| 515 | */ |
||
| 516 | 1 | public function getTemplateLoader() { |
|
| 519 | |||
| 520 | /** |
||
| 521 | * Set the template loader. |
||
| 522 | * |
||
| 523 | * The template loader translates component names into template contents. |
||
| 524 | * |
||
| 525 | * @param TemplateLoaderInterface $templateLoader The new template loader. |
||
| 526 | * @return $this |
||
| 527 | */ |
||
| 528 | public function setTemplateLoader($templateLoader) { |
||
| 532 | |||
| 533 | /** |
||
| 534 | * Get the entire meta array. |
||
| 535 | * |
||
| 536 | * @return array Returns the meta. |
||
| 537 | */ |
||
| 538 | public function getMetaArray() { |
||
| 541 | |||
| 542 | /** |
||
| 543 | * Set the entire meta array. |
||
| 544 | * |
||
| 545 | * @param array $meta The new meta array. |
||
| 546 | * @return $this |
||
| 547 | */ |
||
| 548 | public function setMetaArray(array $meta) { |
||
| 552 | |||
| 553 | /** |
||
| 554 | * Return a dynamic attribute. |
||
| 555 | * |
||
| 556 | * The attribute renders differently depending on the value. |
||
| 557 | * |
||
| 558 | * - If the value is **true** then it will render as an HTML5 boolean attribute. |
||
| 559 | * - If the value is **false** or **null** then the attribute will not render. |
||
| 560 | * - Other values render as attribute values. |
||
| 561 | * - Attributes that start with **aria-** render **true** and **false** as values. |
||
| 562 | * |
||
| 563 | * @param string $name The name of the attribute. |
||
| 564 | * @param mixed $value The value of the attribute. |
||
| 565 | * @return string Returns the attribute definition or an empty string. |
||
| 566 | */ |
||
| 567 | 15 | protected function attribute($name, $value) { |
|
| 579 | } |
||
| 580 |
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.