PartialHTMLField   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 53
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A registerConfigKeys() 0 4 1
B getValue() 0 26 5
1
<?php namespace PascalKleindienst\FormListGenerator\Fields;
2
3
use PascalKleindienst\FormListGenerator\Support\Config;
4
5
/**
6
 * Field which loads a partial or some simple HTML Content
7
 * @package \PascalKleindienst\FormListGenerator\Fields
8
 */
9
class PartialHTMLField extends AbstractField
10
{
11
    /**
12
     * @var array Contains the subheading for the section field (optional)
13
     */
14
    public $comment;
15
16
    /**
17
     * @var string Contains the path to the partial
18
     */
19
    public $path;
20
21
    /**
22
     * {@inheritDoc}
23
     */
24 18
    protected function registerConfigKeys()
25
    {
26 18
        return [ 'comment', 'path' ];
27
    }
28
29
    /**
30
     * Load a partial or some simple HTML Content
31
     *
32
     * @param array $records
33
     * @return string|null
34
     */
35 6
    public function getValue(array $records = [])
36
    {
37 6
        $record  = $this->getRecord($records);
38
39
        // Display a section
40 6
        if ($this->type === 'section') {
41 3
            $content = '<h2>' . $this->label . '</h2>';
42
43 3
            if ($this->comment) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->comment of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
44 3
                $content .= '<p>' . $this->comment . '</p>';
45 3
            }
46
47 3
            return $content;
48
        } // Display a partial
49 3
        elseif ($this->type === 'partial') {
50
            // Replace ~ with root path
51 3
            $this->path = str_replace('~', Config::get('root'), $this->path);
52
53 3
            if (file_exists($this->path)) {
54 3
                $value = $record;
55 3
                include($this->path);
56 3
            }
57 3
        }
58
        
59 3
        return null;
60
    }
61
}
62