code: public static function chain()
      {
          $providers = func_get_args();
          if (empty($providers)) {
              throw new \InvalidArgumentException('No providers in chain');
          }
  
          return function () use ($providers) {
              $provider = array_shift($providers);
              $credentials = $provider();
  
              while (($provider = array_shift($providers))
                  && !($credentials instanceof Credentials)
              ) {
                  $credentials = $provider();
              }
              return $credentials;
          };
      }
docs: Creates an aggregate credentials provider that invokes the provided
  variadic providers one after the other until a provider returns
  credentials
  
  @return callable
  @throws \InvalidArgumentException