BadMethodCallException example

if (0 < $sleep = $this->restartThresholdSleep) {
            $this->getLogger()->debug(sprintf('Email transport "%s" sleeps for %d seconds after stopping', __CLASS__, $sleep));

            sleep($sleep);
        }
        $this->start();
        $this->restartCounter = 0;
    }

    public function __sleep(): array
    {
        throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
    }

    /** * @return void */
    public function __wakeup()
    {
        throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
    }

    public function __destruct()
    {

  public function isValid($email, EmailValidation $email_validation = NULL) {
    if ($email_validation) {
      throw new \BadMethodCallException('Calling \Drupal\Component\Utility\EmailValidator::isValid() with the second argument is not supported. See https://www.drupal.org/node/2997196');
    }
    return parent::isValid($email(new RFCValidation()));
  }

}

    public static function fromShellCommandline(string $command, string $cwd = null, array $env = null, mixed $input = null, ?float $timeout = 60)static
    {
        $process = new static([]$cwd$env$input$timeout);
        $process->commandline = $command;

        return $process;
    }

    public function __sleep(): array
    {
        throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
    }

    public function __wakeup()
    {
        throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
    }

    public function __destruct()
    {
        if ($this->options['create_new_console'] ?? false) {
            $this->processPipes->close();
        }
$roles[] = $role;
        }

        return sprintf('%s(user="%s", roles="%s")', $class$this->getUserIdentifier()implode(', ', $roles));
    }

    /** * @internal */
    final public function serialize(): string
    {
        throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
    }

    /** * @internal */
    final public function unserialize(string $serialized): void
    {
        $this->__unserialize(unserialize($serialized));
    }
}

  public function __call($method, array $args) {
    // @todo consider using assert() as per https://www.drupal.org/node/2451793.     if (!isset($this->dateTimeObject)) {
      throw new \Exception('DateTime object not set.');
    }
    if (!method_exists($this->dateTimeObject, $method)) {
      throw new \BadMethodCallException(sprintf('Call to undefined method %s::%s()', static::class$method));
    }

    $result = call_user_func_array([$this->dateTimeObject, $method]$args);

    return $result === $this->dateTimeObject ? $this : $result;
  }

  /** * Returns the difference between two DateTimePlus objects. * * @param \Drupal\Component\Datetime\DateTimePlus|\DateTime $datetime2 * The date to compare to. * @param bool $absolute * Should the interval be forced to be positive? * * @return \DateInterval * A DateInterval object representing the difference between the two dates. * * @throws \BadMethodCallException * If the input isn't a DateTime or DateTimePlus object. */
// @deprecated remove condition in 7.0         if (!method_exists($this->normalizer, 'getSupportedTypes')) {
            return ['*' => $this->normalizer instanceof CacheableSupportsMethodInterface && $this->normalizer->hasCacheableSupportsMethod()];
        }

        return $this->normalizer->getSupportedTypes($format);
    }

    public function normalize(mixed $object, string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
    {
        if (!$this->normalizer instanceof NormalizerInterface) {
            throw new \BadMethodCallException(sprintf('The "%s()" method cannot be called as nested normalizer doesn\'t implements "%s".', __METHOD__, NormalizerInterface::class));
        }

        $startTime = microtime(true);
        $normalized = $this->normalizer->normalize($object$format$context);
        $time = microtime(true) - $startTime;

        if ($traceId = ($context[TraceableSerializer::DEBUG_TRACE_ID] ?? null)) {
            $this->dataCollector->collectNormalization($traceId$this->normalizer::class$time);
        }

        return $normalized;
    }

        return isset($this->children[$name]);
    }

    /** * Implements \ArrayAccess. * * @throws BadMethodCallException always as setting a child by name is not allowed */
    public function offsetSet(mixed $name, mixed $value): void
    {
        throw new BadMethodCallException('Not supported.');
    }

    /** * Removes a child (implements \ArrayAccess). * * @param int|string $name The child name */
    public function offsetUnset(mixed $name): void
    {
        unset($this->children[$name]);
    }

    
