DataClassTaskView   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 32
dl 0
loc 68
ccs 30
cts 30
cp 1
rs 10
c 0
b 0
f 0
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A renderHr() 0 9 2
A renderHeader() 0 12 2
A renderMessage() 0 13 2
A renderSource() 0 12 2
1
<?php
2
3
namespace CSoellinger\SilverStripe\ModelAnnotations\View;
4
5
use SilverStripe\Control\Director;
6
use SilverStripe\Core\Injector\Injectable;
7
8
/**
9
 * Print out task messages for a data class.
10
 */
11
class DataClassTaskView
12
{
13
    use Injectable;
14
15
    /**
16
     * Data class header output.
17
     */
18 2
    public function renderHeader(string $fqn, string $filename): self
19
    {
20 2
        if (Director::is_cli() === true) {
21 1
            echo $fqn . PHP_EOL;
22 1
            echo 'File: ' . $filename . PHP_EOL . PHP_EOL;
23
        } else {
24 1
            echo '<div class="info">';
25 1
            echo '  <h3 style="margin-bottom: 0;">' . $fqn . '</h3>';
26 1
            echo '</div>';
27
        }
28
29 2
        return $this;
30
    }
31
32
    /**
33
     * Simple message output.
34
     */
35 2
    public function renderMessage(string $message, string $stateClass = 'success'): self
36
    {
37 2
        if (Director::is_cli() === true) {
38 1
            echo $message . PHP_EOL . PHP_EOL;
39
        } else {
40 1
            echo '<div class="build" style="padding-bottom: 0;">';
41 1
            echo '  <div class="' . $stateClass . '" style="font-weight: 600;">';
42 1
            echo $message;
43 1
            echo '  </div>';
44 1
            echo '</div>';
45
        }
46
47 2
        return $this;
48
    }
49
50
    /**
51
     * Source code output.
52
     */
53 2
    public function renderSource(string $filepath, string $source): self
54
    {
55 2
        if (Director::is_cli() === true) {
56 1
            echo $source . PHP_EOL . PHP_EOL;
57
        } else {
58 1
            echo '<div class="info">';
59 1
            echo '  <small>' . $filepath . '</small>';
60 1
            echo '  <pre><code>' . htmlentities($source) . '</code></pre>';
61 1
            echo '</div><div>&nbsp;</div>';
62
        }
63
64 2
        return $this;
65
    }
66
67
    /**
68
     * Hr line
69
     */
70 2
    public function renderHr(): self
71
    {
72 2
        if (Director::is_cli() === true) {
73 1
            echo '--- --- --- --- --- --- --- ---' . PHP_EOL . PHP_EOL;
74
        } else {
75 1
            echo '<div class="info" style="padding: 0;"><hr /></div>';
76
        }
77
78 2
        return $this;
79
    }
80
}
81