Passed
Push — develop ( 319bd8...330c7a )
by Neill
16:41 queued 15s
created

HtmlRaw::getValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php
2
/**
3
 * @link http://www.newicon.net/neon
4
 * @copyright Copyright (c) 2016 Newicon Ltd
5
 * @license http://www.newicon.net/neon/license
6
 */
7
8
namespace neon\core\form\fields;
9
10
use neon\core\grid\query\IQuery;
11
12
/**
13
 * Class Text
14
 * @package neon\core\form
15
 */
16
class HtmlRaw extends TextArea
17
{
18
	const TEXT_TRUNCATE_LENGTH=250;
19
20
	/**
21
	 * Set some allowable tags for single text fields
22
	 * @var string
23
	 */
24
	protected $allowableTags = "<br><em><i><u><b><s><mark><strong>";
25
26
	/**
27
	 * The DDS data type to store the value of the field
28
	 * text data type can be up to 20000 characters long
29
	 * @var string
30
	 */
31
	public $ddsDataType = 'text';
32
33
	/**
34
	 * @inheritdoc
35
	 */
36
	public function getValueDisplay($context='')
37
	{
38
		$text = parent::getValueDisplay();
39
		if (strlen($text) > self::TEXT_TRUNCATE_LENGTH)
40
			return substr($text, 0, self::TEXT_TRUNCATE_LENGTH).'...';
41
		return $text;
42
	}
43
44
	/**
45
	 * @inheritdoc
46
	 */
47
	public function getFilterField()
48
	{
49
		return [
50
			'class' => 'text'
51
		];
52
	}
53
54
	/**
55
	 * @inheritdoc
56
	 */
57
	public function processAsFilter(IQuery $query, $searchData=null)
58
	{
59
		$searchData = ($searchData === null) ? $this->getValue() : $searchData;
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->getValue() targeting neon\core\form\fields\HtmlRaw::getValue() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
60
		if ($searchData !== '') {
61
			$query->where($this->getDataKey(), 'like', $searchData);
62
		}
63
	}
64
65
	/**
66
	 * @inheritdoc
67
	 */
68
	public function fake()
69
	{
70
		return faker()->realText(mt_rand(10, 20000));
71
	}
72
73
	/**
74
	 * @inheritdoc
75
	 */
76
	public function getComponentDetails()
77
	{
78
		return [
79
			'icon' => 'fa fa-paragraph',
80
			'group' => 'Formatted Text',
81
			'order' => 210,
82
			'label' => 'Raw Html',
83
		];
84
	}
85
86
	/**
87
	 * Because this is using raw html, we need to work with the unsanitised value
88
	 * @inheritdoc
89
	 */
90
	public function getValue()
91
	{
92
		return parent::getUnsafeValue();
0 ignored issues
show
Bug introduced by
Are you sure the usage of parent::getUnsafeValue() targeting neon\core\form\fields\Field::getUnsafeValue() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
93
	}
94
95
}