FileVersionCreationTask   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 3
dl 0
loc 51
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getTitle() 0 7 1
A getDescription() 0 7 1
A run() 0 29 5
1
<?php
2
/**
3
 * Creates initial version records for File objects that do not have any
4
 * versioning information. This should be run when the module is first installed
5
 * in order to bootstrap the version history.
6
 *
7
 * @package silverstripe-versionedfiles
8
 */
9
class FileVersionCreationTask extends BuildTask
10
{
11
    public function getTitle()
12
    {
13
        return _t(
14
            'FileVersionCreationTask.Title',
15
            'File Version Creation Task'
16
        );
17
    }
18
19
    public function getDescription()
20
    {
21
        return _t(
22
            'FileVersionCreationTask.Desc',
23
            'Creates version records for files that do not have one.'
24
        );
25
    }
26
27
    /**
28
     * @param HTTPRequest $request
29
     */
30
    public function run($request)
31
    {
32
        $versionless = File::get()->leftJoin(
33
            'FileVersion',
34
            '"FileVersion"."FileID" = "File"."ID"'
35
        )->where('"File"."ClassName" <> \'Folder\' AND "FileVersion"."FileID" IS NULL');
36
        $createdVersions = 0;
37
38
        if ($versionless) {
39
            foreach ($versionless as $file) {
40
                if ($file->createVersion()) {
41
                    ++$createdVersions;
42
                }
43
            }
44
        }
45
46
        if ($createdVersions) {
47
            echo _t(
48
                'FileVersionCreationTask.Created',
49
                "Created {count} file version records.",
50
                array('count' => $createdVersions)
0 ignored issues
show
Documentation introduced by
array('count' => $createdVersions) is of type array<string,integer,{"count":"integer"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
51
            );
52
        } else {
53
            echo _t(
54
                'FileVersionCreationTask.NoCreated',
55
                'No file version records created.'
56
            );
57
        }
58
    }
59
}
60