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

HtmlRaw   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 20
c 2
b 0
f 0
dl 0
loc 77
ccs 0
cts 36
cp 0
rs 10
wmc 9

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getComponentDetails() 0 7 1
A getValueDisplay() 0 6 2
A processAsFilter() 0 5 3
A getFilterField() 0 4 1
A fake() 0 3 1
A getValue() 0 3 1
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
}