These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * Webino (http://webino.sk) |
||
4 | * |
||
5 | * @link https://github.com/webino/WebinoDraw for the canonical source repository |
||
6 | * @copyright Copyright (c) 2012-2017 Webino, s. r. o. (http://webino.sk) |
||
7 | * @author Peter Bačinský <[email protected]> |
||
8 | * @license BSD-3-Clause |
||
9 | */ |
||
10 | |||
11 | namespace WebinoDraw\View\Renderer; |
||
12 | |||
13 | use WebinoDraw\Exception\InvalidArgumentException; |
||
14 | use WebinoDraw\Service\DrawService; |
||
15 | use Zend\View\Model\ViewModel; |
||
16 | use Zend\View\Renderer\RendererInterface; |
||
17 | use Zend\View\Resolver\ResolverInterface; |
||
18 | |||
19 | /** |
||
20 | * |
||
21 | */ |
||
22 | class DrawRenderer implements RendererInterface |
||
23 | { |
||
24 | /** |
||
25 | * @var DrawService |
||
26 | */ |
||
27 | protected $draw; |
||
28 | |||
29 | /** |
||
30 | * @var RendererInterface |
||
31 | */ |
||
32 | protected $renderer; |
||
33 | |||
34 | /** |
||
35 | * @param DrawService|object $draw |
||
36 | * @param RendererInterface|object $renderer |
||
37 | */ |
||
38 | public function __construct(DrawService $draw, RendererInterface $renderer) |
||
39 | { |
||
40 | $this->draw = $draw; |
||
41 | $this->renderer = $renderer; |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * @return mixed |
||
46 | */ |
||
47 | public function getEngine() |
||
48 | { |
||
49 | return $this->renderer->getEngine(); |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * @param ResolverInterface $resolver |
||
54 | * @return RendererInterface |
||
55 | */ |
||
56 | public function setResolver(ResolverInterface $resolver) |
||
57 | { |
||
58 | return $this->renderer->setResolver($resolver); |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * Render & draw the template |
||
63 | * |
||
64 | * @param string|ViewModel $nameOrModel The script/resource process, or a view model |
||
65 | * @param null|array|\ArrayAccess $values Values to use during rendering |
||
66 | * @return string The script output |
||
67 | */ |
||
68 | public function render($nameOrModel, $values = null) |
||
69 | { |
||
70 | $isModel = $nameOrModel instanceof ViewModel; |
||
0 ignored issues
–
show
|
|||
71 | if (!is_string($nameOrModel) && !$isModel) { |
||
72 | throw new InvalidArgumentException('Expected string|ViewModel'); |
||
73 | } |
||
74 | |||
75 | $template = $this->renderer->render($nameOrModel, $values); |
||
76 | $instructions = clone $this->draw->getInstructions(); |
||
77 | $instructions->exchangeArray([]); |
||
78 | |||
79 | if ($isModel) { |
||
80 | // merge draw instructions |
||
81 | foreach ((array) $nameOrModel->getOption('instructions') as $iOptions) { |
||
82 | $instructions->merge($iOptions); |
||
83 | } |
||
84 | } |
||
85 | |||
86 | $modelVars = $isModel ? (array) $nameOrModel->getVariables() : []; |
||
87 | $variables = array_merge($modelVars, (array) $values); |
||
88 | |||
89 | return $this->draw->draw( |
||
90 | $template, |
||
91 | $instructions, |
||
92 | $variables, |
||
93 | $isModel ? (bool) $nameOrModel->getOption('isXml') : false |
||
94 | ); |
||
95 | } |
||
96 | } |
||
97 |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.