VirtualFieldIndexQueuedJob::triggerProcessing()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 15 and the first side effect is on line 12.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * If the queued jobs module is installed, this will be used instead of
4
 * updating vfi's in onBeforeWrite.
5
 *
6
 * @author  Mark Guinn <[email protected]>
7
 * @date    07.02.2015
8
 * @package shop_search
9
 * @subpackage helpers
10
 */
11
if (!interface_exists('QueuedJob')) {
12
    return;
13
}
14
15
class VirtualFieldIndexQueuedJob extends AbstractQueuedJob implements QueuedJob
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
16
{
17
    /**
18
     * The QueuedJob queue to use when processing updates
19
     * @config
20
     * @var int
21
     */
22
    private static $reindex_queue = 2; // QueuedJob::QUEUED;
0 ignored issues
show
Unused Code introduced by
The property $reindex_queue is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
23
24
25
    /**
26
     * @param DataObject $object
27
     * @param array $fields
28
     */
29
    public function __construct($object = null, $fields = array())
30
    {
31
        if ($object) {
32
            $this->setObject($object);
33
        }
34
        $this->rebuildFields = $fields;
35
    }
36
37
38
    /**
39
     * Helper method
40
     */
41
    public function triggerProcessing()
42
    {
43
        singleton('QueuedJobService')->queueJob($this);
44
    }
45
46
47
    /**
48
     * @return string
49
     */
50
    public function getTitle()
51
    {
52
        $obj = $this->getObject();
53
        return "Update Virtual Field Indexes: " . ($obj ? $obj->getTitle() : '???');
54
    }
55
56
57
    /**
58
     * Reprocess any needed fields
59
     */
60
    public function process()
61
    {
62
        Versioned::reading_stage('Stage');
63
        /** @var DataObject|VirtualFieldIndex $obj */
64
        $obj = $this->getObject();
65
66
        if ($obj) {
67
            $obj->rebuildVFI();
0 ignored issues
show
Bug introduced by
The method rebuildVFI does only exist in VirtualFieldIndex, but not in DataObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
68
        }
69
70
        $this->isComplete = true;
71
    }
72
}
73