Completed
Push — develop ( 2c1e6b...179509 )
by Peter
01:59
created

WebinoDraw/View/Strategy/AbstractDrawStrategy.php (2 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

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\Strategy;
12
13
use WebinoDraw\Service\DrawService;
14
use Zend\EventManager\EventManagerInterface;
15
use Zend\Http\PhpEnvironment\Response as PhpResponse;
16
use Zend\View\Model\ViewModel;
17
use Zend\View\Renderer\PhpRenderer;
18
use Zend\View\Strategy\PhpRendererStrategy;
19
use Zend\View\ViewEvent;
20
21
/**
22
 * Draw XHTML with this view strategy
23
 */
24
abstract class AbstractDrawStrategy extends PhpRendererStrategy
25
{
26
    /**
27
     * @var DrawService $draw
28
     */
29
    protected $draw;
30
31
    /**
32
     * @param DrawService $draw
33
     */
34
    public function __construct(DrawService $draw)
35
    {
36
        $this->draw = $draw;
37
    }
38
39
    /**
40
     * @param EventManagerInterface $events
41
     * @param int $priority
42
     */
43
    public function attach(EventManagerInterface $events, $priority = 1)
44
    {
45
        parent::attach($events, $priority - 100); // as last
46
    }
47
48
    /**
49
     * @param ViewEvent $event
50
     * @return bool
51
     */
52
    public function shouldRespond(ViewEvent $event)
53
    {
54
        /* @var $response PhpResponse */
55
        $response = $event->getResponse();
56
        if ($event->getRenderer() instanceof PhpRenderer
0 ignored issues
show
The class Zend\View\Renderer\PhpRenderer does not exist. Did you forget a USE statement, or did you not list all dependencies?

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 the composer.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 or require-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 ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
57
            && $response instanceof PhpResponse
0 ignored issues
show
The class Zend\Http\PhpEnvironment\Response does not exist. Did you forget a USE statement, or did you not list all dependencies?

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 the composer.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 or require-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 ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
58
            && trim($response->getBody())
59
        ) {
60
            return true;
61
        }
62
63
        return false;
64
    }
65
66
    /**
67
     * Collect all variables from the view model
68
     *
69
     * @param ViewModel $model
70
     * @return array
71
     */
72
    public function collectModelVariables(ViewModel $model)
73
    {
74
        $vars = (array) $model->getVariables();
75
        foreach ($model->getChildren() as $child) {
76
            $vars = array_replace($vars, $this->collectModelVariables($child));
77
        }
78
79
        return $vars;
80
    }
81
}
82