Completed
Pull Request — master (#37)
by
unknown
02:19
created

PackageSecurityExtension::updateBadges()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace BringYourOwnIdeas\SecurityChecker\Extensions;
4
5
use BringYourOwnIdeas\SecurityChecker\Models\SecurityAlert;
6
use SilverStripe\View\ArrayData;
7
use SilverStripe\ORM\DataExtension;
8
9
class PackageSecurityExtension extends DataExtension
10
{
11
    private static $has_many = [
0 ignored issues
show
introduced by
The private property $has_many is not used, and could be removed.
Loading history...
12
        'SecurityAlerts' => SecurityAlert::class
13
    ];
14
15
    private static $summary_fields = [
0 ignored issues
show
introduced by
The private property $summary_fields is not used, and could be removed.
Loading history...
16
        'listSecurityAlertIdentifiers' => 'Security alerts',
17
    ];
18
19
    /**
20
     * Simply returns a comma separated list of active SecurityAlert Identifiers for this record.
21
     * Used in CSV exports as a type of brief indication (as opposed to full info)
22
     */
23
    public function listSecurityAlertIdentifiers()
24
    {
25
        $alerts = $this->owner->SecurityAlerts()->Column('Identifier');
26
        return $alerts ? implode(', ', $alerts) : null;
27
    }
28
29
    /**
30
     * Renders the SecurityAlerts relationship
31
     * intended for use in the on screen version of the SiteSummary Report.
32
     */
33
    public function listAlerts()
34
    {
35
        $templates = ['PackageSecurityAlerts'];
36
        $this->owner->extend('updateListAlerts', $templates);
37
        return $this->owner->renderWith($templates);
38
    }
39
40
    /**
41
     * updates the badges that render as part of the screen targeted
42
     * summary for this Package
43
     *
44
     * @param ArrayList $badges
0 ignored issues
show
Bug introduced by
The type BringYourOwnIdeas\Securi...er\Extensions\ArrayList was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
45
     */
46
    public function updateBadges(&$badges)
47
    {
48
        if ($this->owner->SecurityAlerts()->exists()) {
49
            $badges->push(ArrayData::create([
50
                'Title' => _t(__CLASS__ . '.BADGE_SECURITY', 'RISK: Security'),
51
                'Type' => 'warning security-alerts__toggler',
52
            ]));
53
        }
54
    }
55
56
    /**
57
     * Appends our own summary info to that of the default output
58
     * of the Package getSummary method.
59
     *
60
     * @param HTMLText $summary
0 ignored issues
show
Bug introduced by
The type BringYourOwnIdeas\Securi...ker\Extensions\HTMLText was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
61
     */
62
    public function updateSummary(&$summary)
63
    {
64
        $summary->setValue($summary . $this->listAlerts());
65
    }
66
}
67