CoreFiles by mySites.guru
NoCandidateFoundException.php34 lines, 1,155 bytes, from wordpress-7.0.zip
Raw History Compare with 6.9.12
md5
5c53df5f3a80b81a45349c8d4aacbf14
sha1
a44cfe554da9fd45218974f8d4a10c4c3d061888
sha256
e5b69225cd35fa27839c7a23dc3b20b418574666f69eb9e5f722991c627ef733
<?php

namespace WordPress\AiClientDependencies\Http\Discovery\Exception;

use WordPress\AiClientDependencies\Http\Discovery\Exception;
/**
 * When we have used a strategy but no candidates provided by that strategy could be used.
 *
 * @author Tobias Nyholm <[email protected]>
 */
final class NoCandidateFoundException extends \Exception implements Exception
{
    /**
     * @param string $strategy
     */
    public function __construct($strategy, array $candidates)
    {
        $classes = array_map(function ($a) {
            return $a['class'];
        }, $candidates);
        $message = sprintf('No valid candidate found using strategy "%s". We tested the following candidates: %s.', $strategy, implode(', ', array_map([$this, 'stringify'], $classes)));
        parent::__construct($message);
    }
    private function stringify($mixed)
    {
        if (is_string($mixed)) {
            return $mixed;
        }
        if (is_array($mixed) && 2 === count($mixed)) {
            return sprintf('%s::%s', $this->stringify($mixed[0]), $mixed[1]);
        }
        return is_object($mixed) ? get_class($mixed) : gettype($mixed);
    }
}

The same content is in 44 releases, WordPress 7.0-beta1 to 7.2-RC2. See them all, or every version of this file.