Passed
Push — master ( 4f6024...8e5bf0 )
by Nicolaas
03:54
created

ObjectsUpdated   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 7
Bugs 0 Features 0
Metric Value
eloc 23
c 7
b 0
f 0
dl 0
loc 60
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getTitle() 0 7 2
A classes_edited() 0 7 2
1
<?php
2
3
namespace Sunnysideup\SimpleTemplateCaching\Model;
4
5
use SilverStripe\Core\Injector\Injector;
6
use SilverStripe\ORM\DataObject;
7
use SilverStripe\ORM\DB;
8
9
/**
10
 * A blog category for generalising blog posts.
11
 *
12
 * @property string $ClassNameLastEdited
13
 */
14
class ObjectsUpdated extends DataObject
15
{
16
17
    public static function classes_edited(): string
18
    {
19
        $query = DB::query('SELECT DISTINCT ClassNameLastEdited FROM ObjectsUpdated ORDER BY ClassNameLastEdited ASC');
20
        foreach ($query as $row) {
21
            $array[$row['ClassNameLastEdited']] = Injector::inst()->get($row['ClassNameLastEdited'])->i18n_singular_name();
22
        }
23
        return implode(', ', $array);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $array seems to be defined by a foreach iteration on line 20. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
24
    }
25
26
    /**
27
     * @var string
28
     */
29
    private static $table_name = 'ObjectsUpdated';
30
31
    /**
32
     * @var array
33
     */
34
    private static $db = [
35
        'ClassNameLastEdited' => 'Varchar(255)',
36
    ];
37
38
    private static $default_sort = [
39
        'ID' => 'DESC',
40
    ];
41
42
    /**
43
     * @var array
44
     */
45
    private static $summary_fields = [
46
        'Created' => 'Updated',
47
        'Title' => 'Record name    ',
48
        'LastEdited' => 'Last Edited',
49
    ];
50
51
    /**
52
     * @var array
53
     */
54
    private static $field_labels = [
55
        'Created' => 'Updated',
56
        'Title' => 'Human readable name',
57
        'LastEdited' => 'Code name',
58
    ];
59
60
    /**
61
     * @var array
62
     */
63
    private static $casting = [
64
        'Title' => 'Varchar',
65
    ];
66
67
    public function getTitle(): string
68
    {
69
        if (class_exists((string) $this->ClassNameLastEdited)) {
70
            return Injector::inst()->get($this->ClassNameLastEdited)->i18n_singular_name();
71
        }
72
73
        return 'ERROR: class not found';
74
    }
75
}
76