[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* 4 * This file is part of the Symfony package. 5 * 6 * (c) Fabien Potencier <[email protected]> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12 namespace Symfony\Component\ErrorHandler\ErrorEnhancer; 13 14 use Symfony\Component\ErrorHandler\Error\FatalError; 15 use Symfony\Component\ErrorHandler\Error\UndefinedMethodError; 16 17 /** 18 * @author Grégoire Pineau <[email protected]> 19 */ 20 class UndefinedMethodErrorEnhancer implements ErrorEnhancerInterface 21 { 22 /** 23 * {@inheritdoc} 24 */ 25 public function enhance(\Throwable $error): ?\Throwable 26 { 27 if ($error instanceof FatalError) { 28 return null; 29 } 30 31 $message = $error->getMessage(); 32 preg_match('/^Call to undefined method (.*)::(.*)\(\)$/', $message, $matches); 33 if (!$matches) { 34 return null; 35 } 36 37 $className = $matches[1]; 38 $methodName = $matches[2]; 39 40 $message = sprintf('Attempted to call an undefined method named "%s" of class "%s".', $methodName, $className); 41 42 if ('' === $methodName || !class_exists($className) || null === $methods = get_class_methods($className)) { 43 // failed to get the class or its methods on which an unknown method was called (for example on an anonymous class) 44 return new UndefinedMethodError($message, $error); 45 } 46 47 $candidates = []; 48 foreach ($methods as $definedMethodName) { 49 $lev = levenshtein($methodName, $definedMethodName); 50 if ($lev <= \strlen($methodName) / 3 || false !== strpos($definedMethodName, $methodName)) { 51 $candidates[] = $definedMethodName; 52 } 53 } 54 55 if ($candidates) { 56 sort($candidates); 57 $last = array_pop($candidates).'"?'; 58 if ($candidates) { 59 $candidates = 'e.g. "'.implode('", "', $candidates).'" or "'.$last; 60 } else { 61 $candidates = '"'.$last; 62 } 63 64 $message .= "\nDid you mean to call ".$candidates; 65 } 66 67 return new UndefinedMethodError($message, $error); 68 } 69 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |