{"record":{"id":"294c34a8a3599d01","repo":"moodle/moodle","slug":"chart-renderer-must-implement","errorCode":null,"errorMessage":"Chart renderer must implement ","messagePattern":"Chart renderer must implement ","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"public/lib/phpspreadsheet/phpspreadsheet/src/PhpSpreadsheet/Settings.php","lineNumber":62,"sourceCode":"        return Calculation::getInstance()->setLocale($locale);\n    }\n\n    public static function getLocale(): string\n    {\n        return Calculation::getInstance()->getLocale();\n    }\n\n    /**\n     * Identify to PhpSpreadsheet the external library to use for rendering charts.\n     *\n     * @param class-string<IRenderer> $rendererClassName Class name of the chart renderer\n     *    eg: PhpOffice\\PhpSpreadsheet\\Chart\\Renderer\\JpGraph\n     */\n    public static function setChartRenderer(string $rendererClassName): void\n    {\n        // We want phpstan to validate caller, but still need this test\n        if (!is_a($rendererClassName, IRenderer::class, true)) { //* @phpstan-ignore-line\n            throw new Exception('Chart renderer must implement ' . IRenderer::class);\n        }\n\n        self::$chartRenderer = $rendererClassName;\n    }\n\n    public static function unsetChartRenderer(): void\n    {\n        self::$chartRenderer = null;\n    }\n\n    /**\n     * Return the Chart Rendering Library that PhpSpreadsheet is currently configured to use.\n     *\n     * @return null|class-string<IRenderer> Class name of the chart renderer\n     *    eg: PhpOffice\\PhpSpreadsheet\\Chart\\Renderer\\JpGraph\n     */\n    public static function getChartRenderer(): ?string\n    {","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/moodle/moodle/blob/48ea8c33227277e916cdd4079dbecef448b37f2c/public/lib/phpspreadsheet/phpspreadsheet/src/PhpSpreadsheet/Settings.php#L44-L80","documentation":"Thrown by Settings::setChartRenderer() when the supplied class name does not implement the IRenderer interface. The method's contract (@param class-string<IRenderer>) is checked at runtime because PHP cannot enforce it natively; passing any fully-qualified class name that is not a valid chart renderer (typically anything other than PhpOffice\\PhpSpreadsheet\\Chart\\Renderer\\JpGraph or a custom implementation of IRenderer) triggers it. The truncated message in the source continues with the expected interface name.","triggerScenarios":"Calling Settings::setChartRenderer('Some\\Class') where the class exists but doesn't implement IRenderer, or where the string is a typo/nonexistent class (is_a with a missing class returns false).","commonSituations":"Configuring JpGraph or Graphs renderer with a mistyped namespace; switching to a custom renderer that doesn't implement IRenderer; copy-pasted config from an older PhpSpreadsheet version with renamed renderer classes.","solutions":["Pass a class implementing PhpOffice\\PhpSpreadsheet\\Chart\\Renderer\\IRenderer, e.g. \\PhpOffice\\PhpSpreadsheet\\Chart\\Renderer\\JpGraph or ...\\Renderer\\LibreOffice","Verify with class_exists() and is_a($cls, IRenderer::class, true) before calling","Check the class's fully-qualified namespace against your installed package version","Write a custom renderer implementing IRenderer if you need a different backend"],"exampleFix":"// before\nSettings::setChartRenderer('JpGraph'); // not FQCN / wrong interface\n// after\nif (is_a(\\PhpOffice\\PhpSpreadsheet\\Chart\\Renderer\\JpGraph::class, IRenderer::class, true)) {\n    Settings::setChartRenderer(\\PhpOffice\\PhpSpreadsheet\\Chart\\Renderer\\JpGraph::class);\n}","handlingStrategy":"validation","validationCode":"$cls = '\\\\PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\Renderer\\\\JpGraph';\nif (!class_exists($cls) || !is_a($cls, IRenderer::class, true)) {\n    throw new InvalidArgumentException('$cls must implement IRenderer');\n}\nSettings::setChartRenderer($cls);","typeGuard":"function isValidRenderer(string $cls): bool {\n    return class_exists($cls) && is_a($cls, \\PhpOffice\\PhpSpreadsheet\\Chart\\Renderer\\IRenderer::class, true);\n}","tryCatchPattern":"try {\n    Settings::setChartRenderer($config['chartRenderer']);\n} catch (\\PhpOffice\\PhpSpreadsheet\\Exception $e) {\n    // fall back to default renderer or log config error\n}","preventionTips":["Store the fully-qualified class name in config, not a short name","Unit-test chart renderer configuration at boot","Verify renderer class names when upgrading PhpSpreadsheet versions"],"tags":["phpspreadsheet","charts","configuration"],"backgroundTag":"invalid-config-value","analyzedSha":"48ea8c33227277e916cdd4079dbecef448b37f2c","analyzedAt":"2026-09-14T20:34:48.527Z","contentChangedAt":"2026-09-14T20:34:48.527Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}