Passed
Push — main ( 14fda3...e38e76 )
by Jean-Christophe
03:07
created

UVueManager::renderView()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 7
c 1
b 0
f 1
nc 3
nop 3
dl 0
loc 9
ccs 0
cts 8
cp 0
crap 12
rs 10
1
<?php
2
3
4
namespace PHPMV\php\ubiquity;
5
6
7
use PHPMV\VueManager;
8
9
class UVueManager extends VueManager {
10
	public static function start(array &$config):UVueManager{
11
		$instance=self::getInstance();
12
		$instance->config=$config['vuejs']??['delimiters'=>['${','}']];
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return PHPMV\php\ubiquity\UVueManager. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
13
	}
14
	/**
15
	 * Performs Javascript compilation and displays a view
16
	 *
17
	 * @param string $viewName
18
	 * @param mixed $parameters
19
	 *            Variable or associative array to pass to the view <br> If a variable is passed, it will have the name <b> $ data </ b> in the view, <br>
20
	 *            If an associative array is passed, the view retrieves variables from the table's key names
21
	 * @param boolean $asString
22
	 *            If true, the view is not displayed but returned as a string (usable in a variable)
23
	 * @return string|null
24
	 * @throws \Exception
25
	 */
26
	public function renderView($viewName, $parameters = [], $asString = false): ?string {
27
		if (isset($this->container)) {
28
			$view = $this->container->getView();
1 ignored issue
show
Bug introduced by
The method getView() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

28
			/** @scrutinizer ignore-call */ 
29
   $view = $this->container->getView();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
29
			$parameters['script_foot']=$this->getInstance()->__toString();
30
			if (isset($parameters))
31
				$view->setVars($parameters);
32
			return $view->render($viewName, $asString);
33
		}
34
		throw new \Exception(get_class() . " instance is not properly instancied : you omitted the second parameter \$controller!");
35
	}
36
37
	/**
38
	 * Performs javascript compilation and displays the default view
39
	 *
40
	 * @param mixed $parameters
41
	 *            Variable or associative array to pass to the view <br> If a variable is passed, it will have the name <b> $ data </ b> in the view, <br>
42
	 *            If an associative array is passed, the view retrieves variables from the table's key names
43
	 * @param boolean $asString
44
	 *            If true, the view is not displayed but returned as a string (usable in a variable)
45
	 * @return string|null
46
	 * @throws \Exception
47
	 */
48
	public function renderDefaultView($parameters = [], $asString = false):?string {
49
		return $this->renderView($this->container->getDefaultViewName(), $parameters, $asString);
50
	}
51
52
}