code: public static function getRootCause(Exception $exception) : Exception
      {
          $result = null;
          while ($exception !== null) {
              $result = $exception;
              $exception = $exception->getPrevious();
          }
          return $result;
      }
docs: Returns the innermost cause of $exception.
  
  @param Exception $exception
  @return Exception