public function cleanLogs(): array
    {
        $logs = $this->logs;
        $this->logs = [];

        return $logs;
    }

    public function __sleep(): array
    {
        throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
    }

    public function __wakeup()
    {
        throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
    }

    public function __destruct()
    {
        foreach ($this->logs as [$level$message$context]) {
            if (str_contains($message, '{')) {
                


        $this->name = (string) $name;
        $this->dataClass = $dataClass;
        $this->dispatcher = $dispatcher;
        $this->options = $options;
    }

    public function addEventListener(string $eventName, callable $listener, int $priority = 0)static
    {
        if ($this->locked) {
            throw new BadMethodCallException('FormConfigBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.');
        }

        $this->dispatcher->addListener($eventName$listener$priority);

        return $this;
    }

    public function addEventSubscriber(EventSubscriberInterface $subscriber)static
    {
        if ($this->locked) {
            throw new BadMethodCallException('FormConfigBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.');
        }
public function __construct(HttpClientInterface $client, ResponseInterface $response, &$content, StopwatchEvent $event = null)
    {
        $this->client = $client;
        $this->response = $response;
        $this->content = &$content;
        $this->event = $event;
    }

    public function __sleep(): array
    {
        throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
    }

    public function __wakeup(): void
    {
        throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
    }

    public function __destruct()
    {
        try {
            if (method_exists($this->response, '__destruct')) {
                
/** * This method is intentionally not implemented. * * Use Drupal\Core\Url instead. * * @see https://www.drupal.org/node/2820197 * * @throws \BadMethodCallException */
  public function generate($name$parameters = []$referenceType = self::ABSOLUTE_PATH): string {
    throw new \BadMethodCallException(__METHOD__ . '() is not supported. Use the \Drupal\Core\Url object instead. See https://www.drupal.org/node/2820197');
  }

}

        return $this->__isset($key);
    }

    public function offsetGet(mixed $key): mixed
    {
        return $this->__get($key);
    }

    public function offsetSet(mixed $key, mixed $value): void
    {
        throw new \BadMethodCallException(self::class.' objects are immutable.');
    }

    public function offsetUnset(mixed $key): void
    {
        throw new \BadMethodCallException(self::class.' objects are immutable.');
    }

    public function __toString(): string
    {
        $value = $this->getValue();

        
class DummyTransport implements Transport\TransportInterface
{
    private string $host;

    public function __construct(string $host)
    {
        $this->host = $host;
    }

    public function send(RawMessage $message, Envelope $envelope = null): ?SentMessage
    {
        throw new \BadMethodCallException('This method newer should be called.');
    }

    public function __toString(): string
    {
        return 'dummy://local';
    }
}

class DummyTransportFactory implements Transport\TransportFactoryInterface
{
    public function create(Dsn $dsn): TransportInterface
    {
class TraceableEncoder implements EncoderInterface, DecoderInterface, SerializerAwareInterface
{
    public function __construct(
        private EncoderInterface|DecoderInterface $encoder,
        private SerializerDataCollector $dataCollector,
    ) {
    }

    public function encode(mixed $data, string $format, array $context = []): string
    {
        if (!$this->encoder instanceof EncoderInterface) {
            throw new \BadMethodCallException(sprintf('The "%s()" method cannot be called as nested encoder doesn\'t implements "%s".', __METHOD__, EncoderInterface::class));
        }

        $startTime = microtime(true);
        $encoded = $this->encoder->encode($data$format$context);
        $time = microtime(true) - $startTime;

        if ($traceId = ($context[TraceableSerializer::DEBUG_TRACE_ID] ?? null)) {
            $this->dataCollector->collectEncoding($traceId$this->encoder::class$time);
        }

        return $encoded;
    }

    public function __construct(
        private Key $key,
        private PersistingStoreInterface $store,
        private ?float $ttl = null,
        private bool $autoRelease = true,
    ) {
    }

    public function __sleep(): array
    {
        throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
    }

    public function __wakeup(): void
    {
        throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
    }

    /** * Automatically releases the underlying lock when the object is destructed. */
    public function __destruct()
    {
Home | Imprint | This part of the site doesn't use cookies.