Completed
Pull Request — master (#605)
by Tortue
02:06
created

Plaintext::escapeValue()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 3
nc 4
nop 0
1
<?php
2
namespace Former\Form\Fields;
3
4
use Former\Traits\Field;
5
use Illuminate\Support\HtmlString;
6
7
/**
8
 * Renders Plain Text Control
9
 */
10
class Plaintext extends Field
11
{
12
	////////////////////////////////////////////////////////////////////
13
	/////////////////////////// CORE METHODS ///////////////////////////
14
	////////////////////////////////////////////////////////////////////
15
16
	/**
17
	 * Prints out the current tag
18
	 *
19
	 * @return string A plain text tag
20
	 */
21
	public function render()
22
	{
23
		$this->addClass($this->app['former.framework']->getPlainTextClasses());
24
		$this->setId();
25
		$this->escapeValue();
26
27
		return $this->app['former.framework']->createPlainTextField($this);
28
	}
29
30
	protected function escapeValue()
31
	{
32
		$valueToEscape = $this->getValue();
33
		$value = is_string($valueToEscape) || $valueToEscape instanceof HtmlString ? e($valueToEscape) : $valueToEscape;
34
35
		return $this->forceValue($value);
0 ignored issues
show
Bug introduced by
It seems like $value defined by is_string($valueToEscape...scape) : $valueToEscape on line 33 can also be of type null or object<HtmlObject\Traits\Tag>; however, Former\Traits\Field::forceValue() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
36
	}
37
}
